@poe-platform/safe-js 0.1.240 → 0.1.241

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-IIEGYHM4.js";
30
+ } from "./chunk-L2JX3HPQ.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-JD5SV5DJ.js.map
8252
+ //# sourceMappingURL=chunk-DND27FSF.js.map
@@ -16113,48 +16113,67 @@ function predeclareStatementListBindings(statements, context, functionBody = fal
16113
16113
  }
16114
16114
  }
16115
16115
  async function evaluateSwitchStatement(node, context) {
16116
- const discriminant = await evaluateNode(node.discriminant, context);
16116
+ const saved = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
16117
+ if (saved !== void 0 && saved.kind !== "switch") throw new TypeError("Invalid switch continuation.");
16118
+ const discriminant = saved === void 0 ? await evaluateNode(node.discriminant, context) : { kind: "normal", value: saved.value };
16117
16119
  if (discriminant.kind !== "normal") {
16118
16120
  return discriminant;
16119
16121
  }
16120
- const switchContext = { ...context, scope: context.scope.child() };
16121
- predeclareStatementListBindings(
16122
+ const progress = saved === void 0 ? { kind: "switch", phase: "test", index: 0, statementIndex: 0, value: discriminant.value, scope: context.scope.child() } : { ...saved };
16123
+ const switchContext = {
16124
+ ...context,
16125
+ scope: progress.scope,
16126
+ ...context.generatorYield === void 0 || node.nodeId === void 0 ? {} : {
16127
+ generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, progress]])
16128
+ }
16129
+ };
16130
+ if (saved === void 0) predeclareStatementListBindings(
16122
16131
  node.cases.flatMap((switchCase) => switchCase.consequent),
16123
16132
  switchContext
16124
16133
  );
