@poe-platform/safe-js 0.1.295 → 0.1.297

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.
@@ -7163,11 +7163,28 @@ function nativeIterator(collection, method) {
7163
7163
  return collection.kind === "map" ? collection.entries[method]() : collection.values[method]();
7164
7164
  }
7165
7165
 
7166
- // packages/safe-js/src/interp/regexp-iterator.ts
7166
+ // packages/safe-js/src/interp/array-iterator.ts
7167
7167
  var states2 = /* @__PURE__ */ new WeakMap();
7168
- function isSandboxRegExpIterator(value) {
7168
+ function isSandboxArrayIterator(value) {
7169
7169
  return typeof value === "object" && value !== null && states2.has(value);
7170
7170
  }
7171
+ function restoreSandboxArrayIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7172
+ if (!Number.isSafeInteger(state.index) || state.index < 0 || !["keys", "values", "entries"].includes(state.method) || state.source !== void 0 && (state.source === null || typeof state.source !== "object"))
7173
+ throw new TypeError("Invalid Array iterator state.");
7174
+ states2.set(target, { ...state });
7175
+ return target;
7176
+ }
7177
+ function arrayIteratorState(value) {
7178
+ const state = states2.get(value);
7179
+ if (state === void 0) throw new TypeError("Array iterator next requires an Array iterator receiver.");
7180
+ return state;
7181
+ }
7182
+
7183
+ // packages/safe-js/src/interp/regexp-iterator.ts
7184
+ var states3 = /* @__PURE__ */ new WeakMap();
7185
+ function isSandboxRegExpIterator(value) {
7186
+ return typeof value === "object" && value !== null && states3.has(value);
7187
+ }
7171
7188
  function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7172
7189
  if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
7173
7190
  throw new TypeError("Invalid RegExp iterator modes.");
@@ -7175,11 +7192,11 @@ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.cre
7175
7192
  throw new TypeError("Invalid RegExp iterator matcher.");
7176
7193
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
7177
7194
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
7178
- states2.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
7195
+ states3.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
7179
7196
  return target;
7180
7197
  }
7181
7198
  function regexpIteratorState(value) {
7182
- const state = states2.get(value);
7199
+ const state = states3.get(value);
7183
7200
  if (state === void 0) throw new TypeError("Expected a RegExp string iterator.");
7184
7201
  return state;
7185
7202
  }
@@ -7359,6 +7376,7 @@ function graphEntries(value) {
7359
7376
  }
7360
7377
  const entries = [];
7361
7378
  if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
7379
+ if (isSandboxArrayIterator(value)) entries.push([".<source>", arrayIteratorState(value).source]);
7362
7380
  if (isSandboxRegExpIterator(value)) entries.push([".<matcher>", regexpIteratorState(value).matcher]);
7363
7381
  for (const key of Object.keys(value)) {
7364
7382
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
@@ -9375,6 +9393,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9375
9393
  if (context.getProperty === void 0 || isGuestHostObject(value))
9376
9394
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
9377
9395
  if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9396
+ if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
9378
9397
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9379
9398
  if (isSandboxGenerator(value) && value.async)
9380
9399
  return getSandboxAsyncIterator(value, budget, context, signal);
@@ -9382,6 +9401,11 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9382
9401
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
9383
9402
  }
9384
9403
  const factory = await context.getProperty(value, key);
9404
+ if (!asyncProtocol && factory === void 0 && Array.isArray(value) && !hasExplicitSandboxPrototype(value)) {
9405
+ const installed = getSandboxPropertyDescriptor(value, key, budget)?.value;
9406
+ if (typeof installed === "object" && installed !== null && getIntrinsicIdentity(installed) === JSON.stringify(["Array", "prototype", "values"]))
9407
+ return arrayIterator(value, context, budget);
9408
+ }
9385
9409
  if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
9386
9410
  return getSandboxIterator(value, budget, context);
9387
9411
  }
@@ -10423,6 +10447,33 @@ function createDataCheckpoint(budget, context) {
10423
10447
  };
10424
10448
  }
10425
10449
 
10450
+ // packages/safe-js/src/interp/methods/array-iterator.ts
10451
+ async function nextArrayIterator(value, budget, context) {
10452
+ if (!isSandboxArrayIterator(value)) throw new TypeError("Array iterator next requires an Array iterator receiver.");
10453
+ const state = arrayIteratorState(value);
10454
+ const source = state.source;
10455
+ if (source === void 0) return { value: void 0, done: true };
10456
+ const index = state.index;
10457
+ const release = retainValues(budget, () => [value, source]);
10458
+ const read = (key) => context?.getProperty !== void 0 ? context.getProperty(source, key) : readPropertyDescriptor((isFloat32Array(source) ? Object.getOwnPropertyDescriptor(source, key) : void 0) ?? getSandboxPropertyDescriptor(source, key, budget) ?? { value: void 0 }, source, context);
10459
+ try {
10460
+ budget.visitNode();
10461
+ const number = isFloat32Array(source) ? float32Storage(source).length : await sandboxNumber(await read("length"), budget, context);
10462
+ const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
10463
+ if (index >= length) {
10464
+ state.source = void 0;
10465
+ return { value: void 0, done: true };
10466
+ }
10467
+ state.index = index + 1;
10468
+ if (state.method === "keys") return { value: index, done: false };
10469
+ const entry = await read(String(index));
10470
+ if (state.method === "entries") budget.allocateArrayLength(2);
10471
+ return { value: state.method === "entries" ? [index, entry] : entry, done: false };
10472
+ } finally {
10473
+ release();
10474
+ }
10475
+ }
10476
+
10426
10477
  // packages/safe-js/src/interp/globals/numeric-parsers.ts
10427
10478
  function createNumericParsers(budget) {
10428
10479
  return {
@@ -11608,6 +11659,30 @@ function createPrimitiveConstructor(options, budget) {
11608
11659
  }
11609
11660
 
11610
11661
  // packages/safe-js/src/interp/methods/array.ts
11662
+ async function arraySpeciesCreate(value, length, options) {
11663
+ const receiver = arrayLikeSources.get(value) ?? value;
11664
+ const read = (target, key) => options.context?.getProperty !== void 0 ? options.context.getProperty(target, key) : readPropertyDescriptor(getSandboxPropertyDescriptor(target, key, options.budget) ?? { value: void 0 }, target, options.context);
11665
+ let constructor;
11666
+ if (Array.isArray(receiver)) {
11667
+ constructor = await read(receiver, "constructor");
11668
+ if (typeof constructor === "object" && constructor !== null) {
11669
+ constructor = await read(constructor, Symbol.species);
11670
+ if (constructor === null) constructor = void 0;
11671
+ }
11672
+ if (constructor !== void 0) {
11673
+ if (!isSandboxClosure(constructor) || constructor.construct === void 0)
11674
+ throw new TypeError("Array species must be a constructor.");
11675
+ return await invokeBuiltinClosure(constructor, [length], options.budget, options.context, void 0, true);
11676
+ }
11677
+ }
11678
+ options.budget.allocateArrayLength(length);
11679
+ return new Array(length);
11680
+ }
11681
+ function defineArrayResult(result, index, value, options) {
11682
+ if (index >= Number.MAX_SAFE_INTEGER) throw new TypeError("Array result exceeds the safe integer limit.");
11683
+ if (Array.isArray(result)) options.budget.allocateArrayLength(index + 1);
11684
+ defineOwnDataProperty(objectProperties(result, true), String(index), value);
11685
+ }
11611
11686
  var arrayLikeSources = /* @__PURE__ */ new WeakMap();
11612
11687
  var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
11613
11688
  var localeArrays = /* @__PURE__ */ new WeakSet();
@@ -11887,15 +11962,18 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
11887
11962
  ),
11888
11963
  options.budget
11889
11964
  );
11890
- case "flat":
11965
+ case "flat": {
11966
+ const length = value.length;
11891
11967
  return budgetProducedValue(
11892
11968
  await flattenArray(
11893
11969
  value,
11894
11970
  args[0] === void 0 ? 1 : toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context)),
11895
- options
11971
+ options,
11972
+ length
11896
11973
  ),
11897
11974
  options.budget
11898
11975
  );
11976
+ }
11899
11977
  case "includes":
11900
11978
  case "indexOf":
11901
11979
  case "lastIndexOf": {
@@ -11933,22 +12011,23 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
11933
12011
  const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
11934
12012
  const final = end < 0 ? Math.max(length + end, 0) : Math.min(end, length);
11935
12013
  const count = Math.max(final - first, 0);
11936
- options.budget.allocateArrayLength(count);
11937
- const result = new Array(count);
12014
+ const result = await arraySpeciesCreate(value, count, options);
11938
12015
  const release = retainValues(options.budget, () => [result]);
11939
12016
  try {
11940
12017
  for (let index = 0; index < count; index += 1) {
11941
12018
  options.budget.visitNode();
11942
12019
  if (first + index in value)
11943
- result[index] = await readArrayElement(value, first + index, options);
12020
+ defineArrayResult(result, index, await readArrayElement(value, first + index, options), options);
11944
12021
  }
12022
+ await setSandboxProperty(result, "length", count, options.budget, true, options.context);
11945
12023
  return budgetProducedValue(result, options.budget);
11946
12024
  } finally {
11947
12025
  release();
11948
12026
  }
11949
12027
  }
11950
12028
  case "concat": {
11951
- const result = [];
12029
+ const result = await arraySpeciesCreate(value, 0, options);
12030
+ let targetIndex = 0;
11952
12031
  const retained = {};
11953
12032
  options.budget.setRetainedValues(retained, () => [result]);
11954
12033
  try {
@@ -11959,21 +12038,22 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
11959
12038
  spread = flag === void 0 ? Array.isArray(entry) : Boolean(flag);
11960
12039
  }
11961
12040
  if (!spread) {
11962
- options.budget.allocateArrayLength(result.length + 1);
11963
- result.push(entry);
12041
+ defineArrayResult(result, targetIndex++, entry, options);
11964
12042
  continue;
11965
12043
  }
11966
- const start = result.length;
12044
+ const start = targetIndex;
11967
12045
  const source = await arrayLikeView(entry, options);
11968
12046
  const length = source.length;
11969
- options.budget.allocateArrayLength(start + length);
11970
- result.length += length;
12047
+ if (start + length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array result exceeds the safe integer limit.");
12048
+ if (Array.isArray(result)) options.budget.allocateArrayLength(start + length);
12049
+ targetIndex += length;
11971
12050
  for (let index = 0; index < length; index++) {
11972
12051
  options.budget.visitNode();
11973
12052
  if (index in source)
11974
- result[start + index] = await readArrayElement(source, index, options);
12053
+ defineArrayResult(result, start + index, await readArrayElement(source, index, options), options);
11975
12054
  }
11976
12055
  }
12056
+ await setSandboxProperty(result, "length", targetIndex, options.budget, true, options.context);
11977
12057
  return budgetProducedValue(result, options.budget);
11978
12058
  } finally {
11979
12059
  options.budget.setRetainedValues(retained, void 0);
@@ -11998,16 +12078,16 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
11998
12078
  const nextLength = length + inserted - deleted;
11999
12079
  if (nextLength > Number.MAX_SAFE_INTEGER)
12000
12080
  throw new TypeError("Array-like length exceeds the safe integer limit.");
12001
- options.budget.allocateArrayLength(deleted);
12002
- const removed = new Array(deleted);
12081
+ const removed = await arraySpeciesCreate(value, deleted, options);
12003
12082
  const retained = {};
12004
12083
  options.budget.setRetainedValues(retained, () => [removed]);
12005
12084
  try {
12006
12085
  for (let index = 0; index < deleted; index++) {
12007
12086
  options.budget.visitNode();
12008
12087
  if (first + index in value)
12009
- removed[index] = await readArrayElement(value, first + index, options);
12088
+ defineArrayResult(removed, index, await readArrayElement(value, first + index, options), options);
12010
12089
  }
12090
+ await setSandboxProperty(removed, "length", deleted, options.budget, true, options.context);
12011
12091
  if (inserted < deleted) {
12012
12092
  for (let index = first; index < length - deleted; index++)
12013
12093
  await moveArrayElement(value, index + deleted, index + inserted, options);
@@ -12303,8 +12383,7 @@ async function moveArrayElement(value, from, to, options) {
12303
12383
  }
12304
12384
  async function mapArray(value, callback, options, stack, thisValue) {
12305
12385
  const length = value.length;
12306
- options.budget.allocateArrayLength(length);
12307
- const result = new Array(length);
12386
+ const result = await arraySpeciesCreate(value, length, options);
12308
12387
  options.budget.setRetainedValues(result, () => [result]);
12309
12388
  try {
12310
12389
  for (let index = 0; index < length; index += 1) {
@@ -12312,7 +12391,7 @@ async function mapArray(value, callback, options, stack, thisValue) {
12312
12391
  if (!(index in value)) {
12313
12392
  continue;
12314
12393
  }
12315
- result[index] = await callArrayCallback(
12394
+ defineArrayResult(result, index, await callArrayCallback(
12316
12395
  callback,
12317
12396
  await readArrayElement(value, index, options),
12318
12397
  index,
@@ -12320,7 +12399,7 @@ async function mapArray(value, callback, options, stack, thisValue) {
12320
12399
  options,
12321
12400
  stack,
12322
12401
  thisValue
12323
- );
12402
+ ), options);
12324
12403
  }
12325
12404
  return result;
12326
12405
  } finally {
@@ -12329,7 +12408,8 @@ async function mapArray(value, callback, options, stack, thisValue) {
12329
12408
  }
12330
12409
  async function filterArray(value, callback, options, stack, thisValue) {
12331
12410
  const length = value.length;
12332
- const result = [];
12411
+ const result = await arraySpeciesCreate(value, 0, options);
12412
+ let targetIndex = 0;
12333
12413
  options.budget.setRetainedValues(result, () => [result]);
12334
12414
  try {
12335
12415
  for (let index = 0; index < length; index += 1) {
@@ -12339,7 +12419,7 @@ async function filterArray(value, callback, options, stack, thisValue) {
12339
12419
  }
12340
12420
  const entry = await readArrayElement(value, index, options);
12341
12421
  if (await callArrayCallback(callback, entry, index, value, options, stack, thisValue)) {
12342
- result.push(entry);
12422
+ defineArrayResult(result, targetIndex++, entry, options);
12343
12423
  }
12344
12424
  }
12345
12425
  return result;
@@ -12543,7 +12623,8 @@ async function forEachArray(value, callback, options, stack, thisValue) {
12543
12623
  }
12544
12624
  async function flatMapArray(value, callback, options, stack, thisValue) {
12545
12625
  const length = value.length;
12546
- const result = [];
12626
+ const result = await arraySpeciesCreate(value, 0, options);
12627
+ let targetIndex = 0;
12547
12628
  options.budget.setRetainedValues(result, () => [result]);
12548
12629
  try {
12549
12630
  for (let index = 0; index < length; index += 1) {
@@ -12561,37 +12642,35 @@ async function flatMapArray(value, callback, options, stack, thisValue) {
12561
12642
  thisValue
12562
12643
  );
12563
12644
  if (Array.isArray(mapped)) {
12564
- for (let mappedIndex = 0; mappedIndex < mapped.length; mappedIndex += 1) {
12645
+ const mappedLength = mapped.length;
12646
+ for (let mappedIndex = 0; mappedIndex < mappedLength; mappedIndex += 1) {
12565
12647
  options.budget.visitNode();
12566
12648
  if (!(mappedIndex in mapped)) {
12567
12649
  continue;
12568
12650
  }
12569
- result.push(await readArrayElement(mapped, mappedIndex, options));
12570
- options.budget.allocateArrayLength(result.length);
12651
+ defineArrayResult(result, targetIndex++, await readArrayElement(mapped, mappedIndex, options), options);
12571
12652
  }
12572
12653
  continue;
12573
12654
  }
12574
- result.push(mapped);
12575
- options.budget.allocateArrayLength(result.length);
12655
+ defineArrayResult(result, targetIndex++, mapped, options);
12576
12656
  }
12577
12657
  return result;
12578
12658
  } finally {
12579
12659
  options.budget.setRetainedValues(result, void 0);
12580
12660
  }
12581
12661
  }
12582
- async function flattenArray(value, depth, options) {
12583
- const result = [];
12662
+ async function flattenArray(value, depth, options, length) {
12663
+ const result = await arraySpeciesCreate(value, 0, options);
12584
12664
  const retained = {};
12585
12665
  options.budget.setRetainedValues(retained, () => [result]);
12586
12666
  try {
12587
- await appendFlattenedEntries(value, depth, result, options);
12667
+ await appendFlattenedEntries(value, depth, result, options, 0, length);
12588
12668
  return result;
12589
12669
  } finally {
12590
12670
  options.budget.setRetainedValues(retained, void 0);
12591
12671
  }
12592
12672
  }
12593
- async function appendFlattenedEntries(value, depth, result, options) {
12594
- const length = value.length;
12673
+ async function appendFlattenedEntries(value, depth, result, options, targetIndex, length = value.length) {
12595
12674
  for (let index = 0; index < length; index += 1) {
12596
12675
  options.budget.visitNode();
12597
12676
  if (!(index in value)) {
@@ -12599,12 +12678,12 @@ async function appendFlattenedEntries(value, depth, result, options) {
12599
12678
  }
12600
12679
  const entry = await readArrayElement(value, index, options);
12601
12680
  if (depth > 0 && Array.isArray(entry)) {
12602
- await appendFlattenedEntries(entry, depth - 1, result, options);
12681
+ targetIndex = await appendFlattenedEntries(entry, depth - 1, result, options, targetIndex);
12603
12682
  continue;
12604
12683
  }
12605
- result.push(entry);
12606
- options.budget.allocateArrayLength(result.length);
12684
+ defineArrayResult(result, targetIndex++, entry, options);
12607
12685
  }
12686
+ return targetIndex;
12608
12687
  }
12609
12688
  async function sortArray(value, comparator, options, stack) {
12610
12689
  const length = value.length;
@@ -12701,8 +12780,8 @@ function allocateProducedValue(value, budget, seen) {
12701
12780
  return;
12702
12781
  }
12703
12782
  seen.add(value);
12704
- for (const entry of value) {
12705
- allocateProducedValue(entry, budget, seen);
12783
+ for (let index = 0; index < value.length; index++) {
12784
+ allocateProducedValue(value[index], budget, seen);
12706
12785
  }
12707
12786
  return;
12708
12787
  }
@@ -13076,7 +13155,59 @@ function createArrayGlobal(budget) {
13076
13155
  });
13077
13156
  const properties = materializeFunctionProperties(constructor);
13078
13157
  Object.defineProperty(properties, "prototype", { value: prototype, writable: false });
13158
+ Object.defineProperty(properties, Symbol.species, {
13159
+ get: accessorAdapter(createSandboxClosure({
13160
+ guest: true,
13161
+ sandbox: true,
13162
+ name: "get [Symbol.species]",
13163
+ length: 0,
13164
+ call: (_args, context) => context?.thisValue
13165
+ }), "get"),
13166
+ configurable: true
13167
+ });
13079
13168
  Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
13169
+ const iteratorPrototype = /* @__PURE__ */ Object.create(null);
13170
+ const iterablePrototype = /* @__PURE__ */ Object.create(null);
13171
+ Object.defineProperty(iterablePrototype, Symbol.iterator, { value: createSandboxClosure({
13172
+ guest: true,
13173
+ sandbox: true,
13174
+ name: "[Symbol.iterator]",
13175
+ length: 0,
13176
+ call: (_args, context) => context?.thisValue
13177
+ }), writable: true, configurable: true });
13178
+ setSandboxPrototype(iterablePrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
13179
+ setSandboxPrototype(iteratorPrototype, iterablePrototype);
13180
+ Object.defineProperties(iteratorPrototype, {
13181
+ next: { value: createSandboxClosure({
13182
+ guest: true,
13183
+ sandbox: true,
13184
+ name: "next",
13185
+ length: 0,
13186
+ call: (_args, context) => nextArrayIterator(context?.thisValue, budget, context)
13187
+ }), writable: true, configurable: true },
13188
+ [Symbol.toStringTag]: { value: "Array Iterator", configurable: true }
13189
+ });
13190
+ registerBuiltinIdentities(budget, { "%ArrayIteratorPrototype%": iteratorPrototype, "%IteratorPrototype%": iterablePrototype });
13191
+ registerIntrinsicObject(budget, iterablePrototype);
13192
+ registerIntrinsicObject(budget, iteratorPrototype);
13193
+ for (const method of ["keys", "values", "entries"]) {
13194
+ const closure = createSandboxClosure({
13195
+ guest: true,
13196
+ sandbox: true,
13197
+ name: method,
13198
+ length: 0,
13199
+ call: (_args, context) => {
13200
+ const receiver = context?.thisValue;
13201
+ if (receiver === null || receiver === void 0) throw new TypeError("Array iterator method requires a receiver.");
13202
+ const source = typeof receiver === "object" ? receiver : createSandboxBox(receiver);
13203
+ const iterator = restoreSandboxArrayIterator({ source, index: 0, method });
13204
+ setSandboxPrototype(iterator, iteratorPrototype, budget);
13205
+ return iterator;
13206
+ }
13207
+ });
13208
+ Object.defineProperty(prototype, method, { value: closure, writable: true, configurable: true });
13209
+ if (method === "values") Object.defineProperty(prototype, Symbol.iterator, { value: closure, writable: true, configurable: true });
13210
+ }
13080
13211
  for (const name of arrayMethodNames) {
13081
13212
  const method = createSandboxClosure({
13082
13213
  guest: true,
@@ -19973,6 +20104,16 @@ function captureGuestHeapNode(value, encode) {
19973
20104
  }
19974
20105
  if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key, entry]) => [encode(key), encode(entry)]), ...serializeCollectionProperties(value, encode) };
19975
20106
  if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
20107
+ if (isSandboxArrayIterator(value)) {
20108
+ const cursor = arrayIteratorState(value);
20109
+ return {
20110
+ kind: "array-iterator",
20111
+ source: encode(cursor.source),
20112
+ index: cursor.index,
20113
+ method: cursor.method,
20114
+ state: captureObjectState(value, encode)
20115
+ };
20116
+ }
19976
20117
  const classOrigin = classOrigins.get(value);
19977
20118
  if (classOrigin !== void 0) {
19978
20119
  if (!classOrigin.initialized || classOrigin.node.nodeId === void 0)
@@ -23992,7 +24133,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23992
24133
  createRawJson(node.text);
23993
24134
  return true;
23994
24135
  }
23995
- if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "map", "set"].includes(String(node.kind))) return false;
24136
+ if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
23996
24137
  const reference = (value, kinds) => {
23997
24138
  const ref = record3(value);
23998
24139
  fields(ref, ["kind", "id"]);
@@ -24050,6 +24191,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24050
24191
  fields(node, ["kind", "id"], ["state"]);
24051
24192
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
24052
24193
  if (Object.hasOwn(node, "state")) state(node.state);
24194
+ } else if (node.kind === "array-iterator") {
24195
+ fields(node, ["kind", "source", "index", "method", "state"]);
24196
+ integer(node.index);
24197
+ if (!["keys", "values", "entries"].includes(String(node.method))) throw new TypeError("Invalid Array iterator method.");
24198
+ if (!absent(node.source)) {
24199
+ const source = reference(node.source);
24200
+ if (source.kind === "scope-frame" || source.kind === "symbol") throw new TypeError("Invalid Array iterator source.");
24201
+ }
24202
+ state(node.state);
24053
24203
  } else if (node.kind === "guest-object" || node.kind === "guest-array") {
24054
24204
  fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
24055
24205
  if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
@@ -25904,6 +26054,7 @@ function measureSandboxData(values, options = {}) {
25904
26054
  }
25905
26055
  return;
25906
26056
  }
26057
+ if (isSandboxArrayIterator(value)) visit(arrayIteratorState(value).source, depth + 1);
25907
26058
  if (isSandboxRegExpIterator(value)) {
25908
26059
  const state = regexpIteratorState(value);
25909
26060
  visit(state.matcher, depth + 1);
@@ -26083,6 +26234,10 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
26083
26234
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
26084
26235
  return value;
26085
26236
  }
26237
+ if (isSandboxArrayIterator(value)) {
26238
+ if (!cloneSandboxCollections) return value;
26239
+ throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
26240
+ }
26086
26241
  if (isSandboxRegExpIterator(value)) {
26087
26242
  if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
26088
26243
  if (!cloneSandboxCollections) return value;
@@ -26447,6 +26602,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
26447
26602
  if (isSandboxGenerator(value)) {
26448
26603
  throw new TypeError("Sandbox generators cannot cross into host values.");
26449
26604
  }
26605
+ if (isSandboxArrayIterator(value)) throw new TypeError("Sandbox Array iterators cannot cross into host values.");
26450
26606
  if (isSandboxCollectionIterator(value)) {
26451
26607
  throw new TypeError("Sandbox collection iterators cannot cross into host values.");
26452
26608
  }
@@ -26569,8 +26725,8 @@ function allocateSandboxValue2(value, budget, seen) {
26569
26725
  }
26570
26726
  seen.add(value);
26571
26727
  budget.allocateArrayLength(value.length);
26572
- for (const entry of value) {
26573
- allocateSandboxValue2(entry, budget, seen);
26728
+ for (let index = 0; index < value.length; index++) {
26729
+ allocateSandboxValue2(value[index], budget, seen);
26574
26730
  }
26575
26731
  return;
26576
26732
  }
@@ -40765,4 +40921,4 @@ export {
40765
40921
  FileSnapshotBackend,
40766
40922
  run
40767
40923
  };
40768
- //# sourceMappingURL=chunk-CL6E5SM7.js.map
40924
+ //# sourceMappingURL=chunk-MQRGC4JQ.js.map