@poe-platform/safe-js 0.1.225 → 0.1.227

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.
@@ -8581,7 +8581,7 @@ function captureGuestHeapNode(value, encode) {
8581
8581
  ...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
8582
8582
  expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
8583
8583
  String(id),
8584
- expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "member-assignment" ? {
8584
+ expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "for" ? { kind: "for", phase: expression.phase, loopScope: encode(expression.loopScope), activeScope: encode(expression.activeScope) } : expression.kind === "identifier-assignment" ? { kind: "identifier-assignment", current: encode(expression.current) } : expression.kind === "member-assignment" ? {
8585
8585
  kind: "member-assignment",
8586
8586
  object: encode(expression.object),
8587
8587
  property: encode(expression.property),
@@ -16812,18 +16812,18 @@ async function evaluateBinaryExpression(node, context) {
16812
16812
  }
16813
16813
  async function evaluateAssignmentExpression(node, context) {
16814
16814
  if (node.left.type === "ArrayPattern" || node.left.type === "ObjectPattern") {
16815
- const right2 = await evaluateNode(node.right, context);
16816
- if (right2.kind !== "normal") {
16817
- return right2;
16815
+ const right = await evaluateNode(node.right, context);
16816
+ if (right.kind !== "normal") {
16817
+ return right;
16818
16818
  }
16819
- const binding2 = await bindPattern2(node.left, right2.value, { assign: true }, context.scope, createPatternContext(context));
16819
+ const binding2 = await bindPattern2(node.left, right.value, { assign: true }, context.scope, createPatternContext(context));
16820
16820
  if (!binding2.ok) {
16821
16821
  return binding2.result;
16822
16822
  }
16823
16823
  return {
16824
16824
  kind: "normal",
16825
16825
  hasValue: true,
16826
- value: right2.value
16826
+ value: right.value
16827
16827
  };
16828
16828
  }
16829
16829
  if (node.left.type === "MemberExpression") {
@@ -16839,11 +16839,13 @@ async function evaluateAssignmentExpression(node, context) {
16839
16839
  )
16840
16840
  };
16841
16841
  }
16842
- const binding = node.operator === "=" ? void 0 : context.scope.lookup(node.left.name);
16842
+ const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
16843
+ if (restored !== void 0 && restored.kind !== "identifier-assignment") throw new TypeError("Invalid identifier assignment continuation.");
16844
+ const binding = node.operator === "=" || restored !== void 0 ? void 0 : context.scope.lookup(node.left.name);
16843
16845
  if (binding?.found === false) {
16844
16846
  throw new ReferenceError(`Cannot assign to undeclared binding '${node.left.name}'.`);
16845
16847
  }
16846
- const current = binding?.value;
16848
+ const current = restored === void 0 ? binding?.value : restored.current;
16847
16849
  if (node.operator === "&&=" && !isTruthy(current)) {
16848
16850
  return {
16849
16851
  kind: "normal",
@@ -16865,17 +16867,28 @@ async function evaluateAssignmentExpression(node, context) {
16865
16867
  value: current
16866
16868
  };
16867
16869
  }
16868
- const right = await evaluateNode(node.right, { ...context, inferredName: node.left.type === "Identifier" ? node.left.name : void 0 });
16869
- if (right.kind !== "normal") {
16870
- return right;
16870
+ if (context.generatorYield !== void 0 && node.nodeId !== void 0) {
16871
+ context = { ...context, generatorExpressionStates: new Map([
16872
+ ...context.generatorExpressionStates ?? [],
16873
+ [node.nodeId, { kind: "identifier-assignment", current }]
16874
+ ]) };
16875
+ }
16876
+ const release = retainValues(context.budget, () => [current]);
16877
+ try {
16878
+ const right = await evaluateNode(node.right, { ...context, inferredName: node.left.name });
16879
+ if (right.kind !== "normal") {
16880
+ return right;
16881
+ }
16882
+ const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
16883
+ context.scope.assign(node.left.name, value);
16884
+ return {
16885
+ kind: "normal",
16886
+ hasValue: true,
16887
+ value
16888
+ };
16889
+ } finally {
16890
+ release();
16871
16891
  }
16872
- const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
16873
- context.scope.assign(node.left.name, value);
16874
- return {
16875
- kind: "normal",
16876
- hasValue: true,
16877
- value
16878
- };
16879
16892
  }
16880
16893
  async function evaluateMemberAssignmentExpression(node, context) {
16881
16894
  if (node.left.type !== "MemberExpression") {
@@ -17633,14 +17646,27 @@ function normalEmptyResult() {
17633
17646
  return { kind: "normal", hasValue: false, value: void 0 };
17634
17647
  }
17635
17648
  async function evaluateForStatement(node, context) {
17636
- const loopScope = context.scope.child();
17649
+ const restored = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
17650
+ if (restored !== void 0 && restored.kind !== "for") throw new TypeError("Invalid for-loop continuation.");
17651
+ let resumePhase = restored?.phase;
17652
+ const loopScope = restored?.loopScope ?? context.scope.child();
17637
17653
  const loopBindingNames = getForStatementBindingNames(node);
17638
17654
  const loopContext = {
17639
17655
  ...context,
17640
17656
  scope: loopScope
17641
17657
  };
17642
- if (node.init !== void 0) {
17643
- const init = await evaluateNode(node.init, loopContext);
17658
+ const phaseContext = (phase, scope) => ({
17659
+ ...loopContext,
17660
+ scope,
17661
+ ...context.generatorYield === void 0 || node.nodeId === void 0 ? {} : {
17662
+ generatorExpressionStates: new Map([
17663
+ ...context.generatorExpressionStates ?? [],
17664
+ [node.nodeId, { kind: "for", phase, loopScope, activeScope: scope }]
17665
+ ])
17666
+ }
17667
+ });
17668
+ if (node.init !== void 0 && (resumePhase === void 0 || resumePhase === "init")) {
17669
+ const init = await evaluateNode(node.init, phaseContext("init", loopScope));
17644
17670
  if (init.kind !== "normal") {
17645
17671
  return init;
17646
17672
  }
@@ -17648,8 +17674,8 @@ async function evaluateForStatement(node, context) {
17648
17674
  while (true) {
17649
17675
  context.budget.visitNode();
17650
17676
  context.stats.nodeVisits += 1;
17651
- if (node.test !== void 0) {
17652
- const test = await evaluateNode(node.test, loopContext);
17677
+ if (node.test !== void 0 && resumePhase !== "body" && resumePhase !== "update") {
17678
+ const test = await evaluateNode(node.test, phaseContext("test", loopScope));
17653
17679
  if (test.kind !== "normal") {
17654
17680
  return test;
17655
17681
  }
@@ -17661,28 +17687,24 @@ async function evaluateForStatement(node, context) {
17661
17687
  };
17662
17688
  }
17663
17689
  }
17664
- const iterationScope = loopBindingNames.length === 0 ? loopScope : loopScope.iterationChild(loopBindingNames);
17665
- const iterationContext = {
17666
- ...loopContext,
17667
- ...createLoopIterationContext(loopContext, iterationScope)
17668
- };
17669
- emitLoopIterationBreakpoint(node, iterationContext);
17670
- const result = await evaluateNode(node.body, iterationContext);
17671
- if (isMatchingBreak(result, loopLabels(node))) {
17672
- return {
17673
- kind: "normal",
17674
- hasValue: false,
17675
- value: void 0
17676
- };
17677
- }
17678
- if (result.kind !== "normal" && !isMatchingContinue(result, loopLabels(node))) {
17679
- return result;
17690
+ const iterationScope = resumePhase === "body" || resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? loopScope : loopScope.iterationChild(loopBindingNames);
17691
+ if (resumePhase !== "update") {
17692
+ const iterationContext = createLoopIterationContext(phaseContext("body", iterationScope), iterationScope);
17693
+ emitLoopIterationBreakpoint(node, iterationContext);
17694
+ const result = await evaluateNode(node.body, iterationContext);
17695
+ if (isMatchingBreak(result, loopLabels(node))) {
17696
+ return {
17697
+ kind: "normal",
17698
+ hasValue: false,
17699
+ value: void 0
17700
+ };
17701
+ }
17702
+ if (result.kind !== "normal" && !isMatchingContinue(result, loopLabels(node))) {
17703
+ return result;
17704
+ }
17680
17705
  }
17681
- const updateScope = loopBindingNames.length === 0 ? iterationScope : iterationScope.iterationChild(loopBindingNames);
17682
- const updateContext = {
17683
- ...loopContext,
17684
- scope: updateScope
17685
- };
17706
+ const updateScope = resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? iterationScope : iterationScope.iterationChild(loopBindingNames);
17707
+ const updateContext = phaseContext("update", updateScope);
17686
17708
  if (node.update !== void 0) {
17687
17709
  const update = await evaluateNode(node.update, updateContext);
17688
17710
  if (update.kind !== "normal") {
@@ -17690,6 +17712,7 @@ async function evaluateForStatement(node, context) {
17690
17712
  }
17691
17713
  }
17692
17714
  loopScope.copyInitializedBindingsFrom(updateScope, loopBindingNames);
17715
+ resumePhase = void 0;
17693
17716
  }
17694
17717
  }
17695
17718
  async function evaluateWhileStatement(node, context) {
@@ -22472,6 +22495,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22472
22495
  const expression = record2(raw2);
22473
22496
  if (expression.kind === "binary") {
22474
22497
  fields(expression, ["kind", "left"]);
22498
+ } else if (expression.kind === "for") {
22499
+ fields(expression, ["kind", "phase", "loopScope", "activeScope"]);
22500
+ if (!["init", "test", "body", "update"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
22501
+ reference(expression.loopScope, ["scope-frame"]);
22502
+ reference(expression.activeScope, ["scope-frame"]);
22503
+ } else if (expression.kind === "identifier-assignment") {
22504
+ fields(expression, ["kind", "current"]);
22475
22505
  } else if (expression.kind === "member-assignment") {
22476
22506
  fields(expression, ["kind", "object", "property", "current"], ["key", "superReceiver"]);
22477
22507
  if (Object.hasOwn(expression, "key") && typeof expression.key !== "string") reference(expression.key, ["symbol"]);
@@ -22652,7 +22682,7 @@ function validateGuestFunctionAst(record3, origin) {
22652
22682
  pending.push({
22653
22683
  value,
22654
22684
  blocks,
22655
- expressions: node.type === "BinaryExpression" && key === "right" && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "binary" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "MemberExpression" ? new Map([...frame.expressions, [node.nodeId, {
22685
+ expressions: node.type === "ForStatement" && ["init", "test", "body", "update"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for", phase: key }]]) : node.type === "BinaryExpression" && key === "right" && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "binary" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "Identifier" ? new Map([...frame.expressions, [node.nodeId, { kind: "identifier-assignment" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "MemberExpression" ? new Map([...frame.expressions, [node.nodeId, {
22656
22686
  kind: "member-assignment",
22657
22687
  key: node.operator !== "=",
22658
22688
  superReceiver: node.left.object.type === "Super"
@@ -22682,7 +22712,7 @@ function validateGuestFunctionAst(record3, origin) {
22682
22712
  for (const [id, expression] of expressions) {
22683
22713
  const expected = yieldExpressions?.get(Number(id));
22684
22714
  const compatibleKind = expected?.kind === expression.kind || expected?.kind === "call" && expected.member === true && expression.kind === "array-call";
22685
- if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.index !== expression.index || expected.kind === "member-assignment" && (expected.key !== Object.hasOwn(expression, "key") || expected.superReceiver !== Object.hasOwn(expression, "superReceiver")) || expected.kind === "member" && expected.superReceiver !== Object.hasOwn(expression, "superReceiver") || expected.kind === "object" && expected.key !== Object.hasOwn(expression, "key"))
22715
+ if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "identifier-assignment" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.kind !== "for" && expected.index !== expression.index || expected.kind === "for" && expected.phase !== expression.phase || expected.kind === "member-assignment" && (expected.key !== Object.hasOwn(expression, "key") || expected.superReceiver !== Object.hasOwn(expression, "superReceiver")) || expected.kind === "member" && expected.superReceiver !== Object.hasOwn(expression, "superReceiver") || expected.kind === "object" && expected.key !== Object.hasOwn(expression, "key"))
22686
22716
  throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
22687
22717
  }
22688
22718
  }
@@ -22894,8 +22924,8 @@ function validateDumpReferences(value, path, depth, state, heapIds, heap, role =
22894
22924
  fail("invalidValue", path, "Internal scopes cannot be guest data");
22895
22925
  }
22896
22926
  for (const [key, entry] of Object.entries(record3)) {
22897
- const childRole = role === "root" && key === "heap" ? "heap" : role === "heap" ? "heap-node" : role === "heap-node" && record3.kind === "guest-generator" && key === "blockScopes" ? "scope-map" : "data";
22898
- const scopeField = role === "scope-map" || role === "heap-node" && (record3.kind === "scope-frame" && key === "parent" || record3.kind === "guest-function" && key === "scope" || record3.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
22927
+ const childRole = role === "root" && key === "heap" ? "heap" : role === "heap" ? "heap-node" : role === "heap-node" && record3.kind === "guest-generator" && key === "blockScopes" ? "scope-map" : role === "heap-node" && record3.kind === "guest-generator" && key === "expressionStates" ? "expressions" : role === "expressions" ? "expression" : "data";
22928
+ const scopeField = role === "scope-map" || role === "expression" && record3.kind === "for" && ["loopScope", "activeScope"].includes(key) || role === "heap-node" && (record3.kind === "scope-frame" && key === "parent" || record3.kind === "guest-function" && key === "scope" || record3.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
22899
22929
  validateDumpReferences(entry, `${path}${formatKey(key)}`, depth + 1, state, heapIds, heap, childRole, scopeField);
22900
22930
  }
22901
22931
  }
@@ -38928,4 +38958,4 @@ export {
38928
38958
  FileSnapshotBackend,
38929
38959
  run
38930
38960
  };
38931
- //# sourceMappingURL=chunk-P2JEDD2J.js.map
38961
+ //# sourceMappingURL=chunk-DRN33ZMF.js.map