@poe-platform/safe-js 0.1.237 → 0.1.239

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.
@@ -16681,16 +16681,17 @@ async function evaluateYieldExpression(node, context) {
16681
16681
  if (context.generatorYield === void 0) {
16682
16682
  throw new TypeError("yield is only valid inside a generator.");
16683
16683
  }
16684
- if (context.generatorResume !== void 0 && node.nodeId !== context.generatorResume.yieldNodeId) {
16684
+ if (context.generatorResume !== void 0 && node.nodeId !== context.generatorResume.yieldNodeId && (node.argument === void 0 || !containsResumeTarget(node.argument, /* @__PURE__ */ new Set([context.generatorResume.yieldNodeId])))) {
16685
16685
  return { kind: "normal", hasValue: true, value: void 0 };
16686
16686
  }
16687
16687
  if (node.delegate) {
16688
16688
  return evaluateYieldDelegate(node, context);
16689
16689
  }
16690
- const argument = context.generatorResume !== void 0 || node.argument === void 0 ? { kind: "normal", hasValue: true, value: void 0 } : await evaluateNode(node.argument, context);
16690
+ const argument = context.generatorResume !== void 0 && node.nodeId === context.generatorResume.yieldNodeId || node.argument === void 0 ? { kind: "normal", hasValue: true, value: void 0 } : await evaluateNode(node.argument, context);
16691
16691
  if (argument.kind !== "normal") {
16692
16692
  return argument;
16693
16693
  }
16694
+ if (context.generatorResume?.completed === true) context.generatorResume = void 0;
16694
16695
  const completion = await yieldGeneratorValue(argument.value, node, context);
16695
16696
  if (context.generatorResume !== void 0) context.generatorResume.completed = true;
16696
16697
  context.generatorResume = void 0;
@@ -16716,31 +16717,51 @@ async function yieldGeneratorValue(value, node, context) {
16716
16717
  return completion;
16717
16718
  }
16718
16719
  async function evaluateYieldDelegate(node, context) {
16719
- const argument = await evaluateNode(node.argument, context);
16720
+ const saved = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
16721
+ if (saved !== void 0 && saved.kind !== "yield-delegate") throw new TypeError("Invalid delegated yield continuation.");
16722
+ const argument = saved === void 0 ? await evaluateNode(node.argument, context) : { kind: "normal", hasValue: true, value: saved.value };
16720
16723
  if (argument.kind !== "normal") {
16721
16724
  return argument;
16722
16725
  }
16723
- const iterator = await acquireSandboxIterator(
16726
+ if (context.generatorResume?.completed === true) context.generatorResume = void 0;
16727
+ const iterator = saved === void 0 ? await acquireSandboxIterator(
16724
16728
  argument.value,
16725
16729
  context.budget,
16726
16730
  createCoercionContext(context),
16727
16731
  context.asyncGenerator,
16728
16732
  context.signal
16729
- );
16733
+ ) : "kind" in saved.iterator ? await restoreSandboxIterator(saved.iterator, context.budget, createCoercionContext(context), context.signal) : saved.iterator;
16730
16734
  if (iterator === void 0) {
16731
16735
  throw new TypeError(`${String(argument.value)} is not a supported iterable`);
16732
16736
  }
16737
+ const state = {
16738
+ kind: "yield-delegate",
16739
+ async: context.asyncGenerator === true,
16740
+ value: argument.value,
16741
+ current: saved?.current,
16742
+ iterator
16743
+ };
16744
+ if (node.nodeId !== void 0) context = {
16745
+ ...context,
16746
+ generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, state]])
16747
+ };
16733
16748
  const releaseIterator = retainValues(context.budget, () => [
16734
16749
  argument.value,
16735
- iterator.retainedValue
16750
+ iterator.retainedValue,
16751
+ state.current
16736
16752
  ]);
