@poe-platform/safe-js 0.1.354 → 0.1.356

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.
@@ -6887,7 +6887,8 @@ function arrayBufferDataProperties(value) {
6887
6887
  });
6888
6888
  }
6889
6889
 
6890
- // packages/safe-js/src/interp/float32.ts
6890
+ // packages/safe-js/src/interp/typed-array.ts
6891
+ var numericTypedArrayConstructors = { Float32Array, Uint8Array };
6891
6892
  var typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
6892
6893
  var readLength2 = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
6893
6894
  var readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
@@ -6896,57 +6897,62 @@ var readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStri
6896
6897
  var createValuesIterator = Object.getOwnPropertyDescriptor(typedArrayPrototype, "values").value;
6897
6898
  var bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
6898
6899
  var bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
6899
- var float32ViewLayouts = /* @__PURE__ */ new WeakMap();
6900
+ var typedArrayViewLayouts = /* @__PURE__ */ new WeakMap();
6900
6901
  var resizeBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
6901
- function restoreFloat32View(buffer, byteOffset, length, budget) {
6902
+ function restoreTypedArrayView(buffer, byteOffset, length, budget, Native = Float32Array) {
6902
6903
  const originalLength = arrayBufferLength(buffer);
6903
- const required = byteOffset + (length ?? 0) * 4;
6904
+ const required = byteOffset + (length ?? 0) * Native.BYTES_PER_ELEMENT;
6904
6905
  const options = arrayBufferOptions(buffer);
6905
6906
  const grow = required > originalLength;
6906
6907
  if (grow) {
6907
6908
  if (resizeBuffer === void 0 || options === void 0 || required > options.maxByteLength)
6908
6909
  throw new RangeError("Float32Array layout exceeds backing capacity.");
6909
- budget?.allocateArrayLength(Math.ceil(required / 4));
6910
+ budget?.allocateArrayLength(Math.ceil(required / Native.BYTES_PER_ELEMENT));
6910
6911
  budget?.provisionDataUsage(required - originalLength)();
6911
6912
  Reflect.apply(resizeBuffer, buffer, [required]);
6912
6913
  }
6913
6914
  try {
6914
- const view = new Float32Array(buffer, byteOffset, length);
6915
- if (options !== void 0) float32ViewLayouts.set(view, { byteOffset, ...length === void 0 ? {} : { length } });
6915
+ const view = new Native(buffer, byteOffset, length);
6916
+ if (options !== void 0) typedArrayViewLayouts.set(view, { byteOffset, ...length === void 0 ? {} : { length } });
6916
6917
  return view;
6917
6918
  } finally {
6918
6919
  if (grow) Reflect.apply(resizeBuffer, buffer, [originalLength]);
6919
6920
  }
6920
6921
  }
6921
- function isFloat32Array(value) {
6922
- return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
6922
+ function isNumericTypedArray(value) {
6923
+ if (!ArrayBuffer.isView(value)) return false;
6924
+ const tag = Reflect.apply(readTag, value, []);
6925
+ return Object.hasOwn(numericTypedArrayConstructors, tag) && Object.getPrototypeOf(value) === numericTypedArrayConstructors[tag].prototype;
6923
6926
  }
6924
- function float32Storage(value, requireInBounds = false) {
6927
+ function typedArrayStorage(value, requireInBounds = false) {
6925
6928
  if (requireInBounds) Reflect.apply(createValuesIterator, value, []);
6926
6929
  const buffer = Reflect.apply(readBuffer, value, []);
6927
6930
  if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
6928
6931
  throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
6929
6932
  }
6933
+ const Native = numericTypedArrayConstructors[Reflect.apply(readTag, value, [])];
6930
6934
  return {
6935
+ Native,
6936
+ elementSize: Native.BYTES_PER_ELEMENT,
6931
6937
  buffer,
6932
6938
  byteOffset: Reflect.apply(readOffset, value, []),
6933
6939
  length: Reflect.apply(readLength2, value, []),
6934
6940
  byteLength: Reflect.apply(bufferLength, buffer, [])
6935
6941
  };
6936
6942
  }
6937
- function float32Properties(value) {
6943
+ function typedArrayProperties(value) {
6938
6944
  const properties = [];
6939
6945
  for (const key of Reflect.ownKeys(value)) {
6940
- if (typeof key === "string" && isFloat32Index(key)) continue;
6946
+ if (typeof key === "string" && isTypedArrayIndex(key)) continue;
6941
6947
  properties.push([key, Object.getOwnPropertyDescriptor(value, key)]);
6942
6948
  }
6943
6949
  return properties;
6944
6950
  }
6945
- function float32DataProperties(value) {
6951
+ function typedArrayDataProperties(value) {
6946
6952
  if (Object.getOwnPropertySymbols(value).length > 0)
6947
6953
  throw new TypeError("Float32Array symbol properties are not supported.");
6948
6954
  const properties = [];
6949
- for (const [key, descriptor] of float32Properties(value)) {
6955
+ for (const [key, descriptor] of typedArrayProperties(value)) {
6950
6956
  if (typeof key !== "string") throw new TypeError("Float32Array symbol properties are not supported.");
6951
6957
  if (!("value" in descriptor))
6952
6958
  throw new TypeError(`Float32Array accessor property '${key}' is not supported.`);
@@ -6954,10 +6960,10 @@ function float32DataProperties(value) {
6954
6960
  }
6955
6961
  return properties;
6956
6962
  }
6957
- function isFloat32Index(key) {
6963
+ function isTypedArrayIndex(key) {
6958
6964
  return key === "-0" || String(Number(key)) === key;
6959
6965
  }
6960
- function float32Number(value) {
6966
+ function typedArrayNumber(value) {
6961
6967
  if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
6962
6968
  throw new TypeError(
6963
6969
  "Float32Array numeric arguments must be primitive numeric-coercible values."
@@ -6965,19 +6971,19 @@ function float32Number(value) {
6965
6971
  }
6966
6972
  return Number(value);
6967
6973
  }
6968
- function checkFloat32Allocation(length, budget) {
6974
+ function checkTypedArrayAllocation(length, budget, elementSize = Float32Array.BYTES_PER_ELEMENT) {
6969
6975
  budget.allocateArrayLength(length);
6970
- budget.provisionDataUsage(length * Float32Array.BYTES_PER_ELEMENT + 1)();
6976
+ budget.provisionDataUsage(length * elementSize + 1)();
6971
6977
  }
6972
- function copyFloat32Storage(value, state) {
6973
- const storage = float32Storage(value);
6978
+ function copyTypedArrayStorage(value, state) {
6979
+ const storage = typedArrayStorage(value);
6974
6980
  const buffer = copyArrayBufferStorage(storage.buffer, state);
6975
6981
  if (bufferResizable !== void 0 && Reflect.apply(bufferResizable, storage.buffer, [])) {
6976
- const layout = float32ViewLayouts.get(value);
6982
+ const layout = typedArrayViewLayouts.get(value);
6977
6983
  if (layout === void 0) throw new TypeError("Resizable Float32Array copies require known view layout.");
6978
- return restoreFloat32View(buffer, layout.byteOffset, layout.length);
6984
+ return restoreTypedArrayView(buffer, layout.byteOffset, layout.length, void 0, storage.Native);
6979
6985
  }
6980
- return new Float32Array(buffer, storage.byteOffset, storage.length);
6986
+ return new storage.Native(buffer, storage.byteOffset, storage.length);
6981
6987
  }
6982
6988
 
6983
6989
  // packages/safe-js/src/interp/date.ts
@@ -7970,8 +7976,8 @@ function namedKeys(state) {
7970
7976
  // packages/safe-js/src/interp/error-prototypes.ts
7971
7977
  var errorPrototypes = /* @__PURE__ */ new WeakMap();
7972
7978
 
7973
- // packages/safe-js/src/interp/float32-prototypes.ts
7974
- var float32Prototypes = /* @__PURE__ */ new WeakMap();
7979
+ // packages/safe-js/src/interp/typed-array-prototypes.ts
7980
+ var typedArrayPrototypes = /* @__PURE__ */ new WeakMap();
7975
7981
 
7976
7982
  // packages/safe-js/src/interp/object-model.ts
7977
7983
  var guestClosures = /* @__PURE__ */ new WeakSet();
@@ -8198,7 +8204,7 @@ function releaseObjectPrototype(budget) {
8198
8204
  functionPrototypes.delete(budget);
8199
8205
  generatorPrototypes.delete(budget);
8200
8206
  errorPrototypes.delete(budget);
8201
- float32Prototypes.delete(budget);
8207
+ typedArrayPrototypes.delete(budget);
8202
8208
  arrayBufferPrototypes.delete(budget);
8203
8209
  initialRegexDescriptors.delete(budget);
8204
8210
  intrinsicPrototypes.delete(budget);
@@ -8206,7 +8212,7 @@ function releaseObjectPrototype(budget) {
8206
8212
  function getSandboxPrototype(value, budget) {
8207
8213
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
8208
8214
  if (isSandboxArrayBuffer(value)) return budget === void 0 ? null : arrayBufferPrototypes.get(budget) ?? null;
8209
- if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
8215
+ if (isNumericTypedArray(value)) return budget === void 0 ? null : typedArrayPrototypes.get(budget)?.get(typedArrayStorage(value).Native) ?? null;
8210
8216
  const errorType = sandboxErrorTypes.get(value);
8211
8217
  if (budget !== void 0 && errorType !== void 0) {
8212
8218
  const prototype = errorPrototypes.get(budget)?.get(errorType);
@@ -8239,7 +8245,7 @@ function getSandboxPropertyDescriptor(value, key, budget) {
8239
8245
  let current = value;
8240
8246
  let depth = 0;
8241
8247
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8242
- if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8248
+ if (isNumericTypedArray(current) && typeof key !== "symbol" && isTypedArrayIndex(String(key)))
8243
8249
  return Object.getOwnPropertyDescriptor(current, key);
8244
8250
  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;
8245
8251
  if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
@@ -8263,7 +8269,7 @@ function getSandboxDataProperty(value, key, budget) {
8263
8269
  let current = value;
8264
8270
  let depth = 0;
8265
8271
  while (typeof current === "object" && current !== null) {
8266
- if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8272
+ if (isNumericTypedArray(current) && typeof key !== "symbol" && isTypedArrayIndex(String(key)))
8267
8273
  return Object.getOwnPropertyDescriptor(current, key)?.value;
8268
8274
  if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
8269
8275
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
@@ -8317,7 +8323,7 @@ function setSandboxPrototype(value, prototype, budget) {
8317
8323
  }
8318
8324
  function isPrototypeRecord(value) {
8319
8325
  if (isSandboxArrayBuffer(value)) return true;
8320
- if (isFloat32Array(value)) return true;
8326
+ if (isNumericTypedArray(value)) return true;
8321
8327
  if (isGuestClosure(value)) return true;
8322
8328
  if (isGuestHostObject(value)) return false;
8323
8329
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
@@ -8337,7 +8343,7 @@ function hasGuestObjectState(value) {
8337
8343
  if (isLiveCapability(value)) return true;
8338
8344
  if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
8339
8345
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
8340
- return descriptorObjects.has(value) && (isFloat32Array(value) ? float32Properties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
8346
+ return descriptorObjects.has(value) && (isNumericTypedArray(value) ? typedArrayProperties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
8341
8347
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
8342
8348
  );
8343
8349
  }
@@ -9801,8 +9807,8 @@ function getSandboxIterator(value, budget, context) {
9801
9807
  };
9802
9808
  }
9803
9809
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
9804
- if (isFloat32Array(value)) {
9805
- if (hasExplicitSandboxPrototype(value) || budget !== void 0 && float32Prototypes.has(budget)) {
9810
+ if (isNumericTypedArray(value)) {
9811
+ if (hasExplicitSandboxPrototype(value) || budget !== void 0 && typedArrayPrototypes.has(budget)) {
9806
9812
  if (getSandboxPropertyDescriptor(value, Symbol.iterator, budget) === void 0) return void 0;
9807
9813
  return guestProtocolAdapter(value, budget ?? new Budget(), context, false);
9808
9814
  }
@@ -10727,10 +10733,10 @@ async function nextArrayIterator(value, budget, context) {
10727
10733
  if (source === void 0) return { value: void 0, done: true };
10728
10734
  const index = state.index;
10729
10735
  const release = retainValues(budget, () => [value, source]);
10730
- 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);
10736
+ const read = (key) => context?.getProperty !== void 0 ? context.getProperty(source, key) : readPropertyDescriptor((isNumericTypedArray(source) ? Object.getOwnPropertyDescriptor(source, key) : void 0) ?? getSandboxPropertyDescriptor(source, key, budget) ?? { value: void 0 }, source, context);
10731
10737
  try {
10732
10738
  budget.visitNode();
10733
- const number = isFloat32Array(source) ? float32Storage(source, true).length : await sandboxNumber(await read("length"), budget, context);
10739
+ const number = isNumericTypedArray(source) ? typedArrayStorage(source, true).length : await sandboxNumber(await read("length"), budget, context);
10734
10740
  const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
10735
10741
  if (index >= length) {
10736
10742
  state.source = void 0;
@@ -10814,7 +10820,7 @@ async function canonicalizeGuestLocales(input, budget, context) {
10814
10820
  for (let index = 0; index < length; index++) {
10815
10821
  budget.visitNode();
10816
10822
  const key = String(index);
10817
- if (getSandboxPropertyDescriptor(list2, key, budget) === void 0 && !(isFloat32Array(list2) && Object.hasOwn(list2, key))) continue;
10823
+ if (getSandboxPropertyDescriptor(list2, key, budget) === void 0 && !(isNumericTypedArray(list2) && Object.hasOwn(list2, key))) continue;
10818
10824
  const value = await readIntlProperty(list2, key, budget, context);
10819
10825
  if (typeof value !== "string" && (typeof value !== "object" || value === null))
10820
10826
  return Reflect.apply(canonicalLocales, Intl, [[value]]);
@@ -13775,7 +13781,7 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
13775
13781
  }
13776
13782
  function defineDataProperty(target, key, descriptor, budget, context) {
13777
13783
  budget.visitNode();
13778
- if (isFloat32Array(target) && typeof key !== "symbol" && isFloat32Index(String(key)) && "value" in descriptor) {
13784
+ if (isNumericTypedArray(target) && typeof key !== "symbol" && isTypedArrayIndex(String(key)) && "value" in descriptor) {
13779
13785
  const { value, ...attributes } = descriptor;
13780
13786
  Object.defineProperty(target, key, attributes);
13781
13787
  return (async () => {
@@ -14621,52 +14627,57 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14621
14627
  }
14622
14628
  }
14623
14629
 
14624
- // packages/safe-js/src/interp/globals/float32array.ts
14625
- var constructors = /* @__PURE__ */ new WeakSet();
14626
- function createFloat32ArrayGlobal(budget, nativePrototype = false) {
14630
+ // packages/safe-js/src/interp/globals/numeric-typed-array.ts
14631
+ var constructors = /* @__PURE__ */ new WeakMap();
14632
+ function createNumericTypedArrayGlobal(budget, nativePrototype = false, Native = Float32Array) {
14627
14633
  const constructor = createSandboxClosure({
14628
14634
  guest: nativePrototype,
14629
14635
  sandbox: true,
14630
- name: "Float32Array",
14636
+ name: Native.name,
14631
14637
  length: 3,
14632
- properties: { BYTES_PER_ELEMENT: 4 },
14638
+ properties: { BYTES_PER_ELEMENT: Native.BYTES_PER_ELEMENT },
14633
14639
  call: () => {
14634
14640
  throw new TypeError("Constructor Float32Array requires 'new'.");
14635
14641
  },
14636
14642
  construct: (args, context) => {
14637
- if (!nativePrototype) return allocateFloat32Array(args[0], budget);
14643
+ if (!nativePrototype) return allocateTypedArray(args[0], budget, Native);
14638
14644
  return (async () => {
14639
14645
  const newTarget = context?.newTarget ?? constructor;
14640
14646
  const candidate = context?.getProperty === void 0 ? getSandboxDataProperty(newTarget, "prototype", budget) : await context.getProperty(newTarget, "prototype");
14641
- const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
14647
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : typedArrayPrototypes.get(budget).get(Native);
14642
14648
  const release = retainValues(budget, () => [prototype, ...args]);
14643
14649
  try {
14644
14650
  if (isSandboxArrayBuffer(args[0])) {
14645
14651
  const buffer = args[0];
14646
14652
  const number = await sandboxNumber(args[1], budget, context);
14647
14653
  const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
14648
- if (!Number.isSafeInteger(offset) || offset < 0 || offset % 4 !== 0)
14654
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset % Native.BYTES_PER_ELEMENT !== 0)
14649
14655
  throw new RangeError("Invalid Float32Array buffer offset.");
14650
- const bytes = arrayBufferLength(buffer);
14651
14656
  let length;
14652
- if (args[2] === void 0) {
14653
- if (arrayBufferOptions(buffer) === void 0 && bytes % 4 !== 0 || offset > bytes)
14654
- throw new RangeError("Invalid Float32Array buffer length.");
14655
- length = Math.floor((bytes - offset) / 4);
14656
- } else {
14657
+ if (args[2] !== void 0) {
14657
14658
  const size = await sandboxNumber(args[2], budget, context);
14658
14659
  length = Number.isNaN(size) ? 0 : Math.trunc(size);
14659
- if (!Number.isSafeInteger(length) || length < 0 || offset + length * 4 > arrayBufferLength(buffer))
14660
+ if (!Number.isSafeInteger(length) || length < 0)
14661
+ throw new RangeError("Invalid Float32Array view length.");
14662
+ }
14663
+ if (arrayBufferDetached(buffer)) throw new TypeError("Cannot construct Float32Array from a detached ArrayBuffer.");
14664
+ const bytes = arrayBufferLength(buffer);
14665
+ if (length === void 0) {
14666
+ if (arrayBufferOptions(buffer) === void 0 && bytes % Native.BYTES_PER_ELEMENT !== 0 || offset > bytes)
14667
+ throw new RangeError("Invalid Float32Array buffer length.");
14668
+ length = Math.floor((bytes - offset) / Native.BYTES_PER_ELEMENT);
14669
+ } else {
14670
+ if (offset + length * Native.BYTES_PER_ELEMENT > bytes)
14660
14671
  throw new RangeError("Invalid Float32Array view length.");
14661
14672
  }
14662
14673
  budget.allocateArrayLength(length);
14663
- const result2 = new Float32Array(buffer, offset, args[2] === void 0 ? void 0 : length);
14674
+ const result2 = new Native(buffer, offset, args[2] === void 0 ? void 0 : length);
14664
14675
  if (arrayBufferOptions(buffer) !== void 0)
14665
- float32ViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
14676
+ typedArrayViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
14666
14677
  setSandboxPrototype(result2, prototype, budget);
14667
14678
  return result2;
14668
14679
  }
14669
- const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
14680
+ const result = args[0] !== null && typeof args[0] === "object" && !isNumericTypedArray(args[0]) ? await allocateTypedArrayInput(args[0], budget, Native, context) : allocateTypedArray(args[0], budget, Native);
14670
14681
  setSandboxPrototype(result, prototype, budget);
14671
14682
  return result;
14672
14683
  } finally {
@@ -14675,10 +14686,10 @@ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
14675
14686
  })();
14676
14687
  }
14677
14688
  });
14678
- constructors.add(constructor);
14689
+ constructors.set(constructor, Native);
14679
14690
  return constructor;
14680
14691
  }
14681
- async function allocateFloat32Input(source, budget, context) {
14692
+ async function allocateTypedArrayInput(source, budget, Native, context) {
14682
14693
  const callerContext = context;
14683
14694
  const bridge = {
14684
14695
  ...callerContext,
@@ -14716,8 +14727,8 @@ async function allocateFloat32Input(source, budget, context) {
14716
14727
  const number = await sandboxNumber(current, budget, bridge);
14717
14728
  length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14718
14729
  }
14719
- checkFloat32Allocation(length, budget);
14720
- result = new Float32Array(length);
14730
+ checkTypedArrayAllocation(length, budget, Native.BYTES_PER_ELEMENT);
14731
+ result = new Native(length);
14721
14732
  checkData(result, 0, true);
14722
14733
  for (let index = 0; index < length; index++) {
14723
14734
  budget.visitNode();
@@ -14729,30 +14740,29 @@ async function allocateFloat32Input(source, budget, context) {
14729
14740
  release();
14730
14741
  }
14731
14742
  }
14732
- function allocateFloat32Array(source, budget) {
14733
- if (Array.isArray(source) || isFloat32Array(source)) {
14734
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14735
- checkFloat32Allocation(length2, budget);
14736
- if (isFloat32Array(source)) return new Float32Array(source);
14737
- const result = new Float32Array(length2);
14743
+ function allocateTypedArray(source, budget, Native) {
14744
+ if (Array.isArray(source) || isNumericTypedArray(source)) {
14745
+ const length2 = isNumericTypedArray(source) ? typedArrayStorage(source).length : source.length;
14746
+ checkTypedArrayAllocation(length2, budget, Native.BYTES_PER_ELEMENT);
14747
+ if (isNumericTypedArray(source)) return new Native(source);
14748
+ const result = new Native(length2);
14738
14749
  for (let index = 0; index < length2; index += 1) {
14739
14750
  budget.visitNode();
14740
14751
  const descriptor = Object.getOwnPropertyDescriptor(source, index);
14741
14752
  if (descriptor !== void 0 && !("value" in descriptor))
14742
14753
  throw new TypeError("Float32Array input accessors are not supported.");
14743
- result[index] = float32Number(descriptor?.value);
14754
+ result[index] = typedArrayNumber(descriptor?.value);
14744
14755
  }
14745
14756
  return result;
14746
14757
  }
14747
- const number = float32Number(source);
14758
+ const number = typedArrayNumber(source);
14748
14759
  const length = Number.isNaN(number) ? 0 : Math.trunc(number);
14749
14760
  if (length < 0 || !Number.isSafeInteger(length))
14750
14761
  throw new RangeError("Invalid typed array length.");
14751
- checkFloat32Allocation(length, budget);
14752
- return new Float32Array(length);
14762
+ checkTypedArrayAllocation(length, budget, Native.BYTES_PER_ELEMENT);
14763
+ return new Native(length);
14753
14764
  }
14754
- function createFloat32ArrayPrototypes(budget, constructor) {
14755
- const prototype = /* @__PURE__ */ Object.create(null);
14765
+ function createNumericTypedArrayPrototypes(budget, bindings) {
14756
14766
  const shared = /* @__PURE__ */ Object.create(null);
14757
14767
  const abstractCall = () => {
14758
14768
  throw new TypeError("Abstract TypedArray constructor cannot be called.");
@@ -14821,7 +14831,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14821
14831
  length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14822
14832
  }
14823
14833
  result = await invokeBuiltinClosure(target, [length], budget, context, void 0, true);
14824
- if (!isFloat32Array(result) || float32Storage(result).length < length)
14834
+ if (!isNumericTypedArray(result) || typedArrayStorage(result).length < length)
14825
14835
  throw new TypeError("TypedArray.from constructor must return sufficient typed storage.");
14826
14836
  checkData(result, 0, true);
14827
14837
  for (let index = 0; index < length; index++) {
@@ -14854,7 +14864,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14854
14864
  const release = retainValues(budget, () => [target, result, ...args]);
14855
14865
  try {
14856
14866
  result = await invokeBuiltinClosure(target, [args.length], budget, context, void 0, true);
14857
- if (!isFloat32Array(result) || float32Storage(result).length < args.length)
14867
+ if (!isNumericTypedArray(result) || typedArrayStorage(result).length < args.length)
14858
14868
  throw new TypeError("TypedArray.of constructor must return sufficient typed storage.");
14859
14869
  for (let index = 0; index < args.length; index++) {
14860
14870
  budget.visitNode();
@@ -14867,17 +14877,25 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14867
14877
  }
14868
14878
  })
14869
14879
  });
14870
- Object.defineProperties(materializeFunctionProperties(constructor), {
14871
- prototype: { value: prototype, writable: false },
14872
- BYTES_PER_ELEMENT: { value: 4, writable: false, enumerable: false, configurable: false }
14873
- });
14874
- Object.defineProperties(prototype, {
14875
- constructor: { value: constructor, writable: true, configurable: true },
14876
- BYTES_PER_ELEMENT: { value: 4 }
14877
- });
14880
+ const prototypes2 = /* @__PURE__ */ new Map();
14881
+ for (const [name, Native] of Object.entries(numericTypedArrayConstructors)) {
14882
+ const constructor = bindings[name];
14883
+ const prototype = /* @__PURE__ */ Object.create(null);
14884
+ Object.defineProperties(materializeFunctionProperties(constructor), {
14885
+ prototype: { value: prototype, writable: false },
14886
+ BYTES_PER_ELEMENT: { value: Native.BYTES_PER_ELEMENT, writable: false, enumerable: false, configurable: false }
14887
+ });
14888
+ Object.defineProperties(prototype, {
14889
+ constructor: { value: constructor, writable: true, configurable: true },
14890
+ BYTES_PER_ELEMENT: { value: Native.BYTES_PER_ELEMENT }
14891
+ });
14892
+ setSandboxPrototype(constructor, typedArray);
14893
+ setSandboxPrototype(prototype, shared);
14894
+ prototypes2.set(Native, prototype);
14895
+ registerIntrinsicFunction(budget, constructor);
14896
+ registerIntrinsicObject(budget, prototype);
14897
+ }
14878
14898
  Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
14879
- setSandboxPrototype(constructor, typedArray);
14880
- setSandboxPrototype(prototype, shared);
14881
14899
  setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
14882
14900
  const getters = [];
14883
14901
  const species = createSandboxClosure({
@@ -14899,16 +14917,16 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14899
14917
  name: `get ${key}`,
14900
14918
  length: 0,
14901
14919
  call: (_args, context) => {
14902
- if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14903
- const storage = float32Storage(context.thisValue);
14904
- return key === "byteLength" ? storage.length * 4 : storage[key];
14920
+ if (!isNumericTypedArray(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14921
+ const storage = typedArrayStorage(context.thisValue);
14922
+ return key === "byteLength" ? storage.length * storage.elementSize : storage[key];
14905
14923
  }
14906
14924
  });
14907
14925
  getters.push(getter);
14908
14926
  Object.defineProperty(shared, key, { get: accessorAdapter(getter, "get"), configurable: true });
14909
14927
  }
14910
14928
  for (const key of ["set", "slice", "subarray", "fill", "copyWithin", "reverse", "toReversed", "at", "includes", "indexOf", "lastIndexOf", "forEach", "every", "some", "find", "findIndex", "findLast", "findLastIndex", "sort", "toSorted", "with", "reduce", "reduceRight", "map", "filter", "toLocaleString"])
14911
- Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget, constructor), writable: true, configurable: true });
14929
+ Object.defineProperty(shared, key, { value: getTypedArrayMember(new Float32Array(0), key, budget, bindings), writable: true, configurable: true });
14912
14930
  const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
14913
14931
  Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
14914
14932
  Object.defineProperty(shared, "join", {
@@ -14920,9 +14938,9 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14920
14938
  name: "join",
14921
14939
  length: 1,
14922
14940
  call: async (args, context) => {
14923
- if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
14941
+ if (!isNumericTypedArray(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
14924
14942
  const receiver = context.thisValue;
14925
- const length = float32Storage(receiver, true).length;
14943
+ const length = typedArrayStorage(receiver, true).length;
14926
14944
  let separator = ",";
14927
14945
  let text = "";
14928
14946
  const release = retainValues(budget, () => [receiver, separator, text, ...args]);
@@ -14945,7 +14963,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14945
14963
  sandbox: true,
14946
14964
  name: "get [Symbol.toStringTag]",
14947
14965
  length: 0,
14948
- call: (_args, context) => isFloat32Array(context?.thisValue) ? "Float32Array" : void 0
14966
+ call: (_args, context) => isNumericTypedArray(context?.thisValue) ? typedArrayStorage(context.thisValue).Native.name : void 0
14949
14967
  });
14950
14968
  getters.push(tagGetter);
14951
14969
  Object.defineProperty(shared, Symbol.toStringTag, { get: accessorAdapter(tagGetter, "get"), configurable: true });
@@ -14957,38 +14975,36 @@ function createFloat32ArrayPrototypes(budget, constructor) {
14957
14975
  name: key,
14958
14976
  length: 0,
14959
14977
  call: (args, context) => {
14960
- if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14961
- float32Storage(context.thisValue, true);
14978
+ if (!isNumericTypedArray(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14979
+ typedArrayStorage(context.thisValue, true);
14962
14980
  return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
14963
14981
  }
14964
14982
  });
14965
14983
  Object.defineProperty(shared, key, { value: closure, writable: true, configurable: true });
14966
14984
  if (key === "values") Object.defineProperty(shared, Symbol.iterator, { value: closure, writable: true, configurable: true });
14967
14985
  }
14968
- float32Prototypes.set(budget, prototype);
14969
- registerBuiltinIdentities(budget, { Float32Array: constructor, "%TypedArray%": typedArray });
14970
- registerIntrinsicFunction(budget, constructor);
14986
+ typedArrayPrototypes.set(budget, prototypes2);
14987
+ registerBuiltinIdentities(budget, { ...bindings, "%TypedArray%": typedArray });
14971
14988
  registerIntrinsicFunction(budget, typedArray);
14972
- registerIntrinsicObject(budget, prototype);
14973
14989
  registerIntrinsicObject(budget, shared);
14974
14990
  for (const getter of getters) registerIntrinsicFunction(budget, getter);
14975
14991
  }
14976
- function isFloat32ArrayConstructor(value) {
14977
- return typeof value === "object" && value !== null && constructors.has(value);
14992
+ function numericTypedArrayConstructor(value) {
14993
+ return typeof value === "object" && value !== null ? constructors.get(value) : void 0;
14978
14994
  }
14979
- function getFloat32Member(value, property, budget, defaultConstructor) {
14995
+ function getTypedArrayMember(value, property, budget, bindings) {
14980
14996
  const key = String(property);
14981
14997
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
14982
14998
  if (descriptor !== void 0) {
14983
14999
  if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
14984
15000
  return descriptor.value;
14985
15001
  }
14986
- if (float32Prototypes.has(budget)) return void 0;
14987
- const storage = float32Storage(value);
15002
+ if (typedArrayPrototypes.has(budget)) return void 0;
15003
+ const storage = typedArrayStorage(value);
14988
15004
  if (key === "length") return storage.length;
14989
- if (key === "byteLength") return storage.length * 4;
15005
+ if (key === "byteLength") return storage.length * storage.elementSize;
14990
15006
  if (key === "byteOffset") return storage.byteOffset;
14991
- if (key === "BYTES_PER_ELEMENT") return 4;
15007
+ if (key === "BYTES_PER_ELEMENT") return storage.elementSize;
14992
15008
  if (!["set", "slice", "subarray", "fill", "copyWithin", "reverse", "toReversed", "at", "includes", "indexOf", "lastIndexOf", "forEach", "every", "some", "find", "findIndex", "findLast", "findLastIndex", "sort", "toSorted", "with", "reduce", "reduceRight", "map", "filter", "toLocaleString"].includes(key)) return void 0;
14993
15009
  const numberPrototype = key === "toLocaleString" ? getBoxedPrototype(0, budget) : void 0;
14994
15010
  return createSandboxClosure({
@@ -15000,15 +15016,16 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15000
15016
  if ((key === "sort" || key === "toSorted") && args[0] !== void 0 && !isSandboxClosure(args[0]))
15001
15017
  throw new TypeError("TypedArray sort comparator must be callable.");
15002
15018
  const receiver = context?.thisValue;
15003
- if (!isFloat32Array(receiver))
15019
+ if (!isNumericTypedArray(receiver))
15004
15020
  throw new TypeError(`Float32Array#${key} requires a Float32Array receiver.`);
15005
- const storage2 = float32Storage(receiver, key === "sort" || key === "toSorted" || key === "with" || key === "reduce" || key === "reduceRight" || key === "map" || key === "filter" || key === "slice" || key === "fill" || key === "copyWithin" || key === "reverse" || key === "toReversed" || key === "at" || key === "includes" || key === "indexOf" || key === "lastIndexOf" || key === "forEach" || key === "every" || key === "some" || key === "find" || key === "findIndex" || key === "findLast" || key === "findLastIndex" || key === "toLocaleString");
15021
+ const storage2 = typedArrayStorage(receiver, key === "sort" || key === "toSorted" || key === "with" || key === "reduce" || key === "reduceRight" || key === "map" || key === "filter" || key === "slice" || key === "fill" || key === "copyWithin" || key === "reverse" || key === "toReversed" || key === "at" || key === "includes" || key === "indexOf" || key === "lastIndexOf" || key === "forEach" || key === "every" || key === "some" || key === "find" || key === "findIndex" || key === "findLast" || key === "findLastIndex" || key === "toLocaleString");
15022
+ const defaultConstructor = bindings?.[storage2.Native.name];
15006
15023
  if (key === "toReversed") {
15007
15024
  let result;
15008
15025
  const release = retainValues(budget, () => [receiver, result, ...args]);
15009
15026
  try {
15010
- checkFloat32Allocation(storage2.length, budget);
15011
- result = new Float32Array(storage2.length);
15027
+ checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15028
+ result = new storage2.Native(storage2.length);
15012
15029
  createDataCheckpoint(budget, context)(result, 0, true);
15013
15030
  for (let index = 0; index < storage2.length; index++) {
15014
15031
  budget.visitNode();
@@ -15022,14 +15039,14 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15022
15039
  if (key === "reverse") {
15023
15040
  const release = retainValues(budget, () => [receiver, ...args]);
15024
15041
  try {
15025
- const bytes = new Uint8Array(storage2.buffer, storage2.byteOffset, storage2.length * 4);
15042
+ const bytes = new Uint8Array(storage2.buffer, storage2.byteOffset, storage2.length * storage2.elementSize);
15026
15043
  for (let lower = 0; lower < Math.floor(storage2.length / 2); lower++) {
15027
15044
  const upper = storage2.length - lower - 1;
15028
- for (let offset = 0; offset < 4; offset++) {
15045
+ for (let offset = 0; offset < storage2.elementSize; offset++) {
15029
15046
  budget.visitNode();
15030
- const saved = bytes[lower * 4 + offset];
15031
- bytes[lower * 4 + offset] = bytes[upper * 4 + offset];
15032
- bytes[upper * 4 + offset] = saved;
15047
+ const saved = bytes[lower * storage2.elementSize + offset];
15048
+ bytes[lower * storage2.elementSize + offset] = bytes[upper * storage2.elementSize + offset];
15049
+ bytes[upper * storage2.elementSize + offset] = saved;
15033
15050
  }
15034
15051
  }
15035
15052
  return receiver;
@@ -15057,16 +15074,16 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15057
15074
  const release = retainValues(budget, () => [receiver, items, scratch, comparisonResult, ...args]);
15058
15075
  const checkData = createDataCheckpoint(budget, bridge);
15059
15076
  try {
15060
- checkFloat32Allocation(storage2.length, budget);
15061
- items = new Float32Array(storage2.length);
15077
+ checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15078
+ items = new storage2.Native(storage2.length);
15062
15079
  checkData(items, 0, true);
15063
15080
  for (let index = 0; index < storage2.length; index++) {
15064
15081
  budget.visitNode();
15065
15082
  items[index] = receiver[index];
15066
15083
  }
15067
15084
  if (storage2.length < 2) return items;
15068
- checkFloat32Allocation(storage2.length, budget);
15069
- scratch = new Float32Array(storage2.length);
15085
+ checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15086
+ scratch = new storage2.Native(storage2.length);
15070
15087
  checkData(scratch, 0, true);
15071
15088
  for (let width = 1; width < storage2.length; width *= 2) {
15072
15089
  for (let start = 0; start < storage2.length; start += width * 2) {
@@ -15211,10 +15228,10 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15211
15228
  const relative = Number.isNaN(number) ? 0 : Math.trunc(number);
15212
15229
  const index = relative < 0 ? storage2.length + relative : relative;
15213
15230
  const replacement = await sandboxNumber(args[1], budget, bridge);
15214
- if (index < 0 || index >= float32Storage(receiver).length)
15231
+ if (index < 0 || index >= typedArrayStorage(receiver).length)
15215
15232
  throw new RangeError("Float32Array#with index is out of bounds.");
15216
- checkFloat32Allocation(storage2.length, budget);
15217
- result = new Float32Array(storage2.length);
15233
+ checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15234
+ result = new storage2.Native(storage2.length);
15218
15235
  createDataCheckpoint(budget, bridge)(result, 0, true);
15219
15236
  for (let offset = 0; offset < storage2.length; offset++) {
15220
15237
  budget.visitNode();
@@ -15248,14 +15265,14 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15248
15265
  const end = args[2] === void 0 ? storage2.length : relativeIndex(await sandboxNumber(args[2], budget, bridge), storage2.length);
15249
15266
  let count = Math.min(end - start, storage2.length - target);
15250
15267
  if (count > 0) {
15251
- const current = float32Storage(receiver, true);
15268
+ const current = typedArrayStorage(receiver, true);
15252
15269
  count = Math.min(count, current.length - start, current.length - target);
15253
15270
  if (count > 0) {
15254
- const bytes = new Uint8Array(current.buffer, current.byteOffset, current.length * 4);
15271
+ const bytes = new Uint8Array(current.buffer, current.byteOffset, current.length * storage2.elementSize);
15255
15272
  const direction = start < target && target < start + count ? -1 : 1;
15256
- let from = start * 4 + (direction < 0 ? count * 4 - 1 : 0);
15257
- let to = target * 4 + (direction < 0 ? count * 4 - 1 : 0);
15258
- for (let remaining = count * 4; remaining > 0; remaining--) {
15273
+ let from = start * storage2.elementSize + (direction < 0 ? count * storage2.elementSize - 1 : 0);
15274
+ let to = target * storage2.elementSize + (direction < 0 ? count * storage2.elementSize - 1 : 0);
15275
+ for (let remaining = count * storage2.elementSize; remaining > 0; remaining--) {
15259
15276
  budget.visitNode();
15260
15277
  bytes[to] = bytes[from];
15261
15278
  from += direction;
@@ -15276,7 +15293,7 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15276
15293
  const value2 = await sandboxNumber(args[0], budget, bridge);
15277
15294
  const start = relativeIndex(await sandboxNumber(args[1], budget, bridge), storage2.length);
15278
15295
  const end = args[2] === void 0 ? storage2.length : relativeIndex(await sandboxNumber(args[2], budget, bridge), storage2.length);
15279
- const current = float32Storage(receiver, true);
15296
+ const current = typedArrayStorage(receiver, true);
15280
15297
  for (let index = start; index < Math.min(end, current.length); index++) {
15281
15298
  budget.visitNode();
15282
15299
  receiver[index] = value2;
@@ -15297,10 +15314,10 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15297
15314
  const number = await sandboxNumber(offsetValue, budget, bridge);
15298
15315
  const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
15299
15316
  if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
15300
- const targetStorage = float32Storage(receiver, true);
15317
+ const targetStorage = typedArrayStorage(receiver, true);
15301
15318
  if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
15302
15319
  let length;
15303
- if (isFloat32Array(source)) length = float32Storage(source, true).length;
15320
+ if (isNumericTypedArray(source)) length = typedArrayStorage(source, true).length;
15304
15321
  else {
15305
15322
  sourceObject = typeof source === "object" ? source : createSandboxBox(source);
15306
15323
  current = await bridge.getProperty(sourceObject, "length");
@@ -15308,7 +15325,7 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15308
15325
  length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
15309
15326
  }
15310
15327
  if (offset + length > targetStorage.length) throw new RangeError("Float32Array#set source is out of bounds.");
15311
- if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
15328
+ if (isNumericTypedArray(source)) Float32Array.prototype.set.call(receiver, source, offset);
15312
15329
  else for (let index = 0; index < length; index++) {
15313
15330
  budget.visitNode();
15314
15331
  current = await bridge.getProperty(sourceObject, String(index));
@@ -15346,8 +15363,8 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15346
15363
  }
15347
15364
  length = kept.length;
15348
15365
  }
15349
- const layout = float32ViewLayouts.get(receiver);
15350
- const offset = (layout?.byteOffset ?? storage2.byteOffset) + start * 4;
15366
+ const layout = typedArrayViewLayouts.get(receiver);
15367
+ const offset = (layout?.byteOffset ?? storage2.byteOffset) + start * storage2.elementSize;
15351
15368
  const tracking = layout !== void 0 && layout.length === void 0 && args[1] === void 0;
15352
15369
  if (defaultConstructor !== void 0) {
15353
15370
  candidate = await bridge.getProperty(receiver, "constructor");
@@ -15362,24 +15379,24 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15362
15379
  if (candidate !== void 0 && candidate !== null && candidate !== defaultConstructor) {
15363
15380
  const values = key !== "subarray" ? [length] : [storage2.buffer, offset, tracking ? void 0 : length];
15364
15381
  result = await invokeBuiltinClosure(candidate, values, budget, bridge, void 0, true);
15365
- if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
15366
- const target = float32Storage(result, key !== "subarray");
15382
+ if (!isNumericTypedArray(result)) throw new TypeError("TypedArray species must return typed storage.");
15383
+ const target = typedArrayStorage(result, key !== "subarray");
15367
15384
  if (key !== "subarray" && target.length < length)
15368
15385
  throw new TypeError("TypedArray species returned insufficient storage.");
15369
15386
  }
15370
15387
  if (key === "subarray") {
15371
15388
  if (result === void 0) {
15372
- result = new Float32Array(storage2.buffer, offset, tracking ? void 0 : length);
15389
+ result = new storage2.Native(storage2.buffer, offset, tracking ? void 0 : length);
15373
15390
  if (arrayBufferOptions(storage2.buffer) !== void 0)
15374
- float32ViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
15391
+ typedArrayViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
15375
15392
  }
15376
15393
  return result;
15377
15394
  }
15378
15395
  if (result === void 0) {
15379
- checkFloat32Allocation(length, budget);
15380
- result = new Float32Array(length);
15396
+ checkTypedArrayAllocation(length, budget, storage2.elementSize);
15397
+ result = new storage2.Native(length);
15381
15398
  }
15382
- if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
15399
+ if (!isNumericTypedArray(result)) throw new TypeError("TypedArray species must return typed storage.");
15383
15400
  if (key === "filter") {
15384
15401
  for (let index = 0; index < length; index++) {
15385
15402
  budget.visitNode();
@@ -15396,12 +15413,17 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15396
15413
  return result;
15397
15414
  }
15398
15415
  if (length > 0) {
15399
- const current = float32Storage(receiver, true);
15400
- const target = float32Storage(result, true);
15416
+ const current = typedArrayStorage(receiver, true);
15417
+ const target = typedArrayStorage(result, true);
15401
15418
  const count = Math.min(length, Math.max(current.length - start, 0));
15402
- if (count > 0) {
15403
- const sourceBytes = new Uint8Array(current.buffer, current.byteOffset + start * 4, count * 4);
15404
- const targetBytes = new Uint8Array(target.buffer, target.byteOffset, count * 4);
15419
+ if (count > 0 && current.Native !== target.Native) {
15420
+ for (let index = 0; index < count; index++) {
15421
+ budget.visitNode();
15422
+ result[index] = receiver[start + index];
15423
+ }
15424
+ } else if (count > 0) {
15425
+ const sourceBytes = new Uint8Array(current.buffer, current.byteOffset + start * storage2.elementSize, count * storage2.elementSize);
15426
+ const targetBytes = new Uint8Array(target.buffer, target.byteOffset, count * storage2.elementSize);
15405
15427
  if (current.buffer === target.buffer && targetBytes.byteOffset > sourceBytes.byteOffset && targetBytes.byteOffset < sourceBytes.byteOffset + sourceBytes.length) {
15406
15428
  for (let index = 0; index < sourceBytes.length; index++) {
15407
15429
  budget.visitNode();
@@ -15418,9 +15440,9 @@ function getFloat32Member(value, property, budget, defaultConstructor) {
15418
15440
  }
15419
15441
  });
15420
15442
  }
15421
- function setFloat32Member(value, property, entry, budget, context) {
15443
+ function setTypedArrayMember(value, property, entry, budget, context) {
15422
15444
  const key = typeof property === "symbol" ? property : String(property);
15423
- if (typeof key !== "symbol" && isFloat32Index(key)) {
15445
+ if (typeof key !== "symbol" && isTypedArrayIndex(key)) {
15424
15446
  return (async () => {
15425
15447
  const release = retainValues(budget, () => [value, entry]);
15426
15448
  try {
@@ -15433,7 +15455,7 @@ function setFloat32Member(value, property, entry, budget, context) {
15433
15455
  }
15434
15456
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
15435
15457
  const inherited = descriptor ?? getSandboxPropertyDescriptor(value, key, budget);
15436
- if (descriptor === void 0 && typeof key === "string" && !float32Prototypes.has(budget) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
15458
+ if (descriptor === void 0 && typeof key === "string" && !typedArrayPrototypes.has(budget) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
15437
15459
  throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
15438
15460
  if (inherited !== void 0 && (!("value" in inherited) || !inherited.writable))
15439
15461
  throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
@@ -15606,7 +15628,8 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
15606
15628
  budget.visitNode();
15607
15629
  return evaluateInstanceof(value, constructor.boundTarget, budget, context);
15608
15630
  }
15609
- if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
15631
+ if (numericTypedArrayConstructor(constructor) !== void 0 && !isGuestClosure(constructor))
15632
+ return isNumericTypedArray(value) && typedArrayStorage(value).Native === numericTypedArrayConstructor(constructor);
15610
15633
  if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
15611
15634
  if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
15612
15635
  const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
@@ -17360,7 +17383,7 @@ function forInObject(value) {
17360
17383
  if (value === null || value === void 0 || isSandboxClosure(value)) {
17361
17384
  return void 0;
17362
17385
  }
17363
- if (typeof value === "string" || Array.isArray(value) || isFloat32Array(value) || isPlainForInObject(value)) {
17386
+ if (typeof value === "string" || Array.isArray(value) || isNumericTypedArray(value) || isPlainForInObject(value)) {
17364
17387
  return Object(value);
17365
17388
  }
17366
17389
  return void 0;
@@ -17939,7 +17962,7 @@ function getPropertyValue(target, property, context, receiver = target) {
17939
17962
  if (typeof target === "string") return getStringMember(target, property, context.budget);
17940
17963
  if (typeof target === "number") return getNumberMember(property, context.budget);
17941
17964
  if (typeof target === "boolean") return void 0;
17942
- if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
17965
+ if (isNumericTypedArray(target)) return getTypedArrayMember(target, property, context.budget);
17943
17966
  if (isSandboxDate(target)) return void 0;
17944
17967
  if (isSandboxMap(target)) return getSandboxPrototype(target, context.budget) === null ? getMapMember(target, property, createMapMethodOptions(context)) : void 0;
17945
17968
  if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
@@ -18243,7 +18266,7 @@ async function evaluateMemberCallExpression(node, context) {
18243
18266
  if (isSandboxDate(member.object)) {
18244
18267
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
18245
18268
  }
18246
- if (isFloat32Array(member.object)) {
18269
+ if (isNumericTypedArray(member.object)) {
18247
18270
  return evaluateResolvedCallExpression(
18248
18271
  node,
18249
18272
  await getPropertyValue(member.object, member.property, context),
@@ -18534,7 +18557,7 @@ function hasSandboxProperty(value, key, context) {
18534
18557
  while (typeof current === "object" && current !== null) {
18535
18558
  if (isGuestHostObject(current)) return typeof key === "symbol" ? false : hasHostObjectMember(current, String(key));
18536
18559
  if (hasOwnSandboxProperty(current, key, false)) return true;
18537
- if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || isSandboxGenerator(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
18560
+ if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || isSandboxGenerator(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isNumericTypedArray(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
18538
18561
  return getPropertyValue(current, key, context) !== void 0;
18539
18562
  }
18540
18563
  current = getSandboxPrototype(current, context.budget);
@@ -18746,7 +18769,7 @@ function getMemberValue(target, property, context) {
18746
18769
  while (typeof current === "object" && current !== null) {
18747
18770
  if (isSandboxClosure(current)) return getClosureMemberValue(current, property, context);
18748
18771
  if (Array.isArray(current)) return getArrayMemberValue(current, property, context);
18749
- if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current) || isFloat32Array(current)) {
18772
+ if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current) || isNumericTypedArray(current)) {
18750
18773
  return getPropertyValue(current, property, context);
18751
18774
  }
18752
18775
  if (Object.hasOwn(current, String(property))) return current[String(property)];
@@ -18782,8 +18805,8 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
18782
18805
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
18783
18806
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
18784
18807
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
18785
- if (isFloat32Array(target)) {
18786
- return setFloat32Member(target, property, value, budget, context);
18808
+ if (isNumericTypedArray(target)) {
18809
+ return setTypedArrayMember(target, property, value, budget, context);
18787
18810
  }
18788
18811
  if (isSandboxRegex(target)) {
18789
18812
  setRegexMember(target, property, value, budget);
@@ -19416,7 +19439,7 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
19416
19439
  }
19417
19440
  }
19418
19441
  function conversionHook(value, name, budget, context) {
19419
- const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) && getSandboxPrototype(value, budget) === null || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
19442
+ const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isNumericTypedArray(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) && getSandboxPrototype(value, budget) === null || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
19420
19443
  let current = value;
19421
19444
  let depth = 0;
19422
19445
  while (current !== null) {
@@ -19449,14 +19472,14 @@ async function defaultToString(value, budget, context, joining) {
19449
19472
  if (isSandboxGenerator(value)) return "[object Generator]";
19450
19473
  if (isSandboxRegex(value)) return regexToString(value, budget, context);
19451
19474
  if (isSandboxDate(value)) return budget.allocateString(dateString(value));
19452
- if (Array.isArray(value) || isFloat32Array(value)) {
19475
+ if (Array.isArray(value) || isNumericTypedArray(value)) {
19453
19476
  if (Object.hasOwn(value, "join")) {
19454
19477
  const join = await readCoercionProperty(value, "join", context);
19455
19478
  if (!isSandboxClosure(join))
19456
- return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
19479
+ return isNumericTypedArray(value) ? `[object ${typedArrayStorage(value).Native.name}]` : "[object Array]";
19457
19480
  return invokeBuiltinClosure(join, [], budget, context, value);
19458
19481
  }
19459
- const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
19482
+ const length = isNumericTypedArray(value) ? typedArrayStorage(value).length : value.length;
19460
19483
  return joinSandboxArray(value, length, ",", budget, context, joining);
19461
19484
  }
19462
19485
  if (sandboxErrorTypes.has(value)) {
@@ -19663,7 +19686,7 @@ function typeTag(value, builtinOnly = false) {
19663
19686
  if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "Map Iterator" : "Set Iterator";
19664
19687
  if (isSandboxPromise(value)) return "Promise";
19665
19688
  if (isSandboxGenerator(value)) return "Generator";
19666
- if (isFloat32Array(value)) return "Float32Array";
19689
+ if (isNumericTypedArray(value)) return typedArrayStorage(value).Native.name;
19667
19690
  return "Object";
19668
19691
  }
19669
19692
 
@@ -21529,33 +21552,36 @@ function serializeArray(value, serializeValue) {
21529
21552
  return { kind: "array", length: value.length, entries };
21530
21553
  }
21531
21554
 
21532
- // packages/safe-js/src/snapshot/float32array.ts
21533
- function encodeFloat32Layout(value) {
21534
- const storage = float32Storage(value);
21535
- if (arrayBufferDetached(storage.buffer)) return { byteOffset: 0, length: 0 };
21536
- if (arrayBufferOptions(storage.buffer) === void 0) return { byteOffset: storage.byteOffset, length: storage.length };
21537
- const layout = float32ViewLayouts.get(value);
21555
+ // packages/safe-js/src/snapshot/typed-array.ts
21556
+ function encodeTypedArrayLayout(value) {
21557
+ const storage = typedArrayStorage(value);
21558
+ const identity = storage.Native === Float32Array ? { kind: "float32array" } : { kind: "typedarray", arrayType: storage.Native.name };
21559
+ if (arrayBufferDetached(storage.buffer)) return { ...identity, byteOffset: 0, length: 0 };
21560
+ if (arrayBufferOptions(storage.buffer) === void 0) return { ...identity, byteOffset: storage.byteOffset, length: storage.length };
21561
+ const layout = typedArrayViewLayouts.get(value);
21538
21562
  if (layout === void 0) throw new TypeError("Resizable Float32Array snapshots require known view layout.");
21539
21563
  return {
21564
+ ...identity,
21540
21565
  byteOffset: layout.byteOffset,
21541
21566
  length: layout.length ?? 0,
21542
21567
  ...layout.length === void 0 ? { lengthTracking: true } : {}
21543
21568
  };
21544
21569
  }
21545
- function validateFloat32Storage(value) {
21570
+ function validateTypedArrayStorage(value) {
21571
+ const Native = snapshotTypedArrayConstructor(value);
21546
21572
  if (Object.hasOwn(value, "lengthTracking") && (value.lengthTracking !== true || value.length !== 0 || Object.hasOwn(value, "bytes")))
21547
21573
  throw new TypeError("Invalid Float32Array length-tracking layout.");
21548
- if (!Number.isSafeInteger(value.length) || Number(value.length) < 0 || !Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || Number(value.byteOffset) % 4 !== 0)
21574
+ if (!Number.isSafeInteger(value.length) || Number(value.length) < 0 || !Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || Number(value.byteOffset) % Native.BYTES_PER_ELEMENT !== 0)
21549
21575
  throw new TypeError("Invalid Float32Array view dimensions.");
21550
21576
  if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
21551
21577
  throw new TypeError("Float32Array requires one backing storage description.");
21552
21578
  if (Object.hasOwn(value, "bytes")) {
21553
- if (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255) || Number(value.length) > Math.floor((value.bytes.length - Number(value.byteOffset)) / 4))
21579
+ if (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255) || Number(value.length) > Math.floor((value.bytes.length - Number(value.byteOffset)) / Native.BYTES_PER_ELEMENT))
21554
21580
  throw new TypeError("Invalid Float32Array backing bytes.");
21555
21581
  }
21556
21582
  }
21557
- function decodeFloat32Storage(value, resolve, budget) {
21558
- validateFloat32Storage(value);
21583
+ function decodeTypedArrayStorage(value, resolve, budget) {
21584
+ validateTypedArrayStorage(value);
21559
21585
  let buffer;
21560
21586
  if (Array.isArray(value.bytes)) {
21561
21587
  buffer = new ArrayBuffer(value.bytes.length);
@@ -21563,12 +21589,21 @@ function decodeFloat32Storage(value, resolve, budget) {
21563
21589
  } else {
21564
21590
  const referenced = resolve(value.buffer);
21565
21591
  if (isSandboxArrayBuffer(referenced)) buffer = referenced;
21566
- else if (isFloat32Array(referenced)) buffer = float32Storage(referenced).buffer;
21592
+ else if (isNumericTypedArray(referenced)) buffer = typedArrayStorage(referenced).buffer;
21567
21593
  else throw new TypeError("Invalid Float32Array backing reference.");
21568
21594
  }
21569
21595
  if (value.lengthTracking === true && arrayBufferOptions(buffer) === void 0)
21570
21596
  throw new TypeError("Length-tracking layout requires resizable backing storage.");
21571
- return restoreFloat32View(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.length), budget);
21597
+ return restoreTypedArrayView(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.length), budget, snapshotTypedArrayConstructor(value));
21598
+ }
21599
+ function snapshotTypedArrayConstructor(value) {
21600
+ if (value.kind !== "typedarray") {
21601
+ if (Object.hasOwn(value, "arrayType")) throw new TypeError("Legacy Float32Array storage cannot specify another array type.");
21602
+ return Float32Array;
21603
+ }
21604
+ if (typeof value.arrayType !== "string" || !Object.hasOwn(numericTypedArrayConstructors, value.arrayType))
21605
+ throw new TypeError("Invalid typed array storage type.");
21606
+ return numericTypedArrayConstructors[value.arrayType];
21572
21607
  }
21573
21608
 
21574
21609
  // packages/safe-js/src/snapshot/array-buffer.ts
@@ -21623,7 +21658,7 @@ function decodeArrayBufferStorage(value, resolve, budget, deferredDetachment) {
21623
21658
  }
21624
21659
  const referenced = resolve(value.buffer);
21625
21660
  if (isSandboxArrayBuffer(referenced)) return referenced;
21626
- if (isFloat32Array(referenced)) return float32Storage(referenced).buffer;
21661
+ if (isNumericTypedArray(referenced)) return typedArrayStorage(referenced).buffer;
21627
21662
  throw new TypeError("Invalid ArrayBuffer backing reference.");
21628
21663
  }
21629
21664
 
@@ -21755,7 +21790,7 @@ function serializeDumpValue(value, path, state) {
21755
21790
  if (hasGuestObjectState(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
21756
21791
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
21757
21792
  }
21758
- if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
21793
+ if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isNumericTypedArray(value)) return serializeHeapReference(value, path, state);
21759
21794
  if (Array.isArray(value)) {
21760
21795
  const reference2 = serializeHeapReference(value, path, state);
21761
21796
  if (reference2 !== void 0) {
@@ -21835,16 +21870,15 @@ function serializeHeapReference(value, path, state) {
21835
21870
  return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
21836
21871
  })
21837
21872
  };
21838
- } else if (isFloat32Array(value)) {
21839
- const backing = float32Storage(value);
21873
+ } else if (isNumericTypedArray(value)) {
21874
+ const backing = typedArrayStorage(value);
21840
21875
  const storage = {
21841
- kind: "float32array",
21842
- ...encodeFloat32Layout(value),
21876
+ ...encodeTypedArrayLayout(value),
21843
21877
  buffer: serializeHeapReference(backing.buffer, `${path}.buffer`, state)
21844
21878
  };
21845
21879
  const entries = /* @__PURE__ */ Object.create(null);
21846
21880
  state.heap[String(id)] = { ...storage, entries };
21847
- for (const [key, descriptor] of float32DataProperties(value)) {
21881
+ for (const [key, descriptor] of typedArrayDataProperties(value)) {
21848
21882
  const serialized = serializeDumpValue(descriptor.value, `${path}.${key}`, state);
21849
21883
  entries[key] = serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
21850
21884
  }
@@ -21907,7 +21941,7 @@ function indexHeapContainers(snapshot) {
21907
21941
  const heapIds = /* @__PURE__ */ new Map();
21908
21942
  let nextId = 1;
21909
21943
  for (const [value, stat2] of stats.entries()) {
21910
- 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)) {
21944
+ 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) || isNumericTypedArray(value) || isSandboxArrayBuffer(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
21911
21945
  heapIds.set(value, nextId);
21912
21946
  nextId += 1;
21913
21947
  }
@@ -21939,7 +21973,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
21939
21973
  stat2.expanded = true;
21940
21974
  ancestors.add(value);
21941
21975
  const guestEntries = [];
21942
- if (isFloat32Array(value)) guestEntries.push(float32Storage(value).buffer);
21976
+ if (isNumericTypedArray(value)) guestEntries.push(typedArrayStorage(value).buffer);
21943
21977
  const guest = isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
21944
21978
  guestEntries.push(entry);
21945
21979
  return null;
@@ -21957,7 +21991,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
21957
21991
  return;
21958
21992
  }
21959
21993
  for (const entry of guestEntries) collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
21960
- if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
21994
+ if (!Array.isArray(value) && !isPlainObject(value) && !isNumericTypedArray(value) && !isSandboxDate(value)) {
21961
21995
  ancestors.delete(value);
21962
21996
  return;
21963
21997
  }
@@ -22291,11 +22325,11 @@ function encodeReplayData(value, options = {}) {
22291
22325
  let symbolIndex = 0;
22292
22326
  const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path, { symbol: Math.floor(symbolIndex++ / 2) }]));
22293
22327
  nodes[id] = { ...storage, properties, extensible: Object.isExtensible(entry), symbolEntries };
22294
- } else if (isFloat32Array(entry)) {
22295
- const backing = float32Storage(entry);
22296
- const storage = { kind: "float32array", ...encodeFloat32Layout(entry), buffer: child(backing.buffer, "<buffer>") };
22328
+ } else if (isNumericTypedArray(entry)) {
22329
+ const backing = typedArrayStorage(entry);
22330
+ const storage = { ...encodeTypedArrayLayout(entry), buffer: child(backing.buffer, "<buffer>") };
22297
22331
  const properties = /* @__PURE__ */ Object.create(null);
22298
- for (const [key, descriptor] of float32DataProperties(entry)) {
22332
+ for (const [key, descriptor] of typedArrayDataProperties(entry)) {
22299
22333
  properties[key] = {
22300
22334
  value: child(descriptor.value, key),
22301
22335
  configurable: descriptor.configurable === true,
@@ -22532,10 +22566,10 @@ function decodeReplayData(input, options = {}, parent) {
22532
22566
  });
22533
22567
  return result3;
22534
22568
  }
22535
- if (kind === "float32array") {
22569
+ if (kind === "float32array" || kind === "typedarray") {
22536
22570
  if (typeof node.extensible !== "boolean")
22537
22571
  throw new TypeError("Invalid Float32Array extensibility.");
22538
- const result3 = decodeFloat32Storage(node, child, compilation.owner?.budget);
22572
+ const result3 = decodeTypedArrayStorage(node, child, compilation.owner?.budget);
22539
22573
  restored.set(id, result3);
22540
22574
  defineProperties(result3, record2(own(node, "properties")), child);
22541
22575
  if (!node.extensible) Object.preventExtensions(result3);
@@ -23446,22 +23480,23 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
23446
23480
  if (!Object.isExtensible(value)) Object.preventExtensions(copy);
23447
23481
  return copy;
23448
23482
  }
23449
- if (isFloat32Array(value)) {
23483
+ if (isNumericTypedArray(value)) {
23450
23484
  const existing = state.seen.get(value);
23451
23485
  if (existing !== void 0) return existing;
23452
- const capacity = arrayBufferOptions(float32Storage(value).buffer)?.maxByteLength;
23486
+ const capacity = arrayBufferOptions(typedArrayStorage(value).buffer)?.maxByteLength;
23453
23487
  if (capacity !== void 0) budget.allocateArrayLength(capacity);
23454
- checkFloat32Allocation(Math.ceil(float32Storage(value).byteLength / 4), budget);
23455
- const copy = copyFloat32Storage(value, state);
23488
+ const storage = typedArrayStorage(value);
23489
+ checkTypedArrayAllocation(Math.ceil(storage.byteLength / storage.elementSize), budget, storage.elementSize);
23490
+ const copy = copyTypedArrayStorage(value, state);
23456
23491
  state.seen.set(value, copy);
23457
23492
  copyHostValueToSandbox(
23458
- float32Storage(value).buffer,
23493
+ typedArrayStorage(value).buffer,
23459
23494
  stackFrames,
23460
23495
  { ...options, capabilityPath: [...options.capabilityPath ?? [], "buffer"] },
23461
23496
  state,
23462
23497
  `${path}.buffer`
23463
23498
  );
23464
- for (const [key, descriptor] of float32DataProperties(value)) {
23499
+ for (const [key, descriptor] of typedArrayDataProperties(value)) {
23465
23500
  Object.defineProperty(copy, key, {
23466
23501
  ...descriptor,
23467
23502
  value: copyHostValueToSandbox(
@@ -25736,7 +25771,7 @@ function createBuiltinBindings(options) {
25736
25771
  const bindings = {
25737
25772
  ...createConsoleJsonGlobals(options),
25738
25773
  ...createCollectionGlobals(options),
25739
- Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
25774
+ ...Object.fromEntries(Object.entries(numericTypedArrayConstructors).map(([name, Native]) => [name, createNumericTypedArrayGlobal(options.budget, options.typedArrayPrototypes !== false, Native)])),
25740
25775
  Date: createDateGlobal(options),
25741
25776
  Symbol: createSymbolGlobal(options.budget),
25742
25777
  BigInt: createBigIntGlobal(options.budget),
@@ -25750,7 +25785,7 @@ function createBuiltinBindings(options) {
25750
25785
  ...createRegexGlobals(options)
25751
25786
  };
25752
25787
  createFunctionPrototype(options.budget, options.functionHasInstance);
25753
- if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
25788
+ if (options.typedArrayPrototypes !== false) createNumericTypedArrayPrototypes(options.budget, bindings);
25754
25789
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
25755
25790
  createGeneratorPrototypes(options.budget);
25756
25791
  registerBuiltinIdentities(options.budget, bindings);
@@ -26485,8 +26520,8 @@ function validateDumpHeap(root, state) {
26485
26520
  validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
26486
26521
  continue;
26487
26522
  }
26488
- if (entry.kind === "float32array") {
26489
- validateFloat32Storage(entry);
26523
+ if (entry.kind === "float32array" || entry.kind === "typedarray") {
26524
+ validateTypedArrayStorage(entry);
26490
26525
  requireRecord(entry.entries, `${path}.entries`);
26491
26526
  if (Object.hasOwn(entry, "state")) {
26492
26527
  if (Object.keys(entry.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
@@ -26708,7 +26743,7 @@ function validateHeapValue(value, path, state, heap) {
26708
26743
  fail("invalidValue", path, String(error));
26709
26744
  }
26710
26745
  validateErrorType(record4, path);
26711
- if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
26746
+ if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "typedarray", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
26712
26747
  fail("unknownTag", `${path}.kind`, "unknown heap tag");
26713
26748
  validateValue(record4, path, 1, state);
26714
26749
  if (record4.kind === "symbol") validateSymbolRecord(record4, path, state);
@@ -26721,8 +26756,8 @@ function validateHeapValue(value, path, state, heap) {
26721
26756
  validateArrayBufferStorage(record4);
26722
26757
  validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
26723
26758
  }
26724
- if (record4.kind === "float32array") {
26725
- validateFloat32Storage(record4);
26759
+ if (record4.kind === "float32array" || record4.kind === "typedarray") {
26760
+ validateTypedArrayStorage(record4);
26726
26761
  requireRecord(record4.entries, `${path}.entries`);
26727
26762
  if (Object.hasOwn(record4, "state")) {
26728
26763
  if (Object.keys(record4.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
@@ -27717,10 +27752,10 @@ function measureSandboxData(values, options = {}) {
27717
27752
  const prototype = getSandboxPrototype(value);
27718
27753
  if (prototype !== null) visit(prototype, depth + 1);
27719
27754
  if (isSandboxArrayBuffer(value)) usage += arrayBufferLength(value);
27720
- if (isFloat32Array(value)) {
27721
- const storage = float32Storage(value);
27755
+ if (isNumericTypedArray(value)) {
27756
+ const storage = typedArrayStorage(value);
27722
27757
  visit(storage.buffer, depth + 1);
27723
- for (const [key, descriptor] of float32Properties(value)) {
27758
+ for (const [key, descriptor] of typedArrayProperties(value)) {
27724
27759
  usage += 1;
27725
27760
  if (typeof key === "string") usage += key.length;
27726
27761
  else visit(key, depth + 1);
@@ -27990,7 +28025,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
27990
28025
  }
27991
28026
  return copy;
27992
28027
  }
27993
- if (typeof value === "object" && value !== null && hasGuestObjectState(value) && !(state.structuredClone && isSandboxDate(value))) {
28028
+ if (typeof value === "object" && value !== null && hasGuestObjectState(value) && !(state.structuredClone && (isSandboxDate(value) || isSandboxArrayBuffer(value) || isNumericTypedArray(value)))) {
27994
28029
  throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
27995
28030
  }
27996
28031
  const primitive = nativeBoxedValue(value);
@@ -28059,6 +28094,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
28059
28094
  if (existing !== void 0) return existing;
28060
28095
  const copy = copyArrayBufferStorage(value, state);
28061
28096
  state.seen.set(value, copy);
28097
+ if (state.structuredClone) return copy;
28062
28098
  for (const [key, descriptor] of arrayBufferDataProperties(value)) {
28063
28099
  Object.defineProperty(copy, key, {
28064
28100
  ...descriptor,
@@ -28081,13 +28117,14 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
28081
28117
  if (!state.structuredClone && !Object.isExtensible(value)) Object.preventExtensions(copy);
28082
28118
  return copy;
28083
28119
  }
28084
- if (isFloat32Array(value)) {
28120
+ if (isNumericTypedArray(value)) {
28085
28121
  const existing = state.seen.get(value);
28086
28122
  if (existing !== void 0) return existing;
28087
- const copy = copyFloat32Storage(value, state);
28123
+ const copy = copyTypedArrayStorage(value, state);
28088
28124
  state.seen.set(value, copy);
28089
- copyToSandbox(float32Storage(value).buffer, state, `${path}.buffer`, cloneSandboxCollections, depth + 1);
28090
- for (const [key, descriptor] of float32DataProperties(value)) {
28125
+ if (state.structuredClone) return copy;
28126
+ copyToSandbox(typedArrayStorage(value).buffer, state, `${path}.buffer`, cloneSandboxCollections, depth + 1);
28127
+ for (const [key, descriptor] of typedArrayDataProperties(value)) {
28091
28128
  Object.defineProperty(copy, key, {
28092
28129
  ...descriptor,
28093
28130
  value: copyToSandbox(
@@ -28303,13 +28340,13 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
28303
28340
  guard.close();
28304
28341
  }
28305
28342
  }
28306
- if (isFloat32Array(value)) {
28343
+ if (isNumericTypedArray(value)) {
28307
28344
  const existing = state.seen.get(value);
28308
28345
  if (existing !== void 0) return existing;
28309
- const copy = copyFloat32Storage(value, state);
28346
+ const copy = copyTypedArrayStorage(value, state);
28310
28347
  state.seen.set(value, copy);
28311
- copyFromSandbox(float32Storage(value).buffer, state, `${path}.buffer`, options, depth + 1);
28312
- for (const [key, descriptor] of float32DataProperties(value)) {
28348
+ copyFromSandbox(typedArrayStorage(value).buffer, state, `${path}.buffer`, options, depth + 1);
28349
+ for (const [key, descriptor] of typedArrayDataProperties(value)) {
28313
28350
  Object.defineProperty(copy, key, {
28314
28351
  ...descriptor,
28315
28352
  value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
@@ -28514,13 +28551,14 @@ function allocateSandboxValue2(value, budget, seen) {
28514
28551
  }
28515
28552
  return;
28516
28553
  }
28517
- if (isFloat32Array(value)) {
28554
+ if (isNumericTypedArray(value)) {
28518
28555
  if (seen.has(value)) return;
28519
28556
  seen.add(value);
28520
- budget.allocateArrayLength(Math.ceil(float32Storage(value).byteLength / 4));
28521
- const capacity = arrayBufferOptions(float32Storage(value).buffer)?.maxByteLength;
28557
+ const storage = typedArrayStorage(value);
28558
+ budget.allocateArrayLength(Math.ceil(storage.byteLength / storage.elementSize));
28559
+ const capacity = arrayBufferOptions(typedArrayStorage(value).buffer)?.maxByteLength;
28522
28560
  if (capacity !== void 0) budget.allocateArrayLength(capacity);
28523
- for (const [key, descriptor] of float32DataProperties(value)) {
28561
+ for (const [key, descriptor] of typedArrayDataProperties(value)) {
28524
28562
  budget.allocateString(key);
28525
28563
  allocateSandboxValue2(descriptor.value, budget, seen);
28526
28564
  }
@@ -29267,20 +29305,20 @@ function normalize(value, seen) {
29267
29305
  properties
29268
29306
  });
29269
29307
  }
29270
- if (isFloat32Array(value)) {
29271
- const storage = float32Storage(value);
29308
+ if (isNumericTypedArray(value)) {
29309
+ const storage = typedArrayStorage(value);
29272
29310
  const resizable = arrayBufferOptions(storage.buffer) !== void 0;
29273
- const layout = resizable ? float32ViewLayouts.get(value) : void 0;
29311
+ const layout = resizable ? typedArrayViewLayouts.get(value) : void 0;
29274
29312
  if (resizable && layout === void 0)
29275
29313
  throw new TypeError("Resizable Float32Array host-call identity requires known view layout.");
29276
29314
  const properties = /* @__PURE__ */ Object.create(null);
29277
- for (const [key, descriptor] of float32DataProperties(value).sort(
29315
+ for (const [key, descriptor] of typedArrayDataProperties(value).sort(
29278
29316
  ([left], [right]) => left < right ? -1 : left > right ? 1 : 0
29279
29317
  )) {
29280
29318
  defineOwnDataProperty(properties, key, normalize(descriptor.value, seen));
29281
29319
  }
29282
29320
  return Object.assign(/* @__PURE__ */ Object.create(null), {
29283
- $type: "float32array",
29321
+ $type: storage.Native === Float32Array ? "float32array" : storage.Native.name,
29284
29322
  bytes: normalize(Array.from(new Uint8Array(storage.buffer)), seen),
29285
29323
  byteOffset: storage.byteOffset,
29286
29324
  length: storage.length,
@@ -30257,6 +30295,7 @@ var KNOWN_RUNTIME_GLOBALS = [
30257
30295
  "JSON",
30258
30296
  "Map",
30259
30297
  "Float32Array",
30298
+ "Uint8Array",
30260
30299
  "Math",
30261
30300
  "NaN",
30262
30301
  "Number",
@@ -42755,4 +42794,4 @@ export {
42755
42794
  FileSnapshotBackend,
42756
42795
  run
42757
42796
  };
42758
- //# sourceMappingURL=chunk-CJ7PNS2V.js.map
42797
+ //# sourceMappingURL=chunk-GMJXANAZ.js.map