16125
- let defaultIndex;
16126
- let startIndex;
16127
- for (let index = 0; index < node.cases.length; index += 1) {
16128
- const switchCase = node.cases[index];
16129
- if (switchCase.test === void 0) {
16130
- defaultIndex = index;
16131
- continue;
16132
- }
16133
- const test = await evaluateNode(switchCase.test, switchContext);
16134
- if (test.kind !== "normal") {
16135
- return test;
16134
+ const release = retainValues(context.budget, () => [progress.value]);
16135
+ try {
16136
+ const defaultIndex = node.cases.findIndex((entry) => entry.test === void 0);
16137
+ let startIndex = saved?.phase === "body" ? saved.index : void 0;
16138
+ for (let index = progress.index; startIndex === void 0 && index < node.cases.length; index += 1) {
16139
+ const switchCase = node.cases[index];
16140
+ if (switchCase.test === void 0) {
16141
+ continue;
16142
+ }
16143
+ progress.index = index;
16144
+ const test = await evaluateNode(switchCase.test, switchContext);
16145
+ if (test.kind !== "normal") {
16146
+ return test;
16147
+ }
16148
+ if (discriminant.value === test.value) {
16149
+ startIndex = index;
16150
+ break;
16151
+ }
16136
16152
  }
16137
- if (discriminant.value === test.value) {
16138
- startIndex = index;
16139
- break;
16153
+ startIndex ??= defaultIndex < 0 ? void 0 : defaultIndex;
16154
+ if (startIndex === void 0) {
16155
+ return normalEmptyResult();
16140
16156
  }
16141
- }
16142
- startIndex ??= defaultIndex;
16143
- if (startIndex === void 0) {
16144
- return normalEmptyResult();
16145
- }
16146
- for (let caseIndex = startIndex; caseIndex < node.cases.length; caseIndex += 1) {
16147
- for (const statement of node.cases[caseIndex].consequent) {
16148
- const result = await evaluateNode(statement, switchContext);
16149
- if (result.kind === "break" && result.label === void 0) {
16150
- return normalEmptyResult();
16151
- }
16152
- if (result.kind !== "normal") {
16153
- return result;
16157
+ for (let caseIndex = startIndex; caseIndex < node.cases.length; caseIndex += 1) {
16158
+ progress.phase = "body";
16159
+ progress.index = caseIndex;
16160
+ const statements = node.cases[caseIndex].consequent;
16161
+ for (let statementIndex = saved?.phase === "body" && caseIndex === saved.index ? saved.statementIndex : 0; statementIndex < statements.length; statementIndex++) {
16162
+ progress.statementIndex = statementIndex;
16163
+ const statement = statements[statementIndex];
16164
+ const result = await evaluateNode(statement, switchContext);
16165
+ if (result.kind === "break" && result.label === void 0) {
16166
+ return normalEmptyResult();
16167
+ }
16168
+ if (result.kind !== "normal") {
16169
+ return result;
16170
+ }
16154
16171
  }
16155
16172
  }
16173
+ return normalEmptyResult();
16174
+ } finally {
16175
+ release();
16156
16176
  }
16157
- return normalEmptyResult();
16158
16177
  }
16159
16178
  async function evaluateIfStatement(node, context) {
16160
16179
  const test = await evaluateNode(node.test, context);
@@ -21059,7 +21078,7 @@ function captureGuestHeapNode(value, encode) {
21059
21078
  ...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
21060
21079
  expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
21061
21080
  String(id),
21062
- expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "declaration" ? { ...expression } : expression.kind === "yield-delegate" ? {
21081
+ expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "declaration" ? { ...expression } : expression.kind === "switch" ? { ...expression, value: encode(expression.value), scope: encode(expression.scope) } : expression.kind === "yield-delegate" ? {
21063
21082
  ...expression,
21064
21083
  value: encode(expression.value),
21065
21084
  current: encode(expression.current),
@@ -22806,6 +22825,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22806
22825
  if (Object.hasOwn(expression, "phase") && !["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-in phase.");
22807
22826
  if (array(expression.keys).some((key) => typeof key !== "string") || integer(expression.index) >= array(expression.keys).length) throw new TypeError("Invalid for-in continuation.");
22808
22827
  reference(expression.scope, ["scope-frame"]);
22828
+ } else if (expression.kind === "switch") {
22829
+ fields(expression, ["kind", "phase", "index", "statementIndex", "value", "scope"]);
22830
+ if (!["test", "body"].includes(String(expression.phase))) throw new TypeError("Invalid switch phase.");
22831
+ integer(expression.index);
22832
+ integer(expression.statementIndex);
22833
+ if (expression.phase === "test" && expression.statementIndex !== 0) throw new TypeError("Invalid switch test position.");
22834
+ reference(expression.scope, ["scope-frame"]);
22809
22835
  } else if (expression.kind === "for") {
22810
22836
  fields(expression, ["kind", "phase", "loopScope", "activeScope"]);
22811
22837
  if (!["init", "test", "body", "update"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
@@ -22944,6 +22970,24 @@ function validateGuestFunctionAst(record3, origin) {
22944
22970
  yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record3.async === true }]]) : frame.expressions;
22945
22971
  }
22946
22972
  for (const [key, value] of Object.entries(node)) {
22973
+ if (node.type === "SwitchStatement" && key === "cases" && typeof node.nodeId === "number" && Array.isArray(value)) {
22974
+ const id = node.nodeId;
22975
+ value.forEach((entry, index) => {
22976
+ pending.push({
22977
+ value: entry.test,
22978
+ blocks,
22979
+ finalizers: frame.finalizers,
22980
+ expressions: new Map([...frame.expressions, [id, { kind: "switch", phase: "test", index, statementIndex: 0 }]])
22981
+ });
22982
+ entry.consequent.forEach((statement, statementIndex) => pending.push({
22983
+ value: statement,
22984
+ blocks,
22985
+ finalizers: frame.finalizers,
22986
+ expressions: new Map([...frame.expressions, [id, { kind: "switch", phase: "body", index, statementIndex }]])
22987
+ }));
22988
+ });
22989
+ continue;
22990
+ }
22947
22991
  if (node.type === "VariableDeclaration" && key === "declarations" && typeof node.nodeId === "number" && Array.isArray(value)) {
22948
22992
  value.forEach((declarator, index) => pending.push({
22949
22993
  value: declarator,
@@ -23046,7 +23090,7 @@ function validateGuestFunctionAst(record3, origin) {
23046
23090
  for (const [id, expression] of expressions) {
23047
23091
  const expected = yieldExpressions?.get(Number(id));
23048
23092
  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";
23049
- 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"))
23093
+ 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 === "switch" && (expected.phase !== expression.phase || expected.statementIndex !== expression.statementIndex) || (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"))
23050
23094
  throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
23051
23095
  }
23052
23096
  }
@@ -23259,7 +23303,7 @@ function validateDumpReferences(value, path, depth, state, heapIds, heap, role =
23259
23303
  }
23260
23304
  for (const [key, entry] of Object.entries(record3)) {
23261
23305
  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";
23262
- const scopeField = role === "scope-map" || role === "expression" && (record3.kind === "for" && ["loopScope", "activeScope"].includes(key) || ["for-in", "for-of-array", "for-of-iterator"].includes(String(record3.kind)) && key === "scope") || role === "heap-node" && (record3.kind === "scope-frame" && key === "parent" || record3.kind === "guest-function" && key === "scope" || record3.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
23306
+ const scopeField = role === "scope-map" || role === "expression" && (record3.kind === "for" && ["loopScope", "activeScope"].includes(key) || ["switch", "for-in", "for-of-array", "for-of-iterator"].includes(String(record3.kind)) && key === "scope") || role === "heap-node" && (record3.kind === "scope-frame" && key === "parent" || record3.kind === "guest-function" && key === "scope" || record3.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
23263
23307
  validateDumpReferences(entry, `${path}${formatKey(key)}`, depth + 1, state, heapIds, heap, childRole, scopeField);
23264
23308
  }
23265
23309
  }
@@ -39292,4 +39336,4 @@ export {
39292
39336
  FileSnapshotBackend,
39293
39337
  run
39294
39338
  };
39295
- //# sourceMappingURL=chunk-IIEGYHM4.js.map
39339
+ //# sourceMappingURL=chunk-L2JX3HPQ.js.map