@poe-platform/safe-js 0.1.306 → 0.1.308

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.
@@ -6835,13 +6835,20 @@ function float32Storage(value) {
6835
6835
  byteLength: Reflect.apply(bufferLength, buffer, [])
6836
6836
  };
6837
6837
  }
6838
+ function float32Properties(value) {
6839
+ const properties = [];
6840
+ for (const key of Reflect.ownKeys(value)) {
6841
+ if (typeof key === "string" && isFloat32Index(key)) continue;
6842
+ properties.push([key, Object.getOwnPropertyDescriptor(value, key)]);
6843
+ }
6844
+ return properties;
6845
+ }
6838
6846
  function float32DataProperties(value) {
6839
6847
  if (Object.getOwnPropertySymbols(value).length > 0)
6840
6848
  throw new TypeError("Float32Array symbol properties are not supported.");
6841
6849
  const properties = [];
6842
- for (const key of Object.getOwnPropertyNames(value)) {
6843
- if (isFloat32Index(key)) continue;
6844
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
6850
+ for (const [key, descriptor] of float32Properties(value)) {
6851
+ if (typeof key !== "string") throw new TypeError("Float32Array symbol properties are not supported.");
6845
6852
  if (!("value" in descriptor))
6846
6853
  throw new TypeError(`Float32Array accessor property '${key}' is not supported.`);
6847
6854
  properties.push([key, descriptor]);
@@ -7013,42 +7020,6 @@ function serializedDateTime(value) {
7013
7020
  // packages/safe-js/src/interp/internal-symbols.ts
7014
7021
  var internalSymbols = /* @__PURE__ */ new Set();
7015
7022
 
7016
- // packages/safe-js/src/interp/generator-properties.ts
7017
- var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
7018
- function getGeneratorProperties(value) {
7019
- let properties = generatorGuestProperties.get(value);
7020
- if (properties === void 0) {
7021
- properties = /* @__PURE__ */ Object.create(null);
7022
- generatorGuestProperties.set(value, properties);
7023
- }
7024
- return properties;
7025
- }
7026
-
7027
- // packages/safe-js/src/interp/regexp-properties.ts
7028
- var regexGuestProperties = /* @__PURE__ */ new WeakMap();
7029
- function getRegexProperties(value) {
7030
- const properties = regexGuestProperties.get(value);
7031
- if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
7032
- return properties;
7033
- }
7034
-
7035
- // packages/safe-js/src/interp/collection-properties.ts
7036
- var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
7037
- function getCollectionProperties(value) {
7038
- const properties = collectionGuestProperties.get(value);
7039
- if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
7040
- return properties;
7041
- }
7042
- function copyCollectionProperties(source, target, encode) {
7043
- const properties = collectionGuestProperties.get(source) ?? source;
7044
- for (const key of Reflect.ownKeys(properties)) {
7045
- const descriptor = Object.getOwnPropertyDescriptor(properties, key);
7046
- if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
7047
- Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
7048
- }
7049
- if (!Object.isExtensible(properties)) Object.preventExtensions(target);
7050
- }
7051
-
7052
7023
  // packages/safe-js/src/interp/accessors.ts
7053
7024
  var accessorClosures = /* @__PURE__ */ new WeakMap();
7054
7025
  var getterAdapters = /* @__PURE__ */ new WeakMap();
@@ -7107,6 +7078,110 @@ function writePropertyDescriptor(descriptor, receiver, value, context) {
7107
7078
  return context.invokeClosure(setter, [value], receiver).then(() => void 0);
7108
7079
  }
7109
7080
 
7081
+ // packages/safe-js/src/interp/symbols.ts
7082
+ var wellKnownSymbols = Object.freeze({
7083
+ iterator: Symbol.iterator,
7084
+ asyncIterator: Symbol.asyncIterator,
7085
+ hasInstance: Symbol.hasInstance,
7086
+ isConcatSpreadable: Symbol.isConcatSpreadable,
7087
+ match: Symbol.match,
7088
+ matchAll: Symbol.matchAll,
7089
+ replace: Symbol.replace,
7090
+ search: Symbol.search,
7091
+ species: Symbol.species,
7092
+ split: Symbol.split,
7093
+ toPrimitive: Symbol.toPrimitive,
7094
+ toStringTag: Symbol.toStringTag,
7095
+ unscopables: Symbol.unscopables
7096
+ });
7097
+
7098
+ // packages/safe-js/src/interp/intrinsics.ts
7099
+ var identities = /* @__PURE__ */ new WeakMap();
7100
+ var realms2 = /* @__PURE__ */ new WeakMap();
7101
+ function registerBuiltinIdentities(budget, bindings) {
7102
+ let realm = realms2.get(budget);
7103
+ if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
7104
+ const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
7105
+ const visited = /* @__PURE__ */ new WeakSet();
7106
+ for (let index = 0; index < pending.length; index++) {
7107
+ const [path, value] = pending[index];
7108
+ if (value === null || typeof value !== "object") continue;
7109
+ const id = JSON.stringify(path);
7110
+ const previous = realm.get(id);
7111
+ if (previous !== void 0 && previous !== value)
7112
+ throw new TypeError(`Duplicate intrinsic identity: ${id}`);
7113
+ realm.set(id, value);
7114
+ if (!identities.has(value)) identities.set(value, id);
7115
+ if (visited.has(value)) continue;
7116
+ visited.add(value);
7117
+ const owner = isSandboxClosure(value) ? value.properties : value;
7118
+ if (owner === void 0) continue;
7119
+ for (const key of Reflect.ownKeys(owner)) {
7120
+ if (typeof key === "symbol" && internalSymbols.has(key)) continue;
7121
+ const descriptor = Object.getOwnPropertyDescriptor(owner, key);
7122
+ const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
7123
+ if (typeof key === "symbol" && symbolName === void 0)
7124
+ throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
7125
+ const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
7126
+ if ("value" in descriptor) pending.push([member, descriptor.value]);
7127
+ for (const kind of ["get", "set"]) {
7128
+ const closure = accessorClosure(descriptor[kind]);
7129
+ if (closure !== void 0) pending.push([[...member, kind], closure]);
7130
+ }
7131
+ }
7132
+ }
7133
+ }
7134
+ function getIntrinsicIdentity(value) {
7135
+ return identities.get(value);
7136
+ }
7137
+ function resolveIntrinsicIdentity(budget, id) {
7138
+ const value = realms2.get(budget)?.get(id);
7139
+ if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
7140
+ return value;
7141
+ }
7142
+ function listIntrinsicIdentities(budget) {
7143
+ return [...realms2.get(budget)?.keys() ?? []];
7144
+ }
7145
+ function releaseIntrinsicIdentities(budget) {
7146
+ realms2.delete(budget);
7147
+ }
7148
+
7149
+ // packages/safe-js/src/interp/generator-properties.ts
7150
+ var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
7151
+ function getGeneratorProperties(value) {
7152
+ let properties = generatorGuestProperties.get(value);
7153
+ if (properties === void 0) {
7154
+ properties = /* @__PURE__ */ Object.create(null);
7155
+ generatorGuestProperties.set(value, properties);
7156
+ }
7157
+ return properties;
7158
+ }
7159
+
7160
+ // packages/safe-js/src/interp/regexp-properties.ts
7161
+ var regexGuestProperties = /* @__PURE__ */ new WeakMap();
7162
+ function getRegexProperties(value) {
7163
+ const properties = regexGuestProperties.get(value);
7164
+ if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
7165
+ return properties;
7166
+ }
7167
+
7168
+ // packages/safe-js/src/interp/collection-properties.ts
7169
+ var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
7170
+ function getCollectionProperties(value) {
7171
+ const properties = collectionGuestProperties.get(value);
7172
+ if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
7173
+ return properties;
7174
+ }
7175
+ function copyCollectionProperties(source, target, encode) {
7176
+ const properties = collectionGuestProperties.get(source) ?? source;
7177
+ for (const key of Reflect.ownKeys(properties)) {
7178
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key);
7179
+ if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
7180
+ Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
7181
+ }
7182
+ if (!Object.isExtensible(properties)) Object.preventExtensions(target);
7183
+ }
7184
+
7110
7185
  // packages/safe-js/src/interp/collection-brands.ts
7111
7186
  var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
7112
7187
  var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
@@ -7450,74 +7525,6 @@ async function withRunResources(signal, execute) {
7450
7525
  return result;
7451
7526
  }
7452
7527
 
7453
- // packages/safe-js/src/interp/symbols.ts
7454
- var wellKnownSymbols = Object.freeze({
7455
- iterator: Symbol.iterator,
7456
- asyncIterator: Symbol.asyncIterator,
7457
- hasInstance: Symbol.hasInstance,
7458
- isConcatSpreadable: Symbol.isConcatSpreadable,
7459
- match: Symbol.match,
7460
- matchAll: Symbol.matchAll,
7461
- replace: Symbol.replace,
7462
- search: Symbol.search,
7463
- species: Symbol.species,
7464
- split: Symbol.split,
7465
- toPrimitive: Symbol.toPrimitive,
7466
- toStringTag: Symbol.toStringTag,
7467
- unscopables: Symbol.unscopables
7468
- });
7469
-
7470
- // packages/safe-js/src/interp/intrinsics.ts
7471
- var identities = /* @__PURE__ */ new WeakMap();
7472
- var realms2 = /* @__PURE__ */ new WeakMap();
7473
- function registerBuiltinIdentities(budget, bindings) {
7474
- let realm = realms2.get(budget);
7475
- if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
7476
- const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
7477
- const visited = /* @__PURE__ */ new WeakSet();
7478
- for (let index = 0; index < pending.length; index++) {
7479
- const [path, value] = pending[index];
7480
- if (value === null || typeof value !== "object") continue;
7481
- const id = JSON.stringify(path);
7482
- const previous = realm.get(id);
7483
- if (previous !== void 0 && previous !== value)
7484
- throw new TypeError(`Duplicate intrinsic identity: ${id}`);
7485
- realm.set(id, value);
7486
- if (!identities.has(value)) identities.set(value, id);
7487
- if (visited.has(value)) continue;
7488
- visited.add(value);
7489
- const owner = isSandboxClosure(value) ? value.properties : value;
7490
- if (owner === void 0) continue;
7491
- for (const key of Reflect.ownKeys(owner)) {
7492
- if (typeof key === "symbol" && internalSymbols.has(key)) continue;
7493
- const descriptor = Object.getOwnPropertyDescriptor(owner, key);
7494
- const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
7495
- if (typeof key === "symbol" && symbolName === void 0)
7496
- throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
7497
- const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
7498
- if ("value" in descriptor) pending.push([member, descriptor.value]);
7499
- for (const kind of ["get", "set"]) {
7500
- const closure = accessorClosure(descriptor[kind]);
7501
- if (closure !== void 0) pending.push([[...member, kind], closure]);
7502
- }
7503
- }
7504
- }
7505
- }
7506
- function getIntrinsicIdentity(value) {
7507
- return identities.get(value);
7508
- }
7509
- function resolveIntrinsicIdentity(budget, id) {
7510
- const value = realms2.get(budget)?.get(id);
7511
- if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
7512
- return value;
7513
- }
7514
- function listIntrinsicIdentities(budget) {
7515
- return [...realms2.get(budget)?.keys() ?? []];
7516
- }
7517
- function releaseIntrinsicIdentities(budget) {
7518
- realms2.delete(budget);
7519
- }
7520
-
7521
7528
  // packages/safe-js/src/interp/host-capabilities.ts
7522
7529
  import { types as types4 } from "node:util";
7523
7530
  var MAX_INDEXED_LENGTH = 65536;
@@ -7862,6 +7869,12 @@ function namedKeys(state) {
7862
7869
  });
7863
7870
  }
7864
7871
 
7872
+ // packages/safe-js/src/interp/error-prototypes.ts
7873
+ var errorPrototypes = /* @__PURE__ */ new WeakMap();
7874
+
7875
+ // packages/safe-js/src/interp/float32-prototypes.ts
7876
+ var float32Prototypes = /* @__PURE__ */ new WeakMap();
7877
+
7865
7878
  // packages/safe-js/src/interp/object-model.ts
7866
7879
  var guestClosures = /* @__PURE__ */ new WeakSet();
7867
7880
  var functionProperties = /* @__PURE__ */ new WeakMap();
@@ -8086,11 +8099,19 @@ function releaseObjectPrototype(budget) {
8086
8099
  arrayPrototypes.delete(budget);
8087
8100
  functionPrototypes.delete(budget);
8088
8101
  generatorPrototypes.delete(budget);
8102
+ errorPrototypes.delete(budget);
8103
+ float32Prototypes.delete(budget);
8089
8104
  initialRegexDescriptors.delete(budget);
8090
8105
  intrinsicPrototypes.delete(budget);
8091
8106
  }
8092
8107
  function getSandboxPrototype(value, budget) {
8093
8108
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
8109
+ if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
8110
+ const errorType = sandboxErrorTypes.get(value);
8111
+ if (budget !== void 0 && errorType !== void 0) {
8112
+ const prototype = errorPrototypes.get(budget)?.get(errorType);
8113
+ if (prototype !== void 0) return prototype;
8114
+ }
8094
8115
  if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
8095
8116
  return functionPrototypes.get(budget) ?? null;
8096
8117
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
@@ -8118,6 +8139,8 @@ function getSandboxPropertyDescriptor(value, key, budget) {
8118
8139
  let current = value;
8119
8140
  let depth = 0;
8120
8141
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8142
+ if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8143
+ return Object.getOwnPropertyDescriptor(current, key);
8121
8144
  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;
8122
8145
  if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
8123
8146
  return {
@@ -8140,6 +8163,8 @@ function getSandboxDataProperty(value, key, budget) {
8140
8163
  let current = value;
8141
8164
  let depth = 0;
8142
8165
  while (typeof current === "object" && current !== null) {
8166
+ if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
8167
+ return Object.getOwnPropertyDescriptor(current, key)?.value;
8143
8168
  if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
8144
8169
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
8145
8170
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key)?.value;
@@ -8191,6 +8216,7 @@ function setSandboxPrototype(value, prototype, budget) {
8191
8216
  prototypes.set(value, prototype);
8192
8217
  }
8193
8218
  function isPrototypeRecord(value) {
8219
+ if (isFloat32Array(value)) return true;
8194
8220
  if (isGuestClosure(value)) return true;
8195
8221
  if (isGuestHostObject(value)) return false;
8196
8222
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
@@ -8210,7 +8236,7 @@ function hasGuestObjectState(value) {
8210
8236
  if (isLiveCapability(value)) return true;
8211
8237
  if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
8212
8238
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
8213
- return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
8239
+ return descriptorObjects.has(value) && (isFloat32Array(value) ? float32Properties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
8214
8240
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
8215
8241
  );
8216
8242
  }
@@ -9526,7 +9552,7 @@ async function readIteratorResult(iterator, result, property) {
9526
9552
  }
9527
9553
  function getSandboxAsyncIterator(value, budget, context, signal) {
9528
9554
  if (isSandboxGenerator(value) && value.async) {
9529
- return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
9555
+ return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? guestProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
9530
9556
  }
9531
9557
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
9532
9558
  const method = value[Symbol.asyncIterator];
@@ -9673,11 +9699,15 @@ function getSandboxIterator(value, budget, context) {
9673
9699
  }
9674
9700
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
9675
9701
  if (isFloat32Array(value)) {
9702
+ if (hasExplicitSandboxPrototype(value) || budget !== void 0 && float32Prototypes.has(budget)) {
9703
+ if (getSandboxPropertyDescriptor(value, Symbol.iterator, budget) === void 0) return void 0;
9704
+ return guestProtocolAdapter(value, budget ?? new Budget(), context, false);
9705
+ }
9676
9706
  return syncIterator(Float32Array.prototype.values.call(value));
9677
9707
  }
9678
9708
  if (isSandboxGenerator(value)) {
9679
9709
  if (value.async) return void 0;
9680
- if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9710
+ if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9681
9711
  return generatorObjectIterator(value, budget, context);
9682
9712
  }
9683
9713
  if (typeof value === "string") {
@@ -9755,7 +9785,7 @@ function collectionIterator(collection, value) {
9755
9785
  return adapter;
9756
9786
  }
9757
9787
  var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
9758
- function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
9788
+ function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
9759
9789
  const bridge = {
9760
9790
  ...context,
9761
9791
  stack: context?.stack ?? [],
@@ -9769,7 +9799,7 @@ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal)
9769
9799
  let resolved;
9770
9800
  let pending;
9771
9801
  const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
9772
- if (iterator === void 0) throw new TypeError("Generator does not provide an iterator protocol.");
9802
+ if (iterator === void 0) throw new TypeError("Value does not provide an iterator protocol.");
9773
9803
  return resolved = iterator;
9774
9804
  });
9775
9805
  return {
@@ -13640,8 +13670,8 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
13640
13670
  }
13641
13671
  function defineDataProperty(target, key, descriptor, budget) {
13642
13672
  budget.visitNode();
13643
- if (isFloat32Array(target))
13644
- throw new TypeError("Typed array property descriptors are not supported.");
13673
+ if (isFloat32Array(target) && typeof key !== "symbol" && isFloat32Index(String(key)) && "value" in descriptor)
13674
+ descriptor = { ...descriptor, value: float32Number(descriptor.value) };
13645
13675
  const properties = objectProperties(target, true);
13646
13676
  if (Array.isArray(properties)) {
13647
13677
  if (key === "length" && "value" in descriptor)
@@ -14476,8 +14506,9 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14476
14506
 
14477
14507
  // packages/safe-js/src/interp/globals/float32array.ts
14478
14508
  var constructors = /* @__PURE__ */ new WeakSet();
14479
- function createFloat32ArrayGlobal(budget) {
14509
+ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
14480
14510
  const constructor = createSandboxClosure({
14511
+ guest: nativePrototype,
14481
14512
  sandbox: true,
14482
14513
  name: "Float32Array",
14483
14514
  length: 3,
@@ -14485,32 +14516,155 @@ function createFloat32ArrayGlobal(budget) {
14485
14516
  call: () => {
14486
14517
  throw new TypeError("Constructor Float32Array requires 'new'.");
14487
14518
  },
14488
- construct: ([source]) => {
14489
- if (Array.isArray(source) || isFloat32Array(source)) {
14490
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14491
- checkFloat32Allocation(length2, budget);
14492
- if (isFloat32Array(source)) return new Float32Array(source);
14493
- const result = new Float32Array(length2);
14494
- for (let index = 0; index < length2; index += 1) {
14495
- budget.visitNode();
14496
- const descriptor = Object.getOwnPropertyDescriptor(source, index);
14497
- if (descriptor !== void 0 && !("value" in descriptor))
14498
- throw new TypeError("Float32Array input accessors are not supported.");
14499
- result[index] = float32Number(descriptor?.value);
14519
+ construct: (args, context) => {
14520
+ if (!nativePrototype) return allocateFloat32Array(args[0], budget);
14521
+ return (async () => {
14522
+ const newTarget = context?.newTarget ?? constructor;
14523
+ const candidate = context?.getProperty === void 0 ? getSandboxDataProperty(newTarget, "prototype", budget) : await context.getProperty(newTarget, "prototype");
14524
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
14525
+ const release = retainValues(budget, () => [prototype, ...args]);
14526
+ try {
14527
+ const result = allocateFloat32Array(args[0], budget);
14528
+ setSandboxPrototype(result, prototype, budget);
14529
+ return result;
14530
+ } finally {
14531
+ release();
14500
14532
  }
14501
- return result;
14502
- }
14503
- const number = float32Number(source);
14504
- const length = Number.isNaN(number) ? 0 : Math.trunc(number);
14505
- if (length < 0 || !Number.isSafeInteger(length))
14506
- throw new RangeError("Invalid typed array length.");
14507
- checkFloat32Allocation(length, budget);
14508
- return new Float32Array(length);
14533
+ })();
14509
14534
  }
14510
14535
  });
14511
14536
  constructors.add(constructor);
14512
14537
  return constructor;
14513
14538
  }
14539
+ function allocateFloat32Array(source, budget) {
14540
+ if (Array.isArray(source) || isFloat32Array(source)) {
14541
+ const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
14542
+ checkFloat32Allocation(length2, budget);
14543
+ if (isFloat32Array(source)) return new Float32Array(source);
14544
+ const result = new Float32Array(length2);
14545
+ for (let index = 0; index < length2; index += 1) {
14546
+ budget.visitNode();
14547
+ const descriptor = Object.getOwnPropertyDescriptor(source, index);
14548
+ if (descriptor !== void 0 && !("value" in descriptor))
14549
+ throw new TypeError("Float32Array input accessors are not supported.");
14550
+ result[index] = float32Number(descriptor?.value);
14551
+ }
14552
+ return result;
14553
+ }
14554
+ const number = float32Number(source);
14555
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
14556
+ if (length < 0 || !Number.isSafeInteger(length))
14557
+ throw new RangeError("Invalid typed array length.");
14558
+ checkFloat32Allocation(length, budget);
14559
+ return new Float32Array(length);
14560
+ }
14561
+ function createFloat32ArrayPrototypes(budget, constructor) {
14562
+ const prototype = /* @__PURE__ */ Object.create(null);
14563
+ const shared = /* @__PURE__ */ Object.create(null);
14564
+ const abstractCall = () => {
14565
+ throw new TypeError("Abstract TypedArray constructor cannot be called.");
14566
+ };
14567
+ const typedArray = createSandboxClosure({
14568
+ guest: true,
14569
+ sandbox: true,
14570
+ name: "TypedArray",
14571
+ length: 0,
14572
+ call: abstractCall,
14573
+ construct: abstractCall
14574
+ });
14575
+ Object.defineProperty(materializeFunctionProperties(typedArray), "prototype", { value: shared, writable: false });
14576
+ Object.defineProperties(materializeFunctionProperties(constructor), {
14577
+ prototype: { value: prototype, writable: false },
14578
+ BYTES_PER_ELEMENT: { value: 4, writable: false, enumerable: false, configurable: false }
14579
+ });
14580
+ Object.defineProperties(prototype, {
14581
+ constructor: { value: constructor, writable: true, configurable: true },
14582
+ BYTES_PER_ELEMENT: { value: 4 }
14583
+ });
14584
+ Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
14585
+ setSandboxPrototype(constructor, typedArray);
14586
+ setSandboxPrototype(prototype, shared);
14587
+ setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
14588
+ const getters = [];
14589
+ for (const key of ["length", "byteLength", "byteOffset"]) {
14590
+ const getter = createSandboxClosure({
14591
+ guest: true,
14592
+ sandbox: true,
14593
+ name: `get ${key}`,
14594
+ length: 0,
14595
+ call: (_args, context) => {
14596
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14597
+ const storage = float32Storage(context.thisValue);
14598
+ return key === "byteLength" ? storage.length * 4 : storage[key];
14599
+ }
14600
+ });
14601
+ getters.push(getter);
14602
+ Object.defineProperty(shared, key, { get: accessorAdapter(getter, "get"), configurable: true });
14603
+ }
14604
+ for (const key of ["set", "slice", "subarray"])
14605
+ Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget), writable: true, configurable: true });
14606
+ const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
14607
+ Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
14608
+ Object.defineProperty(shared, "join", {
14609
+ writable: true,
14610
+ configurable: true,
14611
+ value: createSandboxClosure({
14612
+ guest: true,
14613
+ sandbox: true,
14614
+ name: "join",
14615
+ length: 1,
14616
+ call: async (args, context) => {
14617
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
14618
+ const receiver = context.thisValue;
14619
+ const length = float32Storage(receiver).length;
14620
+ let separator = ",";
14621
+ let text = "";
14622
+ const release = retainValues(budget, () => [receiver, separator, text, ...args]);
14623
+ try {
14624
+ if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
14625
+ for (let index = 0; index < length; index++) {
14626
+ budget.visitNode();
14627
+ text = budget.allocateString(text + (index === 0 ? "" : separator) + String(receiver[index]));
14628
+ }
14629
+ return text;
14630
+ } finally {
14631
+ release();
14632
+ }
14633
+ }
14634
+ })
14635
+ });
14636
+ const tagGetter = createSandboxClosure({
14637
+ guest: true,
14638
+ sandbox: true,
14639
+ name: "get [Symbol.toStringTag]",
14640
+ length: 0,
14641
+ call: (_args, context) => isFloat32Array(context?.thisValue) ? "Float32Array" : void 0
14642
+ });
14643
+ getters.push(tagGetter);
14644
+ Object.defineProperty(shared, Symbol.toStringTag, { get: accessorAdapter(tagGetter, "get"), configurable: true });
14645
+ for (const key of ["values", "keys", "entries"]) {
14646
+ const method = getSandboxDataProperty(arrayPrototype, key, budget);
14647
+ const closure = createSandboxClosure({
14648
+ guest: true,
14649
+ sandbox: true,
14650
+ name: key,
14651
+ length: 0,
14652
+ call: (args, context) => {
14653
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
14654
+ return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
14655
+ }
14656
+ });
14657
+ Object.defineProperty(shared, key, { value: closure, writable: true, configurable: true });
14658
+ if (key === "values") Object.defineProperty(shared, Symbol.iterator, { value: closure, writable: true, configurable: true });
14659
+ }
14660
+ float32Prototypes.set(budget, prototype);
14661
+ registerBuiltinIdentities(budget, { Float32Array: constructor, "%TypedArray%": typedArray });
14662
+ registerIntrinsicFunction(budget, constructor);
14663
+ registerIntrinsicFunction(budget, typedArray);
14664
+ registerIntrinsicObject(budget, prototype);
14665
+ registerIntrinsicObject(budget, shared);
14666
+ for (const getter of getters) registerIntrinsicFunction(budget, getter);
14667
+ }
14514
14668
  function isFloat32ArrayConstructor(value) {
14515
14669
  return typeof value === "object" && value !== null && constructors.has(value);
14516
14670
  }
@@ -14521,6 +14675,7 @@ function getFloat32Member(value, property, budget) {
14521
14675
  if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
14522
14676
  return descriptor.value;
14523
14677
  }
14678
+ if (float32Prototypes.has(budget)) return void 0;
14524
14679
  const storage = float32Storage(value);
14525
14680
  if (key === "length") return storage.length;
14526
14681
  if (key === "byteLength") return storage.length * 4;
@@ -14528,6 +14683,7 @@ function getFloat32Member(value, property, budget) {
14528
14683
  if (key === "BYTES_PER_ELEMENT") return 4;
14529
14684
  if (!["set", "slice", "subarray"].includes(key)) return void 0;
14530
14685
  return createSandboxClosure({
14686
+ guest: true,
14531
14687
  sandbox: true,
14532
14688
  name: key,
14533
14689
  length: key === "set" ? 1 : 2,
@@ -14575,17 +14731,18 @@ function getFloat32Member(value, property, budget) {
14575
14731
  }
14576
14732
  });
14577
14733
  }
14578
- function setFloat32Member(value, property, entry) {
14579
- const key = String(property);
14580
- if (isFloat32Index(key)) {
14734
+ function setFloat32Member(value, property, entry, budget) {
14735
+ const key = typeof property === "symbol" ? property : String(property);
14736
+ if (typeof key !== "symbol" && isFloat32Index(key)) {
14581
14737
  Reflect.set(value, key, float32Number(entry));
14582
14738
  return;
14583
14739
  }
14584
14740
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
14585
- if (descriptor === void 0 && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
14586
- throw new TypeError(`Cannot assign to read only property '${key}'.`);
14587
- if (descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable))
14588
- throw new TypeError(`Cannot assign to read only property '${key}'.`);
14741
+ const inherited = descriptor ?? (budget === void 0 ? void 0 : getSandboxPropertyDescriptor(value, key, budget));
14742
+ if (descriptor === void 0 && typeof key === "string" && (budget === void 0 || !float32Prototypes.has(budget)) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
14743
+ throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
14744
+ if (inherited !== void 0 && (!("value" in inherited) || !inherited.writable))
14745
+ throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
14589
14746
  Object.defineProperty(
14590
14747
  value,
14591
14748
  key,
@@ -14613,7 +14770,7 @@ var errorNames = [
14613
14770
  ];
14614
14771
  function createErrorGlobals(options) {
14615
14772
  return Object.fromEntries(
14616
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14773
+ errorNames.map((name) => [name, createErrorConstructor(name, options.budget, options.errorPrototypes === true)])
14617
14774
  );
14618
14775
  }
14619
14776
  function isSandboxErrorConstructorInstance2(value, constructor) {
@@ -14626,12 +14783,100 @@ function isSandboxErrorConstructorInstance2(value, constructor) {
14626
14783
  }
14627
14784
  return isSandboxErrorConstructorInstance(value, name);
14628
14785
  }
14629
- function createErrorConstructor(name, budget) {
14630
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14631
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14786
+ function createErrorConstructor(name, budget, guest) {
14787
+ const call = (args, context) => errorPrototypes.has(budget) ? createNativeError(name, args, budget, context, closure) : createSubsetError(name, args, context?.stack ?? [], budget);
14788
+ const closure = createSandboxClosure({ guest, sandbox: true, call, construct: call, name, length: name === "AggregateError" ? 2 : 1 });
14632
14789
  errorConstructorNames.set(closure, name);
14633
14790
  return closure;
14634
14791
  }
14792
+ function createErrorPrototypes(budget, constructors2) {
14793
+ const prototypes2 = /* @__PURE__ */ new Map();
14794
+ for (const name of errorNames) prototypes2.set(name, /* @__PURE__ */ Object.create(null));
14795
+ errorPrototypes.set(budget, prototypes2);
14796
+ for (const name of errorNames) {
14797
+ const constructor = constructors2[name];
14798
+ const prototype = prototypes2.get(name);
14799
+ Object.defineProperties(prototype, {
14800
+ name: { value: name, writable: true, configurable: true },
14801
+ message: { value: "", writable: true, configurable: true },
14802
+ constructor: { value: constructor, writable: true, configurable: true }
14803
+ });
14804
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
14805
+ setSandboxPrototype(prototype, name === "Error" ? getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget) : prototypes2.get("Error"));
14806
+ if (name !== "Error") setSandboxPrototype(constructor, constructors2.Error);
14807
+ }
14808
+ Object.defineProperty(prototypes2.get("Error"), "toString", {
14809
+ writable: true,
14810
+ configurable: true,
14811
+ value: createSandboxClosure({
14812
+ guest: true,
14813
+ sandbox: true,
14814
+ name: "toString",
14815
+ length: 0,
14816
+ call: async (_args, context) => {
14817
+ const receiver = context?.thisValue;
14818
+ if (receiver === null || typeof receiver !== "object") throw new TypeError("Error.prototype.toString requires an object.");
14819
+ let name;
14820
+ const release = retainValues(budget, () => [receiver, name]);
14821
+ try {
14822
+ const rawName = await readErrorProperty(receiver, "name", budget, context);
14823
+ name = rawName === void 0 ? "Error" : await sandboxString(rawName, budget, context);
14824
+ const rawMessage = await readErrorProperty(receiver, "message", budget, context);
14825
+ const message = rawMessage === void 0 ? "" : await sandboxString(rawMessage, budget, context);
14826
+ return budget.allocateString(name === "" ? message : message === "" ? name : `${name}: ${message}`);
14827
+ } finally {
14828
+ release();
14829
+ }
14830
+ }
14831
+ })
14832
+ });
14833
+ registerBuiltinIdentities(budget, Object.fromEntries(errorNames.map((name) => [name, constructors2[name]])));
14834
+ for (const name of errorNames) {
14835
+ registerIntrinsicFunction(budget, constructors2[name]);
14836
+ registerIntrinsicObject(budget, prototypes2.get(name));
14837
+ }
14838
+ }
14839
+ async function readErrorProperty(value, key, budget, context) {
14840
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
14841
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14842
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
14843
+ }
14844
+ async function createNativeError(name, args, budget, context, constructor) {
14845
+ const newTarget = context?.newTarget ?? constructor;
14846
+ const candidate = await readErrorProperty(newTarget, "prototype", budget, context);
14847
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : errorPrototypes.get(budget).get(name);
14848
+ let error;
14849
+ let iterator;
14850
+ const errors = [];
14851
+ const release = retainValues(budget, () => [prototype, error, iterator?.retainedValue, ...errors, ...args]);
14852
+ try {
14853
+ const message = name === "AggregateError" ? args[1] : args[0];
14854
+ const options = name === "AggregateError" ? args[2] : args[1];
14855
+ const text = message === void 0 ? void 0 : await sandboxString(message, budget, context);
14856
+ error = createSubsetErrorValue(name, text, context?.stack ?? [], budget);
14857
+ setSandboxPrototype(error, prototype, budget);
14858
+ if (options !== null && typeof options === "object" && getSandboxPropertyDescriptor(options, "cause", budget) !== void 0) {
14859
+ const cause = await readErrorProperty(options, "cause", budget, context);
14860
+ Object.defineProperty(error, "cause", { value: cause, writable: true, configurable: true });
14861
+ }
14862
+ if (name === "AggregateError") {
14863
+ iterator = context === void 0 ? getSandboxIterator(args[0], budget) : await acquireSandboxIterator(args[0], budget, context);
14864
+ if (iterator === void 0) throw new TypeError("AggregateError errors must be iterable.");
14865
+ while (true) {
14866
+ budget.visitNode();
14867
+ const result = await iterator.next();
14868
+ if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
14869
+ if ((await readIteratorResult(iterator, result, "done")).value) break;
14870
+ budget.allocateArrayLength(errors.length + 1);
14871
+ errors.push((await readIteratorResult(iterator, result, "value")).value);
14872
+ }
14873
+ Object.defineProperty(error, "errors", { value: errors, writable: true, configurable: true });
14874
+ }
14875
+ return error;
14876
+ } finally {
14877
+ release();
14878
+ }
14879
+ }
14635
14880
  function createSubsetError(name, args, stackFrames, budget) {
14636
14881
  const message = name === "AggregateError" ? args[1] : args[0];
14637
14882
  const options = name === "AggregateError" ? args[2] : args[1];
@@ -14669,8 +14914,8 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
14669
14914
  budget.visitNode();
14670
14915
  return evaluateInstanceof(value, constructor.boundTarget, budget, context);
14671
14916
  }
14672
- if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
14673
- if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
14917
+ if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
14918
+ if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
14674
14919
  if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
14675
14920
  const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
14676
14921
  if (typeof prototype !== "object" || prototype === null)
@@ -17309,7 +17554,7 @@ async function evaluateMemberCallExpression(node, context) {
17309
17554
  if (isFloat32Array(member.object)) {
17310
17555
  return evaluateResolvedCallExpression(
17311
17556
  node,
17312
- getFloat32Member(member.object, member.property, context.budget),
17557
+ await getPropertyValue(member.object, member.property, context),
17313
17558
  context,
17314
17559
  member.object
17315
17560
  );
@@ -17846,8 +18091,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
17846
18091
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
17847
18092
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
17848
18093
  if (isFloat32Array(target)) {
17849
- if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
17850
- setFloat32Member(target, property, value);
18094
+ setFloat32Member(target, property, value, budget);
17851
18095
  return;
17852
18096
  }
17853
18097
  if (isSandboxRegex(target)) {
@@ -18869,11 +19113,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
18869
19113
  throw reason;
18870
19114
  }
18871
19115
  if (isSubsetErrorValue(reason)) {
18872
- normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
18873
- return reason;
19116
+ return normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
18874
19117
  }
18875
19118
  if (reason instanceof Error) {
18876
- const error = createSubsetErrorValue(
19119
+ const error2 = createSubsetErrorValue(
18877
19120
  reason.name || "Error",
18878
19121
  reason.message,
18879
19122
  stackFrames,
@@ -18884,11 +19127,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
18884
19127
  span
18885
19128
  }
18886
19129
  );
18887
- normalizeSurfacedSubsetError(error, budget, stackFrames, span);
18888
- return error;
19130
+ return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
18889
19131
  }
18890
19132
  if (isErrorLikeValue(reason)) {
18891
- const error = createSubsetErrorValue(
19133
+ const error2 = createSubsetErrorValue(
18892
19134
  reason.name || "Error",
18893
19135
  reason.message,
18894
19136
  stackFrames,
@@ -18899,13 +19141,13 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
18899
19141
  span
18900
19142
  }
18901
19143
  );
18902
- normalizeSurfacedSubsetError(error, budget, stackFrames, span);
18903
- return error;
19144
+ return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
18904
19145
  }
18905
- return createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
19146
+ const error = createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
18906
19147
  chargeBudget: false,
18907
19148
  span
18908
19149
  });
19150
+ return normalizeSurfacedSubsetError(error, budget, stackFrames, span);
18909
19151
  }
18910
19152
  function createSubsetErrorValue(name, message, stackFrames, budget, options = {}) {
18911
19153
  const resumeChecks = options.chargeBudget === false ? budget.suspendChecks() : void 0;
@@ -18914,11 +19156,15 @@ function createSubsetErrorValue(name, message, stackFrames, budget, options = {}
18914
19156
  const errorMessage = budget.allocateString(coerceErrorMessage(message));
18915
19157
  const header = errorMessage === "" ? errorName : `${errorName}: ${errorMessage}`;
18916
19158
  const stack = budget.allocateString([header, ...[...stackFrames].reverse()].join("\n"));
18917
- const error = {
18918
- name: errorName,
18919
- message: errorMessage,
18920
- stack
18921
- };
19159
+ const prototype = options.transport ? void 0 : errorPrototypes.get(budget)?.get(toSandboxErrorName(errorName));
19160
+ const error = prototype === void 0 ? { name: errorName, message: errorMessage, stack } : {};
19161
+ if (prototype !== void 0) {
19162
+ if (message !== void 0) Object.defineProperty(error, "message", { value: errorMessage, writable: true, configurable: true });
19163
+ if (!errorPrototypes.get(budget).has(errorName))
19164
+ Object.defineProperty(error, "name", { value: errorName, writable: true, configurable: true });
19165
+ Object.defineProperty(error, "stack", { value: stack, writable: true, configurable: true });
19166
+ setSandboxPrototype(error, prototype, budget);
19167
+ }
18922
19168
  sandboxErrorTypes.set(error, toSandboxErrorName(errorName));
18923
19169
  attachErrorSpan(error, options.span);
18924
19170
  attachWrappedErrorCause(error, options.cause);
@@ -18939,6 +19185,7 @@ function isSubsetErrorValue(value) {
18939
19185
  if (typeof value !== "object" || value === null) {
18940
19186
  return false;
18941
19187
  }
19188
+ if (sandboxErrorTypes.has(value)) return true;
18942
19189
  const prototype = Object.getPrototypeOf(value);
18943
19190
  return (prototype === Object.prototype || prototype === null) && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
18944
19191
  }
@@ -18948,21 +19195,37 @@ function normalizeSurfacedSubsetError(error, budget, stackFrames, span) {
18948
19195
  const name = budget.allocateString(toSandboxErrorName(readErrorName(error)));
18949
19196
  const message = budget.allocateString(readSurfacedErrorMessage(error, name));
18950
19197
  const frames = readSandboxStackFrames(error.stack);
19198
+ if (!Object.isExtensible(error) || ["name", "message", "stack"].some((key) => {
19199
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
19200
+ return descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable);
19201
+ })) {
19202
+ const original = error;
19203
+ const descriptors2 = Object.getOwnPropertyDescriptors(original);
19204
+ delete descriptors2.name;
19205
+ delete descriptors2.message;
19206
+ delete descriptors2.stack;
19207
+ error = Object.defineProperties({}, descriptors2);
19208
+ const errorType = sandboxErrorTypes.get(original);
19209
+ if (errorType !== void 0) sandboxErrorTypes.set(error, errorType);
19210
+ }
18951
19211
  error.name = name;
18952
19212
  error.message = message;
18953
19213
  error.stack = budget.allocateString(
18954
19214
  formatErrorStack(name, message, frames.length > 0 ? frames : [...stackFrames].reverse())
18955
19215
  );
18956
19216
  attachErrorSpan(error, readErrorSpan(error) ?? span);
19217
+ return error;
18957
19218
  } finally {
18958
19219
  resumeChecks();
18959
19220
  }
18960
19221
  }
18961
19222
  function readErrorName(error) {
18962
- return typeof error.name === "string" && error.name.length > 0 ? error.name : "Error";
19223
+ const name = getSandboxDataProperty(error, "name");
19224
+ return typeof name === "string" && name.length > 0 ? name : sandboxErrorTypes.get(error) ?? "Error";
18963
19225
  }
18964
19226
  function readSurfacedErrorMessage(error, name) {
18965
- const message = typeof error.message === "string" ? error.message : "";
19227
+ const value = getSandboxDataProperty(error, "message");
19228
+ const message = typeof value === "string" ? value : "";
18966
19229
  if (message === "") {
18967
19230
  return `${name} thrown`;
18968
19231
  }
@@ -20472,8 +20735,14 @@ function captureGuestHeapNode(value, encode) {
20472
20735
  }
20473
20736
  if (isLiveCapability(value) || isSandboxClosure(value) || isSandboxBox(value) || isSandboxDate(value) || isSandboxRegex(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxArguments(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value)) return void 0;
20474
20737
  const prototype = Object.getPrototypeOf(value);
20475
- if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
20476
- return { kind: "guest-object", state: captureObjectState(value, encode) };
20738
+ if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value)) {
20739
+ const errorType = sandboxErrorTypes.get(value);
20740
+ return {
20741
+ kind: "guest-object",
20742
+ state: captureObjectState(value, encode),
20743
+ ...errorType === void 0 ? {} : { errorType }
20744
+ };
20745
+ }
20477
20746
  return void 0;
20478
20747
  }
20479
20748
  if (origin.node.nodeId === void 0) throw new TypeError("Guest closures require an AST node identity.");
@@ -22065,9 +22334,11 @@ function createHostErrorValue(reason, stackFrames, budget, span, state = { seen:
22065
22334
  }
22066
22335
  const error = reason instanceof Error ? createSubsetErrorValue(reason.name, reason.message, stackFrames, budget, {
22067
22336
  cause: reason,
22068
- chargeBudget
22337
+ chargeBudget,
22338
+ transport: true
22069
22339
  }) : createSubsetErrorValue("Error", describeThrownReason(reason), stackFrames, budget, {
22070
- chargeBudget: false
22340
+ chargeBudget: false,
22341
+ transport: true
22071
22342
  });
22072
22343
  if (reason instanceof Error) {
22073
22344
  state.seen.set(reason, error);
@@ -24394,11 +24665,11 @@ function createBuiltinBindings(options) {
24394
24665
  const bindings = {
24395
24666
  ...createConsoleJsonGlobals(options),
24396
24667
  ...createCollectionGlobals(options),
24397
- Float32Array: createFloat32ArrayGlobal(options.budget),
24668
+ Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
24398
24669
  Date: createDateGlobal(options),
24399
24670
  Symbol: createSymbolGlobal(options.budget),
24400
24671
  BigInt: createBigIntGlobal(options.budget),
24401
- ...createErrorGlobals(options),
24672
+ ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
24402
24673
  ...createMathGlobals({ random: options.random, budget: options.budget }),
24403
24674
  ...createObjectArrayGlobals(options),
24404
24675
  ...createMiscGlobals(options),
@@ -24407,6 +24678,8 @@ function createBuiltinBindings(options) {
24407
24678
  ...createRegexGlobals(options)
24408
24679
  };
24409
24680
  createFunctionPrototype(options.budget, options.functionHasInstance);
24681
+ if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
24682
+ if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
24410
24683
  createGeneratorPrototypes(options.budget);
24411
24684
  registerBuiltinIdentities(options.budget, bindings);
24412
24685
  return bindings;
@@ -24526,7 +24799,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24526
24799
  }
24527
24800
  state(node.state);
24528
24801
  } else if (node.kind === "guest-object" || node.kind === "guest-array") {
24529
- fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
24802
+ fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : ["errorType"]);
24803
+ if (Object.hasOwn(node, "errorType") && !sandboxErrorNames.includes(node.errorType))
24804
+ throw new TypeError("Invalid guest error type.");
24530
24805
  if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
24531
24806
  if (Object.hasOwn(node, "templateNodeId") && integer(node.templateNodeId) < 1)
24532
24807
  throw new TypeError("Invalid template source identity.");
@@ -25136,6 +25411,10 @@ function validateDumpHeap(root, state) {
25136
25411
  if (entry.kind === "float32array") {
25137
25412
  validateFloat32Storage(entry);
25138
25413
  requireRecord(entry.entries, `${path}.entries`);
25414
+ if (Object.hasOwn(entry, "state")) {
25415
+ if (Object.keys(entry.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
25416
+ validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
25417
+ }
25139
25418
  continue;
25140
25419
  }
25141
25420
  if (entry.kind === "arguments") {
@@ -25364,6 +25643,10 @@ function validateHeapValue(value, path, state, heap) {
25364
25643
  if (record4.kind === "float32array") {
25365
25644
  validateFloat32Storage(record4);
25366
25645
  requireRecord(record4.entries, `${path}.entries`);
25646
+ if (Object.hasOwn(record4, "state")) {
25647
+ if (Object.keys(record4.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
25648
+ validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
25649
+ }
25367
25650
  }
25368
25651
  if (record4.kind === "map") {
25369
25652
  const entries = requireArray(record4.entries, `${path}.entries`, state);
@@ -25496,7 +25779,7 @@ function validateArrayHeap(record4, path, state) {
25496
25779
  }
25497
25780
  function validateErrorType(record4, path) {
25498
25781
  if (!Object.hasOwn(record4, "errorType")) return;
25499
- if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
25782
+ if (record4.kind !== "object" && record4.kind !== "guest-object" || !sandboxErrorNames.includes(record4.errorType)) {
25500
25783
  fail("invalidValue", `${path}.errorType`, "invalid error metadata");
25501
25784
  }
25502
25785
  }
@@ -26358,9 +26641,12 @@ function measureSandboxData(values, options = {}) {
26358
26641
  seen.add(storage.buffer);
26359
26642
  usage += storage.byteLength;
26360
26643
  }
26361
- for (const [key, descriptor] of float32DataProperties(value)) {
26362
- usage += key.length + 1;
26363
- visit(descriptor.value, depth + 1);
26644
+ for (const [key, descriptor] of float32Properties(value)) {
26645
+ usage += 1;
26646
+ if (typeof key === "string") usage += key.length;
26647
+ else visit(key, depth + 1);
26648
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
26649
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
26364
26650
  }
26365
26651
  return;
26366
26652
  }
@@ -26493,7 +26779,7 @@ function measureSandboxData(values, options = {}) {
26493
26779
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
26494
26780
  if (descriptor !== void 0) descriptors2.push([key, descriptor]);
26495
26781
  }
26496
- const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
26782
+ const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
26497
26783
  for (const [key, descriptor] of descriptors2) {
26498
26784
  if (!descriptor.enumerable && !includeNonEnumerable) continue;
26499
26785
  usage += 1 + key.length;
@@ -26826,6 +27112,53 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
26826
27112
  return options.unwrapHostObject(value);
26827
27113
  }
26828
27114
  if (nodeTypes.isProxy(value)) throw new TypeError("Unsupported proxy sandbox value.");
27115
+ if (sandboxErrorTypes.has(value) && hasExplicitSandboxPrototype(value)) {
27116
+ const prototype = getSandboxPrototype(value);
27117
+ let nativePrototype = null;
27118
+ if (prototype !== null) {
27119
+ const identity = getIntrinsicIdentity(prototype);
27120
+ const nativePrototypes = {
27121
+ Error: Error.prototype,
27122
+ TypeError: TypeError.prototype,
27123
+ RangeError: RangeError.prototype,
27124
+ ReferenceError: ReferenceError.prototype,
27125
+ SyntaxError: SyntaxError.prototype,
27126
+ URIError: URIError.prototype,
27127
+ EvalError: EvalError.prototype,
27128
+ AggregateError: AggregateError.prototype
27129
+ };
27130
+ const path2 = identity === void 0 ? [] : JSON.parse(identity);
27131
+ if (path2.length !== 2 || typeof path2[0] !== "string" || path2[1] !== "prototype" || !Object.hasOwn(nativePrototypes, path2[0]))
27132
+ throw new TypeError("Custom Error prototype links cannot be copied as data.");
27133
+ nativePrototype = nativePrototypes[path2[0]];
27134
+ let current = prototype;
27135
+ let prototypeDepth = 0;
27136
+ while (current !== null) {
27137
+ assertSandboxDataDepth(++prototypeDepth);
27138
+ const objectPrototype = getIntrinsicIdentity(current) === '["Object","prototype"]';
27139
+ const owner = objectPrototype ? Object.getOwnPropertyDescriptor(current, "constructor")?.value : current;
27140
+ if (owner === null || typeof owner !== "object" || objectPrototype && getIntrinsicIdentity(owner) !== '["Object"]' || hasGuestObjectState(owner))
27141
+ throw new TypeError("Modified Error prototype links cannot be copied as data.");
27142
+ current = getSandboxPrototype(current);
27143
+ }
27144
+ }
27145
+ const existing = state.seen.get(value);
27146
+ if (existing !== void 0) return existing;
27147
+ const descriptors2 = Reflect.ownKeys(value).filter((key) => typeof key !== "symbol" || !internalSymbols.has(key)).map((key) => [key, Object.getOwnPropertyDescriptor(value, key)]);
27148
+ if (descriptors2.some(([, descriptor]) => !("value" in descriptor)))
27149
+ throw new TypeError("Error accessor properties cannot be copied as data.");
27150
+ const copy = new Error();
27151
+ delete copy.stack;
27152
+ Object.setPrototypeOf(copy, nativePrototype);
27153
+ state.seen.set(value, copy);
27154
+ for (const [key, descriptor] of descriptors2)
27155
+ Object.defineProperty(copy, key, {
27156
+ ...descriptor,
27157
+ value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
27158
+ });
27159
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
27160
+ return copy;
27161
+ }
26829
27162
  if (!isSandboxClosure(value) && hasGuestObjectState(value)) {
26830
27163
  throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
26831
27164
  }
@@ -41274,4 +41607,4 @@ export {
41274
41607
  FileSnapshotBackend,
41275
41608
  run
41276
41609
  };
41277
- //# sourceMappingURL=chunk-ZSYBRZU6.js.map
41610
+ //# sourceMappingURL=chunk-F7WO3VT4.js.map