@poe-platform/safe-js 0.1.215 → 0.1.217
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-VJZDZJ6B.js → chunk-42FLUHBI.js} +2 -2
- package/dist/safe-js/chunks/{chunk-XEABTBIE.js → chunk-F2O4RZOG.js} +82 -14
- package/dist/safe-js/chunks/chunk-F2O4RZOG.js.map +7 -0
- 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/budget.d.ts +1 -0
- package/dist/safe-js/interp/generator-expression-state.d.ts +12 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-XEABTBIE.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-VJZDZJ6B.js.map → chunk-42FLUHBI.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-F2O4RZOG.js";
|
|
31
31
|
|
|
32
32
|
// packages/safe-js/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8249,4 +8249,4 @@ export {
|
|
|
8249
8249
|
parseMcpConfig,
|
|
8250
8250
|
makeMcpModule
|
|
8251
8251
|
};
|
|
8252
|
-
//# sourceMappingURL=chunk-
|
|
8252
|
+
//# sourceMappingURL=chunk-42FLUHBI.js.map
|
|
@@ -191,6 +191,7 @@ var Budget = class {
|
|
|
191
191
|
retainedValueSources = /* @__PURE__ */ new Map();
|
|
192
192
|
compileGeneration = 0;
|
|
193
193
|
activeCompileOwner;
|
|
194
|
+
defaultCompileOwner;
|
|
194
195
|
compileUses = 0;
|
|
195
196
|
provisionalScopes = 0;
|
|
196
197
|
compileTickets = /* @__PURE__ */ new Map();
|
|
@@ -273,7 +274,7 @@ var Budget = class {
|
|
|
273
274
|
throw new SandboxError("reentry");
|
|
274
275
|
}
|
|
275
276
|
if (reset) this.reset();
|
|
276
|
-
const selected = owner ?? Object.freeze({ budget: this, generation: this.compileGeneration });
|
|
277
|
+
const selected = owner ?? (this.defaultCompileOwner ??= Object.freeze({ budget: this, generation: this.compileGeneration }));
|
|
277
278
|
this.activeCompileOwner = selected;
|
|
278
279
|
this.compileUses += 1;
|
|
279
280
|
let released = false;
|
|
@@ -391,6 +392,7 @@ var Budget = class {
|
|
|
391
392
|
reset() {
|
|
392
393
|
if (this.compileUses !== 0) throw new SandboxError("reentry");
|
|
393
394
|
this.compileGeneration += 1;
|
|
395
|
+
this.defaultCompileOwner = void 0;
|
|
394
396
|
this.provisionalScopes = 0;
|
|
395
397
|
this.compileTickets.clear();
|
|
396
398
|
this.completedCompileTickets.clear();
|
|
@@ -8536,7 +8538,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
8536
8538
|
...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
|
|
8537
8539
|
expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
|
|
8538
8540
|
String(id),
|
|
8539
|
-
expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : { kind: "array", values: encode(expression.values), index: expression.index }
|
|
8541
|
+
expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "array" ? { kind: "array", values: encode(expression.values), index: expression.index } : expression.kind === "array-call" ? { kind: "array-call", target: encode(expression.target), method: expression.method, args: encode(expression.args), index: expression.index } : { kind: expression.kind, callee: encode(expression.callee), thisValue: encode(expression.thisValue), args: encode(expression.args), index: expression.index }
|
|
8540
8542
|
]))
|
|
8541
8543
|
},
|
|
8542
8544
|
sent: channel.sent.map((completion) => ({ type: completion.type, value: encode(completion.value) })),
|
|
@@ -9846,7 +9848,7 @@ function typeTag(value, builtinOnly = false) {
|
|
|
9846
9848
|
|
|
9847
9849
|
// packages/safe-js/src/interp/resume-target.ts
|
|
9848
9850
|
function containsResumeTarget(node, targetNodeIds) {
|
|
9849
|
-
if (node.nodeId !== void 0 && targetNodeIds.has(node.nodeId)) {
|
|
9851
|
+
if (targetNodeIds === void 0 ? node.type === "YieldExpression" : node.nodeId !== void 0 && targetNodeIds.has(node.nodeId)) {
|
|
9850
9852
|
return true;
|
|
9851
9853
|
}
|
|
9852
9854
|
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression") {
|
|
@@ -18073,6 +18075,12 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
|
|
|
18073
18075
|
};
|
|
18074
18076
|
}
|
|
18075
18077
|
async function evaluateCallExpression(node, context) {
|
|
18078
|
+
const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
18079
|
+
if (restored?.kind === "call") return evaluateResolvedCallExpression(node, restored.callee, context, restored.thisValue);
|
|
18080
|
+
if (restored?.kind === "array-call") {
|
|
18081
|
+
if (!Array.isArray(restored.target) || !isArrayMethodName(restored.method)) throw new TypeError("Invalid array call continuation.");
|
|
18082
|
+
return evaluateArrayMethodCall(node, restored.target, restored.method, context);
|
|
18083
|
+
}
|
|
18076
18084
|
if (node.callee.type === "Super") {
|
|
18077
18085
|
const construction = context.functionEnvironment?.construction;
|
|
18078
18086
|
if (construction === void 0)
|
|
@@ -18093,12 +18101,15 @@ async function evaluateCallExpression(node, context) {
|
|
|
18093
18101
|
return evaluateResolvedCallExpression(node, callee.value, context);
|
|
18094
18102
|
}
|
|
18095
18103
|
async function evaluateNewExpression(node, context) {
|
|
18096
|
-
const
|
|
18104
|
+
const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
18105
|
+
const callee = restored?.kind === "new" ? { kind: "normal", value: restored.callee } : await evaluateNode(node.callee, context);
|
|
18097
18106
|
if (callee.kind !== "normal") {
|
|
18098
18107
|
return callee;
|
|
18099
18108
|
}
|
|
18100
18109
|
const name = getConstructorName(node.callee);
|
|
18101
|
-
const
|
|
18110
|
+
const call = createCallContinuation(node, callee.value, context);
|
|
18111
|
+
context = call.context;
|
|
18112
|
+
const args = await evaluateCallArguments(node.arguments, context, call.state);
|
|
18102
18113
|
if (!args.ok) {
|
|
18103
18114
|
return args.result;
|
|
18104
18115
|
}
|
|
@@ -18231,6 +18242,12 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
18231
18242
|
...reference,
|
|
18232
18243
|
property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
|
|
18233
18244
|
};
|
|
18245
|
+
if (context.generatorYield !== void 0 && node.arguments.some((argument) => containsResumeTarget(argument.type === "SpreadElement" ? argument.argument : argument))) {
|
|
18246
|
+
if (Array.isArray(member.object) && !hasExplicitSandboxPrototype(member.object) && typeof member.property !== "symbol" && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property))
|
|
18247
|
+
return evaluateArrayMethodCall(node, member.object, member.property, context);
|
|
18248
|
+
const receiver = member.superReceiver?.value ?? member.object;
|
|
18249
|
+
return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context, receiver), context, receiver);
|
|
18250
|
+
}
|
|
18234
18251
|
if (member.superReceiver !== void 0)
|
|
18235
18252
|
return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context, member.superReceiver.value), context, member.superReceiver.value);
|
|
18236
18253
|
if (typeof member.property === "symbol")
|
|
@@ -18395,7 +18412,21 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
|
|
|
18395
18412
|
}
|
|
18396
18413
|
}
|
|
18397
18414
|
async function evaluateArrayMethodCall(node, target, methodName, context) {
|
|
18398
|
-
const
|
|
18415
|
+
const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
18416
|
+
if (restored !== void 0 && (restored.kind !== "array-call" || !Array.isArray(restored.args)))
|
|
18417
|
+
throw new TypeError("Invalid array call continuation.");
|
|
18418
|
+
const state = {
|
|
18419
|
+
kind: "array-call",
|
|
18420
|
+
target,
|
|
18421
|
+
method: methodName,
|
|
18422
|
+
args: restored?.kind === "array-call" ? restored.args : [],
|
|
18423
|
+
index: restored?.kind === "array-call" ? restored.index : 0
|
|
18424
|
+
};
|
|
18425
|
+
if (context.generatorYield !== void 0 && node.nodeId !== void 0) context = {
|
|
18426
|
+
...context,
|
|
18427
|
+
generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, state]])
|
|
18428
|
+
};
|
|
18429
|
+
const args = await evaluateCallArguments(node.arguments, context, state);
|
|
18399
18430
|
if (!args.ok) {
|
|
18400
18431
|
return args.result;
|
|
18401
18432
|
}
|
|
@@ -18941,7 +18972,9 @@ async function evaluateResolvedCallExpression(node, callee, context, thisValue =
|
|
|
18941
18972
|
value: void 0
|
|
18942
18973
|
};
|
|
18943
18974
|
}
|
|
18944
|
-
const
|
|
18975
|
+
const call = createCallContinuation(node, callee, context, thisValue);
|
|
18976
|
+
context = call.context;
|
|
18977
|
+
const args = await evaluateCallArguments(node.arguments, context, call.state);
|
|
18945
18978
|
if (!args.ok) {
|
|
18946
18979
|
return args.result;
|
|
18947
18980
|
}
|
|
@@ -19041,11 +19074,30 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
|
|
|
19041
19074
|
leaveCall();
|
|
19042
19075
|
}
|
|
19043
19076
|
}
|
|
19044
|
-
|
|
19045
|
-
const
|
|
19077
|
+
function createCallContinuation(node, callee, context, thisValue = void 0) {
|
|
19078
|
+
const kind = node.type === "NewExpression" ? "new" : "call";
|
|
19079
|
+
const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
19080
|
+
if (restored !== void 0 && (restored.kind !== "call" && restored.kind !== "new" || restored.kind !== kind || !Array.isArray(restored.args)))
|
|
19081
|
+
throw new TypeError("Invalid call expression continuation.");
|
|
19082
|
+
const state = {
|
|
19083
|
+
kind,
|
|
19084
|
+
callee,
|
|
19085
|
+
thisValue,
|
|
19086
|
+
args: restored?.kind === "call" || restored?.kind === "new" ? restored.args : [],
|
|
19087
|
+
index: restored?.kind === "call" || restored?.kind === "new" ? restored.index : 0
|
|
19088
|
+
};
|
|
19089
|
+
return { state, context: context.generatorYield === void 0 || node.nodeId === void 0 ? context : {
|
|
19090
|
+
...context,
|
|
19091
|
+
generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, state]])
|
|
19092
|
+
} };
|
|
19093
|
+
}
|
|
19094
|
+
async function evaluateCallArguments(args, context, continuation) {
|
|
19095
|
+
const values = continuation?.args ?? [];
|
|
19046
19096
|
const release = retainValues(context.budget, () => values);
|
|
19047
19097
|
try {
|
|
19048
|
-
for (
|
|
19098
|
+
for (let index = continuation?.index ?? 0; index < args.length; index++) {
|
|
19099
|
+
if (continuation !== void 0) continuation.index = index;
|
|
19100
|
+
const arg = args[index];
|
|
19049
19101
|
if (arg.type === "SpreadElement") {
|
|
19050
19102
|
const spreadValues = await evaluateSpreadElement(arg, context);
|
|
19051
19103
|
if (!spreadValues.ok) {
|
|
@@ -22307,6 +22359,16 @@ function validateGuestHeapNode(raw, heap) {
|
|
|
22307
22359
|
fields(expression, ["kind", "values", "index"]);
|
|
22308
22360
|
integer(expression.index);
|
|
22309
22361
|
reference(expression.values, ["array"]);
|
|
22362
|
+
} else if (expression.kind === "call" || expression.kind === "new") {
|
|
22363
|
+
fields(expression, ["kind", "callee", "thisValue", "args", "index"]);
|
|
22364
|
+
integer(expression.index);
|
|
22365
|
+
reference(expression.args, ["array"]);
|
|
22366
|
+
} else if (expression.kind === "array-call") {
|
|
22367
|
+
fields(expression, ["kind", "target", "method", "args", "index"]);
|
|
22368
|
+
if (typeof expression.method !== "string") throw new TypeError("Invalid array method.");
|
|
22369
|
+
integer(expression.index);
|
|
22370
|
+
reference(expression.args, ["array"]);
|
|
22371
|
+
reference(expression.target, ["array"]);
|
|
22310
22372
|
} else throw new TypeError("Invalid expression continuation.");
|
|
22311
22373
|
}
|
|
22312
22374
|
}
|
|
@@ -22411,12 +22473,17 @@ function validateGuestFunctionAst(record3, origin) {
|
|
|
22411
22473
|
yieldExpressions = frame.expressions;
|
|
22412
22474
|
}
|
|
22413
22475
|
for (const [key, value] of Object.entries(node)) {
|
|
22414
|
-
if (node.type === "ArrayExpression" && key === "elements" && typeof node.nodeId === "number" && Array.isArray(value)) {
|
|
22476
|
+
if ((node.type === "ArrayExpression" && key === "elements" || (node.type === "CallExpression" || node.type === "NewExpression") && key === "arguments") && typeof node.nodeId === "number" && Array.isArray(value)) {
|
|
22477
|
+
const kind = node.type === "ArrayExpression" ? "array" : node.type === "CallExpression" ? "call" : "new";
|
|
22415
22478
|
value.forEach((element, index) => pending.push({
|
|
22416
22479
|
value: element,
|
|
22417
22480
|
blocks,
|
|
22418
22481
|
finalizers: frame.finalizers,
|
|
22419
|
-
expressions: new Map([...frame.expressions, [node.nodeId, {
|
|
22482
|
+
expressions: new Map([...frame.expressions, [node.nodeId, {
|
|
22483
|
+
kind,
|
|
22484
|
+
index,
|
|
22485
|
+
member: kind === "call" && node.callee?.type === "MemberExpression"
|
|
22486
|
+
}]])
|
|
22420
22487
|
}));
|
|
22421
22488
|
continue;
|
|
22422
22489
|
}
|
|
@@ -22448,7 +22515,8 @@ function validateGuestFunctionAst(record3, origin) {
|
|
|
22448
22515
|
throw new TypeError("Invalid generator AST identity: missing expression continuation");
|
|
22449
22516
|
for (const [id, expression] of expressions) {
|
|
22450
22517
|
const expected = yieldExpressions?.get(Number(id));
|
|
22451
|
-
|
|
22518
|
+
const compatibleKind = expected?.kind === expression.kind || expected?.kind === "call" && expected.member === true && expression.kind === "array-call";
|
|
22519
|
+
if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.index !== expression.index)
|
|
22452
22520
|
throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
|
|
22453
22521
|
}
|
|
22454
22522
|
}
|
|
@@ -38633,4 +38701,4 @@ export {
|
|
|
38633
38701
|
FileSnapshotBackend,
|
|
38634
38702
|
run
|
|
38635
38703
|
};
|
|
38636
|
-
//# sourceMappingURL=chunk-
|
|
38704
|
+
//# sourceMappingURL=chunk-F2O4RZOG.js.map
|