16737
16753
  try {
16738
16754
  let completion = {
16739
16755
  type: "normal",
16740
16756
  value: void 0
16741
16757
  };
16742
- const replay = context.generatorResume?.sent ?? [];
16758
+ const replay = saved === void 0 ? context.generatorResume?.sent ?? [] : [];
16743
16759
  let replayIndex = 0;
16760
+ if (saved !== void 0) {
16761
+ completion = await yieldGeneratorValue(saved.current, node, context);
16762
+ if (context.generatorResume !== void 0) context.generatorResume.completed = true;
16763
+ context.generatorResume = void 0;
16764
+ }
16744
16765
  while (true) {
16745
16766
  const method = completion.type === "normal" ? "next" : completion.type;
16746
16767
  const iteratorMethod = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
@@ -16773,6 +16794,7 @@ async function evaluateYieldDelegate(node, context) {
16773
16794
  replayIndex += 1;
16774
16795
  continue;
16775
16796
  }
16797
+ state.current = value;
16776
16798
  completion = await yieldGeneratorValue(value, node, context);
16777
16799
  context.generatorResume = void 0;
16778
16800
  }
@@ -21033,7 +21055,12 @@ function captureGuestHeapNode(value, encode) {
21033
21055
  ...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
21034
21056
  expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
21035
21057
  String(id),
21036
- expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "declaration" ? { ...expression } : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "object-pattern" ? {
21058
+ expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "declaration" ? { ...expression } : expression.kind === "yield-delegate" ? {
21059
+ ...expression,
21060
+ value: encode(expression.value),
21061
+ current: encode(expression.current),
21062
+ iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode)
21063
+ } : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "object-pattern" ? {
21037
21064
  kind: "object-pattern",
21038
21065
  phase: expression.phase,
21039
21066
  index: expression.index,
@@ -22712,8 +22739,11 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22712
22739
  if (!absent(expression.key) && typeof expression.key !== "string") reference(expression.key, ["symbol"]);
22713
22740
  if (Object.hasOwn(expression, "referenceObject") && expression.phase !== "binding") throw new TypeError("Invalid prepared object pattern reference.");
22714
22741
  if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
22715
- } else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern") {
22716
- if (expression.kind === "array-pattern") {
22742
+ } else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern" || expression.kind === "yield-delegate") {
22743
+ if (expression.kind === "yield-delegate") {
22744
+ fields(expression, ["kind", "async", "value", "current", "iterator"]);
22745
+ if (typeof expression.async !== "boolean") throw new TypeError("Invalid delegated yield protocol.");
22746
+ } else if (expression.kind === "array-pattern") {
22717
22747
  fields(expression, ["kind", "phase", "index", "done", "current", "iterator"], ["referenceObject", "referenceKey"]);
22718
22748
  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.");
22719
22749
  if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
@@ -22729,7 +22759,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22729
22759
  if (!["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
22730
22760
  reference(expression.scope, ["scope-frame"]);
22731
22761
  }
22732
- integer(expression.index);
22762
+ if (expression.kind !== "yield-delegate") integer(expression.index);
22733
22763
  if (expression.kind === "for-of-array") reference(expression.values, ["array", "guest-array"]);
22734
22764
  else {
22735
22765
  let iterator = record2(expression.iterator);
@@ -22907,7 +22937,7 @@ function validateGuestFunctionAst(record3, origin) {
22907
22937
  if (node.type === "YieldExpression" && node.nodeId === record3.yieldNodeId) {
22908
22938
  yieldBlocks = blocks;
22909
22939
  yieldFinalizers = frame.finalizers;
22910
- yieldExpressions = frame.expressions;
22940
+ yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record3.async === true }]]) : frame.expressions;
22911
22941
  }
22912
22942
  for (const [key, value] of Object.entries(node)) {
22913
22943
  if (node.type === "VariableDeclaration" && key === "declarations" && typeof node.nodeId === "number" && Array.isArray(value)) {
@@ -23012,7 +23042,7 @@ function validateGuestFunctionAst(record3, origin) {
23012
23042
  for (const [id, expression] of expressions) {
23013
23043
  const expected = yieldExpressions?.get(Number(id));
23014
23044
  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";
23015
- if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "pattern-source" && 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 === "object-pattern" && expected.key !== (expression.phase === "key") || 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"))
23045
+ if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "yield-delegate" && expected.kind !== "pattern-source" && 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 === "yield-delegate" && expected.async !== expression.async || (expected.kind === "for" || expected.kind === "for-of") && expected.phase !== expression.phase || expected.kind === "for-in" && expected.phase !== (expression.phase ?? "body") || expected.kind === "object-pattern" && expected.key !== (expression.phase === "key") || 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"))
23016
23046
  throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
23017
23047
  }
23018
23048
  }
@@ -39258,4 +39288,4 @@ export {
39258
39288
  FileSnapshotBackend,
39259
39289
  run
39260
39290
  };
39261
- //# sourceMappingURL=chunk-YXXCUBTE.js.map
39291
+ //# sourceMappingURL=chunk-GM6QCOXT.js.map