@poe-platform/safe-js 0.1.433 → 0.1.435
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-35AKWKAL.js → chunk-H3E7APSE.js} +65 -20
- package/dist/safe-js/chunks/chunk-H3E7APSE.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-HBSJ2KM3.js → chunk-JJ3J6ZJF.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/dist/safe-js/interp/scope.d.ts +6 -1
- package/dist/safe-js/snapshot/guest-heap.d.ts +1 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-35AKWKAL.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-HBSJ2KM3.js.map → chunk-JJ3J6ZJF.js.map} +0 -0
|
@@ -7824,6 +7824,7 @@ var wellKnownSymbols = Object.freeze({
|
|
|
7824
7824
|
var identities = /* @__PURE__ */ new WeakMap();
|
|
7825
7825
|
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7826
7826
|
var mutableBuiltinBindings = /* @__PURE__ */ new WeakMap();
|
|
7827
|
+
var builtinGlobalObjects = /* @__PURE__ */ new WeakMap();
|
|
7827
7828
|
function registerBuiltinIdentities(budget, bindings) {
|
|
7828
7829
|
let realm = realms2.get(budget);
|
|
7829
7830
|
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
@@ -8411,8 +8412,8 @@ function registerIntrinsicFunction(budget, closure) {
|
|
|
8411
8412
|
registerBuiltinIdentities(budget, { [closure.name]: closure });
|
|
8412
8413
|
trackIntrinsicState(budget, closure, closure, [closure]);
|
|
8413
8414
|
}
|
|
8414
|
-
function registerIntrinsicObject(budget, value) {
|
|
8415
|
-
const methods2 = Object.values(Object.getOwnPropertyDescriptors(value)).map((descriptor) => descriptor.value).filter(isGuestClosure);
|
|
8415
|
+
function registerIntrinsicObject(budget, value, trackMethods = true) {
|
|
8416
|
+
const methods2 = trackMethods ? Object.values(Object.getOwnPropertyDescriptors(value)).map((descriptor) => descriptor.value).filter(isGuestClosure) : [];
|
|
8416
8417
|
trackIntrinsicState(budget, value, value, [value, ...methods2]);
|
|
8417
8418
|
}
|
|
8418
8419
|
function trackIntrinsicState(budget, root, owner, targets) {
|
|
@@ -11798,7 +11799,8 @@ var Scope = class _Scope {
|
|
|
11798
11799
|
this.options = options;
|
|
11799
11800
|
this.#restoredBindings = parent === void 0 ? new Map(Object.entries(restoredBindings ?? {})) : parent.#restoredBindings;
|
|
11800
11801
|
const mutable = mutableBuiltinBindings.get(bindings);
|
|
11801
|
-
|
|
11802
|
+
this.objectEnvironment = builtinGlobalObjects.get(bindings);
|
|
11803
|
+
for (const [name, value] of Object.entries(this.objectEnvironment === void 0 ? bindings : {})) {
|
|
11802
11804
|
this.#bindings.set(name, {
|
|
11803
11805
|
kind: mutable?.has(name) ? "var" : "const",
|
|
11804
11806
|
value
|
|
@@ -11808,6 +11810,7 @@ var Scope = class _Scope {
|
|
|
11808
11810
|
parent;
|
|
11809
11811
|
importMeta;
|
|
11810
11812
|
options;
|
|
11813
|
+
objectEnvironment;
|
|
11811
11814
|
resourceState;
|
|
11812
11815
|
privateNames;
|
|
11813
11816
|
#bindings = /* @__PURE__ */ new Map();
|
|
@@ -11876,6 +11879,14 @@ var Scope = class _Scope {
|
|
|
11876
11879
|
}
|
|
11877
11880
|
return {};
|
|
11878
11881
|
}
|
|
11882
|
+
lookupThis() {
|
|
11883
|
+
const binding = this.#bindings.get("this");
|
|
11884
|
+
if (binding !== void 0) {
|
|
11885
|
+
if (binding.value === uninitialized) throw new ReferenceError("Cannot access 'this' before initialization.");
|
|
11886
|
+
return binding.value;
|
|
11887
|
+
}
|
|
11888
|
+
return this.parent?.lookupThis();
|
|
11889
|
+
}
|
|
11879
11890
|
retainedValues() {
|
|
11880
11891
|
const values = this.parent?.retainedValues() ?? [];
|
|
11881
11892
|
if (this.resourceState !== void 0) values.push(this.resourceState);
|
|
@@ -11939,12 +11950,20 @@ var Scope = class _Scope {
|
|
|
11939
11950
|
value: uninitialized
|
|
11940
11951
|
});
|
|
11941
11952
|
}
|
|
11942
|
-
assign(name, value) {
|
|
11953
|
+
assign(name, value, setProperty) {
|
|
11943
11954
|
const scope = this.resolveScope(name);
|
|
11944
11955
|
if (scope === void 0) {
|
|
11945
11956
|
if (name === "undefined") throw new TypeError("Cannot assign to const binding 'undefined'.");
|
|
11946
11957
|
throw new ReferenceError(`Cannot assign to undeclared binding '${name}'.`);
|
|
11947
11958
|
}
|
|
11959
|
+
if (!scope.#bindings.has(name) && scope.objectEnvironment !== void 0) {
|
|
11960
|
+
if (setProperty !== void 0) return setProperty(scope.objectEnvironment, name, value);
|
|
11961
|
+
const descriptor = getSandboxPropertyDescriptor(scope.objectEnvironment, name);
|
|
11962
|
+
if (descriptor === void 0) throw new ReferenceError(`Cannot assign to undeclared binding '${name}'.`);
|
|
11963
|
+
if (!("value" in descriptor)) throw new TypeError("Object environment accessors require a guest call context.");
|
|
11964
|
+
if (!Reflect.set(scope.objectEnvironment, name, value)) throw new TypeError(`Cannot assign to read-only binding '${name}'.`);
|
|
11965
|
+
return;
|
|
11966
|
+
}
|
|
11948
11967
|
const binding = scope.#bindings.get(name);
|
|
11949
11968
|
if (binding === void 0) {
|
|
11950
11969
|
throw new ReferenceError(`Cannot assign to undeclared binding '${name}'.`);
|
|
@@ -11970,6 +11989,10 @@ var Scope = class _Scope {
|
|
|
11970
11989
|
value: binding.value
|
|
11971
11990
|
};
|
|
11972
11991
|
}
|
|
11992
|
+
if (this.objectEnvironment !== void 0) {
|
|
11993
|
+
const descriptor = getSandboxPropertyDescriptor(this.objectEnvironment, name);
|
|
11994
|
+
if (descriptor !== void 0) return { found: true, kind: "var", value: descriptor.value, object: this.objectEnvironment };
|
|
11995
|
+
}
|
|
11973
11996
|
if (this.parent !== void 0) {
|
|
11974
11997
|
return this.parent.lookup(name);
|
|
11975
11998
|
}
|
|
@@ -11985,6 +12008,12 @@ var Scope = class _Scope {
|
|
|
11985
12008
|
}
|
|
11986
12009
|
const bindings = {};
|
|
11987
12010
|
for (let index = scopes.length - 1; index >= 0; index -= 1) {
|
|
12011
|
+
const object = scopes[index].objectEnvironment;
|
|
12012
|
+
if (object !== void 0) {
|
|
12013
|
+
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(object))) {
|
|
12014
|
+
if ("value" in descriptor) defineSnapshotBinding(bindings, name, descriptor.value);
|
|
12015
|
+
}
|
|
12016
|
+
}
|
|
11988
12017
|
for (const [name, binding] of scopes[index].#bindings.entries()) {
|
|
11989
12018
|
if (binding.value === uninitialized) {
|
|
11990
12019
|
continue;
|
|
@@ -12011,6 +12040,7 @@ var Scope = class _Scope {
|
|
|
12011
12040
|
}
|
|
12012
12041
|
return {
|
|
12013
12042
|
parent: this.parent,
|
|
12043
|
+
...this.objectEnvironment === void 0 ? {} : { objectEnvironment: this.objectEnvironment },
|
|
12014
12044
|
importMeta: this.importMeta,
|
|
12015
12045
|
functionBoundary: this.isFunctionBoundary(),
|
|
12016
12046
|
chargeData: this.options.chargeData !== false,
|
|
@@ -12044,6 +12074,7 @@ var Scope = class _Scope {
|
|
|
12044
12074
|
const restored = new Map(frame.restoredBindings ?? []);
|
|
12045
12075
|
if (restored.size !== (frame.restoredBindings?.length ?? 0)) throw new TypeError("Duplicate restored binding.");
|
|
12046
12076
|
this.importMeta = frame.importMeta;
|
|
12077
|
+
this.objectEnvironment = frame.objectEnvironment;
|
|
12047
12078
|
this.resourceState = frame.resourceState;
|
|
12048
12079
|
if (frame.privateNames !== void 0) this.privateNames = new Map(frame.privateNames);
|
|
12049
12080
|
for (const [name, binding] of bindings) {
|
|
@@ -12068,7 +12099,7 @@ var Scope = class _Scope {
|
|
|
12068
12099
|
}
|
|
12069
12100
|
}
|
|
12070
12101
|
resolveScope(name) {
|
|
12071
|
-
if (this.#bindings.has(name)) {
|
|
12102
|
+
if (this.#bindings.has(name) || this.objectEnvironment !== void 0 && getSandboxPropertyDescriptor(this.objectEnvironment, name) !== void 0) {
|
|
12072
12103
|
return this;
|
|
12073
12104
|
}
|
|
12074
12105
|
return this.parent?.resolveScope(name);
|
|
@@ -12314,7 +12345,7 @@ function deferred() {
|
|
|
12314
12345
|
async function bindPattern(pattern, value, target, scope, context, reference) {
|
|
12315
12346
|
switch (pattern.type) {
|
|
12316
12347
|
case "Identifier":
|
|
12317
|
-
bindIdentifier(pattern, value, target, scope);
|
|
12348
|
+
await bindIdentifier(pattern, value, target, scope, context);
|
|
12318
12349
|
return { ok: true };
|
|
12319
12350
|
case "MemberExpression":
|
|
12320
12351
|
if ("kind" in target) {
|
|
@@ -12331,7 +12362,7 @@ async function bindPattern(pattern, value, target, scope, context, reference) {
|
|
|
12331
12362
|
return bindPattern(pattern.argument, value, target, scope, context, reference);
|
|
12332
12363
|
}
|
|
12333
12364
|
}
|
|
12334
|
-
function bindIdentifier(pattern, value, target, scope) {
|
|
12365
|
+
function bindIdentifier(pattern, value, target, scope, context) {
|
|
12335
12366
|
if ("assign" in target || target.kind === "var" && target.initialize !== true) {
|
|
12336
12367
|
if ("assign" in target) {
|
|
12337
12368
|
const binding = scope.lookup(pattern.name);
|
|
@@ -12342,8 +12373,7 @@ function bindIdentifier(pattern, value, target, scope) {
|
|
|
12342
12373
|
throw new TypeError(`Cannot assign to const '${pattern.name}'`);
|
|
12343
12374
|
}
|
|
12344
12375
|
}
|
|
12345
|
-
scope.assign(pattern.name, value);
|
|
12346
|
-
return;
|
|
12376
|
+
return scope.assign(pattern.name, value, context.setProperty);
|
|
12347
12377
|
}
|
|
12348
12378
|
scope.declare(pattern.name, target.kind, value);
|
|
12349
12379
|
}
|
|
@@ -18371,6 +18401,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
18371
18401
|
functionBoundary: frame.functionBoundary,
|
|
18372
18402
|
chargeData: frame.chargeData,
|
|
18373
18403
|
bindings: frame.bindings,
|
|
18404
|
+
...frame.objectEnvironment === void 0 ? {} : { objectEnvironment: encode(frame.objectEnvironment) },
|
|
18374
18405
|
...frame.resourceState === void 0 ? {} : { resourceState: encode(frame.resourceState) },
|
|
18375
18406
|
...frame.privateNames === void 0 ? {} : { privateNames: frame.privateNames.map(([name, identity]) => [name, encode(identity)]) },
|
|
18376
18407
|
cells: frame.cells.map((cell) => cell.initialized ? { ...cell, value: encode(cell.value) } : cell),
|
|
@@ -24649,6 +24680,16 @@ function createBuiltinBindings(options) {
|
|
|
24649
24680
|
createGeneratorPrototypes(options.budget);
|
|
24650
24681
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24651
24682
|
mutableBuiltinBindings.set(bindings, new Set(Object.keys(bindings).filter((name) => name !== "Infinity" && name !== "NaN" && name !== "undefined")));
|
|
24683
|
+
const globalObject = createIntrinsicObject();
|
|
24684
|
+
registerBuiltinIdentities(options.budget, { globalThis: globalObject });
|
|
24685
|
+
for (const [name, value] of Object.entries({ ...bindings, undefined: void 0 })) {
|
|
24686
|
+
const mutable = name !== "Infinity" && name !== "NaN" && name !== "undefined";
|
|
24687
|
+
Object.defineProperty(globalObject, name, { value, writable: mutable, configurable: mutable });
|
|
24688
|
+
}
|
|
24689
|
+
Object.defineProperty(globalObject, "globalThis", { value: globalObject, writable: true, configurable: true });
|
|
24690
|
+
setSandboxPrototype(globalObject, getSandboxPrototype(globalObject, options.budget), options.budget);
|
|
24691
|
+
registerIntrinsicObject(options.budget, globalObject, false);
|
|
24692
|
+
builtinGlobalObjects.set(bindings, globalObject);
|
|
24652
24693
|
return bindings;
|
|
24653
24694
|
}
|
|
24654
24695
|
|
|
@@ -25459,7 +25500,12 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
25459
25500
|
if (Object.hasOwn(environment, "construction")) reference(environment.construction, ["construction-environment"]);
|
|
25460
25501
|
}
|
|
25461
25502
|
} else {
|
|
25462
|
-
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState"]);
|
|
25503
|
+
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState", "objectEnvironment"]);
|
|
25504
|
+
if (node.objectEnvironment !== void 0) {
|
|
25505
|
+
if (!absent(node.parent)) throw new TypeError("Only root scopes own global object environments.");
|
|
25506
|
+
const globalObject = reference(node.objectEnvironment, ["intrinsic"]);
|
|
25507
|
+
if (globalObject.id !== '["globalThis"]') throw new TypeError("Invalid global object environment.");
|
|
25508
|
+
}
|
|
25463
25509
|
if (node.resourceState !== void 0) reference(node.resourceState, ["object"]);
|
|
25464
25510
|
if (node.privateNames !== void 0) {
|
|
25465
25511
|
const names2 = /* @__PURE__ */ new Set();
|
|
@@ -27629,7 +27675,7 @@ async function evaluateAssignmentExpression(node, context) {
|
|
|
27629
27675
|
if (binding?.found === false) {
|
|
27630
27676
|
throw new ReferenceError(`Cannot assign to undeclared binding '${node.left.name}'.`);
|
|
27631
27677
|
}
|
|
27632
|
-
const current = restored === void 0 ? binding?.value : restored.current;
|
|
27678
|
+
const current = restored === void 0 ? binding?.found && binding.object !== void 0 ? await getPropertyValue(binding.object, node.left.name, context) : binding?.value : restored.current;
|
|
27633
27679
|
if (node.operator === "&&=" && !isTruthy(current)) {
|
|
27634
27680
|
return {
|
|
27635
27681
|
kind: "normal",
|
|
@@ -27664,7 +27710,7 @@ async function evaluateAssignmentExpression(node, context) {
|
|
|
27664
27710
|
return right;
|
|
27665
27711
|
}
|
|
27666
27712
|
const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
|
|
27667
|
-
context.scope.assign(node.left.name, value);
|
|
27713
|
+
await context.scope.assign(node.left.name, value, (object, key, assigned) => setSandboxProperty(object, key, assigned, context.budget, true, createCoercionContext(context)));
|
|
27668
27714
|
return {
|
|
27669
27715
|
kind: "normal",
|
|
27670
27716
|
hasValue: true,
|
|
@@ -27855,15 +27901,14 @@ async function evaluateIdentifier(node, context) {
|
|
|
27855
27901
|
return {
|
|
27856
27902
|
kind: "normal",
|
|
27857
27903
|
hasValue: true,
|
|
27858
|
-
value: binding.value
|
|
27904
|
+
value: binding.object === void 0 ? binding.value : await getPropertyValue(binding.object, node.name, context)
|
|
27859
27905
|
};
|
|
27860
27906
|
}
|
|
27861
27907
|
async function evaluateThisExpression(_node, context) {
|
|
27862
|
-
const binding = context.scope.lookup("this");
|
|
27863
27908
|
return {
|
|
27864
27909
|
kind: "normal",
|
|
27865
27910
|
hasValue: true,
|
|
27866
|
-
value:
|
|
27911
|
+
value: context.scope.lookupThis()
|
|
27867
27912
|
};
|
|
27868
27913
|
}
|
|
27869
27914
|
async function evaluateMetaProperty(_node, context) {
|
|
@@ -29094,10 +29139,10 @@ async function evaluateIdentifierUpdateExpression(node, context) {
|
|
|
29094
29139
|
)
|
|
29095
29140
|
};
|
|
29096
29141
|
}
|
|
29097
|
-
const primitive = await toNumericPrimitive(binding.value, context);
|
|
29142
|
+
const primitive = await toNumericPrimitive(binding.object === void 0 ? binding.value : await getPropertyValue(binding.object, node.argument.name, context), context);
|
|
29098
29143
|
const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
|
|
29099
29144
|
const next = typeof current === "bigint" ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget) : node.operator === "++" ? current + 1 : current - 1;
|
|
29100
|
-
context.scope.assign(node.argument.name, next);
|
|
29145
|
+
await context.scope.assign(node.argument.name, next, (object, key, assigned) => setSandboxProperty(object, key, assigned, context.budget, true, createCoercionContext(context)));
|
|
29101
29146
|
return {
|
|
29102
29147
|
kind: "normal",
|
|
29103
29148
|
hasValue: true,
|
|
@@ -29325,8 +29370,7 @@ function attachFatalSandboxErrorContext(error, node, stackFrames) {
|
|
|
29325
29370
|
async function evaluateMemberAccess(node, context, consume) {
|
|
29326
29371
|
const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
29327
29372
|
if (restored !== void 0 && restored.kind !== "member") throw new TypeError("Invalid member continuation.");
|
|
29328
|
-
const
|
|
29329
|
-
const superReceiver = restored?.kind === "member" && Object.hasOwn(restored, "superReceiver") ? { value: restored.superReceiver } : thisBinding === void 0 ? void 0 : { value: thisBinding.found ? thisBinding.value : void 0 };
|
|
29373
|
+
const superReceiver = restored?.kind === "member" && Object.hasOwn(restored, "superReceiver") ? { value: restored.superReceiver } : node.object.type === "Super" ? { value: context.scope.lookupThis() } : void 0;
|
|
29330
29374
|
const object = restored?.kind === "member" ? { kind: "normal", value: restored.object } : await evaluateNode(node.object, context);
|
|
29331
29375
|
if (object.kind !== "normal") return object;
|
|
29332
29376
|
if ((object.value === null || object.value === void 0) && node.optional) {
|
|
@@ -34683,6 +34727,7 @@ var KNOWN_RUNTIME_GLOBALS = [
|
|
|
34683
34727
|
"Error",
|
|
34684
34728
|
"EvalError",
|
|
34685
34729
|
"Infinity",
|
|
34730
|
+
"globalThis",
|
|
34686
34731
|
"isFinite",
|
|
34687
34732
|
"isNaN",
|
|
34688
34733
|
"Iterator",
|
|
@@ -47195,4 +47240,4 @@ export {
|
|
|
47195
47240
|
FileSnapshotBackend,
|
|
47196
47241
|
run
|
|
47197
47242
|
};
|
|
47198
|
-
//# sourceMappingURL=chunk-
|
|
47243
|
+
//# sourceMappingURL=chunk-H3E7APSE.js.map
|