@poe-platform/safe-js 0.1.122 → 0.1.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/safe-js/chunks/{chunk-OZTC4BT3.js → chunk-DHD453E5.js} +278 -290
- package/dist/safe-js/chunks/chunk-DHD453E5.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-MQSVO6I2.js → chunk-WKRFMSJA.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-OZTC4BT3.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-MQSVO6I2.js.map → chunk-WKRFMSJA.js.map} +0 -0
|
@@ -8576,7 +8576,8 @@ async function callRegexMethod(target, methodName, args, budget, context) {
|
|
|
8576
8576
|
}
|
|
8577
8577
|
const retained = {};
|
|
8578
8578
|
let cursor;
|
|
8579
|
-
|
|
8579
|
+
let convertedInput;
|
|
8580
|
+
budget.setRetainedValues(retained, () => [target, ...args, cursor, convertedInput]);
|
|
8580
8581
|
try {
|
|
8581
8582
|
const input = await sandboxString(args[0], budget, context);
|
|
8582
8583
|
if (methodName === "test") {
|
|
@@ -8590,6 +8591,7 @@ async function callRegexMethod(target, methodName, args, budget, context) {
|
|
|
8590
8591
|
}
|
|
8591
8592
|
}
|
|
8592
8593
|
if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
|
|
8594
|
+
if (typeof args[0] !== "string") convertedInput = input;
|
|
8593
8595
|
cursor = target.lastIndex;
|
|
8594
8596
|
const lastIndex = await sandboxNumber(cursor, budget, context);
|
|
8595
8597
|
const match = executeRegex(target, input, lastIndex);
|
|
@@ -23878,6 +23880,44 @@ function hoistVarDeclarations(node, scope) {
|
|
|
23878
23880
|
}
|
|
23879
23881
|
}
|
|
23880
23882
|
|
|
23883
|
+
// packages/safe-js/src/interp/resources.ts
|
|
23884
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
23885
|
+
var runResources = new AsyncLocalStorage5();
|
|
23886
|
+
async function withRunResources(signal, execute) {
|
|
23887
|
+
const controller = new AbortController();
|
|
23888
|
+
const cancel = () => controller.abort(signal?.reason);
|
|
23889
|
+
const cleanups = /* @__PURE__ */ new Set();
|
|
23890
|
+
const resources = {
|
|
23891
|
+
signal: controller.signal,
|
|
23892
|
+
referenceReleases: /* @__PURE__ */ new Set(),
|
|
23893
|
+
add(close) {
|
|
23894
|
+
cleanups.add(close);
|
|
23895
|
+
}
|
|
23896
|
+
};
|
|
23897
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
23898
|
+
if (signal?.aborted) cancel();
|
|
23899
|
+
let result;
|
|
23900
|
+
let failure;
|
|
23901
|
+
let errors = [];
|
|
23902
|
+
try {
|
|
23903
|
+
result = await runResources.run(resources, execute);
|
|
23904
|
+
} catch (error) {
|
|
23905
|
+
failure = { reason: error };
|
|
23906
|
+
} finally {
|
|
23907
|
+
signal?.removeEventListener("abort", cancel);
|
|
23908
|
+
controller.abort(new Error("SafeJS run finished."));
|
|
23909
|
+
for (const release of resources.referenceReleases) release();
|
|
23910
|
+
resources.referenceReleases.clear();
|
|
23911
|
+
const outcomes = await Promise.allSettled(
|
|
23912
|
+
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
23913
|
+
);
|
|
23914
|
+
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
23915
|
+
}
|
|
23916
|
+
if (failure !== void 0) throw failure.reason;
|
|
23917
|
+
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
23918
|
+
return result;
|
|
23919
|
+
}
|
|
23920
|
+
|
|
23881
23921
|
// packages/safe-js/src/interp/methods/array.ts
|
|
23882
23922
|
var arrayLikeSources = /* @__PURE__ */ new WeakMap();
|
|
23883
23923
|
var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
|
|
@@ -25219,7 +25259,7 @@ async function replaceRegex(value, regex, replacement, replaceAll, budget, callC
|
|
|
25219
25259
|
if (regex.flags.includes("g")) regex.lastIndex = 0;
|
|
25220
25260
|
const cursor = regex.lastIndex;
|
|
25221
25261
|
const retained = {};
|
|
25222
|
-
budget.setRetainedValues(retained, () => [regex, cursor, replacement]);
|
|
25262
|
+
budget.setRetainedValues(retained, () => [value, regex, cursor, replacement]);
|
|
25223
25263
|
try {
|
|
25224
25264
|
const lastIndex = await sandboxNumber(cursor, budget, context);
|
|
25225
25265
|
const matches = collectRegexMatches(regex, value, replaceAll || regex.flags.includes("g"), void 0, lastIndex);
|
|
@@ -25352,7 +25392,7 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
|
|
|
25352
25392
|
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
25353
25393
|
const compilation = new CompileScope(operation.owner);
|
|
25354
25394
|
const retainedPattern = {};
|
|
25355
|
-
budget.setRetainedValues(retainedPattern, () => [pattern]);
|
|
25395
|
+
budget.setRetainedValues(retainedPattern, () => [value, pattern]);
|
|
25356
25396
|
try {
|
|
25357
25397
|
const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
|
|
25358
25398
|
const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
|
|
@@ -25368,7 +25408,7 @@ async function callStringRegexCursor(value, methodName, regex, budget, parent, c
|
|
|
25368
25408
|
const compilation = new CompileScope(operation.owner);
|
|
25369
25409
|
const cursor = regex.lastIndex;
|
|
25370
25410
|
const retained = {};
|
|
25371
|
-
budget.setRetainedValues(retained, () => [regex, cursor]);
|
|
25411
|
+
budget.setRetainedValues(retained, () => [value, regex, cursor]);
|
|
25372
25412
|
try {
|
|
25373
25413
|
const lastIndex = await sandboxNumber(cursor, budget, context);
|
|
25374
25414
|
return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex);
|
|
@@ -26814,61 +26854,56 @@ async function evaluateMemberAssignmentExpression(node, context) {
|
|
|
26814
26854
|
if (node.left.type !== "MemberExpression") {
|
|
26815
26855
|
throw new TypeError("Expected member assignment target.");
|
|
26816
26856
|
}
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
|
|
26826
|
-
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26857
|
+
return evaluateMemberAccess(node.left, context, async (member) => {
|
|
26858
|
+
if (member.kind === "nullish") {
|
|
26859
|
+
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26860
|
+
}
|
|
26861
|
+
let property;
|
|
26862
|
+
let current = void 0;
|
|
26863
|
+
if (node.operator !== "=") {
|
|
26864
|
+
if (member.object === null || member.object === void 0) {
|
|
26865
|
+
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26866
|
+
}
|
|
26867
|
+
property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
26868
|
+
current = getPropertyValue(member.object, property, context);
|
|
26869
|
+
}
|
|
26870
|
+
if (node.operator === "&&=" && !isTruthy(current)) {
|
|
26871
|
+
return {
|
|
26872
|
+
kind: "normal",
|
|
26873
|
+
hasValue: true,
|
|
26874
|
+
value: current
|
|
26875
|
+
};
|
|
26876
|
+
}
|
|
26877
|
+
if (node.operator === "||=" && isTruthy(current)) {
|
|
26878
|
+
return {
|
|
26879
|
+
kind: "normal",
|
|
26880
|
+
hasValue: true,
|
|
26881
|
+
value: current
|
|
26882
|
+
};
|
|
26883
|
+
}
|
|
26884
|
+
if (node.operator === "??=" && current !== null && current !== void 0) {
|
|
26885
|
+
return {
|
|
26886
|
+
kind: "normal",
|
|
26887
|
+
hasValue: true,
|
|
26888
|
+
value: current
|
|
26889
|
+
};
|
|
26890
|
+
}
|
|
26891
|
+
const right = await evaluateNode(node.right, context);
|
|
26892
|
+
if (right.kind !== "normal") {
|
|
26893
|
+
return right;
|
|
26894
|
+
}
|
|
26895
|
+
const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
|
|
26830
26896
|
if (member.object === null || member.object === void 0) {
|
|
26831
26897
|
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26832
26898
|
}
|
|
26833
|
-
property
|
|
26834
|
-
|
|
26835
|
-
}
|
|
26836
|
-
if (node.operator === "&&=" && !isTruthy(current)) {
|
|
26837
|
-
return {
|
|
26838
|
-
kind: "normal",
|
|
26839
|
-
hasValue: true,
|
|
26840
|
-
value: current
|
|
26841
|
-
};
|
|
26842
|
-
}
|
|
26843
|
-
if (node.operator === "||=" && isTruthy(current)) {
|
|
26899
|
+
property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
26900
|
+
setSandboxProperty(member.object, property, value, context.budget);
|
|
26844
26901
|
return {
|
|
26845
26902
|
kind: "normal",
|
|
26846
26903
|
hasValue: true,
|
|
26847
|
-
value
|
|
26848
|
-
};
|
|
26849
|
-
}
|
|
26850
|
-
if (node.operator === "??=" && current !== null && current !== void 0) {
|
|
26851
|
-
return {
|
|
26852
|
-
kind: "normal",
|
|
26853
|
-
hasValue: true,
|
|
26854
|
-
value: current
|
|
26904
|
+
value
|
|
26855
26905
|
};
|
|
26856
|
-
}
|
|
26857
|
-
const right = await evaluateNode(node.right, context);
|
|
26858
|
-
if (right.kind !== "normal") {
|
|
26859
|
-
return right;
|
|
26860
|
-
}
|
|
26861
|
-
const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
|
|
26862
|
-
if (member.object === null || member.object === void 0) {
|
|
26863
|
-
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26864
|
-
}
|
|
26865
|
-
property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
26866
|
-
setSandboxProperty(member.object, property, value, context.budget);
|
|
26867
|
-
return {
|
|
26868
|
-
kind: "normal",
|
|
26869
|
-
hasValue: true,
|
|
26870
|
-
value
|
|
26871
|
-
};
|
|
26906
|
+
});
|
|
26872
26907
|
}
|
|
26873
26908
|
async function evaluateLogicalExpression(node, context) {
|
|
26874
26909
|
const left = await evaluateNode(node.left, context);
|
|
@@ -27847,33 +27882,28 @@ async function evaluateDeleteExpression(node, context) {
|
|
|
27847
27882
|
"Unary operator 'delete' requires a member target."
|
|
27848
27883
|
);
|
|
27849
27884
|
}
|
|
27850
|
-
|
|
27851
|
-
|
|
27852
|
-
|
|
27853
|
-
|
|
27854
|
-
|
|
27855
|
-
|
|
27856
|
-
|
|
27857
|
-
|
|
27858
|
-
|
|
27859
|
-
|
|
27860
|
-
kind: "normal",
|
|
27861
|
-
hasValue: true,
|
|
27862
|
-
value: true
|
|
27863
|
-
};
|
|
27885
|
+
return evaluateMemberAccess(node.argument, context, async (member) => {
|
|
27886
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27887
|
+
if (member.kind === "nullish") {
|
|
27888
|
+
return {
|
|
27889
|
+
kind: "normal",
|
|
27890
|
+
hasValue: true,
|
|
27891
|
+
value: true
|
|
27892
|
+
};
|
|
27893
|
+
}
|
|
27894
|
+
throw new TypeError("Cannot delete properties of null or undefined.");
|
|
27864
27895
|
}
|
|
27865
|
-
|
|
27866
|
-
|
|
27867
|
-
|
|
27868
|
-
|
|
27869
|
-
|
|
27870
|
-
|
|
27871
|
-
|
|
27872
|
-
|
|
27873
|
-
|
|
27874
|
-
|
|
27875
|
-
|
|
27876
|
-
};
|
|
27896
|
+
if (!isIndexableSandboxValue(member.object)) {
|
|
27897
|
+
throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
|
|
27898
|
+
}
|
|
27899
|
+
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
27900
|
+
const deleted = deleteSandboxProperty(member.object, property);
|
|
27901
|
+
return {
|
|
27902
|
+
kind: "normal",
|
|
27903
|
+
hasValue: true,
|
|
27904
|
+
value: deleted
|
|
27905
|
+
};
|
|
27906
|
+
});
|
|
27877
27907
|
}
|
|
27878
27908
|
async function evaluateUpdateExpression(node, context) {
|
|
27879
27909
|
if (node.argument.type === "Identifier") {
|
|
@@ -27909,41 +27939,35 @@ async function evaluateMemberUpdateExpression(node, context) {
|
|
|
27909
27939
|
if (node.argument.type !== "MemberExpression") {
|
|
27910
27940
|
throw new TypeError("Expected member update target.");
|
|
27911
27941
|
}
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
|
|
27915
|
-
|
|
27916
|
-
|
|
27917
|
-
|
|
27918
|
-
|
|
27919
|
-
|
|
27920
|
-
|
|
27921
|
-
|
|
27922
|
-
|
|
27923
|
-
|
|
27924
|
-
|
|
27925
|
-
|
|
27926
|
-
|
|
27927
|
-
|
|
27928
|
-
return {
|
|
27929
|
-
kind: "normal",
|
|
27930
|
-
hasValue: true,
|
|
27931
|
-
value: node.prefix ? next : current
|
|
27932
|
-
};
|
|
27942
|
+
return evaluateMemberAccess(node.argument, context, async (member) => {
|
|
27943
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27944
|
+
throw new TypeError("Cannot update properties of null or undefined.");
|
|
27945
|
+
}
|
|
27946
|
+
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
27947
|
+
const current = toNumber(
|
|
27948
|
+
await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
|
|
27949
|
+
);
|
|
27950
|
+
const next = node.operator === "++" ? current + 1 : current - 1;
|
|
27951
|
+
setSandboxProperty(member.object, property, next, context.budget);
|
|
27952
|
+
return {
|
|
27953
|
+
kind: "normal",
|
|
27954
|
+
hasValue: true,
|
|
27955
|
+
value: node.prefix ? next : current
|
|
27956
|
+
};
|
|
27957
|
+
});
|
|
27933
27958
|
}
|
|
27934
27959
|
async function evaluateMemberExpression(node, context) {
|
|
27935
|
-
|
|
27936
|
-
|
|
27937
|
-
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
27943
|
-
|
|
27944
|
-
|
|
27945
|
-
|
|
27946
|
-
};
|
|
27960
|
+
return evaluateMemberAccess(node, context, async (member) => {
|
|
27961
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27962
|
+
if (member.kind === "nullish") return { kind: "normal", hasValue: true, value: void 0 };
|
|
27963
|
+
throw new TypeError("Cannot read properties of null or undefined.");
|
|
27964
|
+
}
|
|
27965
|
+
return {
|
|
27966
|
+
kind: "normal",
|
|
27967
|
+
hasValue: true,
|
|
27968
|
+
value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
|
|
27969
|
+
};
|
|
27970
|
+
});
|
|
27947
27971
|
}
|
|
27948
27972
|
function getPropertyValue(target, property, context) {
|
|
27949
27973
|
if (isGuestHostObject(target)) return getHostObjectMember(target, String(property));
|
|
@@ -28051,26 +28075,27 @@ function attachFatalSandboxErrorContext(error, node, stackFrames) {
|
|
|
28051
28075
|
attachErrorSpan(error, node.span);
|
|
28052
28076
|
replaceErrorStack(error, stackFrames);
|
|
28053
28077
|
}
|
|
28054
|
-
async function evaluateMemberAccess(node, context) {
|
|
28078
|
+
async function evaluateMemberAccess(node, context, consume) {
|
|
28055
28079
|
const object = await evaluateNode(node.object, context);
|
|
28056
|
-
if (object.kind !== "normal")
|
|
28057
|
-
return {
|
|
28058
|
-
kind: "completion",
|
|
28059
|
-
result: object
|
|
28060
|
-
};
|
|
28061
|
-
}
|
|
28080
|
+
if (object.kind !== "normal") return object;
|
|
28062
28081
|
if ((object.value === null || object.value === void 0) && node.optional) {
|
|
28063
|
-
return {
|
|
28064
|
-
|
|
28065
|
-
|
|
28082
|
+
return consume({ kind: "nullish" });
|
|
28083
|
+
}
|
|
28084
|
+
const retained = {};
|
|
28085
|
+
let property;
|
|
28086
|
+
context.budget.setRetainedValues(retained, () => [object.value, property]);
|
|
28087
|
+
const release = () => context.budget.setRetainedValues(retained, void 0);
|
|
28088
|
+
const pending = runResources.getStore()?.referenceReleases;
|
|
28089
|
+
pending?.add(release);
|
|
28090
|
+
try {
|
|
28091
|
+
const result = node.computed ? await evaluateNode(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
|
|
28092
|
+
if (result.kind !== "normal") return result;
|
|
28093
|
+
property = result.value;
|
|
28094
|
+
return await consume({ kind: "resolved", object: object.value, property });
|
|
28095
|
+
} finally {
|
|
28096
|
+
release();
|
|
28097
|
+
pending?.delete(release);
|
|
28066
28098
|
}
|
|
28067
|
-
const property = node.computed ? await evaluateNode(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
|
|
28068
|
-
if (property.kind !== "normal") return { kind: "completion", result: property };
|
|
28069
|
-
return {
|
|
28070
|
-
kind: "resolved",
|
|
28071
|
-
object: object.value,
|
|
28072
|
-
property: property.value
|
|
28073
|
-
};
|
|
28074
28099
|
}
|
|
28075
28100
|
async function evaluateMemberProperty(node, context) {
|
|
28076
28101
|
const property = await evaluateNode(node, context);
|
|
@@ -28107,137 +28132,132 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
28107
28132
|
if (node.callee.type !== "MemberExpression") {
|
|
28108
28133
|
throw new TypeError("Expected member call expression.");
|
|
28109
28134
|
}
|
|
28110
|
-
|
|
28111
|
-
|
|
28112
|
-
|
|
28113
|
-
|
|
28114
|
-
|
|
28115
|
-
|
|
28116
|
-
|
|
28117
|
-
|
|
28118
|
-
|
|
28119
|
-
|
|
28120
|
-
kind: "normal",
|
|
28121
|
-
hasValue: true,
|
|
28122
|
-
value: void 0
|
|
28123
|
-
};
|
|
28135
|
+
return evaluateMemberAccess(node.callee, context, async (reference) => {
|
|
28136
|
+
if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
|
|
28137
|
+
if (reference.kind === "nullish") {
|
|
28138
|
+
return {
|
|
28139
|
+
kind: "normal",
|
|
28140
|
+
hasValue: true,
|
|
28141
|
+
value: void 0
|
|
28142
|
+
};
|
|
28143
|
+
}
|
|
28144
|
+
throw new TypeError("Cannot read properties of null or undefined.");
|
|
28124
28145
|
}
|
|
28125
|
-
|
|
28126
|
-
|
|
28127
|
-
|
|
28128
|
-
|
|
28129
|
-
|
|
28130
|
-
|
|
28131
|
-
if (typeof member.object === "string" && isStringMethodName(member.property)) {
|
|
28132
|
-
return evaluateStringMethodCall(node, member.object, member.property, context);
|
|
28133
|
-
}
|
|
28134
|
-
if (typeof member.object === "number" && isNumberMethodName(member.property)) {
|
|
28135
|
-
return evaluateNumberMethodCall(node, member.object, member.property, context);
|
|
28136
|
-
}
|
|
28137
|
-
if (Array.isArray(member.object) && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property)) {
|
|
28138
|
-
return evaluateArrayMethodCall(node, member.object, member.property, context);
|
|
28139
|
-
}
|
|
28140
|
-
if (isSandboxMap(member.object) && isMapMethodName(member.property)) {
|
|
28141
|
-
return evaluateMapMethodCall(node, member.object, member.property, context);
|
|
28142
|
-
}
|
|
28143
|
-
if (isSandboxSet(member.object) && isSetMethodName(member.property)) {
|
|
28144
|
-
return evaluateSetMethodCall(node, member.object, member.property, context);
|
|
28145
|
-
}
|
|
28146
|
-
if (typeof member.object === "string") {
|
|
28147
|
-
return evaluatePrimitiveMemberCall(
|
|
28148
|
-
node,
|
|
28149
|
-
"String",
|
|
28150
|
-
member.property,
|
|
28151
|
-
getStringMember(member.object, member.property, context.budget),
|
|
28152
|
-
context
|
|
28153
|
-
);
|
|
28154
|
-
}
|
|
28155
|
-
if (typeof member.object === "number") {
|
|
28156
|
-
return evaluatePrimitiveMemberCall(
|
|
28157
|
-
node,
|
|
28158
|
-
"Number",
|
|
28159
|
-
member.property,
|
|
28160
|
-
getNumberMember(member.property, context.budget),
|
|
28161
|
-
context
|
|
28162
|
-
);
|
|
28163
|
-
}
|
|
28164
|
-
if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
|
|
28165
|
-
return evaluatePrimitiveMemberCall(
|
|
28166
|
-
node,
|
|
28167
|
-
"Array",
|
|
28168
|
-
member.property,
|
|
28169
|
-
getArrayMemberValue(member.object, member.property, context),
|
|
28170
|
-
context
|
|
28171
|
-
);
|
|
28172
|
-
}
|
|
28173
|
-
if (isSandboxMap(member.object)) {
|
|
28174
|
-
return evaluatePrimitiveMemberCall(
|
|
28175
|
-
node,
|
|
28176
|
-
"Map",
|
|
28177
|
-
member.property,
|
|
28178
|
-
getMapMember(member.object, member.property, createMapMethodOptions(context)),
|
|
28179
|
-
context
|
|
28180
|
-
);
|
|
28181
|
-
}
|
|
28182
|
-
if (isSandboxDate(member.object)) {
|
|
28183
|
-
return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
|
|
28184
|
-
}
|
|
28185
|
-
if (isFloat32Array(member.object)) {
|
|
28186
|
-
return evaluateResolvedCallExpression(
|
|
28187
|
-
node,
|
|
28188
|
-
getFloat32Member(member.object, member.property, context.budget),
|
|
28189
|
-
context,
|
|
28190
|
-
member.object
|
|
28191
|
-
);
|
|
28192
|
-
}
|
|
28193
|
-
if (isSandboxSet(member.object)) {
|
|
28194
|
-
return evaluatePrimitiveMemberCall(
|
|
28195
|
-
node,
|
|
28196
|
-
"Set",
|
|
28197
|
-
member.property,
|
|
28198
|
-
getSetMember(member.object, member.property, createSetMethodOptions(context)),
|
|
28199
|
-
context
|
|
28200
|
-
);
|
|
28201
|
-
}
|
|
28202
|
-
if (isSandboxGenerator(member.object)) {
|
|
28203
|
-
const memberValue = getGeneratorMember(member.object, member.property, context.budget);
|
|
28204
|
-
if (memberValue === void 0) {
|
|
28205
|
-
throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
|
|
28146
|
+
const member = {
|
|
28147
|
+
...reference,
|
|
28148
|
+
property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
|
|
28149
|
+
};
|
|
28150
|
+
if (typeof member.object === "string" && isStringMethodName(member.property)) {
|
|
28151
|
+
return evaluateStringMethodCall(node, member.object, member.property, context);
|
|
28206
28152
|
}
|
|
28207
|
-
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
|
|
28211
|
-
|
|
28212
|
-
|
|
28153
|
+
if (typeof member.object === "number" && isNumberMethodName(member.property)) {
|
|
28154
|
+
return evaluateNumberMethodCall(node, member.object, member.property, context);
|
|
28155
|
+
}
|
|
28156
|
+
if (Array.isArray(member.object) && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property)) {
|
|
28157
|
+
return evaluateArrayMethodCall(node, member.object, member.property, context);
|
|
28158
|
+
}
|
|
28159
|
+
if (isSandboxMap(member.object) && isMapMethodName(member.property)) {
|
|
28160
|
+
return evaluateMapMethodCall(node, member.object, member.property, context);
|
|
28161
|
+
}
|
|
28162
|
+
if (isSandboxSet(member.object) && isSetMethodName(member.property)) {
|
|
28163
|
+
return evaluateSetMethodCall(node, member.object, member.property, context);
|
|
28164
|
+
}
|
|
28165
|
+
if (typeof member.object === "string") {
|
|
28166
|
+
return evaluatePrimitiveMemberCall(
|
|
28167
|
+
node,
|
|
28168
|
+
"String",
|
|
28169
|
+
member.property,
|
|
28170
|
+
getStringMember(member.object, member.property, context.budget),
|
|
28171
|
+
context
|
|
28172
|
+
);
|
|
28173
|
+
}
|
|
28174
|
+
if (typeof member.object === "number") {
|
|
28175
|
+
return evaluatePrimitiveMemberCall(
|
|
28176
|
+
node,
|
|
28177
|
+
"Number",
|
|
28178
|
+
member.property,
|
|
28179
|
+
getNumberMember(member.property, context.budget),
|
|
28180
|
+
context
|
|
28181
|
+
);
|
|
28182
|
+
}
|
|
28183
|
+
if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
|
|
28184
|
+
return evaluatePrimitiveMemberCall(
|
|
28185
|
+
node,
|
|
28186
|
+
"Array",
|
|
28187
|
+
member.property,
|
|
28188
|
+
getArrayMemberValue(member.object, member.property, context),
|
|
28189
|
+
context
|
|
28190
|
+
);
|
|
28191
|
+
}
|
|
28192
|
+
if (isSandboxMap(member.object)) {
|
|
28193
|
+
return evaluatePrimitiveMemberCall(
|
|
28194
|
+
node,
|
|
28195
|
+
"Map",
|
|
28196
|
+
member.property,
|
|
28197
|
+
getMapMember(member.object, member.property, createMapMethodOptions(context)),
|
|
28198
|
+
context
|
|
28199
|
+
);
|
|
28200
|
+
}
|
|
28201
|
+
if (isSandboxDate(member.object)) {
|
|
28202
|
+
return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
|
|
28203
|
+
}
|
|
28204
|
+
if (isFloat32Array(member.object)) {
|
|
28205
|
+
return evaluateResolvedCallExpression(
|
|
28206
|
+
node,
|
|
28207
|
+
getFloat32Member(member.object, member.property, context.budget),
|
|
28208
|
+
context,
|
|
28209
|
+
member.object
|
|
28210
|
+
);
|
|
28211
|
+
}
|
|
28212
|
+
if (isSandboxSet(member.object)) {
|
|
28213
|
+
return evaluatePrimitiveMemberCall(
|
|
28214
|
+
node,
|
|
28215
|
+
"Set",
|
|
28216
|
+
member.property,
|
|
28217
|
+
getSetMember(member.object, member.property, createSetMethodOptions(context)),
|
|
28218
|
+
context
|
|
28219
|
+
);
|
|
28220
|
+
}
|
|
28221
|
+
if (isSandboxGenerator(member.object)) {
|
|
28222
|
+
const memberValue = getGeneratorMember(member.object, member.property, context.budget);
|
|
28223
|
+
if (memberValue === void 0) {
|
|
28224
|
+
throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
|
|
28225
|
+
}
|
|
28226
|
+
return evaluateResolvedCallExpression(node, memberValue, context, member.object);
|
|
28227
|
+
}
|
|
28228
|
+
if (isSandboxClosure(member.object)) {
|
|
28229
|
+
const memberValue = getClosureMemberValue(member.object, member.property, context);
|
|
28230
|
+
if (memberValue === void 0) {
|
|
28231
|
+
throw new TypeError(`Function#${String(member.property)} is not a supported method.`);
|
|
28232
|
+
}
|
|
28233
|
+
return evaluateResolvedCallExpression(node, memberValue, context, member.object);
|
|
28234
|
+
}
|
|
28235
|
+
if (isSandboxPromise(member.object)) {
|
|
28236
|
+
return evaluateResolvedCallExpression(
|
|
28237
|
+
node,
|
|
28238
|
+
getPromiseMember(member.property, context.budget),
|
|
28239
|
+
context,
|
|
28240
|
+
member.object
|
|
28241
|
+
);
|
|
28242
|
+
}
|
|
28243
|
+
if (isSandboxRegex(member.object) && isRegexMethodName(member.property)) {
|
|
28244
|
+
return evaluateResolvedCallExpression(
|
|
28245
|
+
node,
|
|
28246
|
+
getRegexMember(member.object, member.property, context.budget),
|
|
28247
|
+
context,
|
|
28248
|
+
member.object
|
|
28249
|
+
);
|
|
28250
|
+
}
|
|
28251
|
+
if (!isIndexableSandboxValue(member.object)) {
|
|
28252
|
+
throw new TypeError("Attempted to read a property from a non-object value.");
|
|
28213
28253
|
}
|
|
28214
|
-
return evaluateResolvedCallExpression(node, memberValue, context, member.object);
|
|
28215
|
-
}
|
|
28216
|
-
if (isSandboxPromise(member.object)) {
|
|
28217
|
-
return evaluateResolvedCallExpression(
|
|
28218
|
-
node,
|
|
28219
|
-
getPromiseMember(member.property, context.budget),
|
|
28220
|
-
context,
|
|
28221
|
-
member.object
|
|
28222
|
-
);
|
|
28223
|
-
}
|
|
28224
|
-
if (isSandboxRegex(member.object) && isRegexMethodName(member.property)) {
|
|
28225
28254
|
return evaluateResolvedCallExpression(
|
|
28226
28255
|
node,
|
|
28227
|
-
|
|
28256
|
+
getMemberValue(member.object, member.property, context),
|
|
28228
28257
|
context,
|
|
28229
28258
|
member.object
|
|
28230
28259
|
);
|
|
28231
|
-
}
|
|
28232
|
-
if (!isIndexableSandboxValue(member.object)) {
|
|
28233
|
-
throw new TypeError("Attempted to read a property from a non-object value.");
|
|
28234
|
-
}
|
|
28235
|
-
return evaluateResolvedCallExpression(
|
|
28236
|
-
node,
|
|
28237
|
-
getMemberValue(member.object, member.property, context),
|
|
28238
|
-
context,
|
|
28239
|
-
member.object
|
|
28240
|
-
);
|
|
28260
|
+
});
|
|
28241
28261
|
}
|
|
28242
28262
|
function evaluatePrimitiveMemberCall(node, receiverType, property, value, context) {
|
|
28243
28263
|
if (value === void 0) {
|
|
@@ -31299,41 +31319,6 @@ function createBuiltinBindings(options) {
|
|
|
31299
31319
|
};
|
|
31300
31320
|
}
|
|
31301
31321
|
|
|
31302
|
-
// packages/safe-js/src/interp/resources.ts
|
|
31303
|
-
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
31304
|
-
var runResources = new AsyncLocalStorage5();
|
|
31305
|
-
async function withRunResources(signal, execute) {
|
|
31306
|
-
const controller = new AbortController();
|
|
31307
|
-
const cancel = () => controller.abort(signal?.reason);
|
|
31308
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
31309
|
-
const resources = {
|
|
31310
|
-
signal: controller.signal,
|
|
31311
|
-
add(close) {
|
|
31312
|
-
cleanups.add(close);
|
|
31313
|
-
}
|
|
31314
|
-
};
|
|
31315
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
31316
|
-
if (signal?.aborted) cancel();
|
|
31317
|
-
let result;
|
|
31318
|
-
let failure;
|
|
31319
|
-
let errors = [];
|
|
31320
|
-
try {
|
|
31321
|
-
result = await runResources.run(resources, execute);
|
|
31322
|
-
} catch (error) {
|
|
31323
|
-
failure = { reason: error };
|
|
31324
|
-
} finally {
|
|
31325
|
-
signal?.removeEventListener("abort", cancel);
|
|
31326
|
-
controller.abort(new Error("SafeJS run finished."));
|
|
31327
|
-
const outcomes = await Promise.allSettled(
|
|
31328
|
-
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
31329
|
-
);
|
|
31330
|
-
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
31331
|
-
}
|
|
31332
|
-
if (failure !== void 0) throw failure.reason;
|
|
31333
|
-
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
31334
|
-
return result;
|
|
31335
|
-
}
|
|
31336
|
-
|
|
31337
31322
|
// packages/safe-js/src/modules/registry.ts
|
|
31338
31323
|
function createUnknownModuleMessage2(moduleName, moduleNames) {
|
|
31339
31324
|
if (moduleNames.length === 0) {
|
|
@@ -31575,6 +31560,7 @@ var RealmState = class {
|
|
|
31575
31560
|
extensions;
|
|
31576
31561
|
consoleExtension;
|
|
31577
31562
|
cleanups = [];
|
|
31563
|
+
referenceReleases = /* @__PURE__ */ new Set();
|
|
31578
31564
|
callbacks = /* @__PURE__ */ new Map();
|
|
31579
31565
|
pendingCallbacks = /* @__PURE__ */ new Set();
|
|
31580
31566
|
callbackCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -31901,7 +31887,7 @@ var RealmState = class {
|
|
|
31901
31887
|
const pending = withSandboxPromiseRejectionTracker(
|
|
31902
31888
|
this.tracker,
|
|
31903
31889
|
() => runResources.run(
|
|
31904
|
-
{ signal: this.controller.signal, add: this.onCleanup },
|
|
31890
|
+
{ signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
|
|
31905
31891
|
() => withCancellationSignal(
|
|
31906
31892
|
this.controller.signal,
|
|
31907
31893
|
() => active && this.phase.getStore()?.active ? runAsyncPrefix(invoke) : this.queue.run(invoke)
|
|
@@ -32096,7 +32082,7 @@ var RealmState = class {
|
|
|
32096
32082
|
() => withSandboxPromiseRejectionTracker(
|
|
32097
32083
|
this.tracker,
|
|
32098
32084
|
() => runResources.run(
|
|
32099
|
-
{ signal: this.controller.signal, add: this.onCleanup },
|
|
32085
|
+
{ signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
|
|
32100
32086
|
() => withCancellationSignal(this.controller.signal, task)
|
|
32101
32087
|
)
|
|
32102
32088
|
)
|
|
@@ -32153,6 +32139,8 @@ var RealmState = class {
|
|
|
32153
32139
|
this.hostObjects.clear();
|
|
32154
32140
|
for (const reference of this.guestReferences.keys()) revokeGuestReference(reference, this);
|
|
32155
32141
|
this.guestReferences.clear();
|
|
32142
|
+
for (const release of this.referenceReleases) release();
|
|
32143
|
+
this.referenceReleases.clear();
|
|
32156
32144
|
this.budget.setRetainedValues(this, void 0);
|
|
32157
32145
|
releaseObjectPrototype(this.budget);
|
|
32158
32146
|
this.disposal = (async () => {
|
|
@@ -33406,9 +33394,9 @@ export {
|
|
|
33406
33394
|
validateSnapshotMigration,
|
|
33407
33395
|
restore,
|
|
33408
33396
|
lint,
|
|
33397
|
+
runResources,
|
|
33409
33398
|
declareHostOperation,
|
|
33410
33399
|
createSeededRandom,
|
|
33411
|
-
runResources,
|
|
33412
33400
|
createReplayableRandom,
|
|
33413
33401
|
createRealm,
|
|
33414
33402
|
dump,
|
|
@@ -33418,4 +33406,4 @@ export {
|
|
|
33418
33406
|
FileSnapshotBackend,
|
|
33419
33407
|
run
|
|
33420
33408
|
};
|
|
33421
|
-
//# sourceMappingURL=chunk-
|
|
33409
|
+
//# sourceMappingURL=chunk-DHD453E5.js.map
|