poe-code 14.0.51 → 14.0.53

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.
Files changed (57) hide show
  1. package/dist/index.js +451 -181
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-bash/dist/browser.js +35 -15
  6. package/packages/safe-bash/dist/browser.js.map +3 -3
  7. package/packages/safe-bash/dist/shell/arrays/state.d.ts +2 -1
  8. package/packages/safe-bash/dist/shell/arrays/state.d.ts.map +1 -1
  9. package/packages/safe-bash/dist/shell/arrays/state.js +23 -5
  10. package/packages/safe-bash/dist/shell/arrays/state.js.map +1 -1
  11. package/packages/safe-bash/dist/shell/cleanup.d.ts.map +1 -1
  12. package/packages/safe-bash/dist/shell/cleanup.js +11 -5
  13. package/packages/safe-bash/dist/shell/cleanup.js.map +1 -1
  14. package/packages/safe-bash/dist/shell/runtime.js +5 -5
  15. package/packages/safe-bash/dist/shell/runtime.js.map +1 -1
  16. package/packages/safe-js/dist/chunks/{chunk-MQU3AETK.js → chunk-4XYGVCOQ.js} +2 -2
  17. package/packages/safe-js/dist/chunks/{chunk-7AIY5C3F.js → chunk-VDFW3EKS.js} +368 -138
  18. package/packages/safe-js/dist/chunks/chunk-VDFW3EKS.js.map +7 -0
  19. package/packages/safe-js/dist/cli.js +2 -2
  20. package/packages/safe-js/dist/core.js +1 -1
  21. package/packages/safe-js/dist/graph-depth.js +10 -4
  22. package/packages/safe-js/dist/index.js +2 -2
  23. package/packages/safe-js/dist/interp/cancel.js +3 -0
  24. package/packages/safe-js/dist/interp/collection-brands.d.ts +5 -0
  25. package/packages/safe-js/dist/interp/collection-brands.js +8 -0
  26. package/packages/safe-js/dist/interp/collection-iterator.d.ts +27 -0
  27. package/packages/safe-js/dist/interp/collection-iterator.js +61 -0
  28. package/packages/safe-js/dist/interp/globals/collections.js +1 -1
  29. package/packages/safe-js/dist/interp/globals/misc.js +3 -2
  30. package/packages/safe-js/dist/interp/globals/object-array.js +2 -2
  31. package/packages/safe-js/dist/interp/globals/object.js +3 -0
  32. package/packages/safe-js/dist/interp/interpreter.js +20 -11
  33. package/packages/safe-js/dist/interp/iteration.d.ts +2 -1
  34. package/packages/safe-js/dist/interp/iteration.js +4 -1
  35. package/packages/safe-js/dist/interp/methods/array.d.ts +12 -3
  36. package/packages/safe-js/dist/interp/methods/array.js +164 -46
  37. package/packages/safe-js/dist/interp/methods/collection-iterator.d.ts +4 -0
  38. package/packages/safe-js/dist/interp/methods/collection-iterator.js +19 -0
  39. package/packages/safe-js/dist/interp/methods/map.js +3 -4
  40. package/packages/safe-js/dist/interp/methods/number.d.ts +2 -2
  41. package/packages/safe-js/dist/interp/methods/number.js +27 -46
  42. package/packages/safe-js/dist/interp/methods/set.js +3 -3
  43. package/packages/safe-js/dist/interp/patterns.d.ts +2 -0
  44. package/packages/safe-js/dist/interp/patterns.js +20 -2
  45. package/packages/safe-js/dist/interp/promise.js +1 -1
  46. package/packages/safe-js/dist/interp/string-coercion.js +4 -0
  47. package/packages/safe-js/dist/interp/values.d.ts +4 -5
  48. package/packages/safe-js/dist/interp/values.js +42 -10
  49. package/packages/safe-js/dist/snapshot/replay-data.d.ts +10 -0
  50. package/packages/safe-js/dist/snapshot/replay-data.js +32 -0
  51. package/packages/safe-js/dist/snapshot/replay-inputs.js +15 -0
  52. package/packages/safe-js/dist/snapshot/restore.js +16 -0
  53. package/packages/safe-js/dist/snapshot/serialize.d.ts +10 -1
  54. package/packages/safe-js/dist/snapshot/serialize.js +25 -9
  55. package/packages/safe-js/dist/snapshot/validation.js +14 -1
  56. package/packages/safe-js/dist/chunks/chunk-7AIY5C3F.js.map +0 -7
  57. /package/packages/safe-js/dist/chunks/{chunk-MQU3AETK.js.map → chunk-4XYGVCOQ.js.map} +0 -0
package/dist/index.js CHANGED
@@ -12249,7 +12249,7 @@ function matchSubsequence(query, text5) {
12249
12249
  const textCharacters = Array.from(text5);
12250
12250
  let previousStates = [];
12251
12251
  for (let queryIndex = 0; queryIndex < queryCharacters.length; queryIndex += 1) {
12252
- const states = [];
12252
+ const states2 = [];
12253
12253
  let offset = 0;
12254
12254
  for (let textIndex = 0; textIndex < textCharacters.length; textIndex += 1) {
12255
12255
  const character2 = textCharacters[textIndex];
@@ -12260,7 +12260,7 @@ function matchSubsequence(query, text5) {
12260
12260
  }
12261
12261
  const positions = character2.length === 2 ? [position, position + 1] : [position];
12262
12262
  if (queryIndex === 0) {
12263
- states[textIndex] = {
12263
+ states2[textIndex] = {
12264
12264
  score: characterScore(textCharacters, textIndex, void 0) + Math.max(0, EARLY_MATCH_BONUS - position),
12265
12265
  positions
12266
12266
  };
@@ -12275,12 +12275,12 @@ function matchSubsequence(query, text5) {
12275
12275
  score: previous.score + characterScore(textCharacters, textIndex, previousIndex),
12276
12276
  positions: [...previous.positions, ...positions]
12277
12277
  };
12278
- if (isBetterMatch(next, states[textIndex])) {
12279
- states[textIndex] = next;
12278
+ if (isBetterMatch(next, states2[textIndex])) {
12279
+ states2[textIndex] = next;
12280
12280
  }
12281
12281
  }
12282
12282
  }
12283
- previousStates = states;
12283
+ previousStates = states2;
12284
12284
  if (!previousStates.some((state) => state !== void 0)) {
12285
12285
  return void 0;
12286
12286
  }
@@ -21524,14 +21524,14 @@ function validateMachine(machine) {
21524
21524
  if (!hasOwnRecordField(machine, "states") || !isStateList(machine.states)) {
21525
21525
  throw new TypeError("State machine states must be a string array.");
21526
21526
  }
21527
- const states = new Set(machine.states);
21527
+ const states2 = new Set(machine.states);
21528
21528
  if (machine.states.some((state) => !hasVisibleName(state))) {
21529
21529
  throw new Error("State names must not be empty.");
21530
21530
  }
21531
21531
  if (!hasOwnRecordField(machine, "initial") || typeof machine.initial !== "string") {
21532
21532
  throw new TypeError("State machine initial must be a string.");
21533
21533
  }
21534
- if (!states.has(machine.initial)) {
21534
+ if (!states2.has(machine.initial)) {
21535
21535
  throw new Error(`Initial state "${machine.initial}" is not declared.`);
21536
21536
  }
21537
21537
  if (!hasOwnRecordField(machine, "events") || !isRecord9(machine.events)) {
@@ -21550,12 +21550,12 @@ function validateMachine(machine) {
21550
21550
  if (!hasOwnRecordField(event, "to") || typeof event.to !== "string") {
21551
21551
  throw new TypeError(`Event "${eventName}" target state must be a string.`);
21552
21552
  }
21553
- if (!states.has(event.to)) {
21553
+ if (!states2.has(event.to)) {
21554
21554
  throw new Error(`Event "${eventName}" references unknown target state "${event.to}".`);
21555
21555
  }
21556
21556
  if (event.from !== "*") {
21557
21557
  for (const fromState of event.from) {
21558
- if (!states.has(fromState)) {
21558
+ if (!states2.has(fromState)) {
21559
21559
  throw new Error(`Event "${eventName}" references unknown source state "${fromState}".`);
21560
21560
  }
21561
21561
  }
@@ -23953,13 +23953,13 @@ async function ghIssuesBackend(deps) {
23953
23953
  }
23954
23954
  function createProjectSession(project, field, labelPrefix) {
23955
23955
  const statusOptions = new Map(field.options.map((option) => [option.name, option.id]));
23956
- const states = field.options.map((option) => option.name);
23956
+ const states2 = field.options.map((option) => option.name);
23957
23957
  const events = Object.fromEntries(
23958
- states.map((state) => [state, Object.freeze({ from: "*", to: state })])
23958
+ states2.map((state) => [state, Object.freeze({ from: "*", to: state })])
23959
23959
  );
23960
23960
  const stateMachine = Object.freeze({
23961
- states: Object.freeze([...states]),
23962
- initial: states[0],
23961
+ states: Object.freeze([...states2]),
23962
+ initial: states2[0],
23963
23963
  events: Object.freeze(events)
23964
23964
  });
23965
23965
  return Object.freeze({
@@ -80210,8 +80210,8 @@ function hasEmptyStringValue(value) {
80210
80210
  }
80211
80211
  return Object.values(value).some((entry) => hasEmptyStringValue(entry));
80212
80212
  }
80213
- function hasOwnState(states, state) {
80214
- return Object.prototype.hasOwnProperty.call(states, state);
80213
+ function hasOwnState(states2, state) {
80214
+ return Object.prototype.hasOwnProperty.call(states2, state);
80215
80215
  }
80216
80216
  function getOwnEntry29(record2, key3) {
80217
80217
  return Object.prototype.hasOwnProperty.call(record2, key3) ? record2[key3] : void 0;
@@ -80245,7 +80245,7 @@ import path98 from "node:path";
80245
80245
  function resolveConfig2(raw, cwd) {
80246
80246
  const rawConfig = isRecord31(raw) ? raw : {};
80247
80247
  const scoped = resolveScope(maestroConfigScope, rawConfig, process.env);
80248
- const { states, stateOrder } = parseStates(getOwnEntry30(rawConfig, "states"));
80248
+ const { states: states2, stateOrder } = parseStates(getOwnEntry30(rawConfig, "states"));
80249
80249
  const polling = scoped.polling;
80250
80250
  const workspace = scoped.workspace;
80251
80251
  const agent3 = scoped.agent;
@@ -80254,9 +80254,9 @@ function resolveConfig2(raw, cwd) {
80254
80254
  }
80255
80255
  return {
80256
80256
  tasks: resolveTasks(getOwnEntry30(rawConfig, "tasks"), cwd),
80257
- states,
80258
- activeStateNames: stateOrder.filter((name) => states[name]?.prompt !== void 0),
80259
- terminalStateNames: stateOrder.filter((name) => states[name]?.terminal === true),
80257
+ states: states2,
80258
+ activeStateNames: stateOrder.filter((name) => states2[name]?.prompt !== void 0),
80259
+ terminalStateNames: stateOrder.filter((name) => states2[name]?.terminal === true),
80260
80260
  stateOrder,
80261
80261
  polling: {
80262
80262
  intervalMs: readPositiveInteger(
@@ -80289,13 +80289,13 @@ function resolveConfig2(raw, cwd) {
80289
80289
  }
80290
80290
  function parseStates(value) {
80291
80291
  validateStateDefinitions(value);
80292
- const states = /* @__PURE__ */ Object.create(null);
80292
+ const states2 = /* @__PURE__ */ Object.create(null);
80293
80293
  const stateOrder = [];
80294
80294
  const entries = value instanceof Map ? value.entries() : Object.entries(value);
80295
80295
  for (const [name, rawDefinition] of entries) {
80296
80296
  const stateName = String(name);
80297
80297
  const definition = rawDefinition;
80298
- Object.defineProperty(states, stateName, {
80298
+ Object.defineProperty(states2, stateName, {
80299
80299
  configurable: true,
80300
80300
  enumerable: true,
80301
80301
  value: parseStateDefinition(definition),
@@ -80303,7 +80303,7 @@ function parseStates(value) {
80303
80303
  });
80304
80304
  stateOrder.push(stateName);
80305
80305
  }
80306
- return { states, stateOrder };
80306
+ return { states: states2, stateOrder };
80307
80307
  }
80308
80308
  function parseStateDefinition(definition) {
80309
80309
  const state = {};
@@ -81573,8 +81573,8 @@ var init_phases = __esm({
81573
81573
  function isRunningPhase(phase) {
81574
81574
  return phase === "running-step";
81575
81575
  }
81576
- function hasOwnState2(states, state) {
81577
- return Object.prototype.hasOwnProperty.call(states, state);
81576
+ function hasOwnState2(states2, state) {
81577
+ return Object.prototype.hasOwnProperty.call(states2, state);
81578
81578
  }
81579
81579
  function isAbortError5(error3) {
81580
81580
  return error3 instanceof Error && error3.name === "AbortError";
@@ -82697,7 +82697,7 @@ function createStateStore(stateDir, fs31 = nodeFs7) {
82697
82697
  }
82698
82698
  throw error3;
82699
82699
  }
82700
- const states = [];
82700
+ const states2 = [];
82701
82701
  for (const entry of [...entries].sort()) {
82702
82702
  if (entry.startsWith(REMOVED_STATE_PREFIX)) {
82703
82703
  continue;
@@ -82716,10 +82716,10 @@ function createStateStore(stateDir, fs31 = nodeFs7) {
82716
82716
  }
82717
82717
  const state = await read(entry);
82718
82718
  if (state !== null) {
82719
- states.push(state);
82719
+ states2.push(state);
82720
82720
  }
82721
82721
  }
82722
- return states;
82722
+ return states2;
82723
82723
  }
82724
82724
  async function remove2(id) {
82725
82725
  const processDir = resolveProcessDir(stateDir, id);
@@ -102105,13 +102105,13 @@ function markApprovalsBuiltIn(group) {
102105
102105
  function isApprovalsBuiltIn(node) {
102106
102106
  return node.kind === "group" && node[approvalsGroupSymbol] === true;
102107
102107
  }
102108
- async function loadApprovals(tasks, states = []) {
102109
- if (states.length === 0) {
102108
+ async function loadApprovals(tasks, states2 = []) {
102109
+ if (states2.length === 0) {
102110
102110
  return tasks.all();
102111
102111
  }
102112
102112
  const seenIds = /* @__PURE__ */ new Set();
102113
102113
  const approvals = [];
102114
- for (const state of states) {
102114
+ for (const state of states2) {
102115
102115
  const matching = await tasks.all({
102116
102116
  state
102117
102117
  });
@@ -125759,6 +125759,84 @@ var init_arguments = __esm({
125759
125759
  }
125760
125760
  });
125761
125761
 
125762
+ // packages/safe-js/src/interp/collection-iterator.ts
125763
+ function isSandboxCollectionIterator(value) {
125764
+ return typeof value === "object" && value !== null && states.has(value);
125765
+ }
125766
+ function createSandboxCollectionIterator(collection, method) {
125767
+ return restoreSandboxCollectionIterator({ collection, collectionKind: collection.kind, method, index: 0, exhausted: false });
125768
+ }
125769
+ function restoreSandboxCollectionIterator(snapshot2, target = /* @__PURE__ */ Object.create(null)) {
125770
+ const { collection, collectionKind, method, index, exhausted } = snapshot2;
125771
+ if (collection !== void 0 && collection.kind !== collectionKind)
125772
+ throw new TypeError("Collection iterator source has the wrong brand.");
125773
+ if (!exhausted && collection === void 0)
125774
+ throw new TypeError("Live collection iterator requires its source collection.");
125775
+ const iterator = exhausted ? void 0 : nativeIterator(collection, method);
125776
+ for (let skipped = 0; skipped < index; skipped += 1) {
125777
+ if (iterator === void 0 || iterator.next().done)
125778
+ throw new TypeError("Collection iterator cursor exceeds its source.");
125779
+ }
125780
+ states.set(target, { collection: exhausted ? void 0 : collection, collectionKind, method, exhausted, iterator });
125781
+ return target;
125782
+ }
125783
+ function collectionIteratorState(value) {
125784
+ const state = states.get(value);
125785
+ if (state === void 0) throw new TypeError("Expected a collection iterator.");
125786
+ return state;
125787
+ }
125788
+ function snapshotCollectionIterator(value) {
125789
+ const state = collectionIteratorState(value);
125790
+ if (state.exhausted) return { ...state, index: 0 };
125791
+ const collection = state.collection;
125792
+ const size = collection.kind === "map" ? collection.entries.size : collection.values.size;
125793
+ let remaining = 0;
125794
+ while (!state.iterator.next().done) remaining += 1;
125795
+ const snapshot2 = { ...state, index: size - remaining };
125796
+ restoreSandboxCollectionIterator(snapshot2, value);
125797
+ return snapshot2;
125798
+ }
125799
+ function nextCollectionIterator(value, budget) {
125800
+ const state = states.get(value);
125801
+ budget?.visitNode();
125802
+ if (state.exhausted) return { value: void 0, done: true };
125803
+ const result = state.iterator.next();
125804
+ if (result.done) {
125805
+ state.exhausted = true;
125806
+ state.collection = void 0;
125807
+ state.iterator = void 0;
125808
+ return { value: void 0, done: true };
125809
+ }
125810
+ if (state.method === "entries") budget?.allocateArrayLength(2);
125811
+ return { value: result.value, done: false };
125812
+ }
125813
+ function nativeIterator(collection, method) {
125814
+ return collection.kind === "map" ? collection.entries[method]() : collection.values[method]();
125815
+ }
125816
+ var states;
125817
+ var init_collection_iterator = __esm({
125818
+ "packages/safe-js/src/interp/collection-iterator.ts"() {
125819
+ "use strict";
125820
+ states = /* @__PURE__ */ new WeakMap();
125821
+ }
125822
+ });
125823
+
125824
+ // packages/safe-js/src/interp/collection-brands.ts
125825
+ function isSandboxMap(value) {
125826
+ return typeof value === "object" && value !== null && sandboxMapBrand in value;
125827
+ }
125828
+ function isSandboxSet(value) {
125829
+ return typeof value === "object" && value !== null && sandboxSetBrand in value;
125830
+ }
125831
+ var sandboxMapBrand, sandboxSetBrand;
125832
+ var init_collection_brands = __esm({
125833
+ "packages/safe-js/src/interp/collection-brands.ts"() {
125834
+ "use strict";
125835
+ sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
125836
+ sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
125837
+ }
125838
+ });
125839
+
125762
125840
  // packages/safe-js/src/graph-depth.ts
125763
125841
  function assertSandboxDataDepth(depth) {
125764
125842
  if (depth > MAX_DATA_DEPTH) {
@@ -125804,16 +125882,19 @@ function graphEntries(value) {
125804
125882
  if (isSandboxArguments(value)) {
125805
125883
  return getSandboxArgumentEntries(value).map(([key3, entry]) => [`.${key3}`, entry]);
125806
125884
  }
125807
- if (value instanceof Map) {
125808
- return [...value.entries()].flatMap(([key3, entry], index) => [
125885
+ const map = isSandboxMap(value) ? value.entries : value instanceof Map ? value : void 0;
125886
+ if (map !== void 0) {
125887
+ return [...map.entries()].flatMap(([key3, entry], index) => [
125809
125888
  [`.<map>[${index}].key`, key3],
125810
125889
  [`.<map>[${index}].value`, entry]
125811
125890
  ]);
125812
125891
  }
125813
- if (value instanceof Set) {
125814
- return [...value.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
125892
+ const set = isSandboxSet(value) ? value.values : value instanceof Set ? value : void 0;
125893
+ if (set !== void 0) {
125894
+ return [...set.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
125815
125895
  }
125816
125896
  const entries = [];
125897
+ if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
125817
125898
  for (const key3 of Object.keys(value)) {
125818
125899
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
125819
125900
  if (descriptor !== void 0 && "value" in descriptor)
@@ -125828,6 +125909,8 @@ var init_graph_depth = __esm({
125828
125909
  init_shape();
125829
125910
  init_budget2();
125830
125911
  init_arguments();
125912
+ init_collection_iterator();
125913
+ init_collection_brands();
125831
125914
  MAX_DATA_DEPTH = 1024;
125832
125915
  SnapshotBudgetError = class extends Error {
125833
125916
  code = "budgetExceeded";
@@ -127159,6 +127242,14 @@ function encodeReplayData(value, options = {}) {
127159
127242
  };
127160
127243
  }
127161
127244
  nodes[id] = { ...storage2, properties, extensible: Object.isExtensible(entry) };
127245
+ } else if (isSandboxCollectionIterator(entry)) {
127246
+ const snapshot2 = snapshotCollectionIterator(entry);
127247
+ const properties = /* @__PURE__ */ Object.create(null);
127248
+ for (const [key3, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(entry))) {
127249
+ if (!("value" in descriptor)) throw new TypeError(`Cannot record replay data accessor '${key3}'.`);
127250
+ properties[key3] = { value: child(descriptor.value, JSON.stringify(["property", key3])), configurable: descriptor.configurable === true, enumerable: descriptor.enumerable === true, writable: descriptor.writable === true };
127251
+ }
127252
+ nodes[id] = { kind: "collection-iterator", collectionKind: snapshot2.collectionKind, method: snapshot2.method, collection: child(snapshot2.collection, "<collection>"), index: snapshot2.index, exhausted: snapshot2.exhausted, properties, extensible: Object.isExtensible(entry) };
127162
127253
  } else if (isSandboxMap(entry)) {
127163
127254
  nodes[id] = {
127164
127255
  kind: "map",
@@ -127217,6 +127308,7 @@ function decodeReplayData(input, options = {}, parent) {
127217
127308
  const graph = record(input);
127218
127309
  const nodes = list(own(graph, "nodes"));
127219
127310
  const restored = /* @__PURE__ */ new Map();
127311
+ const initializeIterators = [];
127220
127312
  const decode = (entry, depth = 0) => {
127221
127313
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
127222
127314
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
@@ -127309,6 +127401,23 @@ function decodeReplayData(input, options = {}, parent) {
127309
127401
  if (!node.extensible) Object.preventExtensions(result3);
127310
127402
  return result3;
127311
127403
  }
127404
+ if (kind === "collection-iterator") {
127405
+ const collectionKind = own(node, "collectionKind");
127406
+ const method = own(node, "method");
127407
+ const index = own(node, "index");
127408
+ const exhausted = own(node, "exhausted");
127409
+ if (collectionKind !== "map" && collectionKind !== "set" || method !== "keys" && method !== "values" && method !== "entries" || typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || typeof exhausted !== "boolean" || typeof node.extensible !== "boolean") throw new TypeError("Invalid replay collection iterator.");
127410
+ const result3 = restoreSandboxCollectionIterator({ collection: void 0, collectionKind, method, index: 0, exhausted: true });
127411
+ restored.set(id, result3);
127412
+ const collection = child(own(node, "collection"));
127413
+ if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid replay collection iterator source.");
127414
+ initializeIterators.push(() => {
127415
+ restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
127416
+ });
127417
+ defineProperties(result3, record(own(node, "properties")), child);
127418
+ if (!node.extensible) Object.preventExtensions(result3);
127419
+ return result3;
127420
+ }
127312
127421
  if (kind === "map") {
127313
127422
  const result3 = createSandboxMap();
127314
127423
  restored.set(id, result3);
@@ -127365,6 +127474,7 @@ function decodeReplayData(input, options = {}, parent) {
127365
127474
  return result2;
127366
127475
  };
127367
127476
  const result = decode(own(graph, "root"));
127477
+ for (const initialize of initializeIterators) initialize();
127368
127478
  if (parent !== void 0) compilation.forward(compilation.tickets, parent);
127369
127479
  return result;
127370
127480
  } finally {
@@ -127407,6 +127517,7 @@ var init_replay_data = __esm({
127407
127517
  "packages/safe-js/src/snapshot/replay-data.ts"() {
127408
127518
  "use strict";
127409
127519
  init_graph_depth();
127520
+ init_collection_iterator();
127410
127521
  init_object_model();
127411
127522
  init_compile_guard();
127412
127523
  init_float32();
@@ -128492,7 +128603,7 @@ async function objectToPrimitive(value, budget, context, joining, hint) {
128492
128603
  }
128493
128604
  }
128494
128605
  function conversionHook(value, name, budget) {
128495
- const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) || isSandboxDate(value) || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxGenerator(value) || isGuestHostObject(value));
128606
+ const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) || isSandboxDate(value) || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxGenerator(value) || isGuestHostObject(value));
128496
128607
  let current = value;
128497
128608
  let depth = 0;
128498
128609
  while (current !== null) {
@@ -128518,6 +128629,7 @@ function conversionHook(value, name, budget) {
128518
128629
  async function defaultToString(value, budget, context, joining) {
128519
128630
  if (isSandboxMap(value)) return "[object Map]";
128520
128631
  if (isSandboxSet(value)) return "[object Set]";
128632
+ if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "[object Map Iterator]" : "[object Set Iterator]";
128521
128633
  if (isSandboxGenerator(value)) return "[object Generator]";
128522
128634
  if (isSandboxRegex(value)) {
128523
128635
  return budget.allocateString(
@@ -128574,6 +128686,7 @@ var init_string_coercion = __esm({
128574
128686
  init_float32();
128575
128687
  init_graph_depth();
128576
128688
  init_host_capabilities();
128689
+ init_collection_iterator();
128577
128690
  init_object_model();
128578
128691
  init_regex();
128579
128692
  init_values();
@@ -129106,7 +129219,8 @@ var init_running_state = __esm({
129106
129219
  });
129107
129220
 
129108
129221
  // packages/safe-js/src/interp/iteration.ts
129109
- function getSandboxIterator(value) {
129222
+ function getSandboxIterator(value, budget) {
129223
+ if (isSandboxCollectionIterator(value)) return { next: () => nextCollectionIterator(value, budget), snapshotIndex: () => 0 };
129110
129224
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
129111
129225
  if (isFloat32Array(value)) {
129112
129226
  return syncIterator(Float32Array.prototype.values.call(value));
@@ -129210,6 +129324,7 @@ var init_iteration = __esm({
129210
129324
  init_running_state();
129211
129325
  init_float32();
129212
129326
  init_host_capabilities();
129327
+ init_collection_iterator();
129213
129328
  }
129214
129329
  });
129215
129330
 
@@ -129684,7 +129799,7 @@ async function settleIterable(iterable, method, budget, constructor, context) {
129684
129799
  const promiseResolve = readPromiseReceiverProperty(constructor, "resolve", prototype);
129685
129800
  if (!isSandboxClosure(promiseResolve))
129686
129801
  throw new TypeError("Promise constructor requires a callable resolve.");
129687
- const iterator = getSandboxIterator(iterable);
129802
+ const iterator = getSandboxIterator(iterable, budget);
129688
129803
  if (iterator === void 0) throw new TypeError("Promise helpers require an iterable.");
129689
129804
  let index = 0;
129690
129805
  while (true) {
@@ -130139,6 +130254,7 @@ function registerCancelablePromises(value, signal) {
130139
130254
  } else if (isSandboxSet(current)) {
130140
130255
  for (const entry of current.values) pending.push(entry);
130141
130256
  } else {
130257
+ if (isSandboxCollectionIterator(current)) pending.push(collectionIteratorState(current).collection);
130142
130258
  for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(current))) {
130143
130259
  if ("value" in descriptor) pending.push(descriptor.value);
130144
130260
  }
@@ -130240,6 +130356,7 @@ var activeCancellation, sandboxPromises, cancelableOutcomes;
130240
130356
  var init_cancel2 = __esm({
130241
130357
  "packages/safe-js/src/interp/cancel.ts"() {
130242
130358
  "use strict";
130359
+ init_collection_iterator();
130243
130360
  init_object_model();
130244
130361
  init_values();
130245
130362
  init_promise_tracker();
@@ -130418,15 +130535,9 @@ function getSandboxRegexPattern(regex) {
130418
130535
  function isSandboxClosure(value) {
130419
130536
  return typeof value === "object" && value !== null && sandboxClosureBrand in value;
130420
130537
  }
130421
- function isSandboxMap(value) {
130422
- return typeof value === "object" && value !== null && sandboxMapBrand in value;
130423
- }
130424
130538
  function isSandboxPromise(value) {
130425
130539
  return typeof value === "object" && value !== null && sandboxPromiseBrand in value;
130426
130540
  }
130427
- function isSandboxSet(value) {
130428
- return typeof value === "object" && value !== null && sandboxSetBrand in value;
130429
- }
130430
130541
  function isSandboxGenerator(value) {
130431
130542
  return typeof value === "object" && value !== null && sandboxGeneratorBrand in value;
130432
130543
  }
@@ -130439,14 +130550,18 @@ function deepCopyToSandbox(value) {
130439
130550
  });
130440
130551
  }
130441
130552
  function cloneSandboxValue(value) {
130442
- return copyToSandbox(
130553
+ const initializeIterators = [];
130554
+ const copy = copyToSandbox(
130443
130555
  value,
130444
130556
  {
130445
- seen: /* @__PURE__ */ new WeakMap()
130557
+ seen: /* @__PURE__ */ new WeakMap(),
130558
+ initializeIterators
130446
130559
  },
130447
130560
  "<root>",
130448
130561
  true
130449
130562
  );
130563
+ for (const initialize of initializeIterators) initialize();
130564
+ return copy;
130450
130565
  }
130451
130566
  function allocateProducedSandboxValue(value, budget) {
130452
130567
  allocateSandboxValue2(value, budget, /* @__PURE__ */ new WeakSet());
@@ -130511,6 +130626,14 @@ function measureSandboxData(values, options = {}) {
130511
130626
  }
130512
130627
  return;
130513
130628
  }
130629
+ if (isSandboxCollectionIterator(value)) {
130630
+ visit(collectionIteratorState(value).collection, depth + 1);
130631
+ for (const [key3, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
130632
+ usage += key3.length + 1;
130633
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
130634
+ }
130635
+ return;
130636
+ }
130514
130637
  if (isSandboxSet(value)) {
130515
130638
  usage += value.values.size;
130516
130639
  for (const entry of value.values) visit(entry, depth + 1);
@@ -130619,6 +130742,24 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
130619
130742
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxRegex(value) || isSandboxPromise(value)) {
130620
130743
  return value;
130621
130744
  }
130745
+ if (isSandboxCollectionIterator(value)) {
130746
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
130747
+ if (!cloneSandboxCollections) return value;
130748
+ const existing = state.seen.get(value);
130749
+ if (existing !== void 0) return existing;
130750
+ const snapshot2 = snapshotCollectionIterator(value);
130751
+ const copy = restoreSandboxCollectionIterator({ ...snapshot2, collection: void 0, index: 0, exhausted: true });
130752
+ state.seen.set(value, copy);
130753
+ const collection = copyToSandbox(snapshot2.collection, state, `${path193}.<collection>`, true, depth + 1);
130754
+ if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid cloned collection iterator source.");
130755
+ state.initializeIterators.push(() => {
130756
+ restoreSandboxCollectionIterator({ ...snapshot2, collection }, copy);
130757
+ });
130758
+ for (const entry of getEnumerableObjectEntries(value, path193)) {
130759
+ defineOwnDataProperty(copy, entry.key, copyToSandbox(entry.value, state, joinPath(path193, entry.key), true, depth + 1));
130760
+ }
130761
+ return copy;
130762
+ }
130622
130763
  if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
130623
130764
  throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
130624
130765
  }
@@ -130874,6 +131015,9 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
130874
131015
  if (isSandboxGenerator(value)) {
130875
131016
  throw new TypeError("Sandbox generators cannot cross into host values.");
130876
131017
  }
131018
+ if (isSandboxCollectionIterator(value)) {
131019
+ throw new TypeError("Sandbox collection iterators cannot cross into host values.");
131020
+ }
130877
131021
  if (isSandboxRegex(value)) {
130878
131022
  throw new TypeError("Invalid sandbox RegExp brand.");
130879
131023
  }
@@ -131099,11 +131243,13 @@ function joinPath(path193, key3) {
131099
131243
  function joinArrayPath(path193, key3) {
131100
131244
  return isArrayIndexKey(key3) ? `${path193}[${key3}]` : joinPath(path193, key3);
131101
131245
  }
131102
- var sandboxClosureBrand, sandboxGeneratorBrand, sandboxMapBrand, sandboxPromiseBrand, sandboxRegexBrand, sandboxRegexPattern, sandboxSetBrand, sandboxRetainedValues;
131246
+ var sandboxClosureBrand, sandboxGeneratorBrand, sandboxPromiseBrand, sandboxRegexBrand, sandboxRegexPattern, sandboxRetainedValues;
131103
131247
  var init_values = __esm({
131104
131248
  "packages/safe-js/src/interp/values.ts"() {
131105
131249
  "use strict";
131106
131250
  init_otel2();
131251
+ init_collection_brands();
131252
+ init_collection_iterator();
131107
131253
  init_date();
131108
131254
  init_host_capabilities();
131109
131255
  init_compile_guard();
@@ -131118,13 +131264,12 @@ var init_values = __esm({
131118
131264
  init_object_model();
131119
131265
  init_arguments();
131120
131266
  init_arguments();
131267
+ init_collection_brands();
131121
131268
  sandboxClosureBrand = /* @__PURE__ */ Symbol("SandboxClosure");
131122
131269
  sandboxGeneratorBrand = /* @__PURE__ */ Symbol("SandboxGenerator");
131123
- sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
131124
131270
  sandboxPromiseBrand = /* @__PURE__ */ Symbol("SandboxPromise");
131125
131271
  sandboxRegexBrand = /* @__PURE__ */ Symbol("SandboxRegex");
131126
131272
  sandboxRegexPattern = /* @__PURE__ */ Symbol("SandboxRegexPattern");
131127
- sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
131128
131273
  sandboxRetainedValues = /* @__PURE__ */ Symbol("SandboxRetainedValues");
131129
131274
  }
131130
131275
  });
@@ -131714,6 +131859,7 @@ function validateTaggedValue(record2, path193, state) {
131714
131859
  case "object":
131715
131860
  case "map":
131716
131861
  case "set":
131862
+ case "collection-iterator":
131717
131863
  return;
131718
131864
  }
131719
131865
  }
@@ -143707,13 +143853,27 @@ async function bindAssignmentPattern2(pattern, value, target, scope, context) {
143707
143853
  return bindPattern2(pattern.left, defaultValue.value, target, scope, context);
143708
143854
  }
143709
143855
  async function bindArrayPattern2(pattern, value, target, scope, context) {
143710
- const values = getArrayPatternValues(value);
143856
+ const iterator = isSandboxCollectionIterator(value) ? value : void 0;
143857
+ const values = iterator === void 0 ? getArrayPatternValues(value) : void 0;
143711
143858
  for (let index = 0; index < pattern.elements.length; index += 1) {
143712
143859
  const element = pattern.elements[index];
143713
143860
  if (element === null) {
143861
+ if (iterator !== void 0) nextCollectionIterator(iterator, context.budget);
143714
143862
  continue;
143715
143863
  }
143716
- const elementValue = element.type === "RestElement" ? values.slice(index) : values[index];
143864
+ let elementValue;
143865
+ if (iterator === void 0) {
143866
+ elementValue = element.type === "RestElement" ? values.slice(index) : values[index];
143867
+ } else if (element.type === "RestElement") {
143868
+ const rest = [];
143869
+ for (let entry = nextCollectionIterator(iterator, context.budget); !entry.done; entry = nextCollectionIterator(iterator, context.budget)) {
143870
+ context.budget?.allocateArrayLength(rest.length + 1);
143871
+ rest.push(entry.value);
143872
+ }
143873
+ elementValue = rest;
143874
+ } else {
143875
+ elementValue = nextCollectionIterator(iterator, context.budget).value;
143876
+ }
143717
143877
  const binding = await bindPattern2(element, elementValue, target, scope, context);
143718
143878
  if (!binding.ok) {
143719
143879
  return binding;
@@ -143845,6 +144005,7 @@ function defineProperty(target, key3, value) {
143845
144005
  var init_patterns = __esm({
143846
144006
  "packages/safe-js/src/interp/patterns.ts"() {
143847
144007
  "use strict";
144008
+ init_collection_iterator();
143848
144009
  init_values();
143849
144010
  }
143850
144011
  });
@@ -143882,7 +144043,7 @@ function getArrayMember(value, property, options) {
143882
144043
  return createSandboxClosure({
143883
144044
  sandbox: true,
143884
144045
  name: `Array#${property}`,
143885
- call: (args, context) => callArrayMethod(value, property, args, options, context?.stack ?? [])
144046
+ call: (args, context) => callArrayMethod(context?.thisValue, property, args, { ...options, context }, context?.stack ?? [])
143886
144047
  });
143887
144048
  }
143888
144049
  return void 0;
@@ -143897,28 +144058,75 @@ function getArrayIndex(property) {
143897
144058
  function isArrayMethodName(property) {
143898
144059
  return typeof property === "string" && arrayMethodNames.has(property);
143899
144060
  }
143900
- async function callArrayMethod(value, methodName, args, options, stack = []) {
143901
- if (isMutatingArrayMethod(methodName)) {
143902
- assertCollectionMutable(value);
143903
- }
143904
- if (isCallbackArrayMethod(methodName)) {
143905
- let callbackState = activeArrayCallbacks.get(value);
143906
- if (callbackState === void 0) {
143907
- callbackState = { depth: 0, leave: enterRunningState(value) };
143908
- activeArrayCallbacks.set(value, callbackState);
144061
+ async function callArrayMethod(receiver, methodName, args, options, stack = []) {
144062
+ if (receiver === null || receiver === void 0) throw new TypeError("Array method requires a receiver.");
144063
+ if (typeof receiver !== "object") throw new TypeError("Object primitive boxing is not supported.");
144064
+ const retainedReceiver = {};
144065
+ options.budget.setRetainedValues(retainedReceiver, () => [receiver]);
144066
+ try {
144067
+ const value = Array.isArray(receiver) || methodName === "concat" ? receiver : await arrayLikeView(receiver, options);
144068
+ if (isMutatingArrayMethod(methodName)) {
144069
+ assertCollectionMutable(receiver);
143909
144070
  }
143910
- callbackState.depth += 1;
143911
- try {
143912
- return await callArrayMethodUnlocked(value, methodName, args, options, stack);
143913
- } finally {
143914
- callbackState.depth -= 1;
143915
- if (callbackState.depth === 0) {
143916
- activeArrayCallbacks.delete(value);
143917
- callbackState.leave();
144071
+ if (isCallbackArrayMethod(methodName)) {
144072
+ let callbackState = activeArrayCallbacks.get(receiver);
144073
+ if (callbackState === void 0) {
144074
+ callbackState = { depth: 0, leave: enterRunningState(receiver) };
144075
+ activeArrayCallbacks.set(receiver, callbackState);
144076
+ }
144077
+ callbackState.depth += 1;
144078
+ try {
144079
+ const result2 = await callArrayMethodUnlocked(value, methodName, args, options, stack);
144080
+ return result2 === value ? receiver : result2;
144081
+ } finally {
144082
+ callbackState.depth -= 1;
144083
+ if (callbackState.depth === 0) {
144084
+ activeArrayCallbacks.delete(receiver);
144085
+ callbackState.leave();
144086
+ }
143918
144087
  }
143919
144088
  }
144089
+ const result = await callArrayMethodUnlocked(value, methodName, args, options, stack);
144090
+ return result === value ? receiver : result;
144091
+ } finally {
144092
+ options.budget.setRetainedValues(retainedReceiver, void 0);
143920
144093
  }
143921
- return callArrayMethodUnlocked(value, methodName, args, options, stack);
144094
+ }
144095
+ async function arrayLikeView(receiver, options) {
144096
+ const rawLength = options.context?.getProperty !== void 0 ? options.context.getProperty(receiver, "length") : getSandboxDataProperty(receiver, "length", options.budget);
144097
+ const number = await sandboxNumber(rawLength, options.budget, options.context);
144098
+ const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
144099
+ const view = new Proxy(/* @__PURE__ */ Object.create(null), {
144100
+ get: (_target, key3) => {
144101
+ options.budget.visitNode();
144102
+ if (key3 === "length") return length;
144103
+ if (typeof key3 !== "string") return void 0;
144104
+ return options.context?.getProperty !== void 0 ? options.context.getProperty(receiver, key3) : getSandboxDataProperty(receiver, key3, options.budget);
144105
+ },
144106
+ has: (_target, key3) => {
144107
+ options.budget.visitNode();
144108
+ if (typeof key3 === "string" && options.hasProperty !== void 0) return options.hasProperty(receiver, key3);
144109
+ for (let current = receiver; current !== null; current = getSandboxPrototype(current, options.budget)) {
144110
+ options.budget.visitNode();
144111
+ if (Object.hasOwn(current, key3)) return true;
144112
+ }
144113
+ return false;
144114
+ },
144115
+ set: (_target, key3, entry) => {
144116
+ options.budget.visitNode();
144117
+ if (typeof key3 !== "string") throw new TypeError("Array indices must be string keys.");
144118
+ if (options.setProperty !== void 0) options.setProperty(receiver, key3, entry);
144119
+ else if (!Reflect.set(receiver, key3, entry)) throw new TypeError(`Cannot assign property '${key3}'.`);
144120
+ return true;
144121
+ },
144122
+ deleteProperty: (_target, key3) => {
144123
+ options.budget.visitNode();
144124
+ if (typeof key3 === "string" && options.deleteProperty !== void 0) return options.deleteProperty(receiver, key3);
144125
+ return Reflect.deleteProperty(receiver, key3);
144126
+ }
144127
+ });
144128
+ arrayLikeSources.set(view, receiver);
144129
+ return view;
143922
144130
  }
143923
144131
  async function callArrayMethodUnlocked(value, methodName, args, options, stack) {
143924
144132
  switch (methodName) {
@@ -144031,11 +144239,21 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
144031
144239
  return Reflect.apply(Array.prototype.lastIndexOf, value, [...args]);
144032
144240
  case "join":
144033
144241
  return options.budget.allocateString(Reflect.apply(Array.prototype.join, value, [...args]));
144034
- case "slice":
144035
- return budgetProducedValue(
144036
- Reflect.apply(Array.prototype.slice, value, [...args]),
144037
- options.budget
144038
- );
144242
+ case "slice": {
144243
+ const length = value.length;
144244
+ const start = toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context));
144245
+ const end = args[1] === void 0 ? length : toIntegerOrInfinity(await sandboxNumber(args[1], options.budget, options.context));
144246
+ const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
144247
+ const final = end < 0 ? Math.max(length + end, 0) : Math.min(end, length);
144248
+ const count = Math.max(final - first, 0);
144249
+ options.budget.allocateArrayLength(count);
144250
+ const result = new Array(count);
144251
+ for (let index = 0; index < count; index += 1) {
144252
+ options.budget.visitNode();
144253
+ if (first + index in value) result[index] = value[first + index];
144254
+ }
144255
+ return budgetProducedValue(result, options.budget);
144256
+ }
144039
144257
  case "concat":
144040
144258
  return budgetProducedValue(
144041
144259
  Reflect.apply(Array.prototype.concat, value, [...args]),
@@ -144062,7 +144280,7 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
144062
144280
  );
144063
144281
  case "sort":
144064
144282
  if (args[0] === void 0) {
144065
- value.sort();
144283
+ Reflect.apply(Array.prototype.sort, value, []);
144066
144284
  budgetProducedValue(value, options.budget);
144067
144285
  return value;
144068
144286
  }
@@ -144070,11 +144288,17 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
144070
144288
  budgetProducedValue(value, options.budget);
144071
144289
  return value;
144072
144290
  case "reverse":
144073
- value.reverse();
144291
+ Reflect.apply(Array.prototype.reverse, value, []);
144074
144292
  budgetProducedValue(value, options.budget);
144075
144293
  return value;
144076
144294
  case "toSorted": {
144077
- const result = Array.from(value);
144295
+ const length = value.length;
144296
+ options.budget.allocateArrayLength(length);
144297
+ const result = new Array(length);
144298
+ for (let index = 0; index < length; index += 1) {
144299
+ options.budget.visitNode();
144300
+ result[index] = value[index];
144301
+ }
144078
144302
  if (args[0] === void 0) {
144079
144303
  result.sort();
144080
144304
  } else {
@@ -144083,13 +144307,29 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
144083
144307
  return budgetProducedValue(result, options.budget);
144084
144308
  }
144085
144309
  case "toReversed": {
144086
- const result = Array.from(value);
144087
- result.reverse();
144310
+ const length = value.length;
144311
+ options.budget.allocateArrayLength(length);
144312
+ const result = new Array(length);
144313
+ for (let index = 0; index < length; index += 1) {
144314
+ options.budget.visitNode();
144315
+ result[index] = value[length - index - 1];
144316
+ }
144088
144317
  return budgetProducedValue(result, options.budget);
144089
144318
  }
144090
144319
  case "toSpliced": {
144091
- const result = Array.from(value);
144092
- Reflect.apply(Array.prototype.splice, result, [...args]);
144320
+ const length = value.length;
144321
+ const start = toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context));
144322
+ const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
144323
+ const inserted = Math.max(args.length - 2, 0);
144324
+ const deleted = args.length === 0 ? 0 : args.length === 1 ? length - first : Math.min(Math.max(toIntegerOrInfinity(await sandboxNumber(args[1], options.budget, options.context)), 0), length - first);
144325
+ const resultLength = length + inserted - deleted;
144326
+ if (resultLength > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
144327
+ options.budget.allocateArrayLength(resultLength);
144328
+ const result = new Array(resultLength);
144329
+ for (let index = 0; index < resultLength; index += 1) {
144330
+ options.budget.visitNode();
144331
+ result[index] = index < first ? value[index] : index < first + inserted ? args[index - first + 2] : value[index - inserted + deleted];
144332
+ }
144093
144333
  return budgetProducedValue(result, options.budget);
144094
144334
  }
144095
144335
  case "with": {
@@ -144103,39 +144343,42 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
144103
144343
  const result = [];
144104
144344
  for (let position = 0; position < length; position += 1) {
144105
144345
  options.budget.visitNode();
144106
- result[position] = position === actualIndex ? args[1] : Object.hasOwn(value, position) ? value[position] : void 0;
144346
+ result[position] = position === actualIndex ? args[1] : Array.isArray(value) && !Object.hasOwn(value, position) ? void 0 : value[position];
144107
144347
  }
144108
144348
  return budgetProducedValue(result, options.budget);
144109
144349
  }
144110
144350
  case "push": {
144111
- appendArrayValues(value, args);
144112
- const nextLength = value.length;
144351
+ const nextLength = appendArrayValues(value, args);
144113
144352
  budgetProducedValue(value, options.budget);
144114
144353
  return nextLength;
144115
144354
  }
144116
144355
  case "pop":
144117
- return budgetProducedValue(value.pop(), options.budget);
144356
+ return budgetProducedValue(Reflect.apply(Array.prototype.pop, value, []), options.budget);
144118
144357
  case "shift":
144119
- return budgetProducedValue(value.shift(), options.budget);
144358
+ return budgetProducedValue(Reflect.apply(Array.prototype.shift, value, []), options.budget);
144120
144359
  case "unshift": {
144121
- prependArrayValues(value, args);
144122
- const nextLength = value.length;
144360
+ const nextLength = prependArrayValues(value, args);
144123
144361
  budgetProducedValue(value, options.budget);
144124
144362
  return nextLength;
144125
144363
  }
144126
144364
  }
144127
144365
  }
144128
144366
  function appendArrayValues(target, values) {
144367
+ let length = target.length;
144368
+ if (length + values.length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
144129
144369
  for (const value of values) {
144130
- target.push(value);
144370
+ target[length++] = value;
144131
144371
  }
144372
+ target.length = length;
144373
+ return length;
144132
144374
  }
144133
144375
  function prependArrayValues(target, values) {
144134
144376
  const originalLength = target.length;
144135
- target.length = originalLength + values.length;
144136
- for (let index = originalLength - 1; index >= 0; index -= 1) {
144377
+ const length = originalLength + values.length;
144378
+ if (length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
144379
+ for (let index = values.length === 0 ? -1 : originalLength - 1; index >= 0; index -= 1) {
144137
144380
  const targetIndex = index + values.length;
144138
- if (Object.hasOwn(target, index)) {
144381
+ if (index in target) {
144139
144382
  target[targetIndex] = target[index];
144140
144383
  } else {
144141
144384
  delete target[targetIndex];
@@ -144144,6 +144387,8 @@ function prependArrayValues(target, values) {
144144
144387
  for (let index = 0; index < values.length; index += 1) {
144145
144388
  target[index] = values[index];
144146
144389
  }
144390
+ target.length = length;
144391
+ return length;
144147
144392
  }
144148
144393
  function isCallbackArrayMethod(methodName) {
144149
144394
  return methodName === "map" || methodName === "filter" || methodName === "find" || methodName === "findIndex" || methodName === "findLast" || methodName === "findLastIndex" || methodName === "some" || methodName === "every" || methodName === "reduce" || methodName === "reduceRight" || methodName === "forEach" || methodName === "flatMap" || methodName === "sort";
@@ -144159,6 +144404,7 @@ function getRequiredCallback(methodName, value) {
144159
144404
  }
144160
144405
  async function mapArray(value, callback, options, stack, thisValue) {
144161
144406
  const length = value.length;
144407
+ options.budget.allocateArrayLength(length);
144162
144408
  const result = new Array(length);
144163
144409
  options.budget.setRetainedValues(result, () => [result]);
144164
144410
  try {
@@ -144304,7 +144550,7 @@ async function reduceFromLeft(value, callback, accumulator, startIndex, length,
144304
144550
  if (!(index in value)) {
144305
144551
  continue;
144306
144552
  }
144307
- current = await options.callClosure(callback, [current, value[index], index, value], stack);
144553
+ current = await options.callClosure(callback, [current, value[index], index, arrayLikeSources.get(value) ?? value], stack);
144308
144554
  }
144309
144555
  return current;
144310
144556
  } finally {
@@ -144321,7 +144567,7 @@ async function reduceFromRight(value, callback, accumulator, startIndex, length,
144321
144567
  if (!(index in value)) {
144322
144568
  continue;
144323
144569
  }
144324
- current = await options.callClosure(callback, [current, value[index], index, value], stack);
144570
+ current = await options.callClosure(callback, [current, value[index], index, arrayLikeSources.get(value) ?? value], stack);
144325
144571
  }
144326
144572
  return current;
144327
144573
  } finally {
@@ -144444,7 +144690,7 @@ async function compareEntries(left, right, comparator, options, stack) {
144444
144690
  return Number.isNaN(result) ? 0 : result;
144445
144691
  }
144446
144692
  async function callArrayCallback(callback, value, index, array, options, stack, thisValue) {
144447
- return options.callClosure(callback, [value, index, array], stack, thisValue);
144693
+ return options.callClosure(callback, [value, index, arrayLikeSources.get(array) ?? array], stack, thisValue);
144448
144694
  }
144449
144695
  function findNextDefinedIndex(value, startIndex, direction, length, budget) {
144450
144696
  for (let index = startIndex; direction > 0 ? index < length : index >= 0; index += direction) {
@@ -144456,6 +144702,7 @@ function findNextDefinedIndex(value, startIndex, direction, length, budget) {
144456
144702
  return -1;
144457
144703
  }
144458
144704
  function budgetProducedValue(value, budget) {
144705
+ if (typeof value === "object" && value !== null) value = arrayLikeSources.get(value) ?? value;
144459
144706
  allocateProducedValue(value, budget, /* @__PURE__ */ new WeakSet());
144460
144707
  return value;
144461
144708
  }
@@ -144519,12 +144766,15 @@ function toIntegerOrInfinity(value) {
144519
144766
  }
144520
144767
  return Math.trunc(number);
144521
144768
  }
144522
- var activeArrayCallbacks, arrayMethodNames;
144769
+ var arrayLikeSources, activeArrayCallbacks, arrayMethodNames;
144523
144770
  var init_array = __esm({
144524
144771
  "packages/safe-js/src/interp/methods/array.ts"() {
144525
144772
  "use strict";
144526
144773
  init_values();
144527
144774
  init_running_state();
144775
+ init_object_model();
144776
+ init_string_coercion();
144777
+ arrayLikeSources = /* @__PURE__ */ new WeakMap();
144528
144778
  activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
144529
144779
  arrayMethodNames = /* @__PURE__ */ new Set([
144530
144780
  "map",
@@ -144771,14 +145021,9 @@ async function callMapMethod(target, methodName, args, options, stack = []) {
144771
145021
  return void 0;
144772
145022
  }
144773
145023
  case "keys":
144774
- return allocateProducedSandboxValue([...target.entries.keys()], options.budget);
144775
145024
  case "values":
144776
- return allocateProducedSandboxValue([...target.entries.values()], options.budget);
144777
145025
  case "entries":
144778
- return allocateProducedSandboxValue(
144779
- [...target.entries].map(([key3, value]) => [key3, value]),
144780
- options.budget
144781
- );
145026
+ return createSandboxCollectionIterator(target, methodName);
144782
145027
  }
144783
145028
  }
144784
145029
  var mapMethodNames;
@@ -144788,6 +145033,7 @@ var init_map = __esm({
144788
145033
  init_values();
144789
145034
  init_running_state();
144790
145035
  init_collection_callback();
145036
+ init_collection_iterator();
144791
145037
  mapMethodNames = /* @__PURE__ */ new Set([
144792
145038
  "get",
144793
145039
  "set",
@@ -144810,68 +145056,48 @@ function getNumberMember(property, budget) {
144810
145056
  return createSandboxClosure({
144811
145057
  sandbox: true,
144812
145058
  name: `Number#${property}`,
144813
- call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget)
145059
+ call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget, context)
144814
145060
  });
144815
145061
  }
144816
145062
  function isNumberMethodName(property) {
144817
145063
  return typeof property === "string" && numberMethodNames.has(property);
144818
145064
  }
144819
- function callNumberMethod(value, methodName, args, budget) {
145065
+ function callNumberMethod(value, methodName, args, budget, context) {
144820
145066
  if (typeof value !== "number") {
144821
145067
  throw new TypeError(`Number#${methodName} requires a number receiver.`);
144822
145068
  }
144823
- return budget.allocateString(callNativeNumberMethod(value, methodName, args));
144824
- }
144825
- function callNativeNumberMethod(value, methodName, args) {
144826
- switch (methodName) {
144827
- case "toString":
144828
- return value.toString(asValidatedRadix(args[0]));
144829
- case "toExponential":
144830
- return args[0] === void 0 ? value.toExponential() : value.toExponential(asValidatedFractionDigits(args[0], methodName));
144831
- case "toFixed":
144832
- return value.toFixed(asValidatedFractionDigits(args[0], methodName));
144833
- case "toPrecision":
144834
- return args[0] === void 0 ? value.toPrecision() : value.toPrecision(asValidatedPrecision(args[0]));
144835
- }
144836
- }
144837
- function asValidatedRadix(value) {
144838
- if (value === void 0) {
144839
- return void 0;
144840
- }
144841
- const radix = toIntegerOrInfinity2(value);
144842
- if (radix < 2 || radix > 36) {
144843
- throw new RangeError("Number#toString radix must be between 2 and 36.");
144844
- }
144845
- return radix;
144846
- }
144847
- function asValidatedFractionDigits(value, methodName) {
144848
- const digits = toIntegerOrInfinity2(value);
144849
- if (digits < 0 || digits > 100) {
144850
- throw new RangeError(`Number#${methodName} digits must be between 0 and 100.`);
145069
+ const argument = args[0];
145070
+ if (argument !== null && typeof argument === "object") {
145071
+ return formatObjectArgument(value, methodName, argument, budget, context);
144851
145072
  }
144852
- return digits;
145073
+ return formatNumber3(value, methodName, argument === void 0 ? void 0 : Number(argument), budget);
144853
145074
  }
144854
- function asValidatedPrecision(value) {
144855
- const precision = toIntegerOrInfinity2(value);
144856
- if (precision < 1 || precision > 100) {
144857
- throw new RangeError("Number#toPrecision precision must be between 1 and 100.");
145075
+ async function formatObjectArgument(value, methodName, argument, budget, context) {
145076
+ const retainedArgument = {};
145077
+ budget.setRetainedValues(retainedArgument, () => [argument]);
145078
+ try {
145079
+ const number = await sandboxNumber(argument, budget, context);
145080
+ return formatNumber3(value, methodName, number, budget);
145081
+ } finally {
145082
+ budget.setRetainedValues(retainedArgument, void 0);
144858
145083
  }
144859
- return precision;
144860
145084
  }
144861
- function toIntegerOrInfinity2(value) {
144862
- const number = Number(value);
144863
- if (Number.isNaN(number) || Object.is(number, 0) || Object.is(number, -0)) {
144864
- return 0;
144865
- }
144866
- if (!Number.isFinite(number)) {
144867
- return number;
145085
+ function formatNumber3(value, methodName, argument, budget) {
145086
+ let result;
145087
+ try {
145088
+ result = value[methodName](argument);
145089
+ } catch (error3) {
145090
+ if (!(error3 instanceof RangeError)) throw error3;
145091
+ const detail = methodName === "toString" ? "radix must be between 2 and 36." : methodName === "toPrecision" ? "precision must be between 1 and 100." : "digits must be between 0 and 100.";
145092
+ throw new RangeError(`Number#${methodName} ${detail}`);
144868
145093
  }
144869
- return Math.trunc(number);
145094
+ return budget.allocateString(result);
144870
145095
  }
144871
145096
  var numberMethodNames;
144872
145097
  var init_number = __esm({
144873
145098
  "packages/safe-js/src/interp/methods/number.ts"() {
144874
145099
  "use strict";
145100
+ init_string_coercion();
144875
145101
  init_values();
144876
145102
  numberMethodNames = /* @__PURE__ */ new Set([
144877
145103
  "toExponential",
@@ -145409,12 +145635,8 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
145409
145635
  }
145410
145636
  case "keys":
145411
145637
  case "values":
145412
- return allocateProducedSandboxValue([...target.values], options.budget);
145413
145638
  case "entries":
145414
- return allocateProducedSandboxValue(
145415
- [...target.values].map((value) => [value, value]),
145416
- options.budget
145417
- );
145639
+ return createSandboxCollectionIterator(target, methodName);
145418
145640
  }
145419
145641
  }
145420
145642
  var setMethodNames;
@@ -145424,6 +145646,7 @@ var init_set = __esm({
145424
145646
  init_values();
145425
145647
  init_running_state();
145426
145648
  init_collection_callback();
145649
+ init_collection_iterator();
145427
145650
  setMethodNames = /* @__PURE__ */ new Set([
145428
145651
  "add",
145429
145652
  "has",
@@ -145616,6 +145839,7 @@ function typeTag(value) {
145616
145839
  if (isSandboxRegex(value)) return "RegExp";
145617
145840
  if (isSandboxMap(value)) return "Map";
145618
145841
  if (isSandboxSet(value)) return "Set";
145842
+ if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "Map Iterator" : "Set Iterator";
145619
145843
  if (isSandboxPromise(value)) return "Promise";
145620
145844
  if (isSandboxGenerator(value)) return "Generator";
145621
145845
  if (isFloat32Array(value)) return "Float32Array";
@@ -145629,6 +145853,7 @@ var init_object2 = __esm({
145629
145853
  init_exceptions();
145630
145854
  init_float32();
145631
145855
  init_host_capabilities();
145856
+ init_collection_iterator();
145632
145857
  init_object_model();
145633
145858
  init_string_coercion();
145634
145859
  init_values();
@@ -145721,7 +145946,7 @@ function isSandboxSetConstructor(value) {
145721
145946
  function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
145722
145947
  budget.allocateCollectionEntries(0);
145723
145948
  if (source === void 0 || source === null) return collection;
145724
- const iterator = getSandboxIterator(source);
145949
+ const iterator = getSandboxIterator(source, budget);
145725
145950
  if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
145726
145951
  let entry;
145727
145952
  let failure;
@@ -145796,6 +146021,30 @@ var init_collections = __esm({
145796
146021
  }
145797
146022
  });
145798
146023
 
146024
+ // packages/safe-js/src/interp/methods/collection-iterator.ts
146025
+ function getCollectionIteratorMember(target, property, budget) {
146026
+ if (Object.hasOwn(target, property)) return target[property];
146027
+ if (property !== "next") return void 0;
146028
+ const { collectionKind } = collectionIteratorState(target);
146029
+ return createSandboxClosure({
146030
+ sandbox: true,
146031
+ name: "next",
146032
+ call: (_args, context) => {
146033
+ const receiver = context?.thisValue;
146034
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
146035
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
146036
+ return nextCollectionIterator(receiver, budget);
146037
+ }
146038
+ });
146039
+ }
146040
+ var init_collection_iterator2 = __esm({
146041
+ "packages/safe-js/src/interp/methods/collection-iterator.ts"() {
146042
+ "use strict";
146043
+ init_collection_iterator();
146044
+ init_values();
146045
+ }
146046
+ });
146047
+
145799
146048
  // packages/safe-js/src/interp/globals/float32array.ts
145800
146049
  function createFloat32ArrayGlobal(budget) {
145801
146050
  const constructor = createSandboxClosure({
@@ -146954,6 +147203,9 @@ function isRestorableBindingValue(value, seen = /* @__PURE__ */ new WeakSet()) {
146954
147203
  }
146955
147204
  if (seen.has(value)) return true;
146956
147205
  seen.add(value);
147206
+ if (isSandboxCollectionIterator(value)) {
147207
+ return isRestorableBindingValue(collectionIteratorState(value).collection, seen);
147208
+ }
146957
147209
  if (isSandboxMap(value)) {
146958
147210
  for (const [key3, entry] of value.entries) {
146959
147211
  if (!isRestorableBindingValue(key3, seen) || !isRestorableBindingValue(entry, seen)) {
@@ -147196,7 +147448,7 @@ async function evaluateForOfStatement(node, context) {
147196
147448
  const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
147197
147449
  if (restored.found && Array.isArray(restored.value)) {
147198
147450
  restoredEntry = { done: false, value: restored.value[1] };
147199
- if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0])) {
147451
+ if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0]) || isSandboxCollectionIterator(restored.value[0])) {
147200
147452
  return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
147201
147453
  }
147202
147454
  }
@@ -147244,7 +147496,7 @@ async function evaluateForOfStatement(node, context) {
147244
147496
  };
147245
147497
  }
147246
147498
  async function evaluateForOfIterator(node, value, context, restoredEntry) {
147247
- const iterator = getSandboxIterator(value);
147499
+ const iterator = getSandboxIterator(value, context.budget);
147248
147500
  if (iterator === void 0) {
147249
147501
  throw new TypeError(`${String(value)} is not a supported iterable`);
147250
147502
  }
@@ -147543,7 +147795,7 @@ function createLoopIterationContext(context, scope) {
147543
147795
  if (context.activeLoopIterations.size === 0) return snapshot2;
147544
147796
  snapshot2.loopIterations = {};
147545
147797
  for (const [nodeId, iteration] of context.activeLoopIterations) {
147546
- if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]))) {
147798
+ if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]) || isSandboxCollectionIterator(iteration.values[0]))) {
147547
147799
  const bindingName = `#for-of:${nodeId}`;
147548
147800
  snapshot2.bindings[bindingName] = iteration.values;
147549
147801
  snapshot2.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
@@ -147670,7 +147922,7 @@ async function evaluateYieldDelegate(node, context) {
147670
147922
  if (argument.kind !== "normal") {
147671
147923
  return argument;
147672
147924
  }
147673
- const iterator = getSandboxIterator(argument.value);
147925
+ const iterator = getSandboxIterator(argument.value, context.budget);
147674
147926
  if (iterator === void 0) {
147675
147927
  throw new TypeError(`${String(argument.value)} is not a supported iterable`);
147676
147928
  }
@@ -147880,6 +148132,7 @@ function getPropertyValue(target, property, context) {
147880
148132
  if (isSandboxDate(target)) return getDateMember(property, context.budget, context.compilation?.owner);
147881
148133
  if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
147882
148134
  if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
148135
+ if (isSandboxCollectionIterator(target)) return getCollectionIteratorMember(target, property, context.budget);
147883
148136
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
147884
148137
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
147885
148138
  if (isSandboxPromise(target)) return getPromiseMember(property, context.budget);
@@ -147892,6 +148145,7 @@ function getPropertyValue(target, property, context) {
147892
148145
  function createPatternContext(context, scope = context.scope, evaluate = evaluateNode2) {
147893
148146
  const evaluationContext = { ...context, scope };
147894
148147
  return {
148148
+ budget: context.budget,
147895
148149
  evaluate: (node) => evaluate(node, evaluationContext),
147896
148150
  toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
147897
148151
  getProperty: (value, key3) => getPropertyValue(value, key3, evaluationContext),
@@ -148399,7 +148653,7 @@ function hasSandboxProperty(value, key3, context) {
148399
148653
  while (typeof current === "object" && current !== null) {
148400
148654
  if (isGuestHostObject(current)) return hasHostObjectMember(current, key3);
148401
148655
  if (hasOwnSandboxProperty(current, key3, false)) return true;
148402
- if (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current)) {
148656
+ if (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current)) {
148403
148657
  return getPropertyValue(current, key3, context) !== void 0;
148404
148658
  }
148405
148659
  current = getSandboxPrototype(current, context.budget);
@@ -148609,7 +148863,7 @@ function getMemberValue(target, property, context) {
148609
148863
  while (typeof current === "object" && current !== null) {
148610
148864
  if (isSandboxClosure(current)) return getClosureMemberValue(current, property, context);
148611
148865
  if (Array.isArray(current)) return getArrayMemberValue(current, property, context);
148612
- if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isFloat32Array(current)) {
148866
+ if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isFloat32Array(current)) {
148613
148867
  return getPropertyValue(current, property, context);
148614
148868
  }
148615
148869
  if (Object.hasOwn(current, String(property))) return current[String(property)];
@@ -148724,7 +148978,7 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
148724
148978
  return {
148725
148979
  kind: "normal",
148726
148980
  hasValue: true,
148727
- value: callNumberMethod(target, methodName, args.value, context.budget)
148981
+ value: await callNumberMethod(target, methodName, args.value, context.budget, createCoercionContext(context))
148728
148982
  };
148729
148983
  } catch (error3) {
148730
148984
  if (isFatalSandboxError(error3)) {
@@ -148736,6 +148990,10 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
148736
148990
  function createArrayMethodOptions(context) {
148737
148991
  return {
148738
148992
  budget: context.budget,
148993
+ context: createCoercionContext(context),
148994
+ hasProperty: (value, property) => hasSandboxProperty(value, property, context),
148995
+ setProperty: (value, property, entry) => setSandboxProperty(value, property, entry, context.budget),
148996
+ deleteProperty: deleteSandboxProperty,
148739
148997
  callClosure: (closure, args, stack, thisValue) => invokeSandboxClosure(closure, args, context, stack, void 0, thisValue)
148740
148998
  };
148741
148999
  }
@@ -148824,7 +149082,7 @@ async function evaluateSpreadElement(node, context) {
148824
149082
  result: value
148825
149083
  };
148826
149084
  }
148827
- const iterator = getSpreadIterator(value.value);
149085
+ const iterator = getSandboxIterator(value.value, context.budget);
148828
149086
  if (iterator === void 0) {
148829
149087
  throw new TypeError("Spread arguments must evaluate to an iterable.");
148830
149088
  }
@@ -148894,9 +149152,6 @@ function describeObjectSpreadValue(value) {
148894
149152
  }
148895
149153
  return typeof value;
148896
149154
  }
148897
- function getSpreadIterator(value) {
148898
- return getSandboxIterator(value);
148899
- }
148900
149155
  async function closeIterator(iterator) {
148901
149156
  if (iterator.generator && iterator.return !== void 0) {
148902
149157
  await iterator.return();
@@ -148960,6 +149215,8 @@ var init_interpreter = __esm({
148960
149215
  init_error();
148961
149216
  init_object2();
148962
149217
  init_collections();
149218
+ init_collection_iterator();
149219
+ init_collection_iterator2();
148963
149220
  init_float32array2();
148964
149221
  init_float32();
148965
149222
  init_date();
@@ -150815,8 +151072,8 @@ function structuredCloneSandboxValue(value, budget) {
150815
151072
  return allocateProducedSandboxValue(clone, budget);
150816
151073
  }
150817
151074
  function assertStructuredCloneable(value, seen) {
150818
- if (isSandboxClosure(value) || isSandboxPromise(value)) {
150819
- throw new TypeError("structuredClone() cannot clone closures or promises.");
151075
+ if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value)) {
151076
+ throw new TypeError("structuredClone() cannot clone closures, promises, or collection iterators.");
150820
151077
  }
150821
151078
  if (typeof value !== "object" || value === null || seen.has(value)) {
150822
151079
  return;
@@ -150842,6 +151099,7 @@ function assertStructuredCloneable(value, seen) {
150842
151099
  var init_misc = __esm({
150843
151100
  "packages/safe-js/src/interp/globals/misc.ts"() {
150844
151101
  "use strict";
151102
+ init_collection_iterator();
150845
151103
  init_graph_depth();
150846
151104
  init_values();
150847
151105
  }
@@ -150951,7 +151209,7 @@ function createObjectArrayGlobals(options) {
150951
151209
  fromEntries: createSandboxClosure({
150952
151210
  sandbox: true,
150953
151211
  call: ([value], context) => {
150954
- const iterator = getSandboxIterator(value);
151212
+ const iterator = getSandboxIterator(value, options.budget);
150955
151213
  if (iterator === void 0) {
150956
151214
  throw new TypeError("Object.fromEntries requires an iterable.");
150957
151215
  }
@@ -151214,7 +151472,7 @@ async function arrayFromSandboxValues(args, budget, context) {
151214
151472
  throw new TypeError("Array.from requires a non-null input.");
151215
151473
  }
151216
151474
  const read = (property) => context?.getProperty !== void 0 ? context.getProperty(items, property) : getSandboxDataProperty(items, property, budget);
151217
- const iterator = getSandboxIterator(items);
151475
+ const iterator = getSandboxIterator(items, budget);
151218
151476
  const constructor = context?.thisValue;
151219
151477
  let result;
151220
151478
  let currentValue;
@@ -152823,6 +153081,7 @@ var init_serialize = __esm({
152823
153081
  "packages/safe-js/src/snapshot/serialize.ts"() {
152824
153082
  "use strict";
152825
153083
  init_hash();
153084
+ init_collection_iterator();
152826
153085
  init_object_model();
152827
153086
  init_shape();
152828
153087
  init_graph_depth();
@@ -152885,6 +153144,16 @@ function prepareReplayInputs(current, saved, preparePromise, onCapabilityRestore
152885
153144
  throw new TypeError("Invalid replay input capability path.");
152886
153145
  let value = current;
152887
153146
  for (const key3 of path193) {
153147
+ if (isSandboxCollectionIterator(value)) {
153148
+ if (key3 === "<collection>") value = collectionIteratorState(value).collection;
153149
+ else {
153150
+ const property = JSON.parse(key3);
153151
+ if (!Array.isArray(property) || property.length !== 2 || property[0] !== "property" || typeof property[1] !== "string") throw new TypeError("Invalid replay input iterator capability path.");
153152
+ const descriptor2 = Object.getOwnPropertyDescriptor(value, property[1]);
153153
+ value = descriptor2 !== void 0 && "value" in descriptor2 ? descriptor2.value : void 0;
153154
+ }
153155
+ continue;
153156
+ }
152888
153157
  if (isSandboxMap(value)) {
152889
153158
  const [kind, ordinal] = key3.split(":");
152890
153159
  const index = Number(ordinal);
@@ -152945,11 +153214,11 @@ function prepareReplayInputs(current, saved, preparePromise, onCapabilityRestore
152945
153214
  return { values: restored, snapshot: structuredClone(saved) };
152946
153215
  }
152947
153216
  function assertReplayInputShape(restored) {
152948
- if (restored === null || typeof restored !== "object" || Array.isArray(restored) || isSandboxClosure(restored) || isSandboxPromise(restored) || isSandboxMap(restored) || isSandboxSet(restored))
153217
+ if (restored === null || typeof restored !== "object" || Array.isArray(restored) || isSandboxClosure(restored) || isSandboxPromise(restored) || isSandboxCollectionIterator(restored) || isSandboxMap(restored) || isSandboxSet(restored))
152949
153218
  throw new TypeError("Invalid replay inputs.");
152950
153219
  const values = restored;
152951
153220
  for (const key3 of ["bindings", "imports"]) {
152952
- if (values[key3] === null || typeof values[key3] !== "object" || Array.isArray(values[key3]) || isSandboxClosure(values[key3]) || isSandboxPromise(values[key3]) || isSandboxMap(values[key3]) || isSandboxSet(values[key3]))
153221
+ if (values[key3] === null || typeof values[key3] !== "object" || Array.isArray(values[key3]) || isSandboxClosure(values[key3]) || isSandboxPromise(values[key3]) || isSandboxCollectionIterator(values[key3]) || isSandboxMap(values[key3]) || isSandboxSet(values[key3]))
152953
153222
  throw new TypeError(`Invalid replay input ${key3}.`);
152954
153223
  }
152955
153224
  if (values.entryPointArgs !== void 0 && !Array.isArray(values.entryPointArgs))
@@ -152959,6 +153228,7 @@ var validationPromise;
152959
153228
  var init_replay_inputs = __esm({
152960
153229
  "packages/safe-js/src/snapshot/replay-inputs.ts"() {
152961
153230
  "use strict";
153231
+ init_collection_iterator();
152962
153232
  init_values();
152963
153233
  init_replay_data();
152964
153234
  init_compile_guard();
@@ -158976,11 +159246,11 @@ async function resolveWorkflowTasksOptions(options) {
158976
159246
  };
158977
159247
  }
158978
159248
  function readGateStates(frontmatter) {
158979
- const states = asRecord6(frontmatter.states);
158980
- if (states === void 0) {
159249
+ const states2 = asRecord6(frontmatter.states);
159250
+ if (states2 === void 0) {
158981
159251
  return [];
158982
159252
  }
158983
- return Object.entries(states).filter(([, definition]) => asRecord6(definition)?.gate === true).map(([name]) => name);
159253
+ return Object.entries(states2).filter(([, definition]) => asRecord6(definition)?.gate === true).map(([name]) => name);
158984
159254
  }
158985
159255
  async function readWorkflowFrontmatter(workflowPath) {
158986
159256
  const workflowContent = await readWorkflow(workflowPath);
@@ -159011,11 +159281,11 @@ function readTaskListOptions(frontmatter, workflowPath) {
159011
159281
  }
159012
159282
  return resolved;
159013
159283
  }
159014
- function createAnyToAnyStateMachine(states) {
159284
+ function createAnyToAnyStateMachine(states2) {
159015
159285
  return {
159016
- initial: states[0],
159017
- states,
159018
- events: Object.fromEntries(states.map((state) => [state, { from: "*", to: state }]))
159286
+ initial: states2[0],
159287
+ states: states2,
159288
+ events: Object.fromEntries(states2.map((state) => [state, { from: "*", to: state }]))
159019
159289
  };
159020
159290
  }
159021
159291
  function parseProject(value) {
@@ -159036,9 +159306,9 @@ function parseProject(value) {
159036
159306
  }
159037
159307
  function resolveRequiredStates(statesOption, frontmatter) {
159038
159308
  if (statesOption !== void 0) {
159039
- const states = parseStatesCsv(statesOption);
159040
- if (states.length > 0) {
159041
- return states;
159309
+ const states2 = parseStatesCsv(statesOption);
159310
+ if (states2.length > 0) {
159311
+ return states2;
159042
159312
  }
159043
159313
  throw new TasksOptionsError(
159044
159314
  "missing_required_states",
@@ -159088,8 +159358,8 @@ function readLegacyTopLevelStates(frontmatter) {
159088
159358
  ]);
159089
159359
  }
159090
159360
  function readDeclaredStates(value) {
159091
- const states = asRecord6(value);
159092
- return states === void 0 ? [] : Object.keys(states);
159361
+ const states2 = asRecord6(value);
159362
+ return states2 === void 0 ? [] : Object.keys(states2);
159093
159363
  }
159094
159364
  function readTasksRepo(frontmatter) {
159095
159365
  const tasks = asRecord6(getOwnEntry37(frontmatter, "tasks"));