poe-code 14.0.83 → 14.0.84

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 (42) hide show
  1. package/dist/index.js +588 -93
  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-js/dist/chunks/{chunk-37V6Q4K3.js → chunk-2EZQJQ2C.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-PT7PBLVT.js → chunk-CYVI4ZUK.js} +536 -85
  7. package/packages/safe-js/dist/chunks/chunk-CYVI4ZUK.js.map +7 -0
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/index.js +2 -2
  11. package/packages/safe-js/dist/interp/array-buffer.d.ts +12 -0
  12. package/packages/safe-js/dist/interp/array-buffer.js +33 -0
  13. package/packages/safe-js/dist/interp/float32.d.ts +6 -1
  14. package/packages/safe-js/dist/interp/float32.js +38 -10
  15. package/packages/safe-js/dist/interp/globals/array-buffer.d.ts +3 -0
  16. package/packages/safe-js/dist/interp/globals/array-buffer.js +112 -0
  17. package/packages/safe-js/dist/interp/globals/float32array.d.ts +1 -1
  18. package/packages/safe-js/dist/interp/globals/float32array.js +104 -15
  19. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  20. package/packages/safe-js/dist/interp/globals.js +2 -0
  21. package/packages/safe-js/dist/interp/host-bridge.d.ts +1 -0
  22. package/packages/safe-js/dist/interp/host-bridge.js +21 -0
  23. package/packages/safe-js/dist/interp/host-call.js +26 -2
  24. package/packages/safe-js/dist/interp/methods/array-iterator.js +1 -1
  25. package/packages/safe-js/dist/interp/object-model.js +6 -0
  26. package/packages/safe-js/dist/interp/values.d.ts +1 -1
  27. package/packages/safe-js/dist/interp/values.js +47 -5
  28. package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
  29. package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
  30. package/packages/safe-js/dist/snapshot/array-buffer.d.ts +13 -0
  31. package/packages/safe-js/dist/snapshot/array-buffer.js +40 -0
  32. package/packages/safe-js/dist/snapshot/dump-format.js +25 -9
  33. package/packages/safe-js/dist/snapshot/float32array.d.ts +8 -1
  34. package/packages/safe-js/dist/snapshot/float32array.js +23 -5
  35. package/packages/safe-js/dist/snapshot/replay-data.d.ts +5 -0
  36. package/packages/safe-js/dist/snapshot/replay-data.js +35 -10
  37. package/packages/safe-js/dist/snapshot/restore.js +13 -1
  38. package/packages/safe-js/dist/snapshot/serialize.d.ts +5 -2
  39. package/packages/safe-js/dist/snapshot/serialize.js +20 -11
  40. package/packages/safe-js/dist/snapshot/validation.js +11 -1
  41. package/packages/safe-js/dist/chunks/chunk-PT7PBLVT.js.map +0 -7
  42. /package/packages/safe-js/dist/chunks/{chunk-37V6Q4K3.js.map → chunk-2EZQJQ2C.js.map} +0 -0
package/dist/index.js CHANGED
@@ -50271,8 +50271,8 @@ function assertNonNegativeInteger3(value, keyword) {
50271
50271
  }
50272
50272
  function validateSchemaObject(schema, dialect) {
50273
50273
  if (schema.type !== void 0) {
50274
- const types8 = Array.isArray(schema.type) ? schema.type : [schema.type];
50275
- if (types8.length === 0 || !types8.every((type) => typeof type === "string" && draftTypeSet.has(type)) || new Set(types8).size !== types8.length) {
50274
+ const types9 = Array.isArray(schema.type) ? schema.type : [schema.type];
50275
+ if (types9.length === 0 || !types9.every((type) => typeof type === "string" && draftTypeSet.has(type)) || new Set(types9).size !== types9.length) {
50276
50276
  throw new Error("type must be a JSON Schema type or a unique array of JSON Schema types.");
50277
50277
  }
50278
50278
  }
@@ -50991,9 +50991,9 @@ function evaluateValidationKeywords(node, schema, value, path193) {
50991
50991
  if (schema.nullable === true && value === null) {
50992
50992
  return results;
50993
50993
  }
50994
- const types8 = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
50995
- if (types8.length > 0 && !types8.some((type) => typeof type === "string" && typeMatches(type, value))) {
50996
- results.push(invalidResult(issue(path193, types8.join(","), value, `must be ${types8.join(",")}`)));
50994
+ const types9 = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
50995
+ if (types9.length > 0 && !types9.some((type) => typeof type === "string" && typeMatches(type, value))) {
50996
+ results.push(invalidResult(issue(path193, types9.join(","), value, `must be ${types9.join(",")}`)));
50997
50997
  return results;
50998
50998
  }
50999
50999
  if (schema.const !== void 0 && !deepEqual(schema.const, value)) {
@@ -126534,6 +126534,45 @@ var init_otel2 = __esm({
126534
126534
  }
126535
126535
  });
126536
126536
 
126537
+ // packages/safe-js/src/interp/array-buffer.ts
126538
+ import { types } from "node:util";
126539
+ function isSandboxArrayBuffer(value) {
126540
+ return types.isArrayBuffer(value) && Object.getPrototypeOf(value) === ArrayBuffer.prototype;
126541
+ }
126542
+ function arrayBufferLength(value) {
126543
+ return Reflect.apply(readLength, value, []);
126544
+ }
126545
+ function arrayBufferOptions(value) {
126546
+ return readResizable !== void 0 && Reflect.apply(readResizable, value, []) ? { maxByteLength: Reflect.apply(readMaxLength, value, []) } : void 0;
126547
+ }
126548
+ function copyArrayBufferStorage(value, state) {
126549
+ state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
126550
+ let copy = state.float32Buffers.get(value);
126551
+ if (copy === void 0) {
126552
+ copy = Reflect.construct(ArrayBuffer, [arrayBufferLength(value), arrayBufferOptions(value)]);
126553
+ new Uint8Array(copy).set(new Uint8Array(value));
126554
+ state.float32Buffers.set(value, copy);
126555
+ }
126556
+ return copy;
126557
+ }
126558
+ function arrayBufferDataProperties(value) {
126559
+ return Reflect.ownKeys(value).map((key3) => {
126560
+ const descriptor = Object.getOwnPropertyDescriptor(value, key3);
126561
+ if (!("value" in descriptor)) throw new TypeError("ArrayBuffer accessors cannot be copied as data.");
126562
+ return [key3, descriptor];
126563
+ });
126564
+ }
126565
+ var readLength, readResizable, readMaxLength, arrayBufferPrototypes;
126566
+ var init_array_buffer = __esm({
126567
+ "packages/safe-js/src/interp/array-buffer.ts"() {
126568
+ "use strict";
126569
+ readLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
126570
+ readResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
126571
+ readMaxLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "maxByteLength")?.get;
126572
+ arrayBufferPrototypes = /* @__PURE__ */ new WeakMap();
126573
+ }
126574
+ });
126575
+
126537
126576
  // packages/safe-js/src/interp/internal-symbols.ts
126538
126577
  var internalSymbols;
126539
126578
  var init_internal_symbols = __esm({
@@ -126877,7 +126916,7 @@ var init_regexp_iterator = __esm({
126877
126916
  });
126878
126917
 
126879
126918
  // packages/safe-js/src/interp/date.ts
126880
- import { types } from "node:util";
126919
+ import { types as types2 } from "node:util";
126881
126920
  function isSandboxDate(value) {
126882
126921
  return typeof value === "object" && value !== null && dates.has(value);
126883
126922
  }
@@ -126890,7 +126929,7 @@ function dateTime(value) {
126890
126929
  return Reflect.apply(readTime, value, []);
126891
126930
  }
126892
126931
  function copyNativeDate(value) {
126893
- if (!types.isDate(value)) return void 0;
126932
+ if (!types2.isDate(value)) return void 0;
126894
126933
  if (Object.getPrototypeOf(value) !== NativeDate.prototype)
126895
126934
  throw new TypeError("Date subclasses are not supported.");
126896
126935
  return createSandboxDate(dateTime(value));
@@ -127071,13 +127110,13 @@ var init_arguments = __esm({
127071
127110
  });
127072
127111
 
127073
127112
  // packages/safe-js/src/interp/boxed.ts
127074
- import { types as types2 } from "node:util";
127113
+ import { types as types3 } from "node:util";
127075
127114
  function nativeBoxedValue(value) {
127076
- if (types2.isNumberObject(value)) return Reflect.apply(numberValue2, value, []);
127077
- if (types2.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
127078
- if (types2.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
127079
- if (types2.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
127080
- if (types2.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
127115
+ if (types3.isNumberObject(value)) return Reflect.apply(numberValue2, value, []);
127116
+ if (types3.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
127117
+ if (types3.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
127118
+ if (types3.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
127119
+ if (types3.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
127081
127120
  return void 0;
127082
127121
  }
127083
127122
  function createSandboxBox(value) {
@@ -127296,9 +127335,9 @@ var init_resources = __esm({
127296
127335
  });
127297
127336
 
127298
127337
  // packages/safe-js/src/extensions.ts
127299
- import { types as types3 } from "node:util";
127338
+ import { types as types4 } from "node:util";
127300
127339
  function readDataRecord(value, label) {
127301
- if (typeof value !== "object" || value === null || types3.isProxy(value)) {
127340
+ if (typeof value !== "object" || value === null || types4.isProxy(value)) {
127302
127341
  throw new TypeError(`${label} must be a plain data record.`);
127303
127342
  }
127304
127343
  const prototype = Object.getPrototypeOf(value);
@@ -127318,7 +127357,7 @@ function readDataRecord(value, label) {
127318
127357
  return result;
127319
127358
  }
127320
127359
  function readStringList(value, label) {
127321
- if (!Array.isArray(value) || types3.isProxy(value) || value.length > 4096) {
127360
+ if (!Array.isArray(value) || types4.isProxy(value) || value.length > 4096) {
127322
127361
  throw new TypeError(`${label} must be a bounded string array.`);
127323
127362
  }
127324
127363
  const result = [];
@@ -127349,7 +127388,7 @@ var init_extensions = __esm({
127349
127388
  });
127350
127389
 
127351
127390
  // packages/safe-js/src/interp/host-capabilities.ts
127352
- import { types as types4 } from "node:util";
127391
+ import { types as types5 } from "node:util";
127353
127392
  function createGuestReference(root, owner, assertActive) {
127354
127393
  const reference = Object.freeze(/* @__PURE__ */ Object.create(null));
127355
127394
  guestReferences.set(reference, { root, owner, assertActive });
@@ -127397,7 +127436,7 @@ function createLiveHostObject(definition, controller) {
127397
127436
  for (const name of ["keys", "get", "set", "delete"]) {
127398
127437
  const operation = data[name];
127399
127438
  if (operation === void 0 && (name === "set" || name === "delete")) continue;
127400
- if (typeof operation !== "function" || types4.isProxy(operation) || types4.isAsyncFunction(operation) || types4.isGeneratorFunction(operation))
127439
+ if (typeof operation !== "function" || types5.isProxy(operation) || types5.isAsyncFunction(operation) || types5.isGeneratorFunction(operation))
127401
127440
  throw new TypeError(`Named ${name} must be a synchronous non-generator function, not a proxy.`);
127402
127441
  }
127403
127442
  if (typeof data.maxKeys !== "number" || !Number.isInteger(data.maxKeys) || data.maxKeys < 1 || data.maxKeys > MAX_NAMED_KEYS)
@@ -127652,7 +127691,7 @@ function namedMutationKeys(state, key3, create) {
127652
127691
  function namedKeys2(state) {
127653
127692
  const named = state.named;
127654
127693
  return state.controller.read(named.keys, (value) => {
127655
- if (!Array.isArray(value) || types4.isProxy(value))
127694
+ if (!Array.isArray(value) || types5.isProxy(value))
127656
127695
  throw new TypeError("Named keys must be a dense own-data array of strings, not a proxy.");
127657
127696
  const length = Object.getOwnPropertyDescriptor(value, "length").value;
127658
127697
  if (length > named.maxKeys) throw new RangeError("Named keys exceed maxKeys.");
@@ -127709,18 +127748,39 @@ var init_error_prototypes = __esm({
127709
127748
  });
127710
127749
 
127711
127750
  // packages/safe-js/src/interp/float32.ts
127751
+ function restoreFloat32View(buffer, byteOffset2, length, budget) {
127752
+ const originalLength = arrayBufferLength(buffer);
127753
+ const required = byteOffset2 + (length ?? 0) * 4;
127754
+ const options = arrayBufferOptions(buffer);
127755
+ const grow = required > originalLength;
127756
+ if (grow) {
127757
+ if (options === void 0 || required > options.maxByteLength)
127758
+ throw new RangeError("Float32Array layout exceeds backing capacity.");
127759
+ budget?.allocateArrayLength(Math.ceil(required / 4));
127760
+ budget?.provisionDataUsage(required - originalLength)();
127761
+ Reflect.apply(resizeBuffer, buffer, [required]);
127762
+ }
127763
+ try {
127764
+ const view = new Float32Array(buffer, byteOffset2, length);
127765
+ if (options !== void 0) float32ViewLayouts.set(view, { byteOffset: byteOffset2, ...length === void 0 ? {} : { length } });
127766
+ return view;
127767
+ } finally {
127768
+ if (grow) Reflect.apply(resizeBuffer, buffer, [originalLength]);
127769
+ }
127770
+ }
127712
127771
  function isFloat32Array(value) {
127713
127772
  return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
127714
127773
  }
127715
- function float32Storage(value) {
127774
+ function float32Storage(value, requireInBounds = false) {
127775
+ if (requireInBounds) Reflect.apply(createValuesIterator, value, []);
127716
127776
  const buffer = Reflect.apply(readBuffer, value, []);
127717
- if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype || bufferResizable !== void 0 && Reflect.apply(bufferResizable, buffer, [])) {
127718
- throw new TypeError("Float32Array requires a fixed, non-shared ArrayBuffer.");
127777
+ if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
127778
+ throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
127719
127779
  }
127720
127780
  return {
127721
127781
  buffer,
127722
127782
  byteOffset: Reflect.apply(readOffset, value, []),
127723
- length: Reflect.apply(readLength, value, []),
127783
+ length: Reflect.apply(readLength2, value, []),
127724
127784
  byteLength: Reflect.apply(bufferLength, buffer, [])
127725
127785
  };
127726
127786
  }
@@ -127761,26 +127821,29 @@ function checkFloat32Allocation(length, budget) {
127761
127821
  }
127762
127822
  function copyFloat32Storage(value, state) {
127763
127823
  const storage2 = float32Storage(value);
127764
- state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
127765
- let buffer = state.float32Buffers.get(storage2.buffer);
127766
- if (buffer === void 0) {
127767
- buffer = new ArrayBuffer(storage2.byteLength);
127768
- new Uint8Array(buffer).set(new Uint8Array(storage2.buffer));
127769
- state.float32Buffers.set(storage2.buffer, buffer);
127824
+ const buffer = copyArrayBufferStorage(storage2.buffer, state);
127825
+ if (bufferResizable !== void 0 && Reflect.apply(bufferResizable, storage2.buffer, [])) {
127826
+ const layout = float32ViewLayouts.get(value);
127827
+ if (layout === void 0) throw new TypeError("Resizable Float32Array copies require known view layout.");
127828
+ return restoreFloat32View(buffer, layout.byteOffset, layout.length);
127770
127829
  }
127771
127830
  return new Float32Array(buffer, storage2.byteOffset, storage2.length);
127772
127831
  }
127773
- var typedArrayPrototype, readLength, readOffset, readBuffer, readTag, bufferLength, bufferResizable;
127832
+ var typedArrayPrototype, readLength2, readOffset, readBuffer, readTag, createValuesIterator, bufferLength, bufferResizable, float32ViewLayouts, resizeBuffer;
127774
127833
  var init_float32 = __esm({
127775
127834
  "packages/safe-js/src/interp/float32.ts"() {
127776
127835
  "use strict";
127836
+ init_array_buffer();
127777
127837
  typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
127778
- readLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
127838
+ readLength2 = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
127779
127839
  readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
127780
127840
  readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
127781
127841
  readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
127842
+ createValuesIterator = Object.getOwnPropertyDescriptor(typedArrayPrototype, "values").value;
127782
127843
  bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
127783
127844
  bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
127845
+ float32ViewLayouts = /* @__PURE__ */ new WeakMap();
127846
+ resizeBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
127784
127847
  }
127785
127848
  });
127786
127849
 
@@ -128000,11 +128063,13 @@ function releaseObjectPrototype(budget) {
128000
128063
  generatorPrototypes.delete(budget);
128001
128064
  errorPrototypes.delete(budget);
128002
128065
  float32Prototypes.delete(budget);
128066
+ arrayBufferPrototypes.delete(budget);
128003
128067
  initialRegexDescriptors.delete(budget);
128004
128068
  intrinsicPrototypes.delete(budget);
128005
128069
  }
128006
128070
  function getSandboxPrototype(value, budget) {
128007
128071
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
128072
+ if (isSandboxArrayBuffer(value)) return budget === void 0 ? null : arrayBufferPrototypes.get(budget) ?? null;
128008
128073
  if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
128009
128074
  const errorType = sandboxErrorTypes.get(value);
128010
128075
  if (budget !== void 0 && errorType !== void 0) {
@@ -128115,6 +128180,7 @@ function setSandboxPrototype(value, prototype, budget) {
128115
128180
  prototypes.set(value, prototype);
128116
128181
  }
128117
128182
  function isPrototypeRecord(value) {
128183
+ if (isSandboxArrayBuffer(value)) return true;
128118
128184
  if (isFloat32Array(value)) return true;
128119
128185
  if (isGuestClosure(value)) return true;
128120
128186
  if (isGuestHostObject(value)) return false;
@@ -128155,6 +128221,7 @@ var init_object_model = __esm({
128155
128221
  init_error_prototypes();
128156
128222
  init_float32();
128157
128223
  init_float32_prototypes();
128224
+ init_array_buffer();
128158
128225
  init_shape();
128159
128226
  init_boxed();
128160
128227
  init_values();
@@ -128835,18 +128902,20 @@ var init_symbols3 = __esm({
128835
128902
  });
128836
128903
 
128837
128904
  // packages/safe-js/src/snapshot/float32array.ts
128838
- function encodeFloat32Storage(value, id, buffers, reference) {
128905
+ function encodeFloat32Layout(value) {
128839
128906
  const storage2 = float32Storage(value);
128840
- const existing = buffers.get(storage2.buffer);
128841
- if (existing === void 0) buffers.set(storage2.buffer, id);
128907
+ if (arrayBufferOptions(storage2.buffer) === void 0) return { byteOffset: storage2.byteOffset, length: storage2.length };
128908
+ const layout = float32ViewLayouts.get(value);
128909
+ if (layout === void 0) throw new TypeError("Resizable Float32Array snapshots require known view layout.");
128842
128910
  return {
128843
- kind: "float32array",
128844
- byteOffset: storage2.byteOffset,
128845
- length: storage2.length,
128846
- ...existing === void 0 ? { bytes: Array.from(new Uint8Array(storage2.buffer)) } : { buffer: reference(existing) }
128911
+ byteOffset: layout.byteOffset,
128912
+ length: layout.length ?? 0,
128913
+ ...layout.length === void 0 ? { lengthTracking: true } : {}
128847
128914
  };
128848
128915
  }
128849
128916
  function validateFloat32Storage(value) {
128917
+ if (Object.hasOwn(value, "lengthTracking") && (value.lengthTracking !== true || value.length !== 0 || Object.hasOwn(value, "bytes")))
128918
+ throw new TypeError("Invalid Float32Array length-tracking layout.");
128850
128919
  if (!Number.isSafeInteger(value.length) || Number(value.length) < 0 || !Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || Number(value.byteOffset) % 4 !== 0)
128851
128920
  throw new TypeError("Invalid Float32Array view dimensions.");
128852
128921
  if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
@@ -128856,7 +128925,7 @@ function validateFloat32Storage(value) {
128856
128925
  throw new TypeError("Invalid Float32Array backing bytes.");
128857
128926
  }
128858
128927
  }
128859
- function decodeFloat32Storage(value, resolve16) {
128928
+ function decodeFloat32Storage(value, resolve16, budget) {
128860
128929
  validateFloat32Storage(value);
128861
128930
  let buffer;
128862
128931
  if (Array.isArray(value.bytes)) {
@@ -128864,10 +128933,13 @@ function decodeFloat32Storage(value, resolve16) {
128864
128933
  new Uint8Array(buffer).set(value.bytes);
128865
128934
  } else {
128866
128935
  const referenced = resolve16(value.buffer);
128867
- if (!isFloat32Array(referenced)) throw new TypeError("Invalid Float32Array backing reference.");
128868
- buffer = float32Storage(referenced).buffer;
128936
+ if (isSandboxArrayBuffer(referenced)) buffer = referenced;
128937
+ else if (isFloat32Array(referenced)) buffer = float32Storage(referenced).buffer;
128938
+ else throw new TypeError("Invalid Float32Array backing reference.");
128869
128939
  }
128870
- return new Float32Array(buffer, Number(value.byteOffset), Number(value.length));
128940
+ if (value.lengthTracking === true && arrayBufferOptions(buffer) === void 0)
128941
+ throw new TypeError("Length-tracking layout requires resizable backing storage.");
128942
+ return restoreFloat32View(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.length), budget);
128871
128943
  }
128872
128944
  var init_float32array = __esm({
128873
128945
  "packages/safe-js/src/snapshot/float32array.ts"() {
@@ -128875,6 +128947,53 @@ var init_float32array = __esm({
128875
128947
  init_float32();
128876
128948
  init_object_model();
128877
128949
  init_property_descriptors();
128950
+ init_array_buffer();
128951
+ }
128952
+ });
128953
+
128954
+ // packages/safe-js/src/snapshot/array-buffer.ts
128955
+ function captureArrayBufferState(value, encode) {
128956
+ return {
128957
+ properties: serializePropertyDescriptors(value, encode),
128958
+ ...hasExplicitSandboxPrototype(value) ? { prototype: encode(getSandboxPrototype(value)) } : {}
128959
+ };
128960
+ }
128961
+ function encodeArrayBufferStorage(value, id, buffers, reference) {
128962
+ arrayBufferLength(value);
128963
+ const existing = buffers.get(value);
128964
+ if (existing === void 0) buffers.set(value, id);
128965
+ return { kind: "arraybuffer", ...existing === void 0 ? { bytes: Array.from(new Uint8Array(value)), ...arrayBufferOptions(value) } : { buffer: reference(existing) } };
128966
+ }
128967
+ function validateArrayBufferStorage(value) {
128968
+ if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
128969
+ throw new TypeError("ArrayBuffer requires one backing storage description.");
128970
+ if (Object.hasOwn(value, "bytes") && (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)))
128971
+ throw new TypeError("Invalid ArrayBuffer bytes.");
128972
+ if (Object.hasOwn(value, "maxByteLength") && (!Array.isArray(value.bytes) || !Number.isSafeInteger(value.maxByteLength) || Number(value.maxByteLength) < value.bytes.length))
128973
+ throw new TypeError("Invalid ArrayBuffer maximum length.");
128974
+ }
128975
+ function decodeArrayBufferStorage(value, resolve16) {
128976
+ validateArrayBufferStorage(value);
128977
+ if (Array.isArray(value.bytes)) {
128978
+ const buffer = Reflect.construct(ArrayBuffer, [
128979
+ value.bytes.length,
128980
+ Object.hasOwn(value, "maxByteLength") ? { maxByteLength: value.maxByteLength } : void 0
128981
+ ]);
128982
+ new Uint8Array(buffer).set(value.bytes);
128983
+ return buffer;
128984
+ }
128985
+ const referenced = resolve16(value.buffer);
128986
+ if (isSandboxArrayBuffer(referenced)) return referenced;
128987
+ if (isFloat32Array(referenced)) return float32Storage(referenced).buffer;
128988
+ throw new TypeError("Invalid ArrayBuffer backing reference.");
128989
+ }
128990
+ var init_array_buffer2 = __esm({
128991
+ "packages/safe-js/src/snapshot/array-buffer.ts"() {
128992
+ "use strict";
128993
+ init_array_buffer();
128994
+ init_float32();
128995
+ init_object_model();
128996
+ init_property_descriptors();
128878
128997
  }
128879
128998
  });
128880
128999
 
@@ -129039,11 +129158,24 @@ function encodeReplayData(value, options = {}) {
129039
129158
  ...symbolProperties.length === 0 ? {} : { symbolProperties },
129040
129159
  ...Object.isExtensible(entry) ? {} : { extensible: false }
129041
129160
  };
129161
+ } else if (isSandboxArrayBuffer(entry)) {
129162
+ const storage2 = encodeArrayBufferStorage(entry, id, float32Buffers, (id2) => ({ tag: "ref", id: id2 }));
129163
+ const properties = /* @__PURE__ */ Object.create(null);
129164
+ for (const [key3, descriptor] of arrayBufferDataProperties(entry)) {
129165
+ if (typeof key3 === "symbol") continue;
129166
+ properties[key3] = {
129167
+ value: child(descriptor.value, key3),
129168
+ configurable: descriptor.configurable === true,
129169
+ enumerable: descriptor.enumerable === true,
129170
+ writable: descriptor.writable === true
129171
+ };
129172
+ }
129173
+ let symbolIndex = 0;
129174
+ const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path193, { symbol: Math.floor(symbolIndex++ / 2) }]));
129175
+ nodes[id] = { ...storage2, properties, extensible: Object.isExtensible(entry), symbolEntries };
129042
129176
  } else if (isFloat32Array(entry)) {
129043
- const storage2 = encodeFloat32Storage(entry, id, float32Buffers, (id2) => ({
129044
- tag: "ref",
129045
- id: id2
129046
- }));
129177
+ const backing = float32Storage(entry);
129178
+ const storage2 = { kind: "float32array", ...encodeFloat32Layout(entry), buffer: child(backing.buffer, "<buffer>") };
129047
129179
  const properties = /* @__PURE__ */ Object.create(null);
129048
129180
  for (const [key3, descriptor] of float32DataProperties(entry)) {
129049
129181
  properties[key3] = {
@@ -129146,7 +129278,7 @@ function decodeReplayData(input, options = {}, parent) {
129146
129278
  const graph = record2(input);
129147
129279
  const nodes = list(own(graph, "nodes"));
129148
129280
  const restored = /* @__PURE__ */ new Map();
129149
- const initializeIterators = [];
129281
+ const initializeValues = [];
129150
129282
  const decode = (entry, depth = 0) => {
129151
129283
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
129152
129284
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
@@ -129271,10 +129403,20 @@ function decodeReplayData(input, options = {}, parent) {
129271
129403
  if (node.extensible === false) Object.preventExtensions(result3);
129272
129404
  return result3;
129273
129405
  }
129406
+ if (kind === "arraybuffer") {
129407
+ if (typeof node.extensible !== "boolean") throw new TypeError("Invalid ArrayBuffer extensibility.");
129408
+ const result3 = decodeArrayBufferStorage(node, child);
129409
+ restored.set(id, result3);
129410
+ initializeValues.push(() => {
129411
+ defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
129412
+ if (!node.extensible) Object.preventExtensions(result3);
129413
+ });
129414
+ return result3;
129415
+ }
129274
129416
  if (kind === "float32array") {
129275
129417
  if (typeof node.extensible !== "boolean")
129276
129418
  throw new TypeError("Invalid Float32Array extensibility.");
129277
- const result3 = decodeFloat32Storage(node, child);
129419
+ const result3 = decodeFloat32Storage(node, child, compilation.owner?.budget);
129278
129420
  restored.set(id, result3);
129279
129421
  defineProperties(result3, record2(own(node, "properties")), child);
129280
129422
  if (!node.extensible) Object.preventExtensions(result3);
@@ -129310,7 +129452,7 @@ function decodeReplayData(input, options = {}, parent) {
129310
129452
  restored.set(id, result3);
129311
129453
  const collection = child(own(node, "collection"));
129312
129454
  if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid replay collection iterator source.");
129313
- initializeIterators.push(() => {
129455
+ initializeValues.push(() => {
129314
129456
  restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
129315
129457
  });
129316
129458
  defineProperties(result3, record2(own(node, "properties")), child);
@@ -129381,7 +129523,7 @@ function decodeReplayData(input, options = {}, parent) {
129381
129523
  return result2;
129382
129524
  };
129383
129525
  const result = decode(own(graph, "root"));
129384
- for (const initialize of initializeIterators) initialize();
129526
+ for (const initialize of initializeValues) initialize();
129385
129527
  if (parent !== void 0) compilation.forward(compilation.tickets, parent);
129386
129528
  return result;
129387
129529
  } finally {
@@ -129462,6 +129604,8 @@ var init_replay_data = __esm({
129462
129604
  init_compile_guard();
129463
129605
  init_float32();
129464
129606
  init_float32array();
129607
+ init_array_buffer();
129608
+ init_array_buffer2();
129465
129609
  init_date();
129466
129610
  init_raw_json();
129467
129611
  init_boxed();
@@ -129697,8 +129841,29 @@ function normalize2(value, seen) {
129697
129841
  try {
129698
129842
  const date = copyNativeDate(value);
129699
129843
  if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
129844
+ if (isSandboxArrayBuffer(value)) {
129845
+ arrayBufferLength(value);
129846
+ const properties = /* @__PURE__ */ Object.create(null);
129847
+ const entries = [];
129848
+ for (const [key3, descriptor] of arrayBufferDataProperties(value)) {
129849
+ if (typeof key3 === "symbol") throw new TypeError("ArrayBuffer symbol properties require an explicit host-call identity.");
129850
+ entries.push([key3, descriptor]);
129851
+ }
129852
+ for (const [key3, descriptor] of entries.sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0))
129853
+ defineOwnDataProperty(properties, key3, normalize2(descriptor.value, seen));
129854
+ return Object.assign(/* @__PURE__ */ Object.create(null), {
129855
+ $type: "arraybuffer",
129856
+ bytes: normalize2(Array.from(new Uint8Array(value)), seen),
129857
+ ...arrayBufferOptions(value),
129858
+ properties
129859
+ });
129860
+ }
129700
129861
  if (isFloat32Array(value)) {
129701
129862
  const storage2 = float32Storage(value);
129863
+ const resizable = arrayBufferOptions(storage2.buffer) !== void 0;
129864
+ const layout = resizable ? float32ViewLayouts.get(value) : void 0;
129865
+ if (resizable && layout === void 0)
129866
+ throw new TypeError("Resizable Float32Array host-call identity requires known view layout.");
129702
129867
  const properties = /* @__PURE__ */ Object.create(null);
129703
129868
  for (const [key3, descriptor] of float32DataProperties(value).sort(
129704
129869
  ([left], [right]) => left < right ? -1 : left > right ? 1 : 0
@@ -129710,7 +129875,12 @@ function normalize2(value, seen) {
129710
129875
  bytes: normalize2(Array.from(new Uint8Array(storage2.buffer)), seen),
129711
129876
  byteOffset: storage2.byteOffset,
129712
129877
  length: storage2.length,
129713
- properties
129878
+ properties,
129879
+ ...resizable || Reflect.ownKeys(storage2.buffer).length > 0 ? { buffer: normalize2(storage2.buffer, seen) } : {},
129880
+ ...layout === void 0 ? {} : { viewLayout: {
129881
+ byteOffset: layout.byteOffset,
129882
+ length: layout.length ?? null
129883
+ } }
129714
129884
  });
129715
129885
  }
129716
129886
  if (Array.isArray(value)) {
@@ -129745,6 +129915,7 @@ var init_host_call = __esm({
129745
129915
  "packages/safe-js/src/interp/host-call.ts"() {
129746
129916
  "use strict";
129747
129917
  init_float32();
129918
+ init_array_buffer();
129748
129919
  init_date();
129749
129920
  init_values();
129750
129921
  init_compile_guard();
@@ -132248,7 +132419,7 @@ async function nextArrayIterator(value, budget, context) {
132248
132419
  const read = (key3) => context?.getProperty !== void 0 ? context.getProperty(source, key3) : readPropertyDescriptor((isFloat32Array(source) ? Object.getOwnPropertyDescriptor(source, key3) : void 0) ?? getSandboxPropertyDescriptor(source, key3, budget) ?? { value: void 0 }, source, context);
132249
132420
  try {
132250
132421
  budget.visitNode();
132251
- const number = isFloat32Array(source) ? float32Storage(source).length : await sandboxNumber(await read("length"), budget, context);
132422
+ const number = isFloat32Array(source) ? float32Storage(source, true).length : await sandboxNumber(await read("length"), budget, context);
132252
132423
  const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
132253
132424
  if (index >= length) {
132254
132425
  state.source = void 0;
@@ -132617,7 +132788,7 @@ var init_string_locale = __esm({
132617
132788
  });
132618
132789
 
132619
132790
  // packages/safe-js/src/interp/methods/string.ts
132620
- import { types as types5 } from "node:util";
132791
+ import { types as types6 } from "node:util";
132621
132792
  function getStringMember(value, property, budget) {
132622
132793
  const index = getStringIndex(property);
132623
132794
  if (index !== void 0) {
@@ -132687,7 +132858,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
132687
132858
  };
132688
132859
  const symbol2 = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "matchAll" ? Symbol.matchAll : methodName === "replace" || methodName === "replaceAll" ? Symbol.replace : methodName === "split" ? Symbol.split : void 0;
132689
132860
  const pattern = args[0];
132690
- if (symbol2 !== void 0 && types5.isRegExp(pattern))
132861
+ if (symbol2 !== void 0 && types6.isRegExp(pattern))
132691
132862
  throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
132692
132863
  if (symbol2 === void 0 || pattern === null || pattern === void 0) return fallback();
132693
132864
  const readProperty = (key3) => context?.getProperty !== void 0 ? context.getProperty(pattern, key3) : key3 === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key3, budget) === void 0 ? getRegexMember(pattern, key3, budget, context) : getSandboxDataProperty(pattern, key3, budget);
@@ -136368,6 +136539,31 @@ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
136368
136539
  const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
136369
136540
  const release2 = retainValues(budget, () => [prototype, ...args]);
136370
136541
  try {
136542
+ if (isSandboxArrayBuffer(args[0])) {
136543
+ const buffer = args[0];
136544
+ const number = await sandboxNumber(args[1], budget, context);
136545
+ const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
136546
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset % 4 !== 0)
136547
+ throw new RangeError("Invalid Float32Array buffer offset.");
136548
+ const bytes = arrayBufferLength(buffer);
136549
+ let length;
136550
+ if (args[2] === void 0) {
136551
+ if (arrayBufferOptions(buffer) === void 0 && bytes % 4 !== 0 || offset > bytes)
136552
+ throw new RangeError("Invalid Float32Array buffer length.");
136553
+ length = Math.floor((bytes - offset) / 4);
136554
+ } else {
136555
+ const size = await sandboxNumber(args[2], budget, context);
136556
+ length = Number.isNaN(size) ? 0 : Math.trunc(size);
136557
+ if (!Number.isSafeInteger(length) || length < 0 || offset + length * 4 > arrayBufferLength(buffer))
136558
+ throw new RangeError("Invalid Float32Array view length.");
136559
+ }
136560
+ budget.allocateArrayLength(length);
136561
+ const result2 = new Float32Array(buffer, offset, args[2] === void 0 ? void 0 : length);
136562
+ if (arrayBufferOptions(buffer) !== void 0)
136563
+ float32ViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
136564
+ setSandboxPrototype(result2, prototype, budget);
136565
+ return result2;
136566
+ }
136371
136567
  const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
136372
136568
  setSandboxPrototype(result, prototype, budget);
136373
136569
  return result;
@@ -136582,7 +136778,19 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136582
136778
  setSandboxPrototype(prototype, shared);
136583
136779
  setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
136584
136780
  const getters = [];
136585
- for (const key3 of ["length", "byteLength", "byteOffset"]) {
136781
+ const species = createSandboxClosure({
136782
+ guest: true,
136783
+ sandbox: true,
136784
+ name: "get [Symbol.species]",
136785
+ length: 0,
136786
+ call: (_args, context) => context?.thisValue
136787
+ });
136788
+ getters.push(species);
136789
+ Object.defineProperty(materializeFunctionProperties(typedArray), Symbol.species, {
136790
+ get: accessorAdapter(species, "get"),
136791
+ configurable: true
136792
+ });
136793
+ for (const key3 of ["length", "byteLength", "byteOffset", "buffer"]) {
136586
136794
  const getter = createSandboxClosure({
136587
136795
  guest: true,
136588
136796
  sandbox: true,
@@ -136598,7 +136806,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136598
136806
  Object.defineProperty(shared, key3, { get: accessorAdapter(getter, "get"), configurable: true });
136599
136807
  }
136600
136808
  for (const key3 of ["set", "slice", "subarray"])
136601
- Object.defineProperty(shared, key3, { value: getFloat32Member(new Float32Array(0), key3, budget), writable: true, configurable: true });
136809
+ Object.defineProperty(shared, key3, { value: getFloat32Member(new Float32Array(0), key3, budget, constructor), writable: true, configurable: true });
136602
136810
  const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
136603
136811
  Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
136604
136812
  Object.defineProperty(shared, "join", {
@@ -136612,7 +136820,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136612
136820
  call: async (args, context) => {
136613
136821
  if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
136614
136822
  const receiver = context.thisValue;
136615
- const length = float32Storage(receiver).length;
136823
+ const length = float32Storage(receiver, true).length;
136616
136824
  let separator = ",";
136617
136825
  let text5 = "";
136618
136826
  const release2 = retainValues(budget, () => [receiver, separator, text5, ...args]);
@@ -136620,7 +136828,8 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136620
136828
  if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
136621
136829
  for (let index = 0; index < length; index++) {
136622
136830
  budget.visitNode();
136623
- text5 = budget.allocateString(text5 + (index === 0 ? "" : separator) + String(receiver[index]));
136831
+ const value = receiver[index];
136832
+ text5 = budget.allocateString(text5 + (index === 0 ? "" : separator) + (value === void 0 ? "" : String(value)));
136624
136833
  }
136625
136834
  return text5;
136626
136835
  } finally {
@@ -136647,6 +136856,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136647
136856
  length: 0,
136648
136857
  call: (args, context) => {
136649
136858
  if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key3} requires a typed array receiver.`);
136859
+ float32Storage(context.thisValue, true);
136650
136860
  return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
136651
136861
  }
136652
136862
  });
@@ -136664,7 +136874,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
136664
136874
  function isFloat32ArrayConstructor(value) {
136665
136875
  return typeof value === "object" && value !== null && constructors.has(value);
136666
136876
  }
136667
- function getFloat32Member(value, property, budget) {
136877
+ function getFloat32Member(value, property, budget, defaultConstructor) {
136668
136878
  const key3 = String(property);
136669
136879
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
136670
136880
  if (descriptor !== void 0) {
@@ -136687,7 +136897,7 @@ function getFloat32Member(value, property, budget) {
136687
136897
  const receiver = context?.thisValue;
136688
136898
  if (!isFloat32Array(receiver))
136689
136899
  throw new TypeError(`Float32Array#${key3} requires a Float32Array receiver.`);
136690
- const storage3 = float32Storage(receiver);
136900
+ const storage3 = float32Storage(receiver, key3 === "slice");
136691
136901
  const bridge = {
136692
136902
  ...context,
136693
136903
  stack: context?.stack ?? [],
@@ -136708,16 +136918,17 @@ function getFloat32Member(value, property, budget) {
136708
136918
  const number = await sandboxNumber(offsetValue, budget, bridge);
136709
136919
  const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
136710
136920
  if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
136921
+ const targetStorage = float32Storage(receiver, true);
136711
136922
  if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
136712
136923
  let length;
136713
- if (isFloat32Array(source)) length = float32Storage(source).length;
136924
+ if (isFloat32Array(source)) length = float32Storage(source, true).length;
136714
136925
  else {
136715
136926
  sourceObject = typeof source === "object" ? source : createSandboxBox(source);
136716
136927
  current = await bridge.getProperty(sourceObject, "length");
136717
136928
  const size = await sandboxNumber(current, budget, bridge);
136718
136929
  length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
136719
136930
  }
136720
- if (offset + length > storage3.length) throw new RangeError("Float32Array#set source is out of bounds.");
136931
+ if (offset + length > targetStorage.length) throw new RangeError("Float32Array#set source is out of bounds.");
136721
136932
  if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
136722
136933
  else for (let index = 0; index < length; index++) {
136723
136934
  budget.visitNode();
@@ -136731,18 +136942,62 @@ function getFloat32Member(value, property, budget) {
136731
136942
  })();
136732
136943
  }
136733
136944
  return (async () => {
136734
- const release2 = retainValues(budget, () => [receiver, ...args]);
136945
+ let candidate;
136946
+ let result;
136947
+ const release2 = retainValues(budget, () => [receiver, candidate, result, ...args]);
136735
136948
  try {
136736
136949
  const start = relativeIndex(await sandboxNumber(args[0], budget, bridge), storage3.length);
136737
136950
  const end = args[1] === void 0 ? storage3.length : relativeIndex(await sandboxNumber(args[1], budget, bridge), storage3.length);
136738
136951
  const length = Math.max(end - start, 0);
136739
- if (key3 === "subarray")
136740
- return new Float32Array(storage3.buffer, storage3.byteOffset + start * 4, length);
136741
- checkFloat32Allocation(length, budget);
136742
- const result = new Float32Array(length);
136743
- new Uint8Array(result.buffer).set(
136744
- new Uint8Array(storage3.buffer, storage3.byteOffset + start * 4, length * 4)
136745
- );
136952
+ const layout = float32ViewLayouts.get(receiver);
136953
+ const offset = (layout?.byteOffset ?? storage3.byteOffset) + start * 4;
136954
+ const tracking = layout !== void 0 && layout.length === void 0 && args[1] === void 0;
136955
+ if (defaultConstructor !== void 0) {
136956
+ candidate = await bridge.getProperty(receiver, "constructor");
136957
+ if (candidate !== void 0) {
136958
+ if (candidate === null || typeof candidate !== "object")
136959
+ throw new TypeError("TypedArray constructor must be an object.");
136960
+ candidate = await bridge.getProperty(candidate, Symbol.species);
136961
+ if (candidate !== void 0 && candidate !== null && (!isSandboxClosure(candidate) || candidate.construct === void 0))
136962
+ throw new TypeError("TypedArray species must be a constructor.");
136963
+ }
136964
+ }
136965
+ if (candidate !== void 0 && candidate !== null && candidate !== defaultConstructor) {
136966
+ const values = key3 === "slice" ? [length] : [storage3.buffer, offset, tracking ? void 0 : length];
136967
+ result = await invokeBuiltinClosure(candidate, values, budget, bridge, void 0, true);
136968
+ if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
136969
+ const target = float32Storage(result, key3 === "slice");
136970
+ if (key3 === "slice" && target.length < length)
136971
+ throw new TypeError("TypedArray species returned insufficient storage.");
136972
+ }
136973
+ if (key3 === "subarray") {
136974
+ if (result === void 0) {
136975
+ result = new Float32Array(storage3.buffer, offset, tracking ? void 0 : length);
136976
+ if (arrayBufferOptions(storage3.buffer) !== void 0)
136977
+ float32ViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
136978
+ }
136979
+ return result;
136980
+ }
136981
+ if (result === void 0) {
136982
+ checkFloat32Allocation(length, budget);
136983
+ result = new Float32Array(length);
136984
+ }
136985
+ if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
136986
+ if (length > 0) {
136987
+ const current = float32Storage(receiver, true);
136988
+ const target = float32Storage(result, true);
136989
+ const count = Math.min(length, Math.max(current.length - start, 0));
136990
+ if (count > 0) {
136991
+ const sourceBytes = new Uint8Array(current.buffer, current.byteOffset + start * 4, count * 4);
136992
+ const targetBytes = new Uint8Array(target.buffer, target.byteOffset, count * 4);
136993
+ if (current.buffer === target.buffer && targetBytes.byteOffset > sourceBytes.byteOffset && targetBytes.byteOffset < sourceBytes.byteOffset + sourceBytes.length) {
136994
+ for (let index = 0; index < sourceBytes.length; index++) {
136995
+ budget.visitNode();
136996
+ targetBytes[index] = sourceBytes[index];
136997
+ }
136998
+ } else targetBytes.set(sourceBytes);
136999
+ }
137000
+ }
136746
137001
  return result;
136747
137002
  } finally {
136748
137003
  release2();
@@ -136789,6 +137044,7 @@ var init_float32array2 = __esm({
136789
137044
  init_iteration();
136790
137045
  init_data_checkpoint();
136791
137046
  init_boxed();
137047
+ init_array_buffer();
136792
137048
  constructors = /* @__PURE__ */ new WeakSet();
136793
137049
  }
136794
137050
  });
@@ -143224,12 +143480,10 @@ function measureSandboxData(values, options = {}) {
143224
143480
  }
143225
143481
  const prototype = getSandboxPrototype(value);
143226
143482
  if (prototype !== null) visit(prototype, depth + 1);
143483
+ if (isSandboxArrayBuffer(value)) usage += arrayBufferLength(value);
143227
143484
  if (isFloat32Array(value)) {
143228
143485
  const storage2 = float32Storage(value);
143229
- if (!seen.has(storage2.buffer)) {
143230
- seen.add(storage2.buffer);
143231
- usage += storage2.byteLength;
143232
- }
143486
+ visit(storage2.buffer, depth + 1);
143233
143487
  for (const [key3, descriptor] of float32Properties(value)) {
143234
143488
  usage += 1;
143235
143489
  if (typeof key3 === "string") usage += key3.length;
@@ -143368,7 +143622,7 @@ function measureSandboxData(values, options = {}) {
143368
143622
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
143369
143623
  if (descriptor !== void 0) descriptors2.push([key3, descriptor]);
143370
143624
  }
143371
- const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
143625
+ const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
143372
143626
  for (const [key3, descriptor] of descriptors2) {
143373
143627
  if (!descriptor.enumerable && !includeNonEnumerable) continue;
143374
143628
  usage += 1 + key3.length;
@@ -143564,6 +143818,20 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
143564
143818
  }
143565
143819
  return sandboxPromise;
143566
143820
  }
143821
+ if (isSandboxArrayBuffer(value)) {
143822
+ const existing = state.seen.get(value);
143823
+ if (existing !== void 0) return existing;
143824
+ const copy = copyArrayBufferStorage(value, state);
143825
+ state.seen.set(value, copy);
143826
+ for (const [key3, descriptor] of arrayBufferDataProperties(value)) {
143827
+ Object.defineProperty(copy, key3, {
143828
+ ...descriptor,
143829
+ value: copyToSandbox(descriptor.value, state, joinPath(path193, key3), cloneSandboxCollections, depth + 1)
143830
+ });
143831
+ }
143832
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
143833
+ return copy;
143834
+ }
143567
143835
  if (nodeTypes.isDate(value)) {
143568
143836
  const existing = state.seen.get(value);
143569
143837
  if (existing !== void 0) return existing;
@@ -143582,6 +143850,7 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
143582
143850
  if (existing !== void 0) return existing;
143583
143851
  const copy = copyFloat32Storage(value, state);
143584
143852
  state.seen.set(value, copy);
143853
+ copyToSandbox(float32Storage(value).buffer, state, `${path193}.buffer`, cloneSandboxCollections, depth + 1);
143585
143854
  for (const [key3, descriptor] of float32DataProperties(value)) {
143586
143855
  Object.defineProperty(copy, key3, {
143587
143856
  ...descriptor,
@@ -143803,6 +144072,7 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
143803
144072
  if (existing !== void 0) return existing;
143804
144073
  const copy = copyFloat32Storage(value, state);
143805
144074
  state.seen.set(value, copy);
144075
+ copyFromSandbox(float32Storage(value).buffer, state, `${path193}.buffer`, options, depth + 1);
143806
144076
  for (const [key3, descriptor] of float32DataProperties(value)) {
143807
144077
  Object.defineProperty(copy, key3, {
143808
144078
  ...descriptor,
@@ -143812,6 +144082,20 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
143812
144082
  if (!Object.isExtensible(value)) Object.preventExtensions(copy);
143813
144083
  return copy;
143814
144084
  }
144085
+ if (isSandboxArrayBuffer(value)) {
144086
+ const existing = state.seen.get(value);
144087
+ if (existing !== void 0) return existing;
144088
+ const copy = copyArrayBufferStorage(value, state);
144089
+ state.seen.set(value, copy);
144090
+ for (const [key3, descriptor] of arrayBufferDataProperties(value)) {
144091
+ Object.defineProperty(copy, key3, {
144092
+ ...descriptor,
144093
+ value: copyFromSandbox(descriptor.value, state, joinPath(path193, key3), options, depth + 1)
144094
+ });
144095
+ }
144096
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
144097
+ return copy;
144098
+ }
143815
144099
  if (isSandboxDate(value)) {
143816
144100
  const existing = state.seen.get(value);
143817
144101
  if (existing !== void 0) return existing;
@@ -143973,6 +144257,16 @@ function allocateSandboxValue2(value, budget, seen) {
143973
144257
  budget.allocateString(value);
143974
144258
  return;
143975
144259
  }
144260
+ if (isSandboxArrayBuffer(value)) {
144261
+ if (seen.has(value)) return;
144262
+ seen.add(value);
144263
+ budget.allocateArrayLength(arrayBufferLength(value));
144264
+ for (const [key3, descriptor] of arrayBufferDataProperties(value)) {
144265
+ if (typeof key3 === "string") budget.allocateString(key3);
144266
+ allocateSandboxValue2(descriptor.value, budget, seen);
144267
+ }
144268
+ return;
144269
+ }
143976
144270
  if (isSandboxBox(value)) {
143977
144271
  if (seen.has(value)) return;
143978
144272
  seen.add(value);
@@ -144133,6 +144427,7 @@ var init_values = __esm({
144133
144427
  "packages/safe-js/src/interp/values.ts"() {
144134
144428
  "use strict";
144135
144429
  init_otel2();
144430
+ init_array_buffer();
144136
144431
  init_internal_symbols();
144137
144432
  init_intrinsics();
144138
144433
  init_generator_properties();
@@ -144601,7 +144896,7 @@ function serializeDumpValue(value, path193, state) {
144601
144896
  if (hasGuestObjectState(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
144602
144897
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
144603
144898
  }
144604
- if (isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path193, state);
144899
+ if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path193, state);
144605
144900
  if (Array.isArray(value)) {
144606
144901
  const reference2 = serializeHeapReference(value, path193, state);
144607
144902
  if (reference2 !== void 0) {
@@ -144673,11 +144968,21 @@ function serializeHeapReference(value, path193, state) {
144673
144968
  const serialized = serializeDumpValue(entry, `${path193}.<date-property>`, state);
144674
144969
  return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
144675
144970
  });
144971
+ } else if (isSandboxArrayBuffer(value)) {
144972
+ state.heap[String(id)] = {
144973
+ ...encodeArrayBufferStorage(value, id, state.float32Buffers, (id2) => ({ kind: "ref", id: id2 })),
144974
+ state: captureArrayBufferState(value, (entry) => {
144975
+ const serialized = serializeDumpValue(entry, `${path193}.<buffer>`, state);
144976
+ return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
144977
+ })
144978
+ };
144676
144979
  } else if (isFloat32Array(value)) {
144677
- const storage2 = encodeFloat32Storage(value, id, state.float32Buffers, (id2) => ({
144678
- kind: "ref",
144679
- id: id2
144680
- }));
144980
+ const backing = float32Storage(value);
144981
+ const storage2 = {
144982
+ kind: "float32array",
144983
+ ...encodeFloat32Layout(value),
144984
+ buffer: serializeHeapReference(backing.buffer, `${path193}.buffer`, state)
144985
+ };
144681
144986
  const entries = /* @__PURE__ */ Object.create(null);
144682
144987
  state.heap[String(id)] = { ...storage2, entries };
144683
144988
  for (const [key3, descriptor] of float32DataProperties(value)) {
@@ -144743,7 +145048,7 @@ function indexHeapContainers(snapshot2) {
144743
145048
  const heapIds = /* @__PURE__ */ new Map();
144744
145049
  let nextId = 1;
144745
145050
  for (const [value, stat35] of stats2.entries()) {
144746
- if (stat35.count > 1 || stat35.forceHeap === true || guestValues.has(value) || stat35.cyclic || hasNullObjectPrototype(value) || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
145051
+ if (stat35.count > 1 || stat35.forceHeap === true || guestValues.has(value) || stat35.cyclic || hasNullObjectPrototype(value) || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || isSandboxArrayBuffer(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
144747
145052
  heapIds.set(value, nextId);
144748
145053
  nextId += 1;
144749
145054
  }
@@ -144775,12 +145080,16 @@ function collectContainerStats(value, stats2, ancestors, guestValues, depth = 0)
144775
145080
  stat35.expanded = true;
144776
145081
  ancestors.add(value);
144777
145082
  const guestEntries = [];
144778
- const guest = captureGuestHeapNode(value, (entry) => {
145083
+ if (isFloat32Array(value)) guestEntries.push(float32Storage(value).buffer);
145084
+ const guest = isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
145085
+ guestEntries.push(entry);
145086
+ return null;
145087
+ }) } : captureGuestHeapNode(value, (entry) => {
144779
145088
  guestEntries.push(entry);
144780
145089
  return null;
144781
145090
  });
144782
145091
  if (guest !== void 0) {
144783
- guestValues.add(value);
145092
+ if (!isSandboxArrayBuffer(value)) guestValues.add(value);
144784
145093
  for (const entry of guestEntries) {
144785
145094
  collectContainerStats(entry, stats2, ancestors, guestValues, depth + 1);
144786
145095
  if (entry !== null && typeof entry === "object") stats2.get(entry).forceHeap = true;
@@ -144788,6 +145097,7 @@ function collectContainerStats(value, stats2, ancestors, guestValues, depth = 0)
144788
145097
  ancestors.delete(value);
144789
145098
  return;
144790
145099
  }
145100
+ for (const entry of guestEntries) collectContainerStats(entry, stats2, ancestors, guestValues, depth + 1);
144791
145101
  if (!Array.isArray(value) && !isPlainObject10(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
144792
145102
  ancestors.delete(value);
144793
145103
  return;
@@ -144854,6 +145164,8 @@ var init_dump_format = __esm({
144854
145164
  init_arrays();
144855
145165
  init_float32();
144856
145166
  init_float32array();
145167
+ init_array_buffer();
145168
+ init_array_buffer2();
144857
145169
  init_date();
144858
145170
  init_date_properties();
144859
145171
  init_boxed();
@@ -145770,12 +146082,43 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path193) {
145770
146082
  state.seen.set(value, date);
145771
146083
  return date;
145772
146084
  }
146085
+ if (isSandboxArrayBuffer(value)) {
146086
+ const existing = state.seen.get(value);
146087
+ if (existing !== void 0) return existing;
146088
+ const length = arrayBufferLength(value);
146089
+ budget.allocateArrayLength(length);
146090
+ budget.provisionDataUsage(length + 1)();
146091
+ const copy = copyArrayBufferStorage(value, state);
146092
+ state.seen.set(value, copy);
146093
+ for (const [key3, descriptor] of arrayBufferDataProperties(value)) {
146094
+ if (typeof key3 === "symbol") throw new TypeError("Host ArrayBuffer symbol properties require an explicit capability path.");
146095
+ Object.defineProperty(copy, key3, {
146096
+ ...descriptor,
146097
+ value: copyHostValueToSandbox(
146098
+ descriptor.value,
146099
+ stackFrames,
146100
+ { ...options, capabilityPath: [...options.capabilityPath ?? [], key3] },
146101
+ state,
146102
+ joinPath2(path193, key3)
146103
+ )
146104
+ });
146105
+ }
146106
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
146107
+ return copy;
146108
+ }
145773
146109
  if (isFloat32Array(value)) {
145774
146110
  const existing = state.seen.get(value);
145775
146111
  if (existing !== void 0) return existing;
145776
146112
  checkFloat32Allocation(Math.ceil(float32Storage(value).byteLength / 4), budget);
145777
146113
  const copy = copyFloat32Storage(value, state);
145778
146114
  state.seen.set(value, copy);
146115
+ copyHostValueToSandbox(
146116
+ float32Storage(value).buffer,
146117
+ stackFrames,
146118
+ { ...options, capabilityPath: [...options.capabilityPath ?? [], "buffer"] },
146119
+ state,
146120
+ `${path193}.buffer`
146121
+ );
145779
146122
  for (const [key3, descriptor] of float32DataProperties(value)) {
145780
146123
  Object.defineProperty(copy, key3, {
145781
146124
  ...descriptor,
@@ -146057,6 +146400,7 @@ var init_host_bridge = __esm({
146057
146400
  init_shape();
146058
146401
  init_budget2();
146059
146402
  init_compile_guard();
146403
+ init_array_buffer();
146060
146404
  init_float32();
146061
146405
  init_exceptions();
146062
146406
  init_otel2();
@@ -148010,6 +148354,142 @@ var init_bigint2 = __esm({
148010
148354
  }
148011
148355
  });
148012
148356
 
148357
+ // packages/safe-js/src/interp/globals/array-buffer.ts
148358
+ function createArrayBufferGlobal(budget) {
148359
+ const prototype = /* @__PURE__ */ Object.create(null);
148360
+ const constructor = createSandboxClosure({
148361
+ guest: true,
148362
+ sandbox: true,
148363
+ name: "ArrayBuffer",
148364
+ length: 1,
148365
+ call: () => {
148366
+ throw new TypeError("ArrayBuffer requires new.");
148367
+ },
148368
+ construct: async (args, context) => {
148369
+ let selected;
148370
+ let current;
148371
+ const bridge = {
148372
+ ...context,
148373
+ stack: context?.stack ?? [],
148374
+ thisValue: void 0,
148375
+ getProperty: context?.getProperty ?? ((value, key3) => {
148376
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
148377
+ return descriptor === void 0 ? getSandboxDataProperty(value, key3, budget) : readPropertyDescriptor(descriptor, value, bridge);
148378
+ }),
148379
+ invokeClosure: context?.invokeClosure ?? ((callee, values, receiver, construct) => invokeBuiltinClosure(callee, values, budget, context, receiver, construct))
148380
+ };
148381
+ const release2 = retainValues(budget, () => [selected, current, ...args]);
148382
+ try {
148383
+ const number = await sandboxNumber(args[0], budget, bridge);
148384
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
148385
+ if (length < 0 || !Number.isSafeInteger(length)) throw new RangeError("Invalid ArrayBuffer length.");
148386
+ let maxByteLength;
148387
+ if (args[1] !== null && typeof args[1] === "object") {
148388
+ current = await bridge.getProperty(args[1], "maxByteLength");
148389
+ if (current !== void 0) {
148390
+ const maximum = await sandboxNumber(current, budget, bridge);
148391
+ maxByteLength = Number.isNaN(maximum) ? 0 : Math.trunc(maximum);
148392
+ if (!Number.isSafeInteger(maxByteLength) || maxByteLength < length)
148393
+ throw new RangeError("Invalid ArrayBuffer maximum length.");
148394
+ }
148395
+ }
148396
+ const target = context?.newTarget ?? constructor;
148397
+ selected = await bridge.getProperty(target, "prototype");
148398
+ budget.allocateArrayLength(maxByteLength ?? length);
148399
+ budget.provisionDataUsage(length + 1)();
148400
+ const result = Reflect.construct(ArrayBuffer, [length, maxByteLength === void 0 ? void 0 : { maxByteLength }]);
148401
+ setSandboxPrototype(result, selected !== null && typeof selected === "object" ? selected : prototype, budget);
148402
+ return result;
148403
+ } finally {
148404
+ release2();
148405
+ }
148406
+ }
148407
+ });
148408
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
148409
+ Object.defineProperty(materializeFunctionProperties(constructor), "isView", {
148410
+ writable: true,
148411
+ configurable: true,
148412
+ value: createSandboxClosure({
148413
+ guest: true,
148414
+ sandbox: true,
148415
+ name: "isView",
148416
+ length: 1,
148417
+ call: (args) => ArrayBuffer.isView(args[0])
148418
+ })
148419
+ });
148420
+ Object.defineProperties(prototype, {
148421
+ constructor: { value: constructor, writable: true, configurable: true },
148422
+ [Symbol.toStringTag]: { value: "ArrayBuffer", configurable: true }
148423
+ });
148424
+ const getters = [];
148425
+ Object.defineProperty(prototype, "resize", {
148426
+ writable: true,
148427
+ configurable: true,
148428
+ value: createSandboxClosure({
148429
+ guest: true,
148430
+ sandbox: true,
148431
+ name: "resize",
148432
+ length: 1,
148433
+ call: async (args, context) => {
148434
+ const receiver = context?.thisValue;
148435
+ if (!isSandboxArrayBuffer(receiver) || arrayBufferOptions(receiver) === void 0)
148436
+ throw new TypeError("ArrayBuffer resize requires a resizable buffer receiver.");
148437
+ const release2 = retainValues(budget, () => [receiver, ...args]);
148438
+ try {
148439
+ const number = await sandboxNumber(args[0], budget, context);
148440
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
148441
+ if (!Number.isSafeInteger(length) || length < 0 || length > arrayBufferOptions(receiver).maxByteLength)
148442
+ throw new RangeError("Invalid ArrayBuffer resize length.");
148443
+ budget.allocateArrayLength(length);
148444
+ budget.provisionDataUsage(Math.max(length - arrayBufferLength(receiver), 0))();
148445
+ Reflect.apply(resizeBuffer2, receiver, [length]);
148446
+ return void 0;
148447
+ } finally {
148448
+ release2();
148449
+ }
148450
+ }
148451
+ })
148452
+ });
148453
+ for (const key3 of ["byteLength", "maxByteLength", "resizable"]) {
148454
+ const getter = createSandboxClosure({
148455
+ guest: true,
148456
+ sandbox: true,
148457
+ name: `get ${key3}`,
148458
+ length: 0,
148459
+ call: (_args, context) => {
148460
+ if (!isSandboxArrayBuffer(context?.thisValue)) throw new TypeError(`ArrayBuffer ${key3} requires a buffer receiver.`);
148461
+ if (key3 === "byteLength") return arrayBufferLength(context.thisValue);
148462
+ const options = arrayBufferOptions(context.thisValue);
148463
+ return key3 === "resizable" ? options !== void 0 : options?.maxByteLength ?? arrayBufferLength(context.thisValue);
148464
+ }
148465
+ });
148466
+ Object.defineProperty(prototype, key3, { get: accessorAdapter(getter, "get"), configurable: true });
148467
+ getters.push(getter);
148468
+ }
148469
+ setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
148470
+ arrayBufferPrototypes.set(budget, prototype);
148471
+ registerBuiltinIdentities(budget, { ArrayBuffer: constructor });
148472
+ registerIntrinsicFunction(budget, constructor);
148473
+ for (const getter of getters) registerIntrinsicFunction(budget, getter);
148474
+ registerIntrinsicObject(budget, prototype);
148475
+ return constructor;
148476
+ }
148477
+ var resizeBuffer2;
148478
+ var init_array_buffer3 = __esm({
148479
+ "packages/safe-js/src/interp/globals/array-buffer.ts"() {
148480
+ "use strict";
148481
+ init_array_buffer();
148482
+ init_accessors();
148483
+ init_values();
148484
+ init_object_model();
148485
+ init_builtin_call();
148486
+ init_intrinsics();
148487
+ init_string_coercion();
148488
+ init_resources();
148489
+ resizeBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
148490
+ }
148491
+ });
148492
+
148013
148493
  // packages/safe-js/src/interp/globals.ts
148014
148494
  function createBuiltinBindings(options) {
148015
148495
  const bindings = {
@@ -148022,6 +148502,7 @@ function createBuiltinBindings(options) {
148022
148502
  ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
148023
148503
  ...createMathGlobals({ random: options.random, budget: options.budget }),
148024
148504
  ...createObjectArrayGlobals(options),
148505
+ ArrayBuffer: createArrayBufferGlobal(options.budget),
148025
148506
  ...createMiscGlobals(options),
148026
148507
  ...createUriGlobals(options.budget),
148027
148508
  ...createPromiseGlobals(options),
@@ -148052,6 +148533,7 @@ var init_globals = __esm({
148052
148533
  init_date2();
148053
148534
  init_symbol();
148054
148535
  init_bigint2();
148536
+ init_array_buffer3();
148055
148537
  init_intrinsics();
148056
148538
  }
148057
148539
  });
@@ -148701,7 +149183,7 @@ var init_template_validation = __esm({
148701
149183
  });
148702
149184
 
148703
149185
  // packages/safe-js/src/snapshot/validation.ts
148704
- import { types as types6 } from "node:util";
149186
+ import { types as types7 } from "node:util";
148705
149187
  function validateSnapshotData(value) {
148706
149188
  validateGenericValue(value, "$", 0, {
148707
149189
  allowFunctions: false,
@@ -148773,6 +149255,11 @@ function validateDumpHeap(root, state) {
148773
149255
  validateDateRecord(entry, path193);
148774
149256
  continue;
148775
149257
  }
149258
+ if (entry.kind === "arraybuffer") {
149259
+ validateArrayBufferStorage(entry);
149260
+ validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
149261
+ continue;
149262
+ }
148776
149263
  if (entry.kind === "float32array") {
148777
149264
  validateFloat32Storage(entry);
148778
149265
  requireRecord3(entry.entries, `${path193}.entries`);
@@ -148996,7 +149483,7 @@ function validateHeapValue(value, path193, state, heap) {
148996
149483
  fail2("invalidValue", path193, String(error3));
148997
149484
  }
148998
149485
  validateErrorType(record4, path193);
148999
- if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
149486
+ if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
149000
149487
  fail2("unknownTag", `${path193}.kind`, "unknown heap tag");
149001
149488
  validateValue(record4, path193, 1, state);
149002
149489
  if (record4.kind === "symbol") validateSymbolRecord(record4, path193, state);
@@ -149005,6 +149492,10 @@ function validateHeapValue(value, path193, state, heap) {
149005
149492
  if (record4.kind === "object") requireRecord3(record4.entries, `${path193}.entries`);
149006
149493
  if (record4.kind === "boxed") validateBoxedRecord(record4, path193, heap);
149007
149494
  if (record4.kind === "date") validateDateRecord(record4, path193);
149495
+ if (record4.kind === "arraybuffer") {
149496
+ validateArrayBufferStorage(record4);
149497
+ validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
149498
+ }
149008
149499
  if (record4.kind === "float32array") {
149009
149500
  validateFloat32Storage(record4);
149010
149501
  requireRecord3(record4.entries, `${path193}.entries`);
@@ -149201,7 +149692,7 @@ function validateGenericValue(value, path193, depth, state) {
149201
149692
  if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
149202
149693
  fail2("invalidState", path193, "guest function properties, prototype links and custom descriptors cannot be restored");
149203
149694
  }
149204
- if (state.dataPropertiesOnly && types6.isProxy(value)) {
149695
+ if (state.dataPropertiesOnly && types7.isProxy(value)) {
149205
149696
  fail2("invalidType", path193, "proxy objects are not snapshot data");
149206
149697
  }
149207
149698
  if (depth > state.limits.maxDepth)
@@ -149338,6 +149829,7 @@ var init_validation = __esm({
149338
149829
  init_dump_format();
149339
149830
  init_graph_depth();
149340
149831
  init_float32array();
149832
+ init_array_buffer2();
149341
149833
  init_date();
149342
149834
  init_boxed2();
149343
149835
  init_object_model();
@@ -150248,6 +150740,7 @@ var init_known_globals = __esm({
150248
150740
  KNOWN_RUNTIME_GLOBALS = [
150249
150741
  "AggregateError",
150250
150742
  "Array",
150743
+ "ArrayBuffer",
150251
150744
  "Boolean",
150252
150745
  "BigInt",
150253
150746
  "Date",
@@ -161007,10 +161500,10 @@ var init_random = __esm({
161007
161500
 
161008
161501
  // packages/safe-js/src/realm.ts
161009
161502
  import { AsyncLocalStorage as AsyncLocalStorage9 } from "node:async_hooks";
161010
- import { types as types7 } from "node:util";
161503
+ import { types as types8 } from "node:util";
161011
161504
  function readModules(input) {
161012
161505
  const entries = (value, label) => {
161013
- if (types7.isMap(value) && !types7.isProxy(value)) {
161506
+ if (types8.isMap(value) && !types8.isProxy(value)) {
161014
161507
  const result = [...Map.prototype.entries.call(value)];
161015
161508
  if (result.length > 4096 || result.some(([key3]) => typeof key3 !== "string" || key3.length === 0))
161016
161509
  throw new TypeError(`${label} requires bounded string keys.`);
@@ -161124,7 +161617,7 @@ var init_realm = __esm({
161124
161617
  throw new TypeError("Realm limits must be positive safe integers with supported names.");
161125
161618
  this.limits[name] = Number(value);
161126
161619
  }
161127
- if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types7.isProxy(options.extensions)))
161620
+ if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types8.isProxy(options.extensions)))
161128
161621
  throw new TypeError("Extensions must be a registration array.");
161129
161622
  const registrations = options.extensions ?? [];
161130
161623
  const extensions = [];
@@ -161359,7 +161852,7 @@ var init_realm = __esm({
161359
161852
  return this.phase.run(phase, () => {
161360
161853
  try {
161361
161854
  const result = call();
161362
- if (types7.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
161855
+ if (types8.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
161363
161856
  return Promise.resolve(result).then(
161364
161857
  async (value) => {
161365
161858
  await Promise.allSettled(phase.pending);
@@ -161428,7 +161921,7 @@ var init_realm = __esm({
161428
161921
  },
161429
161922
  read: (operation, validate2) => {
161430
161923
  const value = this.invokeHost(operation, operation);
161431
- if (types7.isPromise(value)) {
161924
+ if (types8.isPromise(value)) {
161432
161925
  void Promise.resolve(value).catch(() => void 0);
161433
161926
  throw new TypeError("Live property operations must be synchronous.");
161434
161927
  }
@@ -161436,7 +161929,7 @@ var init_realm = __esm({
161436
161929
  },
161437
161930
  write: (operation, value) => {
161438
161931
  const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
161439
- if (types7.isPromise(result)) {
161932
+ if (types8.isPromise(result)) {
161440
161933
  void Promise.resolve(result).catch(() => void 0);
161441
161934
  throw new TypeError("Live property setters must be synchronous.");
161442
161935
  }
@@ -161645,7 +162138,7 @@ var init_realm = __esm({
161645
162138
  }
161646
162139
  });
161647
162140
  const output = getExtensionSetup(extension)(context);
161648
- if (types7.isPromise(output)) {
162141
+ if (types8.isPromise(output)) {
161649
162142
  void Promise.resolve(output).catch(() => void 0);
161650
162143
  throw new TypeError("Extension setup must be synchronous.");
161651
162144
  }
@@ -162279,6 +162772,8 @@ var init_serialize = __esm({
162279
162772
  init_arrays();
162280
162773
  init_float32();
162281
162774
  init_float32array();
162775
+ init_array_buffer();
162776
+ init_array_buffer2();
162282
162777
  init_date();
162283
162778
  init_date_properties();
162284
162779
  init_boxed();