@poe-platform/safe-js 0.1.230 → 0.1.232

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.
@@ -3466,7 +3466,7 @@ var Parser = class {
3466
3466
  throw new Error("for await requires an of loop.");
3467
3467
  }
3468
3468
  if (iterationOperator?.value === "in") {
3469
- const left = this.parseForInLeft();
3469
+ const left = this.parseForOfLeft();
3470
3470
  this.expectKeyword("in");
3471
3471
  const right = this.parseExpression().node;
3472
3472
  this.expectPunctuator(")");
@@ -3520,14 +3520,6 @@ var Parser = class {
3520
3520
  };
3521
3521
  });
3522
3522
  }
3523
- parseForInLeft() {
3524
- const left = this.parseForOfLeft();
3525
- const target = left.type === "VariableDeclaration" ? left.declarations[0]?.id : left;
3526
- if (target?.type !== "Identifier") {
3527
- throw new Error("for...in keys are strings; destructure inside the body");
3528
- }
3529
- return left;
3530
- }
3531
3523
  parseForOfLeft() {
3532
3524
  if ((this.currentToken().type === "keyword" || this.currentToken().type === "identifier") && (this.currentToken().value === "const" || this.currentToken().value === "let" || this.currentToken().value === "var")) {
3533
3525
  return this.parseForOfDeclaration();
@@ -9885,7 +9877,7 @@ async function bindAssignmentPattern2(pattern, value, target, scope, context, re
9885
9877
  }
9886
9878
  return bindPattern2(pattern.left, defaultValue.value, target, scope, context, reference);
9887
9879
  }
9888
- async function bindPatternValue(pattern, readValue, target, scope, context) {
9880
+ async function bindPatternValue(pattern, readValue, target, scope, context, onRead) {
9889
9881
  let member = pattern;
9890
9882
  while (member.type === "AssignmentPattern" || member.type === "RestElement")
9891
9883
  member = member.type === "AssignmentPattern" ? member.left : member.argument;
@@ -9899,6 +9891,7 @@ async function bindPatternValue(pattern, readValue, target, scope, context) {
9899
9891
  const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [reference?.object, reference?.key, value]);
9900
9892
  try {
9901
9893
  value = (await readValue()).value;
9894
+ onRead?.(value, reference);
9902
9895
  return await bindPattern2(pattern, value, target, scope, context, reference);
9903
9896
  } finally {
9904
9897
  release();
@@ -9906,7 +9899,10 @@ async function bindPatternValue(pattern, readValue, target, scope, context) {
9906
9899
  }
9907
9900
  async function bindArrayPattern2(pattern, value, target, scope, context) {
9908
9901
  const budget = context.budget ?? new Budget();
9909
- const iterator = await acquireSandboxIterator(
9902
+ const saved = pattern.nodeId === void 0 ? void 0 : context.restoredPatternState?.(pattern.nodeId);
9903
+ if (saved !== void 0 && saved.kind !== "array-pattern") throw new TypeError("Invalid array pattern continuation.");
9904
+ const callContext = context.callContext ?? { stack: [], thisValue: void 0, getProperty: context.getProperty };
9905
+ const iterator = saved === void 0 ? await acquireSandboxIterator(
9910
9906
  value,
9911
9907
  budget,
9912
9908
  context.callContext ?? {
@@ -9914,9 +9910,9 @@ async function bindArrayPattern2(pattern, value, target, scope, context) {
9914
9910
  thisValue: void 0,
9915
9911
  getProperty: context.getProperty
9916
9912
  }
9917
- );
9913
+ ) : "kind" in saved.iterator ? await restoreSandboxIterator(saved.iterator, budget, callContext) : saved.iterator;
9918
9914
  if (iterator === void 0) throw new TypeError("Array destructuring requires an iterable.");
9919
- let done = false;
9915
+ let done = saved?.done ?? false;
9920
9916
  const next = async (readValue = true) => {
9921
9917
  if (done) return { value: void 0 };
9922
9918
  try {
@@ -9931,15 +9927,42 @@ async function bindArrayPattern2(pattern, value, target, scope, context) {
9931
9927
  }
9932
9928
  };
9933
9929
  let retained;
9934
- const release = retainValues(budget, () => [value, iterator.retainedValue, retained]);
9930
+ let continuation;
9931
+ const release = retainValues(budget, () => [
9932
+ value,
9933
+ iterator.retainedValue,
9934
+ retained,
9935
+ continuation?.current,
9936
+ continuation?.referenceObject,
9937
+ continuation?.referenceKey
9938
+ ]);
9935
9939
  try {
9936
- for (let index = 0; index < pattern.elements.length; index += 1) {
9940
+ for (let index = saved?.index ?? 0; index < pattern.elements.length; index += 1) {
9937
9941
  const element = pattern.elements[index];
9938
9942
  if (element === null) {
9939
9943
  await next(false);
9940
9944
  continue;
9941
9945
  }
9942
- const binding = await bindPatternValue(
9946
+ const resuming = saved !== void 0 && index === saved.index;
9947
+ const state = {
9948
+ kind: "array-pattern",
9949
+ phase: "reference",
9950
+ index,
9951
+ done,
9952
+ current: void 0,
9953
+ iterator
9954
+ };
9955
+ if (resuming) Object.assign(state, saved, { iterator });
9956
+ continuation = state;
9957
+ const elementContext = pattern.nodeId === void 0 ? context : context.withPatternState?.(pattern.nodeId, state) ?? context;
9958
+ const binding = resuming && saved.phase === "binding" ? await bindPattern2(
9959
+ element,
9960
+ saved.current,
9961
+ target,
9962
+ scope,
9963
+ elementContext,
9964
+ Object.hasOwn(saved, "referenceObject") ? { object: saved.referenceObject, key: saved.referenceKey } : void 0
9965
+ ) : await bindPatternValue(
9943
9966
  element,
9944
9967
  async () => {
9945
9968
  if (element.type !== "RestElement") return next();
@@ -9953,7 +9976,16 @@ async function bindArrayPattern2(pattern, value, target, scope, context) {
9953
9976
  },
9954
9977
  target,
9955
9978
  scope,
9956
- context
9979
+ elementContext,
9980
+ (current, reference) => {
9981
+ state.phase = "binding";
9982
+ state.current = current;
9983
+ state.done = done;
9984
+ if (reference !== void 0) {
9985
+ state.referenceObject = reference.object;
9986
+ state.referenceKey = reference.key;
9987
+ }
9988
+ }
9957
9989
  );
9958
9990
  if (!binding.ok) {
9959
9991
  if (!done) {
@@ -16116,7 +16148,7 @@ async function evaluateForOfStatement(node, context) {
16116
16148
  }
16117
16149
  });
16118
16150
  if (!resuming || saved.phase === "left") {
16119
- const binding = await bindForOfLoopVariable(node.left, current, scope, phaseContext("left"));
16151
+ const binding = await bindIterationVariable(node.left, current, scope, phaseContext("left"));
16120
16152
  if (!binding.ok) return binding.result;
16121
16153
  }
16122
16154
  const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
@@ -16211,7 +16243,7 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
16211
16243
  });
16212
16244
  let binding;
16213
16245
  try {
16214
- binding = resuming && saved.phase === "body" ? { ok: true } : await bindForOfLoopVariable(node.left, nextValue, scope, phaseContext("left"));
16246
+ binding = resuming && saved.phase === "body" ? { ok: true } : await bindIterationVariable(node.left, nextValue, scope, phaseContext("left"));
16215
16247
  } catch (error) {
16216
16248
  if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
16217
16249
  await closeIterator(iterator, true);
@@ -16266,22 +16298,23 @@ async function evaluateForInStatement(node, context) {
16266
16298
  continue;
16267
16299
  }
16268
16300
  const scope = resuming ? restored.scope : context.scope.child();
16269
- if (!resuming) {
16270
- const binding = await bindForInLoopVariable(node.left, key, scope, context);
16271
- if (!binding.ok) {
16272
- context.activeLoopIterations.delete(node.nodeId ?? -1);
16273
- return binding.result;
16274
- }
16275
- }
16276
- const iterationContext = createLoopIterationContext({
16301
+ const phaseContext = (phase) => ({
16277
16302
  ...context,
16278
16303
  ...context.generatorYield === void 0 || node.nodeId === void 0 ? {} : {
16279
16304
  generatorExpressionStates: new Map([
16280
16305
  ...context.generatorExpressionStates ?? [],
16281
- [node.nodeId, { kind: "for-in", object: right.value, keys, index, scope }]
16306
+ [node.nodeId, { kind: "for-in", phase, object: right.value, keys, index, scope }]
16282
16307
  ])
16283
16308
  }
16284
- }, scope);
16309
+ });
16310
+ if (!resuming || restored.phase === "left") {
16311
+ const binding = await bindIterationVariable(node.left, key, scope, phaseContext("left"));
16312
+ if (!binding.ok) {
16313
+ context.activeLoopIterations.delete(node.nodeId ?? -1);
16314
+ return binding.result;
16315
+ }
16316
+ }
16317
+ const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
16285
16318
  emitLoopIterationBreakpoint(node, iterationContext);
16286
16319
  const result = await evaluateNode(node.body, iterationContext);
16287
16320
  if (isMatchingBreak(result, loopLabels(node))) {
@@ -16349,16 +16382,6 @@ function isPlainForInObject(value) {
16349
16382
  const prototype = Object.getPrototypeOf(value);
16350
16383
  return prototype === Object.prototype || prototype === null;
16351
16384
  }
16352
- async function bindForInLoopVariable(left, key, scope, context) {
16353
- if (left.type === "Identifier") {
16354
- return bindPattern2(left, key, { assign: true }, scope, createPatternContext(context, scope));
16355
- }
16356
- const [declarator] = left.declarations;
16357
- if (left.declarations.length !== 1 || declarator?.id.type !== "Identifier") {
16358
- throw new TypeError("for...in keys are strings; destructure inside the body");
16359
- }
16360
- return bindPattern2(declarator.id, key, { kind: left.kind }, scope, createPatternContext(context, scope));
16361
- }
16362
16385
  function normalEmptyResult() {
16363
16386
  return { kind: "normal", hasValue: false, value: void 0 };
16364
16387
  }
@@ -16537,7 +16560,7 @@ function loopLabels(node) {
16537
16560
  function hasLoopLabel(labels, target) {
16538
16561
  return Array.isArray(labels) ? labels.includes(target) : labels === target;
16539
16562
  }
16540
- async function bindForOfLoopVariable(left, value, scope, context) {
16563
+ async function bindIterationVariable(left, value, scope, context) {
16541
16564
  if (left.type !== "VariableDeclaration") {
16542
16565
  return bindPattern2(left, value, { assign: true }, scope, createPatternContext(context, scope));
16543
16566
  }
@@ -16880,6 +16903,8 @@ function getPropertyValue(target, property, context, receiver = target) {
16880
16903
  function createPatternContext(context, scope = context.scope, evaluate = evaluateNode) {
16881
16904
  const evaluationContext = { ...context, scope };
16882
16905
  return {
16906
+ restoredPatternState: (id) => context.generatorResume === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(id),
16907
+ withPatternState: (id, state) => context.generatorYield === void 0 ? createPatternContext(context, scope, evaluate) : createPatternContext({ ...context, generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [id, state]]) }, scope, evaluate),
16883
16908
  prepareMemberReference: async (pattern) => {
16884
16909
  let reference;
16885
16910
  const result = await evaluateMemberAccess(pattern, evaluationContext, async (member) => {
@@ -20940,7 +20965,15 @@ function captureGuestHeapNode(value, encode) {
20940
20965
  ...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
20941
20966
  expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
20942
20967
  String(id),
20943
- expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "for-of-array" ? { ...expression, values: encode(expression.values), current: encode(expression.current), scope: encode(expression.scope) } : expression.kind === "for-of-iterator" ? {
20968
+ expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "array-pattern" ? {
20969
+ kind: "array-pattern",
20970
+ phase: expression.phase,
20971
+ index: expression.index,
20972
+ done: expression.done,
20973
+ current: encode(expression.current),
20974
+ iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode),
20975
+ ...Object.hasOwn(expression, "referenceObject") ? { referenceObject: encode(expression.referenceObject), referenceKey: encode(expression.referenceKey) } : {}
20976
+ } : expression.kind === "for-of-array" ? { ...expression, values: encode(expression.values), current: encode(expression.current), scope: encode(expression.scope) } : expression.kind === "for-of-iterator" ? {
20944
20977
  ...expression,
20945
20978
  value: encode(expression.value),
20946
20979
  current: encode(expression.current),
@@ -22590,18 +22623,24 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22590
22623
  const expression = record2(raw2);
22591
22624
  if (expression.kind === "binary") {
22592
22625
  fields(expression, ["kind", "left"]);
22593
- } else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator") {
22594
- fields(expression, [
22595
- "kind",
22596
- "phase",
22597
- "current",
22598
- "index",
22599
- "scope",
22600
- ...expression.kind === "for-of-array" ? ["values"] : ["value", "iterator", "async"]
22601
- ]);
22602
- if (!["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
22626
+ } else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern") {
22627
+ if (expression.kind === "array-pattern") {
22628
+ fields(expression, ["kind", "phase", "index", "done", "current", "iterator"], ["referenceObject", "referenceKey"]);
22629
+ if (!["reference", "binding"].includes(String(expression.phase)) || typeof expression.done !== "boolean" || Object.hasOwn(expression, "referenceObject") !== Object.hasOwn(expression, "referenceKey")) throw new TypeError("Invalid array pattern state.");
22630
+ if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
22631
+ } else {
22632
+ fields(expression, [
22633
+ "kind",
22634
+ "phase",
22635
+ "current",
22636
+ "index",
22637
+ "scope",
22638
+ ...expression.kind === "for-of-array" ? ["values"] : ["value", "iterator", "async"]
22639
+ ]);
22640
+ if (!["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
22641
+ reference(expression.scope, ["scope-frame"]);
22642
+ }
22603
22643
  integer(expression.index);
22604
- reference(expression.scope, ["scope-frame"]);
22605
22644
  if (expression.kind === "for-of-array") reference(expression.values, ["array", "guest-array"]);
22606
22645
  else {
22607
22646
  let iterator = record2(expression.iterator);
@@ -22637,10 +22676,11 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22637
22676
  }
22638
22677
  }
22639
22678
  } else throw new TypeError("Invalid iterator continuation.");
22640
- if (expression.async !== protocol) throw new TypeError("Invalid for-of iterator protocol.");
22679
+ if ((expression.kind === "array-pattern" ? false : expression.async) !== protocol) throw new TypeError("Invalid iterator protocol.");
22641
22680
  }
22642
22681
  } else if (expression.kind === "for-in") {
22643
- fields(expression, ["kind", "object", "keys", "index", "scope"]);
22682
+ fields(expression, ["kind", "object", "keys", "index", "scope"], ["phase"]);
22683
+ if (Object.hasOwn(expression, "phase") && !["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-in phase.");
22644
22684
  if (array(expression.keys).some((key) => typeof key !== "string") || integer(expression.index) >= array(expression.keys).length) throw new TypeError("Invalid for-in continuation.");
22645
22685
  reference(expression.scope, ["scope-frame"]);
22646
22686
  } else if (expression.kind === "for") {
@@ -22813,8 +22853,8 @@ function validateGuestFunctionAst(record3, origin) {
22813
22853
  });
22814
22854
  continue;
22815
22855
  }
22816
- if ((node.type === "ArrayExpression" && key === "elements" || node.type === "TemplateLiteral" && key === "expressions" || (node.type === "CallExpression" || node.type === "NewExpression") && key === "arguments") && typeof node.nodeId === "number" && Array.isArray(value)) {
22817
- const kind = node.type === "ArrayExpression" ? "array" : node.type === "TemplateLiteral" ? "template" : node.type === "CallExpression" ? "call" : "new";
22856
+ if (((node.type === "ArrayExpression" || node.type === "ArrayPattern") && key === "elements" || node.type === "TemplateLiteral" && key === "expressions" || (node.type === "CallExpression" || node.type === "NewExpression") && key === "arguments") && typeof node.nodeId === "number" && Array.isArray(value)) {
22857
+ const kind = node.type === "ArrayPattern" ? "array-pattern" : node.type === "ArrayExpression" ? "array" : node.type === "TemplateLiteral" ? "template" : node.type === "CallExpression" ? "call" : "new";
22818
22858
  value.forEach((element, index) => pending.push({
22819
22859
  value: element,
22820
22860
  blocks,
@@ -22830,7 +22870,7 @@ function validateGuestFunctionAst(record3, origin) {
22830
22870
  pending.push({
22831
22871
  value,
22832
22872
  blocks,
22833
- expressions: node.type === "ForOfStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: key, async: node.await === true }]]) : node.type === "ForInStatement" && key === "body" && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-in" }]]) : 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, {
22873
+ expressions: node.type === "ForOfStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: key, async: node.await === true }]]) : node.type === "ForInStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-in", phase: key }]]) : 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, {
22834
22874
  kind: "member-assignment",
22835
22875
  key: node.operator !== "=",
22836
22876
  superReceiver: node.left.object.type === "Super"
@@ -22860,7 +22900,7 @@ function validateGuestFunctionAst(record3, origin) {
22860
22900
  for (const [id, expression] of expressions) {
22861
22901
  const expected = yieldExpressions?.get(Number(id));
22862
22902
  const compatibleKind = expected?.kind === expression.kind || expected?.kind === "for-of" && (expression.kind === "for-of-iterator" || !expected.async && expression.kind === "for-of-array") || expected?.kind === "call" && expected.member === true && expression.kind === "array-call";
22863
- if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "identifier-assignment" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.kind !== "for" && expected.kind !== "for-in" && expected.kind !== "for-of" && expected.index !== expression.index || (expected.kind === "for" || expected.kind === "for-of") && expected.phase !== expression.phase || expected.kind === "for-of" && expression.kind === "for-of-iterator" && expected.async !== expression.async || 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"))
22903
+ if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "identifier-assignment" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.kind !== "for" && expected.kind !== "for-in" && expected.kind !== "for-of" && expected.index !== expression.index || (expected.kind === "for" || expected.kind === "for-of") && expected.phase !== expression.phase || expected.kind === "for-in" && expected.phase !== (expression.phase ?? "body") || expected.kind === "for-of" && expression.kind === "for-of-iterator" && expected.async !== expression.async || 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"))
22864
22904
  throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
22865
22905
  }
22866
22906
  }
@@ -39106,4 +39146,4 @@ export {
39106
39146
  FileSnapshotBackend,
39107
39147
  run
39108
39148
  };
39109
- //# sourceMappingURL=chunk-5SF3QHIJ.js.map
39149
+ //# sourceMappingURL=chunk-CCJSAZ73.js.map