@poe-platform/safe-js 0.1.303 → 0.1.304
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-S5C5SAU4.js → chunk-I3JCUPXR.js} +60 -22
- package/dist/safe-js/chunks/{chunk-S5C5SAU4.js.map → chunk-I3JCUPXR.js.map} +4 -4
- package/dist/safe-js/chunks/{chunk-5WFKY3Y3.js → chunk-K2TSSLLI.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-5WFKY3Y3.js.map → chunk-K2TSSLLI.js.map} +0 -0
|
@@ -14080,6 +14080,34 @@ function functionString(value) {
|
|
|
14080
14080
|
return `function ${name}() { [native code] }`;
|
|
14081
14081
|
}
|
|
14082
14082
|
|
|
14083
|
+
// packages/safe-js/src/interp/bound-function-state.ts
|
|
14084
|
+
var boundFunctionStates = /* @__PURE__ */ new WeakMap();
|
|
14085
|
+
|
|
14086
|
+
// packages/safe-js/src/interp/bound-function.ts
|
|
14087
|
+
function createBoundFunction(state, name, length, callClosure) {
|
|
14088
|
+
const bound = createSandboxClosure({
|
|
14089
|
+
guest: true,
|
|
14090
|
+
sandbox: true,
|
|
14091
|
+
name,
|
|
14092
|
+
length,
|
|
14093
|
+
boundTarget: state.target,
|
|
14094
|
+
retainedValues: () => [state.target, state.thisValue, ...state.args, bound.name],
|
|
14095
|
+
call: (args, context) => callClosure(state.target, [...state.args, ...args], context?.stack ?? [], state.thisValue),
|
|
14096
|
+
...state.target.construct === void 0 ? {} : {
|
|
14097
|
+
construct: (args, context) => callClosure(
|
|
14098
|
+
state.target,
|
|
14099
|
+
[...state.args, ...args],
|
|
14100
|
+
context?.stack ?? [],
|
|
14101
|
+
void 0,
|
|
14102
|
+
true,
|
|
14103
|
+
context?.newTarget === bound ? state.target : context?.newTarget
|
|
14104
|
+
)
|
|
14105
|
+
}
|
|
14106
|
+
});
|
|
14107
|
+
boundFunctionStates.set(bound, state);
|
|
14108
|
+
return bound;
|
|
14109
|
+
}
|
|
14110
|
+
|
|
14083
14111
|
// packages/safe-js/src/interp/methods/function.ts
|
|
14084
14112
|
var functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
|
|
14085
14113
|
function getFunctionMember(target, property, options) {
|
|
@@ -14134,25 +14162,7 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
|
|
|
14134
14162
|
const explicitPrototype = hasExplicitSandboxPrototype(target);
|
|
14135
14163
|
const prototype = getSandboxPrototype(target, options.budget);
|
|
14136
14164
|
const bind = (length, name) => {
|
|
14137
|
-
const bound =
|
|
14138
|
-
guest: true,
|
|
14139
|
-
sandbox: true,
|
|
14140
|
-
name: `bound ${name}`,
|
|
14141
|
-
length,
|
|
14142
|
-
boundTarget: target,
|
|
14143
|
-
retainedValues: () => [target, thisValue, ...boundArgs, bound.name],
|
|
14144
|
-
call: (callArgs, context2) => options.callClosure(target, [...boundArgs, ...callArgs], context2?.stack ?? [], thisValue),
|
|
14145
|
-
...target.construct === void 0 ? {} : {
|
|
14146
|
-
construct: (callArgs, context2) => options.callClosure(
|
|
14147
|
-
target,
|
|
14148
|
-
[...boundArgs, ...callArgs],
|
|
14149
|
-
context2?.stack ?? [],
|
|
14150
|
-
void 0,
|
|
14151
|
-
true,
|
|
14152
|
-
context2?.newTarget === bound ? target : context2?.newTarget
|
|
14153
|
-
)
|
|
14154
|
-
}
|
|
14155
|
-
});
|
|
14165
|
+
const bound = createBoundFunction({ target, thisValue, args: boundArgs }, `bound ${name}`, length, options.callClosure);
|
|
14156
14166
|
if (explicitPrototype) setSandboxPrototype(bound, prototype, options.budget);
|
|
14157
14167
|
return bound;
|
|
14158
14168
|
};
|
|
@@ -20281,6 +20291,18 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20281
20291
|
const state2 = captureObjectState(value, encode);
|
|
20282
20292
|
return { kind: "intrinsic", id: intrinsic, ...state2 === void 0 ? {} : { state: state2 } };
|
|
20283
20293
|
}
|
|
20294
|
+
const bound = boundFunctionStates.get(value);
|
|
20295
|
+
if (bound !== void 0 && isSandboxClosure(value)) {
|
|
20296
|
+
return {
|
|
20297
|
+
kind: "bound-function",
|
|
20298
|
+
target: encode(bound.target),
|
|
20299
|
+
thisValue: encode(bound.thisValue),
|
|
20300
|
+
args: bound.args.map(encode),
|
|
20301
|
+
length: encode(value.length),
|
|
20302
|
+
...value.name === void 0 ? {} : { name: value.name },
|
|
20303
|
+
state: captureObjectState(value, encode)
|
|
20304
|
+
};
|
|
20305
|
+
}
|
|
20284
20306
|
if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key, entry]) => [encode(key), encode(entry)]), ...serializeCollectionProperties(value, encode) };
|
|
20285
20307
|
if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
|
|
20286
20308
|
if (isSandboxArrayIterator(value)) {
|
|
@@ -24401,7 +24423,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24401
24423
|
createRawJson(node.text);
|
|
24402
24424
|
return true;
|
|
24403
24425
|
}
|
|
24404
|
-
if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
24426
|
+
if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
24405
24427
|
const reference = (value, kinds) => {
|
|
24406
24428
|
const ref = record3(value);
|
|
24407
24429
|
fields(ref, ["kind", "id"]);
|
|
@@ -24412,7 +24434,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24412
24434
|
};
|
|
24413
24435
|
const callable = (value) => {
|
|
24414
24436
|
if (absent(value)) return;
|
|
24415
|
-
const target = reference(value, ["intrinsic", "guest-function", "guest-class"]);
|
|
24437
|
+
const target = reference(value, ["intrinsic", "bound-function", "guest-function", "guest-class"]);
|
|
24416
24438
|
if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
|
|
24417
24439
|
throw new TypeError("Guest accessor reference is not callable.");
|
|
24418
24440
|
};
|
|
@@ -24508,6 +24530,22 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24508
24530
|
if (descriptor.kind !== "data" || descriptor.writable !== false || descriptor.enumerable !== false || descriptor.configurable !== false)
|
|
24509
24531
|
throw new TypeError("Invalid class prototype descriptor.");
|
|
24510
24532
|
reference(descriptor.value, ["object", "guest-object"]);
|
|
24533
|
+
} else if (node.kind === "bound-function") {
|
|
24534
|
+
fields(node, ["kind", "target", "thisValue", "args", "length", "state"], ["name"]);
|
|
24535
|
+
if (Object.hasOwn(node, "name") && typeof node.name !== "string") throw new TypeError("Invalid bound function name.");
|
|
24536
|
+
if (array(node.args).length > maxArrayLength) throw new TypeError("Bound arguments exceed allocation limit.");
|
|
24537
|
+
if (!absent(node.length) && !(typeof node.length === "number" && node.length >= 0) && !(record3(node.length).kind === "number" && record3(node.length).value === "Infinity"))
|
|
24538
|
+
throw new TypeError("Invalid bound function length.");
|
|
24539
|
+
const visited = /* @__PURE__ */ new Set([raw]);
|
|
24540
|
+
let current = node;
|
|
24541
|
+
while (current.kind === "bound-function") {
|
|
24542
|
+
assertSnapshotDataDepth(visited.size, "<bound-target>");
|
|
24543
|
+
callable(current.target);
|
|
24544
|
+
current = reference(current.target);
|
|
24545
|
+
if (visited.has(current)) throw new TypeError("Cyclic bound function target.");
|
|
24546
|
+
visited.add(current);
|
|
24547
|
+
}
|
|
24548
|
+
state(node.state);
|
|
24511
24549
|
} else if (node.kind === "guest-function") {
|
|
24512
24550
|
fields(node, ["kind", "astNodeId", "scope", "state"], ["name", "environment"]);
|
|
24513
24551
|
if (integer(node.astNodeId) < 1) throw new TypeError("Invalid guest AST identity.");
|
|
@@ -41201,4 +41239,4 @@ export {
|
|
|
41201
41239
|
FileSnapshotBackend,
|
|
41202
41240
|
run
|
|
41203
41241
|
};
|
|
41204
|
-
//# sourceMappingURL=chunk-
|
|
41242
|
+
//# sourceMappingURL=chunk-I3JCUPXR.js.map
|