poe-code 14.0.82 → 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 (50) hide show
  1. package/dist/index.js +1105 -223
  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-7LGBDF56.js → chunk-2EZQJQ2C.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-V6LQP64H.js → chunk-CYVI4ZUK.js} +978 -161
  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-prototypes.d.ts +3 -0
  14. package/packages/safe-js/dist/interp/float32-prototypes.js +1 -0
  15. package/packages/safe-js/dist/interp/float32.d.ts +7 -1
  16. package/packages/safe-js/dist/interp/float32.js +50 -14
  17. package/packages/safe-js/dist/interp/globals/array-buffer.d.ts +3 -0
  18. package/packages/safe-js/dist/interp/globals/array-buffer.js +112 -0
  19. package/packages/safe-js/dist/interp/globals/float32array.d.ts +4 -3
  20. package/packages/safe-js/dist/interp/globals/float32array.js +463 -68
  21. package/packages/safe-js/dist/interp/globals/object-array.js +3 -3
  22. package/packages/safe-js/dist/interp/globals.d.ts +2 -0
  23. package/packages/safe-js/dist/interp/globals.js +6 -2
  24. package/packages/safe-js/dist/interp/host-bridge.d.ts +1 -0
  25. package/packages/safe-js/dist/interp/host-bridge.js +21 -0
  26. package/packages/safe-js/dist/interp/host-call.js +26 -2
  27. package/packages/safe-js/dist/interp/instanceof.js +1 -1
  28. package/packages/safe-js/dist/interp/interpreter.js +2 -4
  29. package/packages/safe-js/dist/interp/iteration.js +15 -6
  30. package/packages/safe-js/dist/interp/methods/array-iterator.js +1 -1
  31. package/packages/safe-js/dist/interp/object-model.js +22 -1
  32. package/packages/safe-js/dist/interp/values.d.ts +1 -1
  33. package/packages/safe-js/dist/interp/values.js +59 -9
  34. package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
  35. package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
  36. package/packages/safe-js/dist/parse/parser.js +8 -3
  37. package/packages/safe-js/dist/parse/tokenizer.js +45 -3
  38. package/packages/safe-js/dist/snapshot/array-buffer.d.ts +13 -0
  39. package/packages/safe-js/dist/snapshot/array-buffer.js +40 -0
  40. package/packages/safe-js/dist/snapshot/dump-format.js +25 -9
  41. package/packages/safe-js/dist/snapshot/float32array.d.ts +11 -1
  42. package/packages/safe-js/dist/snapshot/float32array.js +42 -5
  43. package/packages/safe-js/dist/snapshot/replay-data.d.ts +5 -0
  44. package/packages/safe-js/dist/snapshot/replay-data.js +35 -10
  45. package/packages/safe-js/dist/snapshot/restore.js +30 -3
  46. package/packages/safe-js/dist/snapshot/serialize.d.ts +7 -3
  47. package/packages/safe-js/dist/snapshot/serialize.js +24 -14
  48. package/packages/safe-js/dist/snapshot/validation.js +21 -1
  49. package/packages/safe-js/dist/chunks/chunk-V6LQP64H.js.map +0 -7
  50. /package/packages/safe-js/dist/chunks/{chunk-7LGBDF56.js.map → chunk-2EZQJQ2C.js.map} +0 -0
@@ -1175,7 +1175,7 @@ var Lexer = class {
1175
1175
  lastClosedControlParenthesis = false;
1176
1176
  continue;
1177
1177
  }
1178
- if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis)) {
1178
+ if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis, tokens)) {
1179
1179
  if (!this.options.allowRegexLiterals) {
1180
1180
  this.syntaxError("Regular expression literals are not supported", this.position());
1181
1181
  }
@@ -1444,7 +1444,7 @@ var Lexer = class {
1444
1444
  }
1445
1445
  }
1446
1446
  readSlashOrPunctuator(start) {
1447
- if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis)) {
1447
+ if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis, this.tokens)) {
1448
1448
  if (!this.options.allowRegexLiterals) {
1449
1449
  this.syntaxError("Regular expression literals are not supported", start);
1450
1450
  }
@@ -1728,7 +1728,7 @@ function matchPunctuator(source, index) {
1728
1728
  (punctuator) => source.startsWith(punctuator, index) && (punctuator !== "?." || !isDecimalDigit(source[index + 2] ?? ""))
1729
1729
  );
1730
1730
  }
1731
- function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
1731
+ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis, tokens) {
1732
1732
  if (previousToken === void 0) {
1733
1733
  return true;
1734
1734
  }
@@ -1736,6 +1736,7 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
1736
1736
  return false;
1737
1737
  }
1738
1738
  if (previousToken.type === "keyword") {
1739
+ if (previousToken.value === "of") return endsWithForOfSeparator(tokens);
1739
1740
  return !EXPRESSION_ENDING_KEYWORDS.has(previousToken.value);
1740
1741
  }
1741
1742
  if (previousToken.value === ")") {
@@ -1743,6 +1744,35 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
1743
1744
  }
1744
1745
  return !isExpressionEndingPunctuator(previousToken.value);
1745
1746
  }
1747
+ function endsWithForOfSeparator(tokens) {
1748
+ let depth = 0;
1749
+ let start = -1;
1750
+ for (let index = tokens.length - 2; index >= 0; index--) {
1751
+ const token = tokens[index];
1752
+ if (token.type !== "punctuator") continue;
1753
+ if ([")", "]", "}"].includes(token.value)) depth++;
1754
+ else if (["(", "[", "{"].includes(token.value)) {
1755
+ if (depth > 0) {
1756
+ depth--;
1757
+ continue;
1758
+ }
1759
+ if (token.value === "(" && (tokens[index - 1]?.value === "for" || tokens[index - 1]?.value === "await" && tokens[index - 2]?.value === "for")) start = index + 1;
1760
+ break;
1761
+ } else if (depth === 0 && token.value === ";") break;
1762
+ }
1763
+ if (start < 0) return false;
1764
+ depth = 0;
1765
+ for (let index = start; index < tokens.length; index++) {
1766
+ const token = tokens[index];
1767
+ if (token.type === "punctuator") {
1768
+ if (["(", "[", "{"].includes(token.value)) depth++;
1769
+ else if ([")", "]", "}"].includes(token.value)) depth--;
1770
+ }
1771
+ if (depth === 0 && token.type === "keyword" && token.value === "of" && index !== start && tokens[index - 1]?.value !== "." && tokens[index - 1]?.value !== "?." && !(index === start + 1 && ["const", "let", "var"].includes(tokens[start].value)))
1772
+ return index === tokens.length - 1;
1773
+ }
1774
+ return false;
1775
+ }
1746
1776
  function updateGroupingState(groupingStack, previousToken, punctuator) {
1747
1777
  if (punctuator === "(") {
1748
1778
  groupingStack.push({
@@ -5532,6 +5562,7 @@ var Parser = class {
5532
5562
  return void 0;
5533
5563
  }
5534
5564
  findTopLevelForIterationOperator(startIndex) {
5565
+ let operator;
5535
5566
  let depth = 0;
5536
5567
  let previousToken;
5537
5568
  for (let index = startIndex; index < this.tokens.length; index += 1) {
@@ -5541,15 +5572,15 @@ var Parser = class {
5541
5572
  depth += 1;
5542
5573
  } else if (token.value === ")" || token.value === "]" || token.value === "}") {
5543
5574
  if (depth === 0 && token.value === ")") {
5544
- return void 0;
5575
+ return operator;
5545
5576
  }
5546
5577
  depth -= 1;
5547
5578
  } else if (depth === 0 && token.value === ";") {
5548
5579
  return void 0;
5549
5580
  }
5550
5581
  }
5551
- if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && previousToken?.value !== "." && previousToken?.value !== "?.") {
5552
- return token;
5582
+ if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && index !== startIndex && !(token.value === "of" && index === startIndex + 1 && ["const", "let", "var"].includes(previousToken?.value ?? "")) && previousToken?.value !== "." && previousToken?.value !== "?.") {
5583
+ operator ??= token;
5553
5584
  }
5554
5585
  previousToken = token;
5555
5586
  }
@@ -6542,7 +6573,7 @@ function isLiteralPropertyKey(token) {
6542
6573
  return token.type === "numeric" || token.type === "string";
6543
6574
  }
6544
6575
  function isIdentifierLikeToken(token) {
6545
- return token.type === "identifier" || token.type === "keyword" && token.value === "async";
6576
+ return token.type === "identifier" || token.type === "keyword" && (token.value === "async" || token.value === "of");
6546
6577
  }
6547
6578
  function isNewToken(token) {
6548
6579
  return token.value === "new";
@@ -6812,36 +6843,100 @@ function readPendingHostCallPolicyModeValue(value) {
6812
6843
  // packages/safe-js/src/interp/host-call.ts
6813
6844
  import { createHash, randomUUID } from "node:crypto";
6814
6845
 
6846
+ // packages/safe-js/src/interp/array-buffer.ts
6847
+ import { types as types2 } from "node:util";
6848
+ var readLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
6849
+ var readResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
6850
+ var readMaxLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "maxByteLength")?.get;
6851
+ var arrayBufferPrototypes = /* @__PURE__ */ new WeakMap();
6852
+ function isSandboxArrayBuffer(value) {
6853
+ return types2.isArrayBuffer(value) && Object.getPrototypeOf(value) === ArrayBuffer.prototype;
6854
+ }
6855
+ function arrayBufferLength(value) {
6856
+ return Reflect.apply(readLength, value, []);
6857
+ }
6858
+ function arrayBufferOptions(value) {
6859
+ return readResizable !== void 0 && Reflect.apply(readResizable, value, []) ? { maxByteLength: Reflect.apply(readMaxLength, value, []) } : void 0;
6860
+ }
6861
+ function copyArrayBufferStorage(value, state) {
6862
+ state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
6863
+ let copy = state.float32Buffers.get(value);
6864
+ if (copy === void 0) {
6865
+ copy = Reflect.construct(ArrayBuffer, [arrayBufferLength(value), arrayBufferOptions(value)]);
6866
+ new Uint8Array(copy).set(new Uint8Array(value));
6867
+ state.float32Buffers.set(value, copy);
6868
+ }
6869
+ return copy;
6870
+ }
6871
+ function arrayBufferDataProperties(value) {
6872
+ return Reflect.ownKeys(value).map((key) => {
6873
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
6874
+ if (!("value" in descriptor)) throw new TypeError("ArrayBuffer accessors cannot be copied as data.");
6875
+ return [key, descriptor];
6876
+ });
6877
+ }
6878
+
6815
6879
  // packages/safe-js/src/interp/float32.ts
6816
6880
  var typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
6817
- var readLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
6881
+ var readLength2 = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
6818
6882
  var readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
6819
6883
  var readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
6820
6884
  var readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
6885
+ var createValuesIterator = Object.getOwnPropertyDescriptor(typedArrayPrototype, "values").value;
6821
6886
  var bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
6822
6887
  var bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
6888
+ var float32ViewLayouts = /* @__PURE__ */ new WeakMap();
6889
+ var resizeBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
6890
+ function restoreFloat32View(buffer, byteOffset, length, budget) {
6891
+ const originalLength = arrayBufferLength(buffer);
6892
+ const required = byteOffset + (length ?? 0) * 4;
6893
+ const options = arrayBufferOptions(buffer);
6894
+ const grow = required > originalLength;
6895
+ if (grow) {
6896
+ if (options === void 0 || required > options.maxByteLength)
6897
+ throw new RangeError("Float32Array layout exceeds backing capacity.");
6898
+ budget?.allocateArrayLength(Math.ceil(required / 4));
6899
+ budget?.provisionDataUsage(required - originalLength)();
6900
+ Reflect.apply(resizeBuffer, buffer, [required]);
6901
+ }
6902
+ try {
6903
+ const view = new Float32Array(buffer, byteOffset, length);
6904
+ if (options !== void 0) float32ViewLayouts.set(view, { byteOffset, ...length === void 0 ? {} : { length } });
6905
+ return view;
6906
+ } finally {
6907
+ if (grow) Reflect.apply(resizeBuffer, buffer, [originalLength]);
6908
+ }
6909
+ }
6823
6910
  function isFloat32Array(value) {
6824
6911
  return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
6825
6912
  }
6826
- function float32Storage(value) {
6913
+ function float32Storage(value, requireInBounds = false) {
6914
+ if (requireInBounds) Reflect.apply(createValuesIterator, value, []);
6827
6915
  const buffer = Reflect.apply(readBuffer, value, []);
6828
- if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype || bufferResizable !== void 0 && Reflect.apply(bufferResizable, buffer, [])) {
6829
- throw new TypeError("Float32Array requires a fixed, non-shared ArrayBuffer.");
6916
+ if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
6917
+ throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
6830
6918
  }
6831
6919
  return {
6832
6920
  buffer,
6833
6921
  byteOffset: Reflect.apply(readOffset, value, []),
6834
- length: Reflect.apply(readLength, value, []),
6922
+ length: Reflect.apply(readLength2, value, []),
6835
6923
  byteLength: Reflect.apply(bufferLength, buffer, [])
6836
6924
  };
6837
6925
  }
6926
+ function float32Properties(value) {
6927
+ const properties = [];
6928
+ for (const key of Reflect.ownKeys(value)) {
6929
+ if (typeof key === "string" && isFloat32Index(key)) continue;
6930
+ properties.push([key, Object.getOwnPropertyDescriptor(value, key)]);
6931
+ }
6932
+ return properties;
6933
+ }
6838
6934
  function float32DataProperties(value) {
6839
6935
  if (Object.getOwnPropertySymbols(value).length > 0)
6840
6936
  throw new TypeError("Float32Array symbol properties are not supported.");
6841
6937
  const properties = [];
6842
- for (const key of Object.getOwnPropertyNames(value)) {
6843
- if (isFloat32Index(key)) continue;
6844
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
6938
+ for (const [key, descriptor] of float32Properties(value)) {
6939
+ if (typeof key !== "string") throw new TypeError("Float32Array symbol properties are not supported.");
6845
6940
  if (!("value" in descriptor))
6846
6941
  throw new TypeError(`Float32Array accessor property '${key}' is not supported.`);
6847
6942
  properties.push([key, descriptor]);
@@ -6865,18 +6960,17 @@ function checkFloat32Allocation(length, budget) {
6865
6960
  }
6866
6961
  function copyFloat32Storage(value, state) {
6867
6962
  const storage = float32Storage(value);
6868
- state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
6869
- let buffer = state.float32Buffers.get(storage.buffer);
6870
- if (buffer === void 0) {
6871
- buffer = new ArrayBuffer(storage.byteLength);
6872
- new Uint8Array(buffer).set(new Uint8Array(storage.buffer));
6873
- state.float32Buffers.set(storage.buffer, buffer);
6963
+ const buffer = copyArrayBufferStorage(storage.buffer, state);
6964
+ if (bufferResizable !== void 0 && Reflect.apply(bufferResizable, storage.buffer, [])) {
6965
+ const layout = float32ViewLayouts.get(value);
6966
+ if (layout === void 0) throw new TypeError("Resizable Float32Array copies require known view layout.");
6967
+ return restoreFloat32View(buffer, layout.byteOffset, layout.length);
6874
6968
  }
6875
6969
  return new Float32Array(buffer, storage.byteOffset, storage.length);
6876
6970
  }
6877
6971
 
6878
6972
  // packages/safe-js/src/interp/date.ts
6879
- import { types as types2 } from "node:util";
6973
+ import { types as types3 } from "node:util";
6880
6974
  var NativeDate = Date;
6881
6975
  var readTime = NativeDate.prototype.getTime;
6882
6976
  var writeTime = NativeDate.prototype.setTime;
@@ -6893,7 +6987,7 @@ function dateTime(value) {
6893
6987
  return Reflect.apply(readTime, value, []);
6894
6988
  }
6895
6989
  function copyNativeDate(value) {
6896
- if (!types2.isDate(value)) return void 0;
6990
+ if (!types3.isDate(value)) return void 0;
6897
6991
  if (Object.getPrototypeOf(value) !== NativeDate.prototype)
6898
6992
  throw new TypeError("Date subclasses are not supported.");
6899
6993
  return createSandboxDate(dateTime(value));
@@ -7328,7 +7422,7 @@ function copySandboxArgumentProperties(source, target, copyValue) {
7328
7422
  }
7329
7423
 
7330
7424
  // packages/safe-js/src/interp/boxed.ts
7331
- import { types as types3 } from "node:util";
7425
+ import { types as types4 } from "node:util";
7332
7426
  var boxes = /* @__PURE__ */ new WeakSet();
7333
7427
  var numberValue = Number.prototype.valueOf;
7334
7428
  var stringValue = String.prototype.valueOf;
@@ -7336,11 +7430,11 @@ var booleanValue = Boolean.prototype.valueOf;
7336
7430
  var symbolValue = Symbol.prototype.valueOf;
7337
7431
  var bigintValue = BigInt.prototype.valueOf;
7338
7432
  function nativeBoxedValue(value) {
7339
- if (types3.isNumberObject(value)) return Reflect.apply(numberValue, value, []);
7340
- if (types3.isStringObject(value)) return Reflect.apply(stringValue, value, []);
7341
- if (types3.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
7342
- if (types3.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
7343
- if (types3.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
7433
+ if (types4.isNumberObject(value)) return Reflect.apply(numberValue, value, []);
7434
+ if (types4.isStringObject(value)) return Reflect.apply(stringValue, value, []);
7435
+ if (types4.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
7436
+ if (types4.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
7437
+ if (types4.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
7344
7438
  return void 0;
7345
7439
  }
7346
7440
  function createSandboxBox(value) {
@@ -7519,7 +7613,7 @@ async function withRunResources(signal, execute) {
7519
7613
  }
7520
7614
 
7521
7615
  // packages/safe-js/src/interp/host-capabilities.ts
7522
- import { types as types4 } from "node:util";
7616
+ import { types as types5 } from "node:util";
7523
7617
  var MAX_INDEXED_LENGTH = 65536;
7524
7618
  var MAX_NAMED_KEYS = 65536;
7525
7619
  var MAX_NAMED_KEY_CODE_UNITS = 1048576;
@@ -7574,7 +7668,7 @@ function createLiveHostObject(definition, controller) {
7574
7668
  for (const name of ["keys", "get", "set", "delete"]) {
7575
7669
  const operation = data[name];
7576
7670
  if (operation === void 0 && (name === "set" || name === "delete")) continue;
7577
- if (typeof operation !== "function" || types4.isProxy(operation) || types4.isAsyncFunction(operation) || types4.isGeneratorFunction(operation))
7671
+ if (typeof operation !== "function" || types5.isProxy(operation) || types5.isAsyncFunction(operation) || types5.isGeneratorFunction(operation))
7578
7672
  throw new TypeError(`Named ${name} must be a synchronous non-generator function, not a proxy.`);
7579
7673
  }
7580
7674
  if (typeof data.maxKeys !== "number" || !Number.isInteger(data.maxKeys) || data.maxKeys < 1 || data.maxKeys > MAX_NAMED_KEYS)
@@ -7829,7 +7923,7 @@ function namedMutationKeys(state, key, create) {
7829
7923
  function namedKeys(state) {
7830
7924
  const named = state.named;
7831
7925
  return state.controller.read(named.keys, (value) => {
7832
- if (!Array.isArray(value) || types4.isProxy(value))
7926
+ if (!Array.isArray(value) || types5.isProxy(value))
7833
7927
  throw new TypeError("Named keys must be a dense own-data array of strings, not a proxy.");
7834
7928
  const length = Object.getOwnPropertyDescriptor(value, "length").value;
7835
7929
  if (length > named.maxKeys) throw new RangeError("Named keys exceed maxKeys.");
@@ -7865,6 +7959,9 @@ function namedKeys(state) {
7865
7959
  // packages/safe-js/src/interp/error-prototypes.ts
7866
7960
  var errorPrototypes = /* @__PURE__ */ new WeakMap();
7867
7961
 
7962
+ // packages/safe-js/src/interp/float32-prototypes.ts
7963
+ var float32Prototypes = /* @__PURE__ */ new WeakMap();
7964
+
7868
7965
  // packages/safe-js/src/interp/object-model.ts
7869
7966
  var guestClosures = /* @__PURE__ */ new WeakSet();
7870
7967
  var functionProperties = /* @__PURE__ */ new WeakMap();
@@ -8090,11 +8187,15 @@ function releaseObjectPrototype(budget) {
8090
8187
  functionPrototypes.delete(budget);
8091
8188
  generatorPrototypes.delete(budget);
8092
8189
  errorPrototypes.delete(budget);
8190
+ float32Prototypes.delete(budget);
8191
+ arrayBufferPrototypes.delete(budget);
8093
8192
  initialRegexDescriptors.delete(budget);
8094
8193
  intrinsicPrototypes.delete(budget);
8095
8194
  }
8096
8195
  function getSandboxPrototype(value, budget) {
8097
8196
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
8197
+ if (isSandboxArrayBuffer(value)) return budget === void 0 ? null : arrayBufferPrototypes.get(budget) ?? null;
8198
+ if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
8098
8199
  const errorType = sandboxErrorTypes.get(value);
8099
8200
  if (budget !== void 0 && errorType !== void 0) {
8100
8201
  const prototype = errorPrototypes.get(budget)?.get(errorType);
@@ -8127,6 +8228,8 @@ function getSandboxPropertyDescriptor(value, key, budget) {
8127
8228
  let current = value;
8128
8229
  let depth = 0;
8129
8230
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8231
+ if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8232
+ return Object.getOwnPropertyDescriptor(current, key);
8130
8233
  const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8131
8234
  if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
8132
8235
  return {
@@ -8149,6 +8252,8 @@ function getSandboxDataProperty(value, key, budget) {
8149
8252
  let current = value;
8150
8253
  let depth = 0;
8151
8254
  while (typeof current === "object" && current !== null) {
8255
+ if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8256
+ return Object.getOwnPropertyDescriptor(current, key)?.value;
8152
8257
  if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
8153
8258
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
8154
8259
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key)?.value;
@@ -8200,6 +8305,8 @@ function setSandboxPrototype(value, prototype, budget) {
8200
8305
  prototypes.set(value, prototype);
8201
8306
  }
8202
8307
  function isPrototypeRecord(value) {
8308
+ if (isSandboxArrayBuffer(value)) return true;
8309
+ if (isFloat32Array(value)) return true;
8203
8310
  if (isGuestClosure(value)) return true;
8204
8311
  if (isGuestHostObject(value)) return false;
8205
8312
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
@@ -8219,7 +8326,7 @@ function hasGuestObjectState(value) {
8219
8326
  if (isLiveCapability(value)) return true;
8220
8327
  if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
8221
8328
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
8222
- return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
8329
+ return descriptorObjects.has(value) && (isFloat32Array(value) ? float32Properties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
8223
8330
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
8224
8331
  );
8225
8332
  }
@@ -8463,7 +8570,7 @@ function restoreRegexProperties(value, data, decode) {
8463
8570
  }
8464
8571
 
8465
8572
  // packages/safe-js/src/snapshot/validation.ts
8466
- import { types as types6 } from "node:util";
8573
+ import { types as types7 } from "node:util";
8467
8574
 
8468
8575
  // packages/safe-js/src/interp/builtin-call.ts
8469
8576
  async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
@@ -9503,6 +9610,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9503
9610
  const iterator = await invokeBuiltinClosure(factory, [], budget, context, value);
9504
9611
  if (typeof iterator !== "object" && typeof iterator !== "function" || iterator === null)
9505
9612
  throw new TypeError("Iterator must be an object.");
9613
+ if (!asyncProtocol && isSandboxGenerator(iterator) && !iterator.async && !hasExplicitSandboxPrototype(iterator) && getSandboxPropertyDescriptor(iterator, "next", budget) === void 0)
9614
+ return getSandboxIterator(iterator, budget, context);
9506
9615
  const next = await context.getProperty(iterator, "next");
9507
9616
  return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
9508
9617
  }
@@ -9535,7 +9644,7 @@ async function readIteratorResult(iterator, result, property) {
9535
9644
  }
9536
9645
  function getSandboxAsyncIterator(value, budget, context, signal) {
9537
9646
  if (isSandboxGenerator(value) && value.async) {
9538
- return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
9647
+ return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? guestProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
9539
9648
  }
9540
9649
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
9541
9650
  const method = value[Symbol.asyncIterator];
@@ -9682,11 +9791,15 @@ function getSandboxIterator(value, budget, context) {
9682
9791
  }
9683
9792
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
9684
9793
  if (isFloat32Array(value)) {
9794
+ if (hasExplicitSandboxPrototype(value) || budget !== void 0 && float32Prototypes.has(budget)) {
9795
+ if (getSandboxPropertyDescriptor(value, Symbol.iterator, budget) === void 0) return void 0;
9796
+ return guestProtocolAdapter(value, budget ?? new Budget(), context, false);
9797
+ }
9685
9798
  return syncIterator(Float32Array.prototype.values.call(value));
9686
9799
  }
9687
9800
  if (isSandboxGenerator(value)) {
9688
9801
  if (value.async) return void 0;
9689
- if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9802
+ if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9690
9803
  return generatorObjectIterator(value, budget, context);
9691
9804
  }
9692
9805
  if (typeof value === "string") {
@@ -9764,7 +9877,7 @@ function collectionIterator(collection, value) {
9764
9877
  return adapter;
9765
9878
  }
9766
9879
  var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
9767
- function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
9880
+ function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
9768
9881
  const bridge = {
9769
9882
  ...context,
9770
9883
  stack: context?.stack ?? [],
@@ -9778,7 +9891,7 @@ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal)
9778
9891
  let resolved;
9779
9892
  let pending;
9780
9893
  const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
9781
- if (iterator === void 0) throw new TypeError("Generator does not provide an iterator protocol.");
9894
+ if (iterator === void 0) throw new TypeError("Value does not provide an iterator protocol.");
9782
9895
  return resolved = iterator;
9783
9896
  });
9784
9897
  return {
@@ -10606,7 +10719,7 @@ async function nextArrayIterator(value, budget, context) {
10606
10719
  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);
10607
10720
  try {
10608
10721
  budget.visitNode();
10609
- const number = isFloat32Array(source) ? float32Storage(source).length : await sandboxNumber(await read("length"), budget, context);
10722
+ const number = isFloat32Array(source) ? float32Storage(source, true).length : await sandboxNumber(await read("length"), budget, context);
10610
10723
  const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
10611
10724
  if (index >= length) {
10612
10725
  state.source = void 0;
@@ -10871,7 +10984,7 @@ function formatNumber(value, methodName, argument, budget) {
10871
10984
  }
10872
10985
 
10873
10986
  // packages/safe-js/src/interp/methods/string.ts
10874
- import { types as types5 } from "node:util";
10987
+ import { types as types6 } from "node:util";
10875
10988
 
10876
10989
  // packages/safe-js/src/interp/methods/string-locale.ts
10877
10990
  var collatorOptions = [
@@ -11022,7 +11135,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
11022
11135
  };
11023
11136
  const symbol = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "matchAll" ? Symbol.matchAll : methodName === "replace" || methodName === "replaceAll" ? Symbol.replace : methodName === "split" ? Symbol.split : void 0;
11024
11137
  const pattern = args[0];
11025
- if (symbol !== void 0 && types5.isRegExp(pattern))
11138
+ if (symbol !== void 0 && types6.isRegExp(pattern))
11026
11139
  throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
11027
11140
  if (symbol === void 0 || pattern === null || pattern === void 0) return fallback();
11028
11141
  const readProperty = (key) => context?.getProperty !== void 0 ? context.getProperty(pattern, key) : key === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key, budget) === void 0 ? getRegexMember(pattern, key, budget, context) : getSandboxDataProperty(pattern, key, budget);
@@ -13649,8 +13762,8 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
13649
13762
  }
13650
13763
  function defineDataProperty(target, key, descriptor, budget) {
13651
13764
  budget.visitNode();
13652
- if (isFloat32Array(target))
13653
- throw new TypeError("Typed array property descriptors are not supported.");
13765
+ if (isFloat32Array(target) && typeof key !== "symbol" && isFloat32Index(String(key)) && "value" in descriptor)
13766
+ descriptor = { ...descriptor, value: float32Number(descriptor.value) };
13654
13767
  const properties = objectProperties(target, true);
13655
13768
  if (Array.isArray(properties)) {
13656
13769
  if (key === "length" && "value" in descriptor)
@@ -14485,8 +14598,9 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14485
14598
 
14486
14599
  // packages/safe-js/src/interp/globals/float32array.ts
14487
14600
  var constructors = /* @__PURE__ */ new WeakSet();
14488
- function createFloat32ArrayGlobal(budget) {
14601
+ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
14489
14602
  const constructor = createSandboxClosure({
14603
+ guest: nativePrototype,
14490
14604
  sandbox: true,
14491
14605
  name: "Float32Array",
14492
14606
  length: 3,
@@ -14494,42 +14608,357 @@ function createFloat32ArrayGlobal(budget) {
14494
14608
  call: () => {
14495
14609
  throw new TypeError("Constructor Float32Array requires 'new'.");
14496
14610
  },
14497
- construct: ([source]) => {
14498
- if (Array.isArray(source) || isFloat32Array(source)) {
14499
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14500
- checkFloat32Allocation(length2, budget);
14501
- if (isFloat32Array(source)) return new Float32Array(source);
14502
- const result = new Float32Array(length2);
14503
- for (let index = 0; index < length2; index += 1) {
14504
- budget.visitNode();
14505
- const descriptor = Object.getOwnPropertyDescriptor(source, index);
14506
- if (descriptor !== void 0 && !("value" in descriptor))
14507
- throw new TypeError("Float32Array input accessors are not supported.");
14508
- result[index] = float32Number(descriptor?.value);
14611
+ construct: (args, context) => {
14612
+ if (!nativePrototype) return allocateFloat32Array(args[0], budget);
14613
+ return (async () => {
14614
+ const newTarget = context?.newTarget ?? constructor;
14615
+ const candidate = context?.getProperty === void 0 ? getSandboxDataProperty(newTarget, "prototype", budget) : await context.getProperty(newTarget, "prototype");
14616
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
14617
+ const release = retainValues(budget, () => [prototype, ...args]);
14618
+ try {
14619
+ if (isSandboxArrayBuffer(args[0])) {
14620
+ const buffer = args[0];
14621
+ const number = await sandboxNumber(args[1], budget, context);
14622
+ const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
14623
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset % 4 !== 0)
14624
+ throw new RangeError("Invalid Float32Array buffer offset.");
14625
+ const bytes = arrayBufferLength(buffer);
14626
+ let length;
14627
+ if (args[2] === void 0) {
14628
+ if (arrayBufferOptions(buffer) === void 0 && bytes % 4 !== 0 || offset > bytes)
14629
+ throw new RangeError("Invalid Float32Array buffer length.");
14630
+ length = Math.floor((bytes - offset) / 4);
14631
+ } else {
14632
+ const size = await sandboxNumber(args[2], budget, context);
14633
+ length = Number.isNaN(size) ? 0 : Math.trunc(size);
14634
+ if (!Number.isSafeInteger(length) || length < 0 || offset + length * 4 > arrayBufferLength(buffer))
14635
+ throw new RangeError("Invalid Float32Array view length.");
14636
+ }
14637
+ budget.allocateArrayLength(length);
14638
+ const result2 = new Float32Array(buffer, offset, args[2] === void 0 ? void 0 : length);
14639
+ if (arrayBufferOptions(buffer) !== void 0)
14640
+ float32ViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
14641
+ setSandboxPrototype(result2, prototype, budget);
14642
+ return result2;
14643
+ }
14644
+ const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
14645
+ setSandboxPrototype(result, prototype, budget);
14646
+ return result;
14647
+ } finally {
14648
+ release();
14509
14649
  }
14510
- return result;
14511
- }
14512
- const number = float32Number(source);
14513
- const length = Number.isNaN(number) ? 0 : Math.trunc(number);
14514
- if (length < 0 || !Number.isSafeInteger(length))
14515
- throw new RangeError("Invalid typed array length.");
14516
- checkFloat32Allocation(length, budget);
14517
- return new Float32Array(length);
14650
+ })();
14518
14651
  }
14519
14652
  });
14520
14653
  constructors.add(constructor);
14521
14654
  return constructor;
14522
14655
  }
14656
+ async function allocateFloat32Input(source, budget, context) {
14657
+ const callerContext = context;
14658
+ const bridge = {
14659
+ ...callerContext,
14660
+ stack: callerContext?.stack ?? [],
14661
+ thisValue: void 0,
14662
+ getProperty: callerContext?.getProperty ?? ((value, key) => {
14663
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14664
+ return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, bridge);
14665
+ }),
14666
+ invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, receiver, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, receiver, construct))
14667
+ };
14668
+ const values = [];
14669
+ let iterator;
14670
+ let current;
14671
+ let result;
14672
+ const release = retainValues(budget, () => [source, values, iterator?.retainedValue, current, result]);
14673
+ const checkData = createDataCheckpoint(budget, bridge);
14674
+ try {
14675
+ iterator = await acquireSandboxIterator(source, budget, bridge);
14676
+ let length;
14677
+ if (iterator !== void 0) {
14678
+ while (true) {
14679
+ budget.visitNode();
14680
+ const next = await iterator.next();
14681
+ if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
14682
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
14683
+ current = (await readIteratorResult(iterator, next, "value")).value;
14684
+ budget.allocateArrayLength(values.length + 1);
14685
+ values.push(current);
14686
+ checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
14687
+ }
14688
+ length = values.length;
14689
+ } else {
14690
+ current = await bridge.getProperty(source, "length");
14691
+ const number = await sandboxNumber(current, budget, bridge);
14692
+ length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14693
+ }
14694
+ checkFloat32Allocation(length, budget);
14695
+ result = new Float32Array(length);
14696
+ checkData(result, 0, true);
14697
+ for (let index = 0; index < length; index++) {
14698
+ budget.visitNode();
14699
+ current = iterator === void 0 ? await bridge.getProperty(source, String(index)) : values[index];
14700
+ result[index] = await sandboxNumber(current, budget, bridge);
14701
+ }
14702
+ return result;
14703
+ } finally {
14704
+ release();
14705
+ }
14706
+ }
14707
+ function allocateFloat32Array(source, budget) {
14708
+ if (Array.isArray(source) || isFloat32Array(source)) {
14709
+ const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14710
+ checkFloat32Allocation(length2, budget);
14711
+ if (isFloat32Array(source)) return new Float32Array(source);
14712
+ const result = new Float32Array(length2);
14713
+ for (let index = 0; index < length2; index += 1) {
14714
+ budget.visitNode();
14715
+ const descriptor = Object.getOwnPropertyDescriptor(source, index);
14716
+ if (descriptor !== void 0 && !("value" in descriptor))
14717
+ throw new TypeError("Float32Array input accessors are not supported.");
14718
+ result[index] = float32Number(descriptor?.value);
14719
+ }
14720
+ return result;
14721
+ }
14722
+ const number = float32Number(source);
14723
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
14724
+ if (length < 0 || !Number.isSafeInteger(length))
14725
+ throw new RangeError("Invalid typed array length.");
14726
+ checkFloat32Allocation(length, budget);
14727
+ return new Float32Array(length);
14728
+ }
14729
+ function createFloat32ArrayPrototypes(budget, constructor) {
14730
+ const prototype = /* @__PURE__ */ Object.create(null);
14731
+ const shared = /* @__PURE__ */ Object.create(null);
14732
+ const abstractCall = () => {
14733
+ throw new TypeError("Abstract TypedArray constructor cannot be called.");
14734
+ };
14735
+ const typedArray = createSandboxClosure({
14736
+ guest: true,
14737
+ sandbox: true,
14738
+ name: "TypedArray",
14739
+ length: 0,
14740
+ call: abstractCall,
14741
+ construct: abstractCall
14742
+ });
14743
+ Object.defineProperty(materializeFunctionProperties(typedArray), "prototype", { value: shared, writable: false });
14744
+ Object.defineProperty(materializeFunctionProperties(typedArray), "from", {
14745
+ writable: true,
14746
+ configurable: true,
14747
+ value: createSandboxClosure({
14748
+ guest: true,
14749
+ sandbox: true,
14750
+ name: "from",
14751
+ length: 1,
14752
+ call: async (args, context) => {
14753
+ const target = context?.thisValue;
14754
+ const [source, mapper, receiver] = args;
14755
+ if (!isSandboxClosure(target) || target.construct === void 0)
14756
+ throw new TypeError("TypedArray.from requires a constructor receiver.");
14757
+ if (mapper !== void 0 && !isSandboxClosure(mapper))
14758
+ throw new TypeError("TypedArray.from mapper must be callable.");
14759
+ if (source === null || source === void 0)
14760
+ throw new TypeError("TypedArray.from requires a non-null source.");
14761
+ const callerContext = context;
14762
+ context = {
14763
+ ...callerContext,
14764
+ stack: callerContext?.stack ?? [],
14765
+ thisValue: target,
14766
+ getProperty: callerContext?.getProperty ?? ((value, key) => {
14767
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14768
+ return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, context);
14769
+ }),
14770
+ invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, thisValue, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, thisValue, construct))
14771
+ };
14772
+ let result;
14773
+ let current;
14774
+ let iterator;
14775
+ const values = [];
14776
+ const release = retainValues(budget, () => [target, result, current, iterator?.retainedValue, values, ...args]);
14777
+ const checkData = createDataCheckpoint(budget, context);
14778
+ const read = (key) => context?.getProperty === void 0 ? getSandboxDataProperty(source, key, budget) : context.getProperty(source, key);
14779
+ try {
14780
+ iterator = await acquireSandboxIterator(source, budget, context);
14781
+ let length;
14782
+ if (iterator !== void 0) {
14783
+ while (true) {
14784
+ budget.visitNode();
14785
+ const next = await iterator.next();
14786
+ if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
14787
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
14788
+ current = (await readIteratorResult(iterator, next, "value")).value;
14789
+ budget.allocateArrayLength(values.length + 1);
14790
+ values.push(current);
14791
+ checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
14792
+ }
14793
+ length = values.length;
14794
+ } else {
14795
+ const number = await sandboxNumber(await read("length"), budget, context);
14796
+ length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14797
+ }
14798
+ result = await invokeBuiltinClosure(target, [length], budget, context, void 0, true);
14799
+ if (!isFloat32Array(result) || float32Storage(result).length < length)
14800
+ throw new TypeError("TypedArray.from constructor must return sufficient typed storage.");
14801
+ checkData(result, 0, true);
14802
+ for (let index = 0; index < length; index++) {
14803
+ budget.visitNode();
14804
+ current = iterator === void 0 ? await read(String(index)) : values[index];
14805
+ if (mapper !== void 0)
14806
+ current = await invokeBuiltinClosure(mapper, [current, index], budget, context, receiver);
14807
+ result[index] = await sandboxNumber(current, budget, context);
14808
+ }
14809
+ return result;
14810
+ } finally {
14811
+ release();
14812
+ }
14813
+ }
14814
+ })
14815
+ });
14816
+ Object.defineProperty(materializeFunctionProperties(typedArray), "of", {
14817
+ writable: true,
14818
+ configurable: true,
14819
+ value: createSandboxClosure({
14820
+ guest: true,
14821
+ sandbox: true,
14822
+ name: "of",
14823
+ length: 0,
14824
+ call: async (args, context) => {
14825
+ const target = context?.thisValue;
14826
+ if (!isSandboxClosure(target) || target.construct === void 0)
14827
+ throw new TypeError("TypedArray.of requires a constructor receiver.");
14828
+ let result;
14829
+ const release = retainValues(budget, () => [target, result, ...args]);
14830
+ try {
14831
+ result = await invokeBuiltinClosure(target, [args.length], budget, context, void 0, true);
14832
+ if (!isFloat32Array(result) || float32Storage(result).length < args.length)
14833
+ throw new TypeError("TypedArray.of constructor must return sufficient typed storage.");
14834
+ for (let index = 0; index < args.length; index++) {
14835
+ budget.visitNode();
14836
+ result[index] = await sandboxNumber(args[index], budget, context);
14837
+ }
14838
+ return result;
14839
+ } finally {
14840
+ release();
14841
+ }
14842
+ }
14843
+ })
14844
+ });
14845
+ Object.defineProperties(materializeFunctionProperties(constructor), {
14846
+ prototype: { value: prototype, writable: false },
14847
+ BYTES_PER_ELEMENT: { value: 4, writable: false, enumerable: false, configurable: false }
14848
+ });
14849
+ Object.defineProperties(prototype, {
14850
+ constructor: { value: constructor, writable: true, configurable: true },
14851
+ BYTES_PER_ELEMENT: { value: 4 }
14852
+ });
14853
+ Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
14854
+ setSandboxPrototype(constructor, typedArray);
14855
+ setSandboxPrototype(prototype, shared);
14856
+ setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
14857
+ const getters = [];
14858
+ const species = createSandboxClosure({
14859
+ guest: true,
14860
+ sandbox: true,
14861
+ name: "get [Symbol.species]",
14862
+ length: 0,
14863
+ call: (_args, context) => context?.thisValue
14864
+ });
14865
+ getters.push(species);
14866
+ Object.defineProperty(materializeFunctionProperties(typedArray), Symbol.species, {
14867
+ get: accessorAdapter(species, "get"),
14868
+ configurable: true
14869
+ });
14870
+ for (const key of ["length", "byteLength", "byteOffset", "buffer"]) {
14871
+ const getter = createSandboxClosure({
14872
+ guest: true,
14873
+ sandbox: true,
14874
+ name: `get ${key}`,
14875
+ length: 0,
14876
+ call: (_args, context) => {
14877
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14878
+ const storage = float32Storage(context.thisValue);
14879
+ return key === "byteLength" ? storage.length * 4 : storage[key];
14880
+ }
14881
+ });
14882
+ getters.push(getter);
14883
+ Object.defineProperty(shared, key, { get: accessorAdapter(getter, "get"), configurable: true });
14884
+ }
14885
+ for (const key of ["set", "slice", "subarray"])
14886
+ Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget, constructor), writable: true, configurable: true });
14887
+ const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
14888
+ Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
14889
+ Object.defineProperty(shared, "join", {
14890
+ writable: true,
14891
+ configurable: true,
14892
+ value: createSandboxClosure({
14893
+ guest: true,
14894
+ sandbox: true,
14895
+ name: "join",
14896
+ length: 1,
14897
+ call: async (args, context) => {
14898
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
14899
+ const receiver = context.thisValue;
14900
+ const length = float32Storage(receiver, true).length;
14901
+ let separator = ",";
14902
+ let text = "";
14903
+ const release = retainValues(budget, () => [receiver, separator, text, ...args]);
14904
+ try {
14905
+ if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
14906
+ for (let index = 0; index < length; index++) {
14907
+ budget.visitNode();
14908
+ const value = receiver[index];
14909
+ text = budget.allocateString(text + (index === 0 ? "" : separator) + (value === void 0 ? "" : String(value)));
14910
+ }
14911
+ return text;
14912
+ } finally {
14913
+ release();
14914
+ }
14915
+ }
14916
+ })
14917
+ });
14918
+ const tagGetter = createSandboxClosure({
14919
+ guest: true,
14920
+ sandbox: true,
14921
+ name: "get [Symbol.toStringTag]",
14922
+ length: 0,
14923
+ call: (_args, context) => isFloat32Array(context?.thisValue) ? "Float32Array" : void 0
14924
+ });
14925
+ getters.push(tagGetter);
14926
+ Object.defineProperty(shared, Symbol.toStringTag, { get: accessorAdapter(tagGetter, "get"), configurable: true });
14927
+ for (const key of ["values", "keys", "entries"]) {
14928
+ const method = getSandboxDataProperty(arrayPrototype, key, budget);
14929
+ const closure = createSandboxClosure({
14930
+ guest: true,
14931
+ sandbox: true,
14932
+ name: key,
14933
+ length: 0,
14934
+ call: (args, context) => {
14935
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14936
+ float32Storage(context.thisValue, true);
14937
+ return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
14938
+ }
14939
+ });
14940
+ Object.defineProperty(shared, key, { value: closure, writable: true, configurable: true });
14941
+ if (key === "values") Object.defineProperty(shared, Symbol.iterator, { value: closure, writable: true, configurable: true });
14942
+ }
14943
+ float32Prototypes.set(budget, prototype);
14944
+ registerBuiltinIdentities(budget, { Float32Array: constructor, "%TypedArray%": typedArray });
14945
+ registerIntrinsicFunction(budget, constructor);
14946
+ registerIntrinsicFunction(budget, typedArray);
14947
+ registerIntrinsicObject(budget, prototype);
14948
+ registerIntrinsicObject(budget, shared);
14949
+ for (const getter of getters) registerIntrinsicFunction(budget, getter);
14950
+ }
14523
14951
  function isFloat32ArrayConstructor(value) {
14524
14952
  return typeof value === "object" && value !== null && constructors.has(value);
14525
14953
  }
14526
- function getFloat32Member(value, property, budget) {
14954
+ function getFloat32Member(value, property, budget, defaultConstructor) {
14527
14955
  const key = String(property);
14528
14956
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
14529
14957
  if (descriptor !== void 0) {
14530
14958
  if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
14531
14959
  return descriptor.value;
14532
14960
  }
14961
+ if (float32Prototypes.has(budget)) return void 0;
14533
14962
  const storage = float32Storage(value);
14534
14963
  if (key === "length") return storage.length;
14535
14964
  if (key === "byteLength") return storage.length * 4;
@@ -14537,6 +14966,7 @@ function getFloat32Member(value, property, budget) {
14537
14966
  if (key === "BYTES_PER_ELEMENT") return 4;
14538
14967
  if (!["set", "slice", "subarray"].includes(key)) return void 0;
14539
14968
  return createSandboxClosure({
14969
+ guest: true,
14540
14970
  sandbox: true,
14541
14971
  name: key,
14542
14972
  length: key === "set" ? 1 : 2,
@@ -14544,66 +14974,134 @@ function getFloat32Member(value, property, budget) {
14544
14974
  const receiver = context?.thisValue;
14545
14975
  if (!isFloat32Array(receiver))
14546
14976
  throw new TypeError(`Float32Array#${key} requires a Float32Array receiver.`);
14547
- const storage2 = float32Storage(receiver);
14977
+ const storage2 = float32Storage(receiver, key === "slice");
14978
+ const bridge = {
14979
+ ...context,
14980
+ stack: context?.stack ?? [],
14981
+ thisValue: receiver,
14982
+ getProperty: context?.getProperty ?? ((value2, property2) => {
14983
+ const descriptor2 = getSandboxPropertyDescriptor(value2, property2, budget);
14984
+ return descriptor2 === void 0 ? getSandboxDataProperty(value2, property2, budget) : readPropertyDescriptor(descriptor2, value2, bridge);
14985
+ }),
14986
+ invokeClosure: context?.invokeClosure ?? ((callee, values, thisValue, construct) => invokeBuiltinClosure(callee, values, budget, context, thisValue, construct))
14987
+ };
14548
14988
  if (key === "set") {
14549
- const [source, offsetValue = 0] = args;
14550
- if (!Array.isArray(source) && !isFloat32Array(source))
14551
- throw new TypeError("Float32Array#set requires an array or Float32Array.");
14552
- const number = float32Number(offsetValue);
14553
- const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
14554
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14555
- if (offset < 0 || !Number.isSafeInteger(offset) || offset + length2 > storage2.length)
14556
- throw new RangeError("Float32Array#set source is out of bounds.");
14557
- if (isFloat32Array(source)) {
14558
- Float32Array.prototype.set.call(receiver, source, offset);
14559
- return void 0;
14560
- }
14561
- checkFloat32Allocation(length2, budget);
14562
- const copied = new Float32Array(length2);
14563
- for (let index = 0; index < length2; index += 1) {
14564
- budget.visitNode();
14565
- const entry = Object.getOwnPropertyDescriptor(source, index);
14566
- if (entry !== void 0 && !("value" in entry))
14567
- throw new TypeError("Float32Array input accessors are not supported.");
14568
- copied[index] = float32Number(entry?.value);
14569
- }
14570
- Float32Array.prototype.set.call(receiver, copied, offset);
14571
- return void 0;
14989
+ return (async () => {
14990
+ const [source, offsetValue = 0] = args;
14991
+ let current;
14992
+ let sourceObject;
14993
+ const release = retainValues(budget, () => [receiver, sourceObject, current, ...args]);
14994
+ try {
14995
+ const number = await sandboxNumber(offsetValue, budget, bridge);
14996
+ const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
14997
+ if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
14998
+ const targetStorage = float32Storage(receiver, true);
14999
+ if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
15000
+ let length;
15001
+ if (isFloat32Array(source)) length = float32Storage(source, true).length;
15002
+ else {
15003
+ sourceObject = typeof source === "object" ? source : createSandboxBox(source);
15004
+ current = await bridge.getProperty(sourceObject, "length");
15005
+ const size = await sandboxNumber(current, budget, bridge);
15006
+ length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
15007
+ }
15008
+ if (offset + length > targetStorage.length) throw new RangeError("Float32Array#set source is out of bounds.");
15009
+ if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
15010
+ else for (let index = 0; index < length; index++) {
15011
+ budget.visitNode();
15012
+ current = await bridge.getProperty(sourceObject, String(index));
15013
+ receiver[offset + index] = await sandboxNumber(current, budget, bridge);
15014
+ }
15015
+ return void 0;
15016
+ } finally {
15017
+ release();
15018
+ }
15019
+ })();
14572
15020
  }
14573
- const start = relativeIndex(args[0], storage2.length, 0);
14574
- const end = relativeIndex(args[1], storage2.length, storage2.length);
14575
- const length = Math.max(end - start, 0);
14576
- if (key === "subarray")
14577
- return new Float32Array(storage2.buffer, storage2.byteOffset + start * 4, length);
14578
- checkFloat32Allocation(length, budget);
14579
- const result = new Float32Array(length);
14580
- new Uint8Array(result.buffer).set(
14581
- new Uint8Array(storage2.buffer, storage2.byteOffset + start * 4, length * 4)
14582
- );
14583
- return result;
15021
+ return (async () => {
15022
+ let candidate;
15023
+ let result;
15024
+ const release = retainValues(budget, () => [receiver, candidate, result, ...args]);
15025
+ try {
15026
+ const start = relativeIndex(await sandboxNumber(args[0], budget, bridge), storage2.length);
15027
+ const end = args[1] === void 0 ? storage2.length : relativeIndex(await sandboxNumber(args[1], budget, bridge), storage2.length);
15028
+ const length = Math.max(end - start, 0);
15029
+ const layout = float32ViewLayouts.get(receiver);
15030
+ const offset = (layout?.byteOffset ?? storage2.byteOffset) + start * 4;
15031
+ const tracking = layout !== void 0 && layout.length === void 0 && args[1] === void 0;
15032
+ if (defaultConstructor !== void 0) {
15033
+ candidate = await bridge.getProperty(receiver, "constructor");
15034
+ if (candidate !== void 0) {
15035
+ if (candidate === null || typeof candidate !== "object")
15036
+ throw new TypeError("TypedArray constructor must be an object.");
15037
+ candidate = await bridge.getProperty(candidate, Symbol.species);
15038
+ if (candidate !== void 0 && candidate !== null && (!isSandboxClosure(candidate) || candidate.construct === void 0))
15039
+ throw new TypeError("TypedArray species must be a constructor.");
15040
+ }
15041
+ }
15042
+ if (candidate !== void 0 && candidate !== null && candidate !== defaultConstructor) {
15043
+ const values = key === "slice" ? [length] : [storage2.buffer, offset, tracking ? void 0 : length];
15044
+ result = await invokeBuiltinClosure(candidate, values, budget, bridge, void 0, true);
15045
+ if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
15046
+ const target = float32Storage(result, key === "slice");
15047
+ if (key === "slice" && target.length < length)
15048
+ throw new TypeError("TypedArray species returned insufficient storage.");
15049
+ }
15050
+ if (key === "subarray") {
15051
+ if (result === void 0) {
15052
+ result = new Float32Array(storage2.buffer, offset, tracking ? void 0 : length);
15053
+ if (arrayBufferOptions(storage2.buffer) !== void 0)
15054
+ float32ViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
15055
+ }
15056
+ return result;
15057
+ }
15058
+ if (result === void 0) {
15059
+ checkFloat32Allocation(length, budget);
15060
+ result = new Float32Array(length);
15061
+ }
15062
+ if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
15063
+ if (length > 0) {
15064
+ const current = float32Storage(receiver, true);
15065
+ const target = float32Storage(result, true);
15066
+ const count = Math.min(length, Math.max(current.length - start, 0));
15067
+ if (count > 0) {
15068
+ const sourceBytes = new Uint8Array(current.buffer, current.byteOffset + start * 4, count * 4);
15069
+ const targetBytes = new Uint8Array(target.buffer, target.byteOffset, count * 4);
15070
+ if (current.buffer === target.buffer && targetBytes.byteOffset > sourceBytes.byteOffset && targetBytes.byteOffset < sourceBytes.byteOffset + sourceBytes.length) {
15071
+ for (let index = 0; index < sourceBytes.length; index++) {
15072
+ budget.visitNode();
15073
+ targetBytes[index] = sourceBytes[index];
15074
+ }
15075
+ } else targetBytes.set(sourceBytes);
15076
+ }
15077
+ }
15078
+ return result;
15079
+ } finally {
15080
+ release();
15081
+ }
15082
+ })();
14584
15083
  }
14585
15084
  });
14586
15085
  }
14587
- function setFloat32Member(value, property, entry) {
14588
- const key = String(property);
14589
- if (isFloat32Index(key)) {
15086
+ function setFloat32Member(value, property, entry, budget) {
15087
+ const key = typeof property === "symbol" ? property : String(property);
15088
+ if (typeof key !== "symbol" && isFloat32Index(key)) {
14590
15089
  Reflect.set(value, key, float32Number(entry));
14591
15090
  return;
14592
15091
  }
14593
15092
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
14594
- if (descriptor === void 0 && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
14595
- throw new TypeError(`Cannot assign to read only property '${key}'.`);
14596
- if (descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable))
14597
- throw new TypeError(`Cannot assign to read only property '${key}'.`);
15093
+ const inherited = descriptor ?? (budget === void 0 ? void 0 : getSandboxPropertyDescriptor(value, key, budget));
15094
+ if (descriptor === void 0 && typeof key === "string" && (budget === void 0 || !float32Prototypes.has(budget)) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
15095
+ throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
15096
+ if (inherited !== void 0 && (!("value" in inherited) || !inherited.writable))
15097
+ throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
14598
15098
  Object.defineProperty(
14599
15099
  value,
14600
15100
  key,
14601
15101
  descriptor === void 0 ? { value: entry, configurable: true, enumerable: true, writable: true } : { value: entry }
14602
15102
  );
14603
15103
  }
14604
- function relativeIndex(value, length, fallback) {
14605
- if (value === void 0) return fallback;
14606
- const numeric = float32Number(value);
15104
+ function relativeIndex(numeric, length) {
14607
15105
  const integer2 = Number.isNaN(numeric) ? 0 : Math.trunc(numeric);
14608
15106
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
14609
15107
  }
@@ -14766,7 +15264,7 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
14766
15264
  budget.visitNode();
14767
15265
  return evaluateInstanceof(value, constructor.boundTarget, budget, context);
14768
15266
  }
14769
- if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
15267
+ if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
14770
15268
  if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
14771
15269
  if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
14772
15270
  const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
@@ -17406,7 +17904,7 @@ async function evaluateMemberCallExpression(node, context) {
17406
17904
  if (isFloat32Array(member.object)) {
17407
17905
  return evaluateResolvedCallExpression(
17408
17906
  node,
17409
- getFloat32Member(member.object, member.property, context.budget),
17907
+ await getPropertyValue(member.object, member.property, context),
17410
17908
  context,
17411
17909
  member.object
17412
17910
  );
@@ -17943,8 +18441,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
17943
18441
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
17944
18442
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
17945
18443
  if (isFloat32Array(target)) {
17946
- if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
17947
- setFloat32Member(target, property, value);
18444
+ setFloat32Member(target, property, value, budget);
17948
18445
  return;
17949
18446
  }
17950
18447
  if (isSandboxRegex(target)) {
@@ -20692,18 +21189,20 @@ function serializeArray(value, serializeValue) {
20692
21189
  }
20693
21190
 
20694
21191
  // packages/safe-js/src/snapshot/float32array.ts
20695
- function encodeFloat32Storage(value, id, buffers, reference) {
21192
+ function encodeFloat32Layout(value) {
20696
21193
  const storage = float32Storage(value);
20697
- const existing = buffers.get(storage.buffer);
20698
- if (existing === void 0) buffers.set(storage.buffer, id);
21194
+ if (arrayBufferOptions(storage.buffer) === void 0) return { byteOffset: storage.byteOffset, length: storage.length };
21195
+ const layout = float32ViewLayouts.get(value);
21196
+ if (layout === void 0) throw new TypeError("Resizable Float32Array snapshots require known view layout.");
20699
21197
  return {
20700
- kind: "float32array",
20701
- byteOffset: storage.byteOffset,
20702
- length: storage.length,
20703
- ...existing === void 0 ? { bytes: Array.from(new Uint8Array(storage.buffer)) } : { buffer: reference(existing) }
21198
+ byteOffset: layout.byteOffset,
21199
+ length: layout.length ?? 0,
21200
+ ...layout.length === void 0 ? { lengthTracking: true } : {}
20704
21201
  };
20705
21202
  }
20706
21203
  function validateFloat32Storage(value) {
21204
+ if (Object.hasOwn(value, "lengthTracking") && (value.lengthTracking !== true || value.length !== 0 || Object.hasOwn(value, "bytes")))
21205
+ throw new TypeError("Invalid Float32Array length-tracking layout.");
20707
21206
  if (!Number.isSafeInteger(value.length) || Number(value.length) < 0 || !Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || Number(value.byteOffset) % 4 !== 0)
20708
21207
  throw new TypeError("Invalid Float32Array view dimensions.");
20709
21208
  if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
@@ -20713,7 +21212,7 @@ function validateFloat32Storage(value) {
20713
21212
  throw new TypeError("Invalid Float32Array backing bytes.");
20714
21213
  }
20715
21214
  }
20716
- function decodeFloat32Storage(value, resolve) {
21215
+ function decodeFloat32Storage(value, resolve, budget) {
20717
21216
  validateFloat32Storage(value);
20718
21217
  let buffer;
20719
21218
  if (Array.isArray(value.bytes)) {
@@ -20721,10 +21220,50 @@ function decodeFloat32Storage(value, resolve) {
20721
21220
  new Uint8Array(buffer).set(value.bytes);
20722
21221
  } else {
20723
21222
  const referenced = resolve(value.buffer);
20724
- if (!isFloat32Array(referenced)) throw new TypeError("Invalid Float32Array backing reference.");
20725
- buffer = float32Storage(referenced).buffer;
21223
+ if (isSandboxArrayBuffer(referenced)) buffer = referenced;
21224
+ else if (isFloat32Array(referenced)) buffer = float32Storage(referenced).buffer;
21225
+ else throw new TypeError("Invalid Float32Array backing reference.");
20726
21226
  }
20727
- return new Float32Array(buffer, Number(value.byteOffset), Number(value.length));
21227
+ if (value.lengthTracking === true && arrayBufferOptions(buffer) === void 0)
21228
+ throw new TypeError("Length-tracking layout requires resizable backing storage.");
21229
+ return restoreFloat32View(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.length), budget);
21230
+ }
21231
+
21232
+ // packages/safe-js/src/snapshot/array-buffer.ts
21233
+ function captureArrayBufferState(value, encode) {
21234
+ return {
21235
+ properties: serializePropertyDescriptors(value, encode),
21236
+ ...hasExplicitSandboxPrototype(value) ? { prototype: encode(getSandboxPrototype(value)) } : {}
21237
+ };
21238
+ }
21239
+ function encodeArrayBufferStorage(value, id, buffers, reference) {
21240
+ arrayBufferLength(value);
21241
+ const existing = buffers.get(value);
21242
+ if (existing === void 0) buffers.set(value, id);
21243
+ return { kind: "arraybuffer", ...existing === void 0 ? { bytes: Array.from(new Uint8Array(value)), ...arrayBufferOptions(value) } : { buffer: reference(existing) } };
21244
+ }
21245
+ function validateArrayBufferStorage(value) {
21246
+ if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
21247
+ throw new TypeError("ArrayBuffer requires one backing storage description.");
21248
+ if (Object.hasOwn(value, "bytes") && (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)))
21249
+ throw new TypeError("Invalid ArrayBuffer bytes.");
21250
+ if (Object.hasOwn(value, "maxByteLength") && (!Array.isArray(value.bytes) || !Number.isSafeInteger(value.maxByteLength) || Number(value.maxByteLength) < value.bytes.length))
21251
+ throw new TypeError("Invalid ArrayBuffer maximum length.");
21252
+ }
21253
+ function decodeArrayBufferStorage(value, resolve) {
21254
+ validateArrayBufferStorage(value);
21255
+ if (Array.isArray(value.bytes)) {
21256
+ const buffer = Reflect.construct(ArrayBuffer, [
21257
+ value.bytes.length,
21258
+ Object.hasOwn(value, "maxByteLength") ? { maxByteLength: value.maxByteLength } : void 0
21259
+ ]);
21260
+ new Uint8Array(buffer).set(value.bytes);
21261
+ return buffer;
21262
+ }
21263
+ const referenced = resolve(value.buffer);
21264
+ if (isSandboxArrayBuffer(referenced)) return referenced;
21265
+ if (isFloat32Array(referenced)) return float32Storage(referenced).buffer;
21266
+ throw new TypeError("Invalid ArrayBuffer backing reference.");
20728
21267
  }
20729
21268
 
20730
21269
  // packages/safe-js/src/snapshot/date-properties.ts
@@ -20855,7 +21394,7 @@ function serializeDumpValue(value, path, state) {
20855
21394
  if (hasGuestObjectState(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
20856
21395
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
20857
21396
  }
20858
- if (isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
21397
+ if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
20859
21398
  if (Array.isArray(value)) {
20860
21399
  const reference2 = serializeHeapReference(value, path, state);
20861
21400
  if (reference2 !== void 0) {
@@ -20927,11 +21466,21 @@ function serializeHeapReference(value, path, state) {
20927
21466
  const serialized = serializeDumpValue(entry, `${path}.<date-property>`, state);
20928
21467
  return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
20929
21468
  });
21469
+ } else if (isSandboxArrayBuffer(value)) {
21470
+ state.heap[String(id)] = {
21471
+ ...encodeArrayBufferStorage(value, id, state.float32Buffers, (id2) => ({ kind: "ref", id: id2 })),
21472
+ state: captureArrayBufferState(value, (entry) => {
21473
+ const serialized = serializeDumpValue(entry, `${path}.<buffer>`, state);
21474
+ return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
21475
+ })
21476
+ };
20930
21477
  } else if (isFloat32Array(value)) {
20931
- const storage = encodeFloat32Storage(value, id, state.float32Buffers, (id2) => ({
20932
- kind: "ref",
20933
- id: id2
20934
- }));
21478
+ const backing = float32Storage(value);
21479
+ const storage = {
21480
+ kind: "float32array",
21481
+ ...encodeFloat32Layout(value),
21482
+ buffer: serializeHeapReference(backing.buffer, `${path}.buffer`, state)
21483
+ };
20935
21484
  const entries = /* @__PURE__ */ Object.create(null);
20936
21485
  state.heap[String(id)] = { ...storage, entries };
20937
21486
  for (const [key, descriptor] of float32DataProperties(value)) {
@@ -20997,7 +21546,7 @@ function indexHeapContainers(snapshot) {
20997
21546
  const heapIds = /* @__PURE__ */ new Map();
20998
21547
  let nextId = 1;
20999
21548
  for (const [value, stat2] of stats.entries()) {
21000
- if (stat2.count > 1 || stat2.forceHeap === true || guestValues.has(value) || stat2.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)) {
21549
+ if (stat2.count > 1 || stat2.forceHeap === true || guestValues.has(value) || stat2.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)) {
21001
21550
  heapIds.set(value, nextId);
21002
21551
  nextId += 1;
21003
21552
  }
@@ -21029,12 +21578,16 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
21029
21578
  stat2.expanded = true;
21030
21579
  ancestors.add(value);
21031
21580
  const guestEntries = [];
21032
- const guest = captureGuestHeapNode(value, (entry) => {
21581
+ if (isFloat32Array(value)) guestEntries.push(float32Storage(value).buffer);
21582
+ const guest = isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
21583
+ guestEntries.push(entry);
21584
+ return null;
21585
+ }) } : captureGuestHeapNode(value, (entry) => {
21033
21586
  guestEntries.push(entry);
21034
21587
  return null;
21035
21588
  });
21036
21589
  if (guest !== void 0) {
21037
- guestValues.add(value);
21590
+ if (!isSandboxArrayBuffer(value)) guestValues.add(value);
21038
21591
  for (const entry of guestEntries) {
21039
21592
  collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
21040
21593
  if (entry !== null && typeof entry === "object") stats.get(entry).forceHeap = true;
@@ -21042,6 +21595,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
21042
21595
  ancestors.delete(value);
21043
21596
  return;
21044
21597
  }
21598
+ for (const entry of guestEntries) collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
21045
21599
  if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
21046
21600
  ancestors.delete(value);
21047
21601
  return;
@@ -21361,11 +21915,24 @@ function encodeReplayData(value, options = {}) {
21361
21915
  ...symbolProperties.length === 0 ? {} : { symbolProperties },
21362
21916
  ...Object.isExtensible(entry) ? {} : { extensible: false }
21363
21917
  };
21918
+ } else if (isSandboxArrayBuffer(entry)) {
21919
+ const storage = encodeArrayBufferStorage(entry, id, float32Buffers, (id2) => ({ tag: "ref", id: id2 }));
21920
+ const properties = /* @__PURE__ */ Object.create(null);
21921
+ for (const [key, descriptor] of arrayBufferDataProperties(entry)) {
21922
+ if (typeof key === "symbol") continue;
21923
+ properties[key] = {
21924
+ value: child(descriptor.value, key),
21925
+ configurable: descriptor.configurable === true,
21926
+ enumerable: descriptor.enumerable === true,
21927
+ writable: descriptor.writable === true
21928
+ };
21929
+ }
21930
+ let symbolIndex = 0;
21931
+ const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path, { symbol: Math.floor(symbolIndex++ / 2) }]));
21932
+ nodes[id] = { ...storage, properties, extensible: Object.isExtensible(entry), symbolEntries };
21364
21933
  } else if (isFloat32Array(entry)) {
21365
- const storage = encodeFloat32Storage(entry, id, float32Buffers, (id2) => ({
21366
- tag: "ref",
21367
- id: id2
21368
- }));
21934
+ const backing = float32Storage(entry);
21935
+ const storage = { kind: "float32array", ...encodeFloat32Layout(entry), buffer: child(backing.buffer, "<buffer>") };
21369
21936
  const properties = /* @__PURE__ */ Object.create(null);
21370
21937
  for (const [key, descriptor] of float32DataProperties(entry)) {
21371
21938
  properties[key] = {
@@ -21468,7 +22035,7 @@ function decodeReplayData(input, options = {}, parent) {
21468
22035
  const graph = record2(input);
21469
22036
  const nodes = list(own(graph, "nodes"));
21470
22037
  const restored = /* @__PURE__ */ new Map();
21471
- const initializeIterators = [];
22038
+ const initializeValues = [];
21472
22039
  const decode = (entry, depth = 0) => {
21473
22040
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
21474
22041
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
@@ -21593,10 +22160,20 @@ function decodeReplayData(input, options = {}, parent) {
21593
22160
  if (node.extensible === false) Object.preventExtensions(result3);
21594
22161
  return result3;
21595
22162
  }
22163
+ if (kind === "arraybuffer") {
22164
+ if (typeof node.extensible !== "boolean") throw new TypeError("Invalid ArrayBuffer extensibility.");
22165
+ const result3 = decodeArrayBufferStorage(node, child);
22166
+ restored.set(id, result3);
22167
+ initializeValues.push(() => {
22168
+ defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
22169
+ if (!node.extensible) Object.preventExtensions(result3);
22170
+ });
22171
+ return result3;
22172
+ }
21596
22173
  if (kind === "float32array") {
21597
22174
  if (typeof node.extensible !== "boolean")
21598
22175
  throw new TypeError("Invalid Float32Array extensibility.");
21599
- const result3 = decodeFloat32Storage(node, child);
22176
+ const result3 = decodeFloat32Storage(node, child, compilation.owner?.budget);
21600
22177
  restored.set(id, result3);
21601
22178
  defineProperties(result3, record2(own(node, "properties")), child);
21602
22179
  if (!node.extensible) Object.preventExtensions(result3);
@@ -21632,7 +22209,7 @@ function decodeReplayData(input, options = {}, parent) {
21632
22209
  restored.set(id, result3);
21633
22210
  const collection = child(own(node, "collection"));
21634
22211
  if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid replay collection iterator source.");
21635
- initializeIterators.push(() => {
22212
+ initializeValues.push(() => {
21636
22213
  restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
21637
22214
  });
21638
22215
  defineProperties(result3, record2(own(node, "properties")), child);
@@ -21703,7 +22280,7 @@ function decodeReplayData(input, options = {}, parent) {
21703
22280
  return result2;
21704
22281
  };
21705
22282
  const result = decode(own(graph, "root"));
21706
- for (const initialize of initializeIterators) initialize();
22283
+ for (const initialize of initializeValues) initialize();
21707
22284
  if (parent !== void 0) compilation.forward(compilation.tickets, parent);
21708
22285
  return result;
21709
22286
  } finally {
@@ -22482,12 +23059,43 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
22482
23059
  state.seen.set(value, date);
22483
23060
  return date;
22484
23061
  }
23062
+ if (isSandboxArrayBuffer(value)) {
23063
+ const existing = state.seen.get(value);
23064
+ if (existing !== void 0) return existing;
23065
+ const length = arrayBufferLength(value);
23066
+ budget.allocateArrayLength(length);
23067
+ budget.provisionDataUsage(length + 1)();
23068
+ const copy = copyArrayBufferStorage(value, state);
23069
+ state.seen.set(value, copy);
23070
+ for (const [key, descriptor] of arrayBufferDataProperties(value)) {
23071
+ if (typeof key === "symbol") throw new TypeError("Host ArrayBuffer symbol properties require an explicit capability path.");
23072
+ Object.defineProperty(copy, key, {
23073
+ ...descriptor,
23074
+ value: copyHostValueToSandbox(
23075
+ descriptor.value,
23076
+ stackFrames,
23077
+ { ...options, capabilityPath: [...options.capabilityPath ?? [], key] },
23078
+ state,
23079
+ joinPath(path, key)
23080
+ )
23081
+ });
23082
+ }
23083
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
23084
+ return copy;
23085
+ }
22485
23086
  if (isFloat32Array(value)) {
22486
23087
  const existing = state.seen.get(value);
22487
23088
  if (existing !== void 0) return existing;
22488
23089
  checkFloat32Allocation(Math.ceil(float32Storage(value).byteLength / 4), budget);
22489
23090
  const copy = copyFloat32Storage(value, state);
22490
23091
  state.seen.set(value, copy);
23092
+ copyHostValueToSandbox(
23093
+ float32Storage(value).buffer,
23094
+ stackFrames,
23095
+ { ...options, capabilityPath: [...options.capabilityPath ?? [], "buffer"] },
23096
+ state,
23097
+ `${path}.buffer`
23098
+ );
22491
23099
  for (const [key, descriptor] of float32DataProperties(value)) {
22492
23100
  Object.defineProperty(copy, key, {
22493
23101
  ...descriptor,
@@ -24513,24 +25121,148 @@ function createBigIntGlobal(budget) {
24513
25121
  return constructor;
24514
25122
  }
24515
25123
 
25124
+ // packages/safe-js/src/interp/globals/array-buffer.ts
25125
+ var resizeBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
25126
+ function createArrayBufferGlobal(budget) {
25127
+ const prototype = /* @__PURE__ */ Object.create(null);
25128
+ const constructor = createSandboxClosure({
25129
+ guest: true,
25130
+ sandbox: true,
25131
+ name: "ArrayBuffer",
25132
+ length: 1,
25133
+ call: () => {
25134
+ throw new TypeError("ArrayBuffer requires new.");
25135
+ },
25136
+ construct: async (args, context) => {
25137
+ let selected;
25138
+ let current;
25139
+ const bridge = {
25140
+ ...context,
25141
+ stack: context?.stack ?? [],
25142
+ thisValue: void 0,
25143
+ getProperty: context?.getProperty ?? ((value, key) => {
25144
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
25145
+ return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, bridge);
25146
+ }),
25147
+ invokeClosure: context?.invokeClosure ?? ((callee, values, receiver, construct) => invokeBuiltinClosure(callee, values, budget, context, receiver, construct))
25148
+ };
25149
+ const release = retainValues(budget, () => [selected, current, ...args]);
25150
+ try {
25151
+ const number = await sandboxNumber(args[0], budget, bridge);
25152
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
25153
+ if (length < 0 || !Number.isSafeInteger(length)) throw new RangeError("Invalid ArrayBuffer length.");
25154
+ let maxByteLength;
25155
+ if (args[1] !== null && typeof args[1] === "object") {
25156
+ current = await bridge.getProperty(args[1], "maxByteLength");
25157
+ if (current !== void 0) {
25158
+ const maximum = await sandboxNumber(current, budget, bridge);
25159
+ maxByteLength = Number.isNaN(maximum) ? 0 : Math.trunc(maximum);
25160
+ if (!Number.isSafeInteger(maxByteLength) || maxByteLength < length)
25161
+ throw new RangeError("Invalid ArrayBuffer maximum length.");
25162
+ }
25163
+ }
25164
+ const target = context?.newTarget ?? constructor;
25165
+ selected = await bridge.getProperty(target, "prototype");
25166
+ budget.allocateArrayLength(maxByteLength ?? length);
25167
+ budget.provisionDataUsage(length + 1)();
25168
+ const result = Reflect.construct(ArrayBuffer, [length, maxByteLength === void 0 ? void 0 : { maxByteLength }]);
25169
+ setSandboxPrototype(result, selected !== null && typeof selected === "object" ? selected : prototype, budget);
25170
+ return result;
25171
+ } finally {
25172
+ release();
25173
+ }
25174
+ }
25175
+ });
25176
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
25177
+ Object.defineProperty(materializeFunctionProperties(constructor), "isView", {
25178
+ writable: true,
25179
+ configurable: true,
25180
+ value: createSandboxClosure({
25181
+ guest: true,
25182
+ sandbox: true,
25183
+ name: "isView",
25184
+ length: 1,
25185
+ call: (args) => ArrayBuffer.isView(args[0])
25186
+ })
25187
+ });
25188
+ Object.defineProperties(prototype, {
25189
+ constructor: { value: constructor, writable: true, configurable: true },
25190
+ [Symbol.toStringTag]: { value: "ArrayBuffer", configurable: true }
25191
+ });
25192
+ const getters = [];
25193
+ Object.defineProperty(prototype, "resize", {
25194
+ writable: true,
25195
+ configurable: true,
25196
+ value: createSandboxClosure({
25197
+ guest: true,
25198
+ sandbox: true,
25199
+ name: "resize",
25200
+ length: 1,
25201
+ call: async (args, context) => {
25202
+ const receiver = context?.thisValue;
25203
+ if (!isSandboxArrayBuffer(receiver) || arrayBufferOptions(receiver) === void 0)
25204
+ throw new TypeError("ArrayBuffer resize requires a resizable buffer receiver.");
25205
+ const release = retainValues(budget, () => [receiver, ...args]);
25206
+ try {
25207
+ const number = await sandboxNumber(args[0], budget, context);
25208
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
25209
+ if (!Number.isSafeInteger(length) || length < 0 || length > arrayBufferOptions(receiver).maxByteLength)
25210
+ throw new RangeError("Invalid ArrayBuffer resize length.");
25211
+ budget.allocateArrayLength(length);
25212
+ budget.provisionDataUsage(Math.max(length - arrayBufferLength(receiver), 0))();
25213
+ Reflect.apply(resizeBuffer2, receiver, [length]);
25214
+ return void 0;
25215
+ } finally {
25216
+ release();
25217
+ }
25218
+ }
25219
+ })
25220
+ });
25221
+ for (const key of ["byteLength", "maxByteLength", "resizable"]) {
25222
+ const getter = createSandboxClosure({
25223
+ guest: true,
25224
+ sandbox: true,
25225
+ name: `get ${key}`,
25226
+ length: 0,
25227
+ call: (_args, context) => {
25228
+ if (!isSandboxArrayBuffer(context?.thisValue)) throw new TypeError(`ArrayBuffer ${key} requires a buffer receiver.`);
25229
+ if (key === "byteLength") return arrayBufferLength(context.thisValue);
25230
+ const options = arrayBufferOptions(context.thisValue);
25231
+ return key === "resizable" ? options !== void 0 : options?.maxByteLength ?? arrayBufferLength(context.thisValue);
25232
+ }
25233
+ });
25234
+ Object.defineProperty(prototype, key, { get: accessorAdapter(getter, "get"), configurable: true });
25235
+ getters.push(getter);
25236
+ }
25237
+ setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
25238
+ arrayBufferPrototypes.set(budget, prototype);
25239
+ registerBuiltinIdentities(budget, { ArrayBuffer: constructor });
25240
+ registerIntrinsicFunction(budget, constructor);
25241
+ for (const getter of getters) registerIntrinsicFunction(budget, getter);
25242
+ registerIntrinsicObject(budget, prototype);
25243
+ return constructor;
25244
+ }
25245
+
24516
25246
  // packages/safe-js/src/interp/globals.ts
24517
25247
  function createBuiltinBindings(options) {
24518
25248
  const bindings = {
24519
25249
  ...createConsoleJsonGlobals(options),
24520
25250
  ...createCollectionGlobals(options),
24521
- Float32Array: createFloat32ArrayGlobal(options.budget),
25251
+ Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
24522
25252
  Date: createDateGlobal(options),
24523
25253
  Symbol: createSymbolGlobal(options.budget),
24524
25254
  BigInt: createBigIntGlobal(options.budget),
24525
25255
  ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
24526
25256
  ...createMathGlobals({ random: options.random, budget: options.budget }),
24527
25257
  ...createObjectArrayGlobals(options),
25258
+ ArrayBuffer: createArrayBufferGlobal(options.budget),
24528
25259
  ...createMiscGlobals(options),
24529
25260
  ...createUriGlobals(options.budget),
24530
25261
  ...createPromiseGlobals(options),
24531
25262
  ...createRegexGlobals(options)
24532
25263
  };
24533
25264
  createFunctionPrototype(options.budget, options.functionHasInstance);
25265
+ if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
24534
25266
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
24535
25267
  createGeneratorPrototypes(options.budget);
24536
25268
  registerBuiltinIdentities(options.budget, bindings);
@@ -25260,9 +25992,18 @@ function validateDumpHeap(root, state) {
25260
25992
  validateDateRecord(entry, path);
25261
25993
  continue;
25262
25994
  }
25995
+ if (entry.kind === "arraybuffer") {
25996
+ validateArrayBufferStorage(entry);
25997
+ validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
25998
+ continue;
25999
+ }
25263
26000
  if (entry.kind === "float32array") {
25264
26001
  validateFloat32Storage(entry);
25265
26002
  requireRecord(entry.entries, `${path}.entries`);
26003
+ if (Object.hasOwn(entry, "state")) {
26004
+ if (Object.keys(entry.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
26005
+ validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
26006
+ }
25266
26007
  continue;
25267
26008
  }
25268
26009
  if (entry.kind === "arguments") {
@@ -25479,7 +26220,7 @@ function validateHeapValue(value, path, state, heap) {
25479
26220
  fail("invalidValue", path, String(error));
25480
26221
  }
25481
26222
  validateErrorType(record4, path);
25482
- if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
26223
+ if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
25483
26224
  fail("unknownTag", `${path}.kind`, "unknown heap tag");
25484
26225
  validateValue(record4, path, 1, state);
25485
26226
  if (record4.kind === "symbol") validateSymbolRecord(record4, path, state);
@@ -25488,9 +26229,17 @@ function validateHeapValue(value, path, state, heap) {
25488
26229
  if (record4.kind === "object") requireRecord(record4.entries, `${path}.entries`);
25489
26230
  if (record4.kind === "boxed") validateBoxedRecord(record4, path, heap);
25490
26231
  if (record4.kind === "date") validateDateRecord(record4, path);
26232
+ if (record4.kind === "arraybuffer") {
26233
+ validateArrayBufferStorage(record4);
26234
+ validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
26235
+ }
25491
26236
  if (record4.kind === "float32array") {
25492
26237
  validateFloat32Storage(record4);
25493
26238
  requireRecord(record4.entries, `${path}.entries`);
26239
+ if (Object.hasOwn(record4, "state")) {
26240
+ if (Object.keys(record4.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
26241
+ validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
26242
+ }
25494
26243
  }
25495
26244
  if (record4.kind === "map") {
25496
26245
  const entries = requireArray(record4.entries, `${path}.entries`, state);
@@ -25680,7 +26429,7 @@ function validateGenericValue(value, path, depth, state) {
25680
26429
  if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
25681
26430
  fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
25682
26431
  }
25683
- if (state.dataPropertiesOnly && types6.isProxy(value)) {
26432
+ if (state.dataPropertiesOnly && types7.isProxy(value)) {
25684
26433
  fail("invalidType", path, "proxy objects are not snapshot data");
25685
26434
  }
25686
26435
  if (depth > state.limits.maxDepth)
@@ -26479,15 +27228,16 @@ function measureSandboxData(values, options = {}) {
26479
27228
  }
26480
27229
  const prototype = getSandboxPrototype(value);
26481
27230
  if (prototype !== null) visit(prototype, depth + 1);
27231
+ if (isSandboxArrayBuffer(value)) usage += arrayBufferLength(value);
26482
27232
  if (isFloat32Array(value)) {
26483
27233
  const storage = float32Storage(value);
26484
- if (!seen.has(storage.buffer)) {
26485
- seen.add(storage.buffer);
26486
- usage += storage.byteLength;
26487
- }
26488
- for (const [key, descriptor] of float32DataProperties(value)) {
26489
- usage += key.length + 1;
26490
- visit(descriptor.value, depth + 1);
27234
+ visit(storage.buffer, depth + 1);
27235
+ for (const [key, descriptor] of float32Properties(value)) {
27236
+ usage += 1;
27237
+ if (typeof key === "string") usage += key.length;
27238
+ else visit(key, depth + 1);
27239
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
27240
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
26491
27241
  }
26492
27242
  return;
26493
27243
  }
@@ -26620,7 +27370,7 @@ function measureSandboxData(values, options = {}) {
26620
27370
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
26621
27371
  if (descriptor !== void 0) descriptors2.push([key, descriptor]);
26622
27372
  }
26623
- const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
27373
+ const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
26624
27374
  for (const [key, descriptor] of descriptors2) {
26625
27375
  if (!descriptor.enumerable && !includeNonEnumerable) continue;
26626
27376
  usage += 1 + key.length;
@@ -26816,6 +27566,20 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
26816
27566
  }
26817
27567
  return sandboxPromise;
26818
27568
  }
27569
+ if (isSandboxArrayBuffer(value)) {
27570
+ const existing = state.seen.get(value);
27571
+ if (existing !== void 0) return existing;
27572
+ const copy = copyArrayBufferStorage(value, state);
27573
+ state.seen.set(value, copy);
27574
+ for (const [key, descriptor] of arrayBufferDataProperties(value)) {
27575
+ Object.defineProperty(copy, key, {
27576
+ ...descriptor,
27577
+ value: copyToSandbox(descriptor.value, state, joinPath2(path, key), cloneSandboxCollections, depth + 1)
27578
+ });
27579
+ }
27580
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
27581
+ return copy;
27582
+ }
26819
27583
  if (nodeTypes.isDate(value)) {
26820
27584
  const existing = state.seen.get(value);
26821
27585
  if (existing !== void 0) return existing;
@@ -26834,6 +27598,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
26834
27598
  if (existing !== void 0) return existing;
26835
27599
  const copy = copyFloat32Storage(value, state);
26836
27600
  state.seen.set(value, copy);
27601
+ copyToSandbox(float32Storage(value).buffer, state, `${path}.buffer`, cloneSandboxCollections, depth + 1);
26837
27602
  for (const [key, descriptor] of float32DataProperties(value)) {
26838
27603
  Object.defineProperty(copy, key, {
26839
27604
  ...descriptor,
@@ -27055,6 +27820,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
27055
27820
  if (existing !== void 0) return existing;
27056
27821
  const copy = copyFloat32Storage(value, state);
27057
27822
  state.seen.set(value, copy);
27823
+ copyFromSandbox(float32Storage(value).buffer, state, `${path}.buffer`, options, depth + 1);
27058
27824
  for (const [key, descriptor] of float32DataProperties(value)) {
27059
27825
  Object.defineProperty(copy, key, {
27060
27826
  ...descriptor,
@@ -27064,6 +27830,20 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
27064
27830
  if (!Object.isExtensible(value)) Object.preventExtensions(copy);
27065
27831
  return copy;
27066
27832
  }
27833
+ if (isSandboxArrayBuffer(value)) {
27834
+ const existing = state.seen.get(value);
27835
+ if (existing !== void 0) return existing;
27836
+ const copy = copyArrayBufferStorage(value, state);
27837
+ state.seen.set(value, copy);
27838
+ for (const [key, descriptor] of arrayBufferDataProperties(value)) {
27839
+ Object.defineProperty(copy, key, {
27840
+ ...descriptor,
27841
+ value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
27842
+ });
27843
+ }
27844
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
27845
+ return copy;
27846
+ }
27067
27847
  if (isSandboxDate(value)) {
27068
27848
  const existing = state.seen.get(value);
27069
27849
  if (existing !== void 0) return existing;
@@ -27225,6 +28005,16 @@ function allocateSandboxValue2(value, budget, seen) {
27225
28005
  budget.allocateString(value);
27226
28006
  return;
27227
28007
  }
28008
+ if (isSandboxArrayBuffer(value)) {
28009
+ if (seen.has(value)) return;
28010
+ seen.add(value);
28011
+ budget.allocateArrayLength(arrayBufferLength(value));
28012
+ for (const [key, descriptor] of arrayBufferDataProperties(value)) {
28013
+ if (typeof key === "string") budget.allocateString(key);
28014
+ allocateSandboxValue2(descriptor.value, budget, seen);
28015
+ }
28016
+ return;
28017
+ }
27228
28018
  if (isSandboxBox(value)) {
27229
28019
  if (seen.has(value)) return;
27230
28020
  seen.add(value);
@@ -27970,8 +28760,29 @@ function normalize(value, seen) {
27970
28760
  try {
27971
28761
  const date = copyNativeDate(value);
27972
28762
  if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
28763
+ if (isSandboxArrayBuffer(value)) {
28764
+ arrayBufferLength(value);
28765
+ const properties = /* @__PURE__ */ Object.create(null);
28766
+ const entries = [];
28767
+ for (const [key, descriptor] of arrayBufferDataProperties(value)) {
28768
+ if (typeof key === "symbol") throw new TypeError("ArrayBuffer symbol properties require an explicit host-call identity.");
28769
+ entries.push([key, descriptor]);
28770
+ }
28771
+ for (const [key, descriptor] of entries.sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0))
28772
+ defineOwnDataProperty(properties, key, normalize(descriptor.value, seen));
28773
+ return Object.assign(/* @__PURE__ */ Object.create(null), {
28774
+ $type: "arraybuffer",
28775
+ bytes: normalize(Array.from(new Uint8Array(value)), seen),
28776
+ ...arrayBufferOptions(value),
28777
+ properties
28778
+ });
28779
+ }
27973
28780
  if (isFloat32Array(value)) {
27974
28781
  const storage = float32Storage(value);
28782
+ const resizable = arrayBufferOptions(storage.buffer) !== void 0;
28783
+ const layout = resizable ? float32ViewLayouts.get(value) : void 0;
28784
+ if (resizable && layout === void 0)
28785
+ throw new TypeError("Resizable Float32Array host-call identity requires known view layout.");
27975
28786
  const properties = /* @__PURE__ */ Object.create(null);
27976
28787
  for (const [key, descriptor] of float32DataProperties(value).sort(
27977
28788
  ([left], [right]) => left < right ? -1 : left > right ? 1 : 0
@@ -27983,7 +28794,12 @@ function normalize(value, seen) {
27983
28794
  bytes: normalize(Array.from(new Uint8Array(storage.buffer)), seen),
27984
28795
  byteOffset: storage.byteOffset,
27985
28796
  length: storage.length,
27986
- properties
28797
+ properties,
28798
+ ...resizable || Reflect.ownKeys(storage.buffer).length > 0 ? { buffer: normalize(storage.buffer, seen) } : {},
28799
+ ...layout === void 0 ? {} : { viewLayout: {
28800
+ byteOffset: layout.byteOffset,
28801
+ length: layout.length ?? null
28802
+ } }
27987
28803
  });
27988
28804
  }
27989
28805
  if (Array.isArray(value)) {
@@ -28935,6 +29751,7 @@ function classDefinitionContains(node, expression) {
28935
29751
  var KNOWN_RUNTIME_GLOBALS = [
28936
29752
  "AggregateError",
28937
29753
  "Array",
29754
+ "ArrayBuffer",
28938
29755
  "Boolean",
28939
29756
  "BigInt",
28940
29757
  "Date",
@@ -39327,7 +40144,7 @@ function createReplayableRandom(options = {}) {
39327
40144
 
39328
40145
  // packages/safe-js/src/realm.ts
39329
40146
  import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
39330
- import { types as types7 } from "node:util";
40147
+ import { types as types8 } from "node:util";
39331
40148
 
39332
40149
  // packages/safe-js/src/modules/registry.ts
39333
40150
  function createUnknownModuleMessage2(moduleName, moduleNames) {
@@ -39466,7 +40283,7 @@ var RealmState = class {
39466
40283
  throw new TypeError("Realm limits must be positive safe integers with supported names.");
39467
40284
  this.limits[name] = Number(value);
39468
40285
  }
39469
- if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types7.isProxy(options.extensions)))
40286
+ if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types8.isProxy(options.extensions)))
39470
40287
  throw new TypeError("Extensions must be a registration array.");
39471
40288
  const registrations = options.extensions ?? [];
39472
40289
  const extensions = [];
@@ -39701,7 +40518,7 @@ var RealmState = class {
39701
40518
  return this.phase.run(phase, () => {
39702
40519
  try {
39703
40520
  const result = call();
39704
- if (types7.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
40521
+ if (types8.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
39705
40522
  return Promise.resolve(result).then(
39706
40523
  async (value) => {
39707
40524
  await Promise.allSettled(phase.pending);
@@ -39770,7 +40587,7 @@ var RealmState = class {
39770
40587
  },
39771
40588
  read: (operation, validate) => {
39772
40589
  const value = this.invokeHost(operation, operation);
39773
- if (types7.isPromise(value)) {
40590
+ if (types8.isPromise(value)) {
39774
40591
  void Promise.resolve(value).catch(() => void 0);
39775
40592
  throw new TypeError("Live property operations must be synchronous.");
39776
40593
  }
@@ -39778,7 +40595,7 @@ var RealmState = class {
39778
40595
  },
39779
40596
  write: (operation, value) => {
39780
40597
  const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
39781
- if (types7.isPromise(result)) {
40598
+ if (types8.isPromise(result)) {
39782
40599
  void Promise.resolve(result).catch(() => void 0);
39783
40600
  throw new TypeError("Live property setters must be synchronous.");
39784
40601
  }
@@ -39987,7 +40804,7 @@ var RealmState = class {
39987
40804
  }
39988
40805
  });
39989
40806
  const output = getExtensionSetup(extension)(context);
39990
- if (types7.isPromise(output)) {
40807
+ if (types8.isPromise(output)) {
39991
40808
  void Promise.resolve(output).catch(() => void 0);
39992
40809
  throw new TypeError("Extension setup must be synchronous.");
39993
40810
  }
@@ -40179,7 +40996,7 @@ var RealmState = class {
40179
40996
  };
40180
40997
  function readModules(input) {
40181
40998
  const entries = (value, label) => {
40182
- if (types7.isMap(value) && !types7.isProxy(value)) {
40999
+ if (types8.isMap(value) && !types8.isProxy(value)) {
40183
41000
  const result = [...Map.prototype.entries.call(value)];
40184
41001
  if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
40185
41002
  throw new TypeError(`${label} requires bounded string keys.`);
@@ -41448,4 +42265,4 @@ export {
41448
42265
  FileSnapshotBackend,
41449
42266
  run
41450
42267
  };
41451
- //# sourceMappingURL=chunk-V6LQP64H.js.map
42268
+ //# sourceMappingURL=chunk-CYVI4ZUK.js.map