poe-code 14.0.81 → 14.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/index.js +933 -353
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-2LNBLFJ3.js → chunk-37V6Q4K3.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-ZSYBRZU6.js → chunk-PT7PBLVT.js} +764 -224
  7. package/packages/safe-js/dist/chunks/chunk-PT7PBLVT.js.map +7 -0
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/index.js +2 -2
  11. package/packages/safe-js/dist/interp/error-prototypes.d.ts +3 -0
  12. package/packages/safe-js/dist/interp/error-prototypes.js +1 -0
  13. package/packages/safe-js/dist/interp/exceptions.d.ts +1 -0
  14. package/packages/safe-js/dist/interp/exceptions.js +39 -15
  15. package/packages/safe-js/dist/interp/float32-prototypes.d.ts +3 -0
  16. package/packages/safe-js/dist/interp/float32-prototypes.js +1 -0
  17. package/packages/safe-js/dist/interp/float32.d.ts +1 -0
  18. package/packages/safe-js/dist/interp/float32.js +12 -4
  19. package/packages/safe-js/dist/interp/globals/error.d.ts +2 -0
  20. package/packages/safe-js/dist/interp/globals/error.js +104 -4
  21. package/packages/safe-js/dist/interp/globals/float32array.d.ts +3 -2
  22. package/packages/safe-js/dist/interp/globals/float32array.js +371 -65
  23. package/packages/safe-js/dist/interp/globals/object-array.js +3 -3
  24. package/packages/safe-js/dist/interp/globals.d.ts +2 -0
  25. package/packages/safe-js/dist/interp/globals.js +8 -4
  26. package/packages/safe-js/dist/interp/host-bridge.js +4 -2
  27. package/packages/safe-js/dist/interp/instanceof.js +4 -3
  28. package/packages/safe-js/dist/interp/interpreter.js +2 -4
  29. package/packages/safe-js/dist/interp/iteration.js +15 -6
  30. package/packages/safe-js/dist/interp/object-model.js +27 -1
  31. package/packages/safe-js/dist/interp/values.js +59 -6
  32. package/packages/safe-js/dist/parse/parser.js +8 -3
  33. package/packages/safe-js/dist/parse/tokenizer.js +45 -3
  34. package/packages/safe-js/dist/snapshot/float32array.d.ts +3 -0
  35. package/packages/safe-js/dist/snapshot/float32array.js +20 -1
  36. package/packages/safe-js/dist/snapshot/guest-heap-validation.js +4 -1
  37. package/packages/safe-js/dist/snapshot/guest-heap.d.ts +2 -0
  38. package/packages/safe-js/dist/snapshot/guest-heap.js +6 -2
  39. package/packages/safe-js/dist/snapshot/restore.js +33 -3
  40. package/packages/safe-js/dist/snapshot/serialize.d.ts +2 -1
  41. package/packages/safe-js/dist/snapshot/serialize.js +10 -9
  42. package/packages/safe-js/dist/snapshot/validation.js +11 -1
  43. package/packages/safe-js/dist/chunks/chunk-ZSYBRZU6.js.map +0 -7
  44. /package/packages/safe-js/dist/chunks/{chunk-2LNBLFJ3.js.map → chunk-37V6Q4K3.js.map} +0 -0
package/dist/index.js CHANGED
@@ -120507,7 +120507,7 @@ function matchPunctuator(source, index) {
120507
120507
  (punctuator) => source.startsWith(punctuator, index) && (punctuator !== "?." || !isDecimalDigit(source[index + 2] ?? ""))
120508
120508
  );
120509
120509
  }
120510
- function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
120510
+ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis, tokens) {
120511
120511
  if (previousToken === void 0) {
120512
120512
  return true;
120513
120513
  }
@@ -120515,6 +120515,7 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
120515
120515
  return false;
120516
120516
  }
120517
120517
  if (previousToken.type === "keyword") {
120518
+ if (previousToken.value === "of") return endsWithForOfSeparator(tokens);
120518
120519
  return !EXPRESSION_ENDING_KEYWORDS.has(previousToken.value);
120519
120520
  }
120520
120521
  if (previousToken.value === ")") {
@@ -120522,6 +120523,35 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
120522
120523
  }
120523
120524
  return !isExpressionEndingPunctuator(previousToken.value);
120524
120525
  }
120526
+ function endsWithForOfSeparator(tokens) {
120527
+ let depth = 0;
120528
+ let start = -1;
120529
+ for (let index = tokens.length - 2; index >= 0; index--) {
120530
+ const token = tokens[index];
120531
+ if (token.type !== "punctuator") continue;
120532
+ if ([")", "]", "}"].includes(token.value)) depth++;
120533
+ else if (["(", "[", "{"].includes(token.value)) {
120534
+ if (depth > 0) {
120535
+ depth--;
120536
+ continue;
120537
+ }
120538
+ if (token.value === "(" && (tokens[index - 1]?.value === "for" || tokens[index - 1]?.value === "await" && tokens[index - 2]?.value === "for")) start = index + 1;
120539
+ break;
120540
+ } else if (depth === 0 && token.value === ";") break;
120541
+ }
120542
+ if (start < 0) return false;
120543
+ depth = 0;
120544
+ for (let index = start; index < tokens.length; index++) {
120545
+ const token = tokens[index];
120546
+ if (token.type === "punctuator") {
120547
+ if (["(", "[", "{"].includes(token.value)) depth++;
120548
+ else if ([")", "]", "}"].includes(token.value)) depth--;
120549
+ }
120550
+ if (depth === 0 && token.type === "keyword" && token.value === "of" && index !== start && tokens[index - 1]?.value !== "." && tokens[index - 1]?.value !== "?." && !(index === start + 1 && ["const", "let", "var"].includes(tokens[start].value)))
120551
+ return index === tokens.length - 1;
120552
+ }
120553
+ return false;
120554
+ }
120525
120555
  function updateGroupingState(groupingStack, previousToken, punctuator) {
120526
120556
  if (punctuator === "(") {
120527
120557
  groupingStack.push({
@@ -120905,7 +120935,7 @@ var init_tokenizer2 = __esm({
120905
120935
  lastClosedControlParenthesis = false;
120906
120936
  continue;
120907
120937
  }
120908
- if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis)) {
120938
+ if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis, tokens)) {
120909
120939
  if (!this.options.allowRegexLiterals) {
120910
120940
  this.syntaxError("Regular expression literals are not supported", this.position());
120911
120941
  }
@@ -121174,7 +121204,7 @@ var init_tokenizer2 = __esm({
121174
121204
  }
121175
121205
  }
121176
121206
  readSlashOrPunctuator(start) {
121177
- if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis)) {
121207
+ if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis, this.tokens)) {
121178
121208
  if (!this.options.allowRegexLiterals) {
121179
121209
  this.syntaxError("Regular expression literals are not supported", start);
121180
121210
  }
@@ -123372,7 +123402,7 @@ function isLiteralPropertyKey(token) {
123372
123402
  return token.type === "numeric" || token.type === "string";
123373
123403
  }
123374
123404
  function isIdentifierLikeToken(token) {
123375
- return token.type === "identifier" || token.type === "keyword" && token.value === "async";
123405
+ return token.type === "identifier" || token.type === "keyword" && (token.value === "async" || token.value === "of");
123376
123406
  }
123377
123407
  function isNewToken(token) {
123378
123408
  return token.value === "new";
@@ -126051,6 +126081,7 @@ var init_parser3 = __esm({
126051
126081
  return void 0;
126052
126082
  }
126053
126083
  findTopLevelForIterationOperator(startIndex) {
126084
+ let operator;
126054
126085
  let depth = 0;
126055
126086
  let previousToken;
126056
126087
  for (let index = startIndex; index < this.tokens.length; index += 1) {
@@ -126060,15 +126091,15 @@ var init_parser3 = __esm({
126060
126091
  depth += 1;
126061
126092
  } else if (token.value === ")" || token.value === "]" || token.value === "}") {
126062
126093
  if (depth === 0 && token.value === ")") {
126063
- return void 0;
126094
+ return operator;
126064
126095
  }
126065
126096
  depth -= 1;
126066
126097
  } else if (depth === 0 && token.value === ";") {
126067
126098
  return void 0;
126068
126099
  }
126069
126100
  }
126070
- if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && previousToken?.value !== "." && previousToken?.value !== "?.") {
126071
- return token;
126101
+ if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && index !== startIndex && !(token.value === "of" && index === startIndex + 1 && ["const", "let", "var"].includes(previousToken?.value ?? "")) && previousToken?.value !== "." && previousToken?.value !== "?.") {
126102
+ operator ??= token;
126072
126103
  }
126073
126104
  previousToken = token;
126074
126105
  }
@@ -126512,60 +126543,6 @@ var init_internal_symbols = __esm({
126512
126543
  }
126513
126544
  });
126514
126545
 
126515
- // packages/safe-js/src/interp/generator-properties.ts
126516
- function getGeneratorProperties(value) {
126517
- let properties = generatorGuestProperties.get(value);
126518
- if (properties === void 0) {
126519
- properties = /* @__PURE__ */ Object.create(null);
126520
- generatorGuestProperties.set(value, properties);
126521
- }
126522
- return properties;
126523
- }
126524
- var generatorGuestProperties;
126525
- var init_generator_properties = __esm({
126526
- "packages/safe-js/src/interp/generator-properties.ts"() {
126527
- "use strict";
126528
- generatorGuestProperties = /* @__PURE__ */ new WeakMap();
126529
- }
126530
- });
126531
-
126532
- // packages/safe-js/src/interp/regexp-properties.ts
126533
- function getRegexProperties(value) {
126534
- const properties = regexGuestProperties.get(value);
126535
- if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
126536
- return properties;
126537
- }
126538
- var regexGuestProperties;
126539
- var init_regexp_properties = __esm({
126540
- "packages/safe-js/src/interp/regexp-properties.ts"() {
126541
- "use strict";
126542
- regexGuestProperties = /* @__PURE__ */ new WeakMap();
126543
- }
126544
- });
126545
-
126546
- // packages/safe-js/src/interp/collection-properties.ts
126547
- function getCollectionProperties(value) {
126548
- const properties = collectionGuestProperties.get(value);
126549
- if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
126550
- return properties;
126551
- }
126552
- function copyCollectionProperties(source, target, encode) {
126553
- const properties = collectionGuestProperties.get(source) ?? source;
126554
- for (const key3 of Reflect.ownKeys(properties)) {
126555
- const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
126556
- if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
126557
- Object.defineProperty(target, key3, { ...descriptor, value: encode(descriptor.value) });
126558
- }
126559
- if (!Object.isExtensible(properties)) Object.preventExtensions(target);
126560
- }
126561
- var collectionGuestProperties;
126562
- var init_collection_properties = __esm({
126563
- "packages/safe-js/src/interp/collection-properties.ts"() {
126564
- "use strict";
126565
- collectionGuestProperties = /* @__PURE__ */ new WeakMap();
126566
- }
126567
- });
126568
-
126569
126546
  // packages/safe-js/src/interp/accessors.ts
126570
126547
  function accessorAdapter(closure, kind) {
126571
126548
  if (kind === "get") {
@@ -126630,6 +126607,144 @@ var init_accessors = __esm({
126630
126607
  }
126631
126608
  });
126632
126609
 
126610
+ // packages/safe-js/src/interp/symbols.ts
126611
+ var wellKnownSymbols;
126612
+ var init_symbols2 = __esm({
126613
+ "packages/safe-js/src/interp/symbols.ts"() {
126614
+ "use strict";
126615
+ wellKnownSymbols = Object.freeze({
126616
+ iterator: Symbol.iterator,
126617
+ asyncIterator: Symbol.asyncIterator,
126618
+ hasInstance: Symbol.hasInstance,
126619
+ isConcatSpreadable: Symbol.isConcatSpreadable,
126620
+ match: Symbol.match,
126621
+ matchAll: Symbol.matchAll,
126622
+ replace: Symbol.replace,
126623
+ search: Symbol.search,
126624
+ species: Symbol.species,
126625
+ split: Symbol.split,
126626
+ toPrimitive: Symbol.toPrimitive,
126627
+ toStringTag: Symbol.toStringTag,
126628
+ unscopables: Symbol.unscopables
126629
+ });
126630
+ }
126631
+ });
126632
+
126633
+ // packages/safe-js/src/interp/intrinsics.ts
126634
+ function registerBuiltinIdentities(budget, bindings) {
126635
+ let realm = realms2.get(budget);
126636
+ if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
126637
+ const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
126638
+ const visited = /* @__PURE__ */ new WeakSet();
126639
+ for (let index = 0; index < pending.length; index++) {
126640
+ const [path193, value] = pending[index];
126641
+ if (value === null || typeof value !== "object") continue;
126642
+ const id = JSON.stringify(path193);
126643
+ const previous = realm.get(id);
126644
+ if (previous !== void 0 && previous !== value)
126645
+ throw new TypeError(`Duplicate intrinsic identity: ${id}`);
126646
+ realm.set(id, value);
126647
+ if (!identities.has(value)) identities.set(value, id);
126648
+ if (visited.has(value)) continue;
126649
+ visited.add(value);
126650
+ const owner = isSandboxClosure(value) ? value.properties : value;
126651
+ if (owner === void 0) continue;
126652
+ for (const key3 of Reflect.ownKeys(owner)) {
126653
+ if (typeof key3 === "symbol" && internalSymbols.has(key3)) continue;
126654
+ const descriptor = Object.getOwnPropertyDescriptor(owner, key3);
126655
+ const symbolName = typeof key3 === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol2]) => symbol2 === key3)?.[0] : void 0;
126656
+ if (typeof key3 === "symbol" && symbolName === void 0)
126657
+ throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
126658
+ const member = [...path193, typeof key3 === "string" ? key3 : { symbol: symbolName }];
126659
+ if ("value" in descriptor) pending.push([member, descriptor.value]);
126660
+ for (const kind of ["get", "set"]) {
126661
+ const closure = accessorClosure(descriptor[kind]);
126662
+ if (closure !== void 0) pending.push([[...member, kind], closure]);
126663
+ }
126664
+ }
126665
+ }
126666
+ }
126667
+ function getIntrinsicIdentity(value) {
126668
+ return identities.get(value);
126669
+ }
126670
+ function resolveIntrinsicIdentity(budget, id) {
126671
+ const value = realms2.get(budget)?.get(id);
126672
+ if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
126673
+ return value;
126674
+ }
126675
+ function listIntrinsicIdentities(budget) {
126676
+ return [...realms2.get(budget)?.keys() ?? []];
126677
+ }
126678
+ function releaseIntrinsicIdentities(budget) {
126679
+ realms2.delete(budget);
126680
+ }
126681
+ var identities, realms2;
126682
+ var init_intrinsics = __esm({
126683
+ "packages/safe-js/src/interp/intrinsics.ts"() {
126684
+ "use strict";
126685
+ init_accessors();
126686
+ init_symbols2();
126687
+ init_internal_symbols();
126688
+ init_values();
126689
+ identities = /* @__PURE__ */ new WeakMap();
126690
+ realms2 = /* @__PURE__ */ new WeakMap();
126691
+ }
126692
+ });
126693
+
126694
+ // packages/safe-js/src/interp/generator-properties.ts
126695
+ function getGeneratorProperties(value) {
126696
+ let properties = generatorGuestProperties.get(value);
126697
+ if (properties === void 0) {
126698
+ properties = /* @__PURE__ */ Object.create(null);
126699
+ generatorGuestProperties.set(value, properties);
126700
+ }
126701
+ return properties;
126702
+ }
126703
+ var generatorGuestProperties;
126704
+ var init_generator_properties = __esm({
126705
+ "packages/safe-js/src/interp/generator-properties.ts"() {
126706
+ "use strict";
126707
+ generatorGuestProperties = /* @__PURE__ */ new WeakMap();
126708
+ }
126709
+ });
126710
+
126711
+ // packages/safe-js/src/interp/regexp-properties.ts
126712
+ function getRegexProperties(value) {
126713
+ const properties = regexGuestProperties.get(value);
126714
+ if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
126715
+ return properties;
126716
+ }
126717
+ var regexGuestProperties;
126718
+ var init_regexp_properties = __esm({
126719
+ "packages/safe-js/src/interp/regexp-properties.ts"() {
126720
+ "use strict";
126721
+ regexGuestProperties = /* @__PURE__ */ new WeakMap();
126722
+ }
126723
+ });
126724
+
126725
+ // packages/safe-js/src/interp/collection-properties.ts
126726
+ function getCollectionProperties(value) {
126727
+ const properties = collectionGuestProperties.get(value);
126728
+ if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
126729
+ return properties;
126730
+ }
126731
+ function copyCollectionProperties(source, target, encode) {
126732
+ const properties = collectionGuestProperties.get(source) ?? source;
126733
+ for (const key3 of Reflect.ownKeys(properties)) {
126734
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
126735
+ if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
126736
+ Object.defineProperty(target, key3, { ...descriptor, value: encode(descriptor.value) });
126737
+ }
126738
+ if (!Object.isExtensible(properties)) Object.preventExtensions(target);
126739
+ }
126740
+ var collectionGuestProperties;
126741
+ var init_collection_properties = __esm({
126742
+ "packages/safe-js/src/interp/collection-properties.ts"() {
126743
+ "use strict";
126744
+ collectionGuestProperties = /* @__PURE__ */ new WeakMap();
126745
+ }
126746
+ });
126747
+
126633
126748
  // packages/safe-js/src/interp/collection-brands.ts
126634
126749
  function isSandboxMap(value) {
126635
126750
  return typeof value === "object" && value !== null && sandboxMapBrand in value;
@@ -127180,90 +127295,6 @@ var init_resources = __esm({
127180
127295
  }
127181
127296
  });
127182
127297
 
127183
- // packages/safe-js/src/interp/symbols.ts
127184
- var wellKnownSymbols;
127185
- var init_symbols2 = __esm({
127186
- "packages/safe-js/src/interp/symbols.ts"() {
127187
- "use strict";
127188
- wellKnownSymbols = Object.freeze({
127189
- iterator: Symbol.iterator,
127190
- asyncIterator: Symbol.asyncIterator,
127191
- hasInstance: Symbol.hasInstance,
127192
- isConcatSpreadable: Symbol.isConcatSpreadable,
127193
- match: Symbol.match,
127194
- matchAll: Symbol.matchAll,
127195
- replace: Symbol.replace,
127196
- search: Symbol.search,
127197
- species: Symbol.species,
127198
- split: Symbol.split,
127199
- toPrimitive: Symbol.toPrimitive,
127200
- toStringTag: Symbol.toStringTag,
127201
- unscopables: Symbol.unscopables
127202
- });
127203
- }
127204
- });
127205
-
127206
- // packages/safe-js/src/interp/intrinsics.ts
127207
- function registerBuiltinIdentities(budget, bindings) {
127208
- let realm = realms2.get(budget);
127209
- if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
127210
- const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
127211
- const visited = /* @__PURE__ */ new WeakSet();
127212
- for (let index = 0; index < pending.length; index++) {
127213
- const [path193, value] = pending[index];
127214
- if (value === null || typeof value !== "object") continue;
127215
- const id = JSON.stringify(path193);
127216
- const previous = realm.get(id);
127217
- if (previous !== void 0 && previous !== value)
127218
- throw new TypeError(`Duplicate intrinsic identity: ${id}`);
127219
- realm.set(id, value);
127220
- if (!identities.has(value)) identities.set(value, id);
127221
- if (visited.has(value)) continue;
127222
- visited.add(value);
127223
- const owner = isSandboxClosure(value) ? value.properties : value;
127224
- if (owner === void 0) continue;
127225
- for (const key3 of Reflect.ownKeys(owner)) {
127226
- if (typeof key3 === "symbol" && internalSymbols.has(key3)) continue;
127227
- const descriptor = Object.getOwnPropertyDescriptor(owner, key3);
127228
- const symbolName = typeof key3 === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol2]) => symbol2 === key3)?.[0] : void 0;
127229
- if (typeof key3 === "symbol" && symbolName === void 0)
127230
- throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
127231
- const member = [...path193, typeof key3 === "string" ? key3 : { symbol: symbolName }];
127232
- if ("value" in descriptor) pending.push([member, descriptor.value]);
127233
- for (const kind of ["get", "set"]) {
127234
- const closure = accessorClosure(descriptor[kind]);
127235
- if (closure !== void 0) pending.push([[...member, kind], closure]);
127236
- }
127237
- }
127238
- }
127239
- }
127240
- function getIntrinsicIdentity(value) {
127241
- return identities.get(value);
127242
- }
127243
- function resolveIntrinsicIdentity(budget, id) {
127244
- const value = realms2.get(budget)?.get(id);
127245
- if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
127246
- return value;
127247
- }
127248
- function listIntrinsicIdentities(budget) {
127249
- return [...realms2.get(budget)?.keys() ?? []];
127250
- }
127251
- function releaseIntrinsicIdentities(budget) {
127252
- realms2.delete(budget);
127253
- }
127254
- var identities, realms2;
127255
- var init_intrinsics = __esm({
127256
- "packages/safe-js/src/interp/intrinsics.ts"() {
127257
- "use strict";
127258
- init_accessors();
127259
- init_symbols2();
127260
- init_internal_symbols();
127261
- init_values();
127262
- identities = /* @__PURE__ */ new WeakMap();
127263
- realms2 = /* @__PURE__ */ new WeakMap();
127264
- }
127265
- });
127266
-
127267
127298
  // packages/safe-js/src/extensions.ts
127268
127299
  import { types as types3 } from "node:util";
127269
127300
  function readDataRecord(value, label) {
@@ -127668,6 +127699,100 @@ var init_host_capabilities = __esm({
127668
127699
  }
127669
127700
  });
127670
127701
 
127702
+ // packages/safe-js/src/interp/error-prototypes.ts
127703
+ var errorPrototypes;
127704
+ var init_error_prototypes = __esm({
127705
+ "packages/safe-js/src/interp/error-prototypes.ts"() {
127706
+ "use strict";
127707
+ errorPrototypes = /* @__PURE__ */ new WeakMap();
127708
+ }
127709
+ });
127710
+
127711
+ // packages/safe-js/src/interp/float32.ts
127712
+ function isFloat32Array(value) {
127713
+ return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
127714
+ }
127715
+ function float32Storage(value) {
127716
+ const buffer = Reflect.apply(readBuffer, value, []);
127717
+ if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype || bufferResizable !== void 0 && Reflect.apply(bufferResizable, buffer, [])) {
127718
+ throw new TypeError("Float32Array requires a fixed, non-shared ArrayBuffer.");
127719
+ }
127720
+ return {
127721
+ buffer,
127722
+ byteOffset: Reflect.apply(readOffset, value, []),
127723
+ length: Reflect.apply(readLength, value, []),
127724
+ byteLength: Reflect.apply(bufferLength, buffer, [])
127725
+ };
127726
+ }
127727
+ function float32Properties(value) {
127728
+ const properties = [];
127729
+ for (const key3 of Reflect.ownKeys(value)) {
127730
+ if (typeof key3 === "string" && isFloat32Index(key3)) continue;
127731
+ properties.push([key3, Object.getOwnPropertyDescriptor(value, key3)]);
127732
+ }
127733
+ return properties;
127734
+ }
127735
+ function float32DataProperties(value) {
127736
+ if (Object.getOwnPropertySymbols(value).length > 0)
127737
+ throw new TypeError("Float32Array symbol properties are not supported.");
127738
+ const properties = [];
127739
+ for (const [key3, descriptor] of float32Properties(value)) {
127740
+ if (typeof key3 !== "string") throw new TypeError("Float32Array symbol properties are not supported.");
127741
+ if (!("value" in descriptor))
127742
+ throw new TypeError(`Float32Array accessor property '${key3}' is not supported.`);
127743
+ properties.push([key3, descriptor]);
127744
+ }
127745
+ return properties;
127746
+ }
127747
+ function isFloat32Index(key3) {
127748
+ return key3 === "-0" || String(Number(key3)) === key3;
127749
+ }
127750
+ function float32Number(value) {
127751
+ if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
127752
+ throw new TypeError(
127753
+ "Float32Array numeric arguments must be primitive numeric-coercible values."
127754
+ );
127755
+ }
127756
+ return Number(value);
127757
+ }
127758
+ function checkFloat32Allocation(length, budget) {
127759
+ budget.allocateArrayLength(length);
127760
+ budget.provisionDataUsage(length * Float32Array.BYTES_PER_ELEMENT + 1)();
127761
+ }
127762
+ function copyFloat32Storage(value, state) {
127763
+ const storage2 = float32Storage(value);
127764
+ state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
127765
+ let buffer = state.float32Buffers.get(storage2.buffer);
127766
+ if (buffer === void 0) {
127767
+ buffer = new ArrayBuffer(storage2.byteLength);
127768
+ new Uint8Array(buffer).set(new Uint8Array(storage2.buffer));
127769
+ state.float32Buffers.set(storage2.buffer, buffer);
127770
+ }
127771
+ return new Float32Array(buffer, storage2.byteOffset, storage2.length);
127772
+ }
127773
+ var typedArrayPrototype, readLength, readOffset, readBuffer, readTag, bufferLength, bufferResizable;
127774
+ var init_float32 = __esm({
127775
+ "packages/safe-js/src/interp/float32.ts"() {
127776
+ "use strict";
127777
+ typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
127778
+ readLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
127779
+ readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
127780
+ readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
127781
+ readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
127782
+ bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
127783
+ bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
127784
+ }
127785
+ });
127786
+
127787
+ // packages/safe-js/src/interp/float32-prototypes.ts
127788
+ var float32Prototypes;
127789
+ var init_float32_prototypes = __esm({
127790
+ "packages/safe-js/src/interp/float32-prototypes.ts"() {
127791
+ "use strict";
127792
+ float32Prototypes = /* @__PURE__ */ new WeakMap();
127793
+ }
127794
+ });
127795
+
127671
127796
  // packages/safe-js/src/interp/object-model.ts
127672
127797
  function registerGuestClosure(closure) {
127673
127798
  guestClosures.add(closure);
@@ -127873,11 +127998,19 @@ function releaseObjectPrototype(budget) {
127873
127998
  arrayPrototypes.delete(budget);
127874
127999
  functionPrototypes.delete(budget);
127875
128000
  generatorPrototypes.delete(budget);
128001
+ errorPrototypes.delete(budget);
128002
+ float32Prototypes.delete(budget);
127876
128003
  initialRegexDescriptors.delete(budget);
127877
128004
  intrinsicPrototypes.delete(budget);
127878
128005
  }
127879
128006
  function getSandboxPrototype(value, budget) {
127880
128007
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
128008
+ if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
128009
+ const errorType = sandboxErrorTypes.get(value);
128010
+ if (budget !== void 0 && errorType !== void 0) {
128011
+ const prototype = errorPrototypes.get(budget)?.get(errorType);
128012
+ if (prototype !== void 0) return prototype;
128013
+ }
127881
128014
  if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
127882
128015
  return functionPrototypes.get(budget) ?? null;
127883
128016
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
@@ -127905,6 +128038,8 @@ function getSandboxPropertyDescriptor(value, key3, budget) {
127905
128038
  let current = value;
127906
128039
  let depth = 0;
127907
128040
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
128041
+ if (isFloat32Array(current) && typeof key3 !== "symbol" && isFloat32Index(String(key3)))
128042
+ return Object.getOwnPropertyDescriptor(current, key3);
127908
128043
  const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key3 === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
127909
128044
  if (properties === void 0 && isGuestClosure(current) && (key3 === "name" || key3 === "length"))
127910
128045
  return {
@@ -127927,6 +128062,8 @@ function getSandboxDataProperty(value, key3, budget) {
127927
128062
  let current = value;
127928
128063
  let depth = 0;
127929
128064
  while (typeof current === "object" && current !== null) {
128065
+ if (isFloat32Array(current) && typeof key3 !== "symbol" && isFloat32Index(String(key3)))
128066
+ return Object.getOwnPropertyDescriptor(current, key3)?.value;
127930
128067
  if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
127931
128068
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key3)?.value;
127932
128069
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key3)?.value;
@@ -127978,6 +128115,7 @@ function setSandboxPrototype(value, prototype, budget) {
127978
128115
  prototypes.set(value, prototype);
127979
128116
  }
127980
128117
  function isPrototypeRecord(value) {
128118
+ if (isFloat32Array(value)) return true;
127981
128119
  if (isGuestClosure(value)) return true;
127982
128120
  if (isGuestHostObject(value)) return false;
127983
128121
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
@@ -127997,7 +128135,7 @@ function hasGuestObjectState(value) {
127997
128135
  if (isLiveCapability(value)) return true;
127998
128136
  if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
127999
128137
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
128000
- return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
128138
+ return descriptorObjects.has(value) && (isFloat32Array(value) ? float32Properties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
128001
128139
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
128002
128140
  );
128003
128141
  }
@@ -128014,6 +128152,10 @@ var init_object_model = __esm({
128014
128152
  init_date();
128015
128153
  init_accessors();
128016
128154
  init_host_capabilities();
128155
+ init_error_prototypes();
128156
+ init_float32();
128157
+ init_float32_prototypes();
128158
+ init_shape();
128017
128159
  init_boxed();
128018
128160
  init_values();
128019
128161
  guestClosures = /* @__PURE__ */ new WeakSet();
@@ -128062,75 +128204,6 @@ var init_raw_json = __esm({
128062
128204
  }
128063
128205
  });
128064
128206
 
128065
- // packages/safe-js/src/interp/float32.ts
128066
- function isFloat32Array(value) {
128067
- return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
128068
- }
128069
- function float32Storage(value) {
128070
- const buffer = Reflect.apply(readBuffer, value, []);
128071
- if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype || bufferResizable !== void 0 && Reflect.apply(bufferResizable, buffer, [])) {
128072
- throw new TypeError("Float32Array requires a fixed, non-shared ArrayBuffer.");
128073
- }
128074
- return {
128075
- buffer,
128076
- byteOffset: Reflect.apply(readOffset, value, []),
128077
- length: Reflect.apply(readLength, value, []),
128078
- byteLength: Reflect.apply(bufferLength, buffer, [])
128079
- };
128080
- }
128081
- function float32DataProperties(value) {
128082
- if (Object.getOwnPropertySymbols(value).length > 0)
128083
- throw new TypeError("Float32Array symbol properties are not supported.");
128084
- const properties = [];
128085
- for (const key3 of Object.getOwnPropertyNames(value)) {
128086
- if (isFloat32Index(key3)) continue;
128087
- const descriptor = Object.getOwnPropertyDescriptor(value, key3);
128088
- if (!("value" in descriptor))
128089
- throw new TypeError(`Float32Array accessor property '${key3}' is not supported.`);
128090
- properties.push([key3, descriptor]);
128091
- }
128092
- return properties;
128093
- }
128094
- function isFloat32Index(key3) {
128095
- return key3 === "-0" || String(Number(key3)) === key3;
128096
- }
128097
- function float32Number(value) {
128098
- if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
128099
- throw new TypeError(
128100
- "Float32Array numeric arguments must be primitive numeric-coercible values."
128101
- );
128102
- }
128103
- return Number(value);
128104
- }
128105
- function checkFloat32Allocation(length, budget) {
128106
- budget.allocateArrayLength(length);
128107
- budget.provisionDataUsage(length * Float32Array.BYTES_PER_ELEMENT + 1)();
128108
- }
128109
- function copyFloat32Storage(value, state) {
128110
- const storage2 = float32Storage(value);
128111
- state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
128112
- let buffer = state.float32Buffers.get(storage2.buffer);
128113
- if (buffer === void 0) {
128114
- buffer = new ArrayBuffer(storage2.byteLength);
128115
- new Uint8Array(buffer).set(new Uint8Array(storage2.buffer));
128116
- state.float32Buffers.set(storage2.buffer, buffer);
128117
- }
128118
- return new Float32Array(buffer, storage2.byteOffset, storage2.length);
128119
- }
128120
- var typedArrayPrototype, readLength, readOffset, readBuffer, readTag, bufferLength, bufferResizable;
128121
- var init_float32 = __esm({
128122
- "packages/safe-js/src/interp/float32.ts"() {
128123
- "use strict";
128124
- typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
128125
- readLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
128126
- readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
128127
- readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
128128
- readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
128129
- bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
128130
- bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
128131
- }
128132
- });
128133
-
128134
128207
  // packages/safe-js/src/interp/promise-tracker.ts
128135
128208
  import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
128136
128209
  function assertPromiseExecutionAllowed() {
@@ -128800,6 +128873,8 @@ var init_float32array = __esm({
128800
128873
  "packages/safe-js/src/snapshot/float32array.ts"() {
128801
128874
  "use strict";
128802
128875
  init_float32();
128876
+ init_object_model();
128877
+ init_property_descriptors();
128803
128878
  }
128804
128879
  });
128805
128880
 
@@ -130991,6 +131066,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
130991
131066
  const iterator = await invokeBuiltinClosure(factory, [], budget, context, value);
130992
131067
  if (typeof iterator !== "object" && typeof iterator !== "function" || iterator === null)
130993
131068
  throw new TypeError("Iterator must be an object.");
131069
+ if (!asyncProtocol && isSandboxGenerator(iterator) && !iterator.async && !hasExplicitSandboxPrototype(iterator) && getSandboxPropertyDescriptor(iterator, "next", budget) === void 0)
131070
+ return getSandboxIterator(iterator, budget, context);
130994
131071
  const next = await context.getProperty(iterator, "next");
130995
131072
  return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
130996
131073
  }
@@ -131023,7 +131100,7 @@ async function readIteratorResult(iterator, result, property) {
131023
131100
  }
131024
131101
  function getSandboxAsyncIterator(value, budget, context, signal) {
131025
131102
  if (isSandboxGenerator(value) && value.async) {
131026
- return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
131103
+ return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? guestProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
131027
131104
  }
131028
131105
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
131029
131106
  const method = value[Symbol.asyncIterator];
@@ -131170,11 +131247,15 @@ function getSandboxIterator(value, budget, context) {
131170
131247
  }
131171
131248
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
131172
131249
  if (isFloat32Array(value)) {
131250
+ if (hasExplicitSandboxPrototype(value) || budget !== void 0 && float32Prototypes.has(budget)) {
131251
+ if (getSandboxPropertyDescriptor(value, Symbol.iterator, budget) === void 0) return void 0;
131252
+ return guestProtocolAdapter(value, budget ?? new Budget(), context, false);
131253
+ }
131173
131254
  return syncIterator(Float32Array.prototype.values.call(value));
131174
131255
  }
131175
131256
  if (isSandboxGenerator(value)) {
131176
131257
  if (value.async) return void 0;
131177
- if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
131258
+ if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
131178
131259
  return generatorObjectIterator(value, budget, context);
131179
131260
  }
131180
131261
  if (typeof value === "string") {
@@ -131251,7 +131332,7 @@ function collectionIterator(collection, value) {
131251
131332
  adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
131252
131333
  return adapter;
131253
131334
  }
131254
- function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
131335
+ function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
131255
131336
  const bridge = {
131256
131337
  ...context,
131257
131338
  stack: context?.stack ?? [],
@@ -131265,7 +131346,7 @@ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal)
131265
131346
  let resolved;
131266
131347
  let pending;
131267
131348
  const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
131268
- if (iterator === void 0) throw new TypeError("Generator does not provide an iterator protocol.");
131349
+ if (iterator === void 0) throw new TypeError("Value does not provide an iterator protocol.");
131269
131350
  return resolved = iterator;
131270
131351
  });
131271
131352
  return {
@@ -131374,6 +131455,7 @@ var init_iteration = __esm({
131374
131455
  init_values();
131375
131456
  init_running_state();
131376
131457
  init_float32();
131458
+ init_float32_prototypes();
131377
131459
  init_boxed();
131378
131460
  init_host_capabilities();
131379
131461
  init_collection_iterator();
@@ -135313,8 +135395,8 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
135313
135395
  }
135314
135396
  function defineDataProperty8(target, key3, descriptor, budget) {
135315
135397
  budget.visitNode();
135316
- if (isFloat32Array(target))
135317
- throw new TypeError("Typed array property descriptors are not supported.");
135398
+ if (isFloat32Array(target) && typeof key3 !== "symbol" && isFloat32Index(String(key3)) && "value" in descriptor)
135399
+ descriptor = { ...descriptor, value: float32Number(descriptor.value) };
135318
135400
  const properties = objectProperties(target, true);
135319
135401
  if (Array.isArray(properties)) {
135320
135402
  if (key3 === "length" && "value" in descriptor)
@@ -136246,62 +136328,338 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
136246
136328
  return createSandboxCollectionIterator(target, methodName);
136247
136329
  }
136248
136330
  }
136249
- var setMethodNames;
136250
- var init_set = __esm({
136251
- "packages/safe-js/src/interp/methods/set.ts"() {
136252
- "use strict";
136253
- init_values();
136254
- init_running_state();
136255
- init_collection_callback();
136256
- init_collection_iterator();
136257
- setMethodNames = /* @__PURE__ */ new Set([
136258
- "add",
136259
- "has",
136260
- "delete",
136261
- "clear",
136262
- "forEach",
136263
- "keys",
136264
- "values",
136265
- "entries"
136266
- ]);
136331
+ var setMethodNames;
136332
+ var init_set = __esm({
136333
+ "packages/safe-js/src/interp/methods/set.ts"() {
136334
+ "use strict";
136335
+ init_values();
136336
+ init_running_state();
136337
+ init_collection_callback();
136338
+ init_collection_iterator();
136339
+ setMethodNames = /* @__PURE__ */ new Set([
136340
+ "add",
136341
+ "has",
136342
+ "delete",
136343
+ "clear",
136344
+ "forEach",
136345
+ "keys",
136346
+ "values",
136347
+ "entries"
136348
+ ]);
136349
+ }
136350
+ });
136351
+
136352
+ // packages/safe-js/src/interp/globals/float32array.ts
136353
+ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
136354
+ const constructor = createSandboxClosure({
136355
+ guest: nativePrototype,
136356
+ sandbox: true,
136357
+ name: "Float32Array",
136358
+ length: 3,
136359
+ properties: { BYTES_PER_ELEMENT: 4 },
136360
+ call: () => {
136361
+ throw new TypeError("Constructor Float32Array requires 'new'.");
136362
+ },
136363
+ construct: (args, context) => {
136364
+ if (!nativePrototype) return allocateFloat32Array(args[0], budget);
136365
+ return (async () => {
136366
+ const newTarget = context?.newTarget ?? constructor;
136367
+ const candidate = context?.getProperty === void 0 ? getSandboxDataProperty(newTarget, "prototype", budget) : await context.getProperty(newTarget, "prototype");
136368
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
136369
+ const release2 = retainValues(budget, () => [prototype, ...args]);
136370
+ try {
136371
+ const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
136372
+ setSandboxPrototype(result, prototype, budget);
136373
+ return result;
136374
+ } finally {
136375
+ release2();
136376
+ }
136377
+ })();
136378
+ }
136379
+ });
136380
+ constructors.add(constructor);
136381
+ return constructor;
136382
+ }
136383
+ async function allocateFloat32Input(source, budget, context) {
136384
+ const callerContext = context;
136385
+ const bridge = {
136386
+ ...callerContext,
136387
+ stack: callerContext?.stack ?? [],
136388
+ thisValue: void 0,
136389
+ getProperty: callerContext?.getProperty ?? ((value, key3) => {
136390
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
136391
+ return descriptor === void 0 ? getSandboxDataProperty(value, key3, budget) : readPropertyDescriptor(descriptor, value, bridge);
136392
+ }),
136393
+ invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, receiver, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, receiver, construct))
136394
+ };
136395
+ const values = [];
136396
+ let iterator;
136397
+ let current;
136398
+ let result;
136399
+ const release2 = retainValues(budget, () => [source, values, iterator?.retainedValue, current, result]);
136400
+ const checkData = createDataCheckpoint(budget, bridge);
136401
+ try {
136402
+ iterator = await acquireSandboxIterator(source, budget, bridge);
136403
+ let length;
136404
+ if (iterator !== void 0) {
136405
+ while (true) {
136406
+ budget.visitNode();
136407
+ const next = await iterator.next();
136408
+ if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
136409
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
136410
+ current = (await readIteratorResult(iterator, next, "value")).value;
136411
+ budget.allocateArrayLength(values.length + 1);
136412
+ values.push(current);
136413
+ checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
136414
+ }
136415
+ length = values.length;
136416
+ } else {
136417
+ current = await bridge.getProperty(source, "length");
136418
+ const number = await sandboxNumber(current, budget, bridge);
136419
+ length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
136420
+ }
136421
+ checkFloat32Allocation(length, budget);
136422
+ result = new Float32Array(length);
136423
+ checkData(result, 0, true);
136424
+ for (let index = 0; index < length; index++) {
136425
+ budget.visitNode();
136426
+ current = iterator === void 0 ? await bridge.getProperty(source, String(index)) : values[index];
136427
+ result[index] = await sandboxNumber(current, budget, bridge);
136428
+ }
136429
+ return result;
136430
+ } finally {
136431
+ release2();
136432
+ }
136433
+ }
136434
+ function allocateFloat32Array(source, budget) {
136435
+ if (Array.isArray(source) || isFloat32Array(source)) {
136436
+ const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
136437
+ checkFloat32Allocation(length2, budget);
136438
+ if (isFloat32Array(source)) return new Float32Array(source);
136439
+ const result = new Float32Array(length2);
136440
+ for (let index = 0; index < length2; index += 1) {
136441
+ budget.visitNode();
136442
+ const descriptor = Object.getOwnPropertyDescriptor(source, index);
136443
+ if (descriptor !== void 0 && !("value" in descriptor))
136444
+ throw new TypeError("Float32Array input accessors are not supported.");
136445
+ result[index] = float32Number(descriptor?.value);
136446
+ }
136447
+ return result;
136267
136448
  }
136268
- });
136269
-
136270
- // packages/safe-js/src/interp/globals/float32array.ts
136271
- function createFloat32ArrayGlobal(budget) {
136272
- const constructor = createSandboxClosure({
136449
+ const number = float32Number(source);
136450
+ const length = Number.isNaN(number) ? 0 : Math.trunc(number);
136451
+ if (length < 0 || !Number.isSafeInteger(length))
136452
+ throw new RangeError("Invalid typed array length.");
136453
+ checkFloat32Allocation(length, budget);
136454
+ return new Float32Array(length);
136455
+ }
136456
+ function createFloat32ArrayPrototypes(budget, constructor) {
136457
+ const prototype = /* @__PURE__ */ Object.create(null);
136458
+ const shared = /* @__PURE__ */ Object.create(null);
136459
+ const abstractCall = () => {
136460
+ throw new TypeError("Abstract TypedArray constructor cannot be called.");
136461
+ };
136462
+ const typedArray = createSandboxClosure({
136463
+ guest: true,
136273
136464
  sandbox: true,
136274
- name: "Float32Array",
136275
- length: 3,
136276
- properties: { BYTES_PER_ELEMENT: 4 },
136277
- call: () => {
136278
- throw new TypeError("Constructor Float32Array requires 'new'.");
136279
- },
136280
- construct: ([source]) => {
136281
- if (Array.isArray(source) || isFloat32Array(source)) {
136282
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
136283
- checkFloat32Allocation(length2, budget);
136284
- if (isFloat32Array(source)) return new Float32Array(source);
136285
- const result = new Float32Array(length2);
136286
- for (let index = 0; index < length2; index += 1) {
136287
- budget.visitNode();
136288
- const descriptor = Object.getOwnPropertyDescriptor(source, index);
136289
- if (descriptor !== void 0 && !("value" in descriptor))
136290
- throw new TypeError("Float32Array input accessors are not supported.");
136291
- result[index] = float32Number(descriptor?.value);
136465
+ name: "TypedArray",
136466
+ length: 0,
136467
+ call: abstractCall,
136468
+ construct: abstractCall
136469
+ });
136470
+ Object.defineProperty(materializeFunctionProperties(typedArray), "prototype", { value: shared, writable: false });
136471
+ Object.defineProperty(materializeFunctionProperties(typedArray), "from", {
136472
+ writable: true,
136473
+ configurable: true,
136474
+ value: createSandboxClosure({
136475
+ guest: true,
136476
+ sandbox: true,
136477
+ name: "from",
136478
+ length: 1,
136479
+ call: async (args, context) => {
136480
+ const target = context?.thisValue;
136481
+ const [source, mapper, receiver] = args;
136482
+ if (!isSandboxClosure(target) || target.construct === void 0)
136483
+ throw new TypeError("TypedArray.from requires a constructor receiver.");
136484
+ if (mapper !== void 0 && !isSandboxClosure(mapper))
136485
+ throw new TypeError("TypedArray.from mapper must be callable.");
136486
+ if (source === null || source === void 0)
136487
+ throw new TypeError("TypedArray.from requires a non-null source.");
136488
+ const callerContext = context;
136489
+ context = {
136490
+ ...callerContext,
136491
+ stack: callerContext?.stack ?? [],
136492
+ thisValue: target,
136493
+ getProperty: callerContext?.getProperty ?? ((value, key3) => {
136494
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
136495
+ return descriptor === void 0 ? getSandboxDataProperty(value, key3, budget) : readPropertyDescriptor(descriptor, value, context);
136496
+ }),
136497
+ invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, thisValue, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, thisValue, construct))
136498
+ };
136499
+ let result;
136500
+ let current;
136501
+ let iterator;
136502
+ const values = [];
136503
+ const release2 = retainValues(budget, () => [target, result, current, iterator?.retainedValue, values, ...args]);
136504
+ const checkData = createDataCheckpoint(budget, context);
136505
+ const read = (key3) => context?.getProperty === void 0 ? getSandboxDataProperty(source, key3, budget) : context.getProperty(source, key3);
136506
+ try {
136507
+ iterator = await acquireSandboxIterator(source, budget, context);
136508
+ let length;
136509
+ if (iterator !== void 0) {
136510
+ while (true) {
136511
+ budget.visitNode();
136512
+ const next = await iterator.next();
136513
+ if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
136514
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
136515
+ current = (await readIteratorResult(iterator, next, "value")).value;
136516
+ budget.allocateArrayLength(values.length + 1);
136517
+ values.push(current);
136518
+ checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
136519
+ }
136520
+ length = values.length;
136521
+ } else {
136522
+ const number = await sandboxNumber(await read("length"), budget, context);
136523
+ length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
136524
+ }
136525
+ result = await invokeBuiltinClosure(target, [length], budget, context, void 0, true);
136526
+ if (!isFloat32Array(result) || float32Storage(result).length < length)
136527
+ throw new TypeError("TypedArray.from constructor must return sufficient typed storage.");
136528
+ checkData(result, 0, true);
136529
+ for (let index = 0; index < length; index++) {
136530
+ budget.visitNode();
136531
+ current = iterator === void 0 ? await read(String(index)) : values[index];
136532
+ if (mapper !== void 0)
136533
+ current = await invokeBuiltinClosure(mapper, [current, index], budget, context, receiver);
136534
+ result[index] = await sandboxNumber(current, budget, context);
136535
+ }
136536
+ return result;
136537
+ } finally {
136538
+ release2();
136292
136539
  }
136293
- return result;
136294
136540
  }
136295
- const number = float32Number(source);
136296
- const length = Number.isNaN(number) ? 0 : Math.trunc(number);
136297
- if (length < 0 || !Number.isSafeInteger(length))
136298
- throw new RangeError("Invalid typed array length.");
136299
- checkFloat32Allocation(length, budget);
136300
- return new Float32Array(length);
136301
- }
136541
+ })
136302
136542
  });
136303
- constructors.add(constructor);
136304
- return constructor;
136543
+ Object.defineProperty(materializeFunctionProperties(typedArray), "of", {
136544
+ writable: true,
136545
+ configurable: true,
136546
+ value: createSandboxClosure({
136547
+ guest: true,
136548
+ sandbox: true,
136549
+ name: "of",
136550
+ length: 0,
136551
+ call: async (args, context) => {
136552
+ const target = context?.thisValue;
136553
+ if (!isSandboxClosure(target) || target.construct === void 0)
136554
+ throw new TypeError("TypedArray.of requires a constructor receiver.");
136555
+ let result;
136556
+ const release2 = retainValues(budget, () => [target, result, ...args]);
136557
+ try {
136558
+ result = await invokeBuiltinClosure(target, [args.length], budget, context, void 0, true);
136559
+ if (!isFloat32Array(result) || float32Storage(result).length < args.length)
136560
+ throw new TypeError("TypedArray.of constructor must return sufficient typed storage.");
136561
+ for (let index = 0; index < args.length; index++) {
136562
+ budget.visitNode();
136563
+ result[index] = await sandboxNumber(args[index], budget, context);
136564
+ }
136565
+ return result;
136566
+ } finally {
136567
+ release2();
136568
+ }
136569
+ }
136570
+ })
136571
+ });
136572
+ Object.defineProperties(materializeFunctionProperties(constructor), {
136573
+ prototype: { value: prototype, writable: false },
136574
+ BYTES_PER_ELEMENT: { value: 4, writable: false, enumerable: false, configurable: false }
136575
+ });
136576
+ Object.defineProperties(prototype, {
136577
+ constructor: { value: constructor, writable: true, configurable: true },
136578
+ BYTES_PER_ELEMENT: { value: 4 }
136579
+ });
136580
+ Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
136581
+ setSandboxPrototype(constructor, typedArray);
136582
+ setSandboxPrototype(prototype, shared);
136583
+ setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
136584
+ const getters = [];
136585
+ for (const key3 of ["length", "byteLength", "byteOffset"]) {
136586
+ const getter = createSandboxClosure({
136587
+ guest: true,
136588
+ sandbox: true,
136589
+ name: `get ${key3}`,
136590
+ length: 0,
136591
+ call: (_args, context) => {
136592
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key3} requires a typed array receiver.`);
136593
+ const storage2 = float32Storage(context.thisValue);
136594
+ return key3 === "byteLength" ? storage2.length * 4 : storage2[key3];
136595
+ }
136596
+ });
136597
+ getters.push(getter);
136598
+ Object.defineProperty(shared, key3, { get: accessorAdapter(getter, "get"), configurable: true });
136599
+ }
136600
+ for (const key3 of ["set", "slice", "subarray"])
136601
+ Object.defineProperty(shared, key3, { value: getFloat32Member(new Float32Array(0), key3, budget), writable: true, configurable: true });
136602
+ const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
136603
+ Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
136604
+ Object.defineProperty(shared, "join", {
136605
+ writable: true,
136606
+ configurable: true,
136607
+ value: createSandboxClosure({
136608
+ guest: true,
136609
+ sandbox: true,
136610
+ name: "join",
136611
+ length: 1,
136612
+ call: async (args, context) => {
136613
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
136614
+ const receiver = context.thisValue;
136615
+ const length = float32Storage(receiver).length;
136616
+ let separator = ",";
136617
+ let text5 = "";
136618
+ const release2 = retainValues(budget, () => [receiver, separator, text5, ...args]);
136619
+ try {
136620
+ if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
136621
+ for (let index = 0; index < length; index++) {
136622
+ budget.visitNode();
136623
+ text5 = budget.allocateString(text5 + (index === 0 ? "" : separator) + String(receiver[index]));
136624
+ }
136625
+ return text5;
136626
+ } finally {
136627
+ release2();
136628
+ }
136629
+ }
136630
+ })
136631
+ });
136632
+ const tagGetter = createSandboxClosure({
136633
+ guest: true,
136634
+ sandbox: true,
136635
+ name: "get [Symbol.toStringTag]",
136636
+ length: 0,
136637
+ call: (_args, context) => isFloat32Array(context?.thisValue) ? "Float32Array" : void 0
136638
+ });
136639
+ getters.push(tagGetter);
136640
+ Object.defineProperty(shared, Symbol.toStringTag, { get: accessorAdapter(tagGetter, "get"), configurable: true });
136641
+ for (const key3 of ["values", "keys", "entries"]) {
136642
+ const method = getSandboxDataProperty(arrayPrototype, key3, budget);
136643
+ const closure = createSandboxClosure({
136644
+ guest: true,
136645
+ sandbox: true,
136646
+ name: key3,
136647
+ length: 0,
136648
+ call: (args, context) => {
136649
+ if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key3} requires a typed array receiver.`);
136650
+ return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
136651
+ }
136652
+ });
136653
+ Object.defineProperty(shared, key3, { value: closure, writable: true, configurable: true });
136654
+ if (key3 === "values") Object.defineProperty(shared, Symbol.iterator, { value: closure, writable: true, configurable: true });
136655
+ }
136656
+ float32Prototypes.set(budget, prototype);
136657
+ registerBuiltinIdentities(budget, { Float32Array: constructor, "%TypedArray%": typedArray });
136658
+ registerIntrinsicFunction(budget, constructor);
136659
+ registerIntrinsicFunction(budget, typedArray);
136660
+ registerIntrinsicObject(budget, prototype);
136661
+ registerIntrinsicObject(budget, shared);
136662
+ for (const getter of getters) registerIntrinsicFunction(budget, getter);
136305
136663
  }
136306
136664
  function isFloat32ArrayConstructor(value) {
136307
136665
  return typeof value === "object" && value !== null && constructors.has(value);
@@ -136313,6 +136671,7 @@ function getFloat32Member(value, property, budget) {
136313
136671
  if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
136314
136672
  return descriptor.value;
136315
136673
  }
136674
+ if (float32Prototypes.has(budget)) return void 0;
136316
136675
  const storage2 = float32Storage(value);
136317
136676
  if (key3 === "length") return storage2.length;
136318
136677
  if (key3 === "byteLength") return storage2.length * 4;
@@ -136320,6 +136679,7 @@ function getFloat32Member(value, property, budget) {
136320
136679
  if (key3 === "BYTES_PER_ELEMENT") return 4;
136321
136680
  if (!["set", "slice", "subarray"].includes(key3)) return void 0;
136322
136681
  return createSandboxClosure({
136682
+ guest: true,
136323
136683
  sandbox: true,
136324
136684
  name: key3,
136325
136685
  length: key3 === "set" ? 1 : 2,
@@ -136328,65 +136688,88 @@ function getFloat32Member(value, property, budget) {
136328
136688
  if (!isFloat32Array(receiver))
136329
136689
  throw new TypeError(`Float32Array#${key3} requires a Float32Array receiver.`);
136330
136690
  const storage3 = float32Storage(receiver);
136691
+ const bridge = {
136692
+ ...context,
136693
+ stack: context?.stack ?? [],
136694
+ thisValue: receiver,
136695
+ getProperty: context?.getProperty ?? ((value2, property2) => {
136696
+ const descriptor2 = getSandboxPropertyDescriptor(value2, property2, budget);
136697
+ return descriptor2 === void 0 ? getSandboxDataProperty(value2, property2, budget) : readPropertyDescriptor(descriptor2, value2, bridge);
136698
+ }),
136699
+ invokeClosure: context?.invokeClosure ?? ((callee, values, thisValue, construct) => invokeBuiltinClosure(callee, values, budget, context, thisValue, construct))
136700
+ };
136331
136701
  if (key3 === "set") {
136332
- const [source, offsetValue = 0] = args;
136333
- if (!Array.isArray(source) && !isFloat32Array(source))
136334
- throw new TypeError("Float32Array#set requires an array or Float32Array.");
136335
- const number = float32Number(offsetValue);
136336
- const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
136337
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
136338
- if (offset < 0 || !Number.isSafeInteger(offset) || offset + length2 > storage3.length)
136339
- throw new RangeError("Float32Array#set source is out of bounds.");
136340
- if (isFloat32Array(source)) {
136341
- Float32Array.prototype.set.call(receiver, source, offset);
136342
- return void 0;
136343
- }
136344
- checkFloat32Allocation(length2, budget);
136345
- const copied = new Float32Array(length2);
136346
- for (let index = 0; index < length2; index += 1) {
136347
- budget.visitNode();
136348
- const entry = Object.getOwnPropertyDescriptor(source, index);
136349
- if (entry !== void 0 && !("value" in entry))
136350
- throw new TypeError("Float32Array input accessors are not supported.");
136351
- copied[index] = float32Number(entry?.value);
136352
- }
136353
- Float32Array.prototype.set.call(receiver, copied, offset);
136354
- return void 0;
136702
+ return (async () => {
136703
+ const [source, offsetValue = 0] = args;
136704
+ let current;
136705
+ let sourceObject;
136706
+ const release2 = retainValues(budget, () => [receiver, sourceObject, current, ...args]);
136707
+ try {
136708
+ const number = await sandboxNumber(offsetValue, budget, bridge);
136709
+ const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
136710
+ if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
136711
+ if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
136712
+ let length;
136713
+ if (isFloat32Array(source)) length = float32Storage(source).length;
136714
+ else {
136715
+ sourceObject = typeof source === "object" ? source : createSandboxBox(source);
136716
+ current = await bridge.getProperty(sourceObject, "length");
136717
+ const size = await sandboxNumber(current, budget, bridge);
136718
+ length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
136719
+ }
136720
+ if (offset + length > storage3.length) throw new RangeError("Float32Array#set source is out of bounds.");
136721
+ if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
136722
+ else for (let index = 0; index < length; index++) {
136723
+ budget.visitNode();
136724
+ current = await bridge.getProperty(sourceObject, String(index));
136725
+ receiver[offset + index] = await sandboxNumber(current, budget, bridge);
136726
+ }
136727
+ return void 0;
136728
+ } finally {
136729
+ release2();
136730
+ }
136731
+ })();
136355
136732
  }
136356
- const start = relativeIndex(args[0], storage3.length, 0);
136357
- const end = relativeIndex(args[1], storage3.length, storage3.length);
136358
- const length = Math.max(end - start, 0);
136359
- if (key3 === "subarray")
136360
- return new Float32Array(storage3.buffer, storage3.byteOffset + start * 4, length);
136361
- checkFloat32Allocation(length, budget);
136362
- const result = new Float32Array(length);
136363
- new Uint8Array(result.buffer).set(
136364
- new Uint8Array(storage3.buffer, storage3.byteOffset + start * 4, length * 4)
136365
- );
136366
- return result;
136733
+ return (async () => {
136734
+ const release2 = retainValues(budget, () => [receiver, ...args]);
136735
+ try {
136736
+ const start = relativeIndex(await sandboxNumber(args[0], budget, bridge), storage3.length);
136737
+ const end = args[1] === void 0 ? storage3.length : relativeIndex(await sandboxNumber(args[1], budget, bridge), storage3.length);
136738
+ const length = Math.max(end - start, 0);
136739
+ if (key3 === "subarray")
136740
+ return new Float32Array(storage3.buffer, storage3.byteOffset + start * 4, length);
136741
+ checkFloat32Allocation(length, budget);
136742
+ const result = new Float32Array(length);
136743
+ new Uint8Array(result.buffer).set(
136744
+ new Uint8Array(storage3.buffer, storage3.byteOffset + start * 4, length * 4)
136745
+ );
136746
+ return result;
136747
+ } finally {
136748
+ release2();
136749
+ }
136750
+ })();
136367
136751
  }
136368
136752
  });
136369
136753
  }
136370
- function setFloat32Member(value, property, entry) {
136371
- const key3 = String(property);
136372
- if (isFloat32Index(key3)) {
136754
+ function setFloat32Member(value, property, entry, budget) {
136755
+ const key3 = typeof property === "symbol" ? property : String(property);
136756
+ if (typeof key3 !== "symbol" && isFloat32Index(key3)) {
136373
136757
  Reflect.set(value, key3, float32Number(entry));
136374
136758
  return;
136375
136759
  }
136376
136760
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
136377
- if (descriptor === void 0 && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key3))
136378
- throw new TypeError(`Cannot assign to read only property '${key3}'.`);
136379
- if (descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable))
136380
- throw new TypeError(`Cannot assign to read only property '${key3}'.`);
136761
+ const inherited = descriptor ?? (budget === void 0 ? void 0 : getSandboxPropertyDescriptor(value, key3, budget));
136762
+ if (descriptor === void 0 && typeof key3 === "string" && (budget === void 0 || !float32Prototypes.has(budget)) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key3))
136763
+ throw new TypeError(`Cannot assign to read only property '${String(key3)}'.`);
136764
+ if (inherited !== void 0 && (!("value" in inherited) || !inherited.writable))
136765
+ throw new TypeError(`Cannot assign to read only property '${String(key3)}'.`);
136381
136766
  Object.defineProperty(
136382
136767
  value,
136383
136768
  key3,
136384
136769
  descriptor === void 0 ? { value: entry, configurable: true, enumerable: true, writable: true } : { value: entry }
136385
136770
  );
136386
136771
  }
136387
- function relativeIndex(value, length, fallback) {
136388
- if (value === void 0) return fallback;
136389
- const numeric = float32Number(value);
136772
+ function relativeIndex(numeric, length) {
136390
136773
  const integer3 = Number.isNaN(numeric) ? 0 : Math.trunc(numeric);
136391
136774
  return integer3 < 0 ? Math.max(length + integer3, 0) : Math.min(integer3, length);
136392
136775
  }
@@ -136396,6 +136779,16 @@ var init_float32array2 = __esm({
136396
136779
  "use strict";
136397
136780
  init_float32();
136398
136781
  init_values();
136782
+ init_accessors();
136783
+ init_float32_prototypes();
136784
+ init_object_model();
136785
+ init_intrinsics();
136786
+ init_builtin_call();
136787
+ init_resources();
136788
+ init_string_coercion();
136789
+ init_iteration();
136790
+ init_data_checkpoint();
136791
+ init_boxed();
136399
136792
  constructors = /* @__PURE__ */ new WeakSet();
136400
136793
  }
136401
136794
  });
@@ -136403,7 +136796,7 @@ var init_float32array2 = __esm({
136403
136796
  // packages/safe-js/src/interp/globals/error.ts
136404
136797
  function createErrorGlobals(options) {
136405
136798
  return Object.fromEntries(
136406
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
136799
+ errorNames.map((name) => [name, createErrorConstructor(name, options.budget, options.errorPrototypes === true)])
136407
136800
  );
136408
136801
  }
136409
136802
  function isSandboxErrorConstructorInstance2(value, constructor) {
@@ -136416,12 +136809,100 @@ function isSandboxErrorConstructorInstance2(value, constructor) {
136416
136809
  }
136417
136810
  return isSandboxErrorConstructorInstance(value, name);
136418
136811
  }
136419
- function createErrorConstructor(name, budget) {
136420
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
136421
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
136812
+ function createErrorConstructor(name, budget, guest) {
136813
+ const call = (args, context) => errorPrototypes.has(budget) ? createNativeError(name, args, budget, context, closure) : createSubsetError(name, args, context?.stack ?? [], budget);
136814
+ const closure = createSandboxClosure({ guest, sandbox: true, call, construct: call, name, length: name === "AggregateError" ? 2 : 1 });
136422
136815
  errorConstructorNames.set(closure, name);
136423
136816
  return closure;
136424
136817
  }
136818
+ function createErrorPrototypes(budget, constructors2) {
136819
+ const prototypes2 = /* @__PURE__ */ new Map();
136820
+ for (const name of errorNames) prototypes2.set(name, /* @__PURE__ */ Object.create(null));
136821
+ errorPrototypes.set(budget, prototypes2);
136822
+ for (const name of errorNames) {
136823
+ const constructor = constructors2[name];
136824
+ const prototype = prototypes2.get(name);
136825
+ Object.defineProperties(prototype, {
136826
+ name: { value: name, writable: true, configurable: true },
136827
+ message: { value: "", writable: true, configurable: true },
136828
+ constructor: { value: constructor, writable: true, configurable: true }
136829
+ });
136830
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
136831
+ setSandboxPrototype(prototype, name === "Error" ? getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget) : prototypes2.get("Error"));
136832
+ if (name !== "Error") setSandboxPrototype(constructor, constructors2.Error);
136833
+ }
136834
+ Object.defineProperty(prototypes2.get("Error"), "toString", {
136835
+ writable: true,
136836
+ configurable: true,
136837
+ value: createSandboxClosure({
136838
+ guest: true,
136839
+ sandbox: true,
136840
+ name: "toString",
136841
+ length: 0,
136842
+ call: async (_args, context) => {
136843
+ const receiver = context?.thisValue;
136844
+ if (receiver === null || typeof receiver !== "object") throw new TypeError("Error.prototype.toString requires an object.");
136845
+ let name;
136846
+ const release2 = retainValues(budget, () => [receiver, name]);
136847
+ try {
136848
+ const rawName = await readErrorProperty(receiver, "name", budget, context);
136849
+ name = rawName === void 0 ? "Error" : await sandboxString(rawName, budget, context);
136850
+ const rawMessage = await readErrorProperty(receiver, "message", budget, context);
136851
+ const message2 = rawMessage === void 0 ? "" : await sandboxString(rawMessage, budget, context);
136852
+ return budget.allocateString(name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`);
136853
+ } finally {
136854
+ release2();
136855
+ }
136856
+ }
136857
+ })
136858
+ });
136859
+ registerBuiltinIdentities(budget, Object.fromEntries(errorNames.map((name) => [name, constructors2[name]])));
136860
+ for (const name of errorNames) {
136861
+ registerIntrinsicFunction(budget, constructors2[name]);
136862
+ registerIntrinsicObject(budget, prototypes2.get(name));
136863
+ }
136864
+ }
136865
+ async function readErrorProperty(value, key3, budget, context) {
136866
+ if (context?.getProperty !== void 0) return context.getProperty(value, key3);
136867
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
136868
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
136869
+ }
136870
+ async function createNativeError(name, args, budget, context, constructor) {
136871
+ const newTarget = context?.newTarget ?? constructor;
136872
+ const candidate = await readErrorProperty(newTarget, "prototype", budget, context);
136873
+ const prototype = candidate !== null && typeof candidate === "object" ? candidate : errorPrototypes.get(budget).get(name);
136874
+ let error3;
136875
+ let iterator;
136876
+ const errors2 = [];
136877
+ const release2 = retainValues(budget, () => [prototype, error3, iterator?.retainedValue, ...errors2, ...args]);
136878
+ try {
136879
+ const message2 = name === "AggregateError" ? args[1] : args[0];
136880
+ const options = name === "AggregateError" ? args[2] : args[1];
136881
+ const text5 = message2 === void 0 ? void 0 : await sandboxString(message2, budget, context);
136882
+ error3 = createSubsetErrorValue(name, text5, context?.stack ?? [], budget);
136883
+ setSandboxPrototype(error3, prototype, budget);
136884
+ if (options !== null && typeof options === "object" && getSandboxPropertyDescriptor(options, "cause", budget) !== void 0) {
136885
+ const cause = await readErrorProperty(options, "cause", budget, context);
136886
+ Object.defineProperty(error3, "cause", { value: cause, writable: true, configurable: true });
136887
+ }
136888
+ if (name === "AggregateError") {
136889
+ iterator = context === void 0 ? getSandboxIterator(args[0], budget) : await acquireSandboxIterator(args[0], budget, context);
136890
+ if (iterator === void 0) throw new TypeError("AggregateError errors must be iterable.");
136891
+ while (true) {
136892
+ budget.visitNode();
136893
+ const result = await iterator.next();
136894
+ if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
136895
+ if ((await readIteratorResult(iterator, result, "done")).value) break;
136896
+ budget.allocateArrayLength(errors2.length + 1);
136897
+ errors2.push((await readIteratorResult(iterator, result, "value")).value);
136898
+ }
136899
+ Object.defineProperty(error3, "errors", { value: errors2, writable: true, configurable: true });
136900
+ }
136901
+ return error3;
136902
+ } finally {
136903
+ release2();
136904
+ }
136905
+ }
136425
136906
  function createSubsetError(name, args, stackFrames, budget) {
136426
136907
  const message2 = name === "AggregateError" ? args[1] : args[0];
136427
136908
  const options = name === "AggregateError" ? args[2] : args[1];
@@ -136443,6 +136924,13 @@ var errorConstructorNames, errorNames;
136443
136924
  var init_error = __esm({
136444
136925
  "packages/safe-js/src/interp/globals/error.ts"() {
136445
136926
  "use strict";
136927
+ init_error_prototypes();
136928
+ init_object_model();
136929
+ init_intrinsics();
136930
+ init_string_coercion();
136931
+ init_resources();
136932
+ init_accessors();
136933
+ init_iteration();
136446
136934
  init_exceptions();
136447
136935
  init_values();
136448
136936
  errorConstructorNames = /* @__PURE__ */ new WeakMap();
@@ -136478,8 +136966,8 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
136478
136966
  budget.visitNode();
136479
136967
  return evaluateInstanceof(value, constructor.boundTarget, budget, context);
136480
136968
  }
136481
- if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
136482
- if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
136969
+ if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
136970
+ if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
136483
136971
  if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
136484
136972
  const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
136485
136973
  if (typeof prototype !== "object" || prototype === null)
@@ -139078,7 +139566,7 @@ async function evaluateMemberCallExpression(node, context) {
139078
139566
  if (isFloat32Array(member.object)) {
139079
139567
  return evaluateResolvedCallExpression(
139080
139568
  node,
139081
- getFloat32Member(member.object, member.property, context.budget),
139569
+ await getPropertyValue(member.object, member.property, context),
139082
139570
  context,
139083
139571
  member.object
139084
139572
  );
@@ -139615,8 +140103,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
139615
140103
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
139616
140104
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
139617
140105
  if (isFloat32Array(target)) {
139618
- if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
139619
- setFloat32Member(target, property, value);
140106
+ setFloat32Member(target, property, value, budget);
139620
140107
  return;
139621
140108
  }
139622
140109
  if (isSandboxRegex(target)) {
@@ -140820,11 +141307,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
140820
141307
  throw reason;
140821
141308
  }
140822
141309
  if (isSubsetErrorValue(reason)) {
140823
- normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
140824
- return reason;
141310
+ return normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
140825
141311
  }
140826
141312
  if (reason instanceof Error) {
140827
- const error3 = createSubsetErrorValue(
141313
+ const error4 = createSubsetErrorValue(
140828
141314
  reason.name || "Error",
140829
141315
  reason.message,
140830
141316
  stackFrames,
@@ -140835,11 +141321,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
140835
141321
  span
140836
141322
  }
140837
141323
  );
140838
- normalizeSurfacedSubsetError(error3, budget, stackFrames, span);
140839
- return error3;
141324
+ return normalizeSurfacedSubsetError(error4, budget, stackFrames, span);
140840
141325
  }
140841
141326
  if (isErrorLikeValue(reason)) {
140842
- const error3 = createSubsetErrorValue(
141327
+ const error4 = createSubsetErrorValue(
140843
141328
  reason.name || "Error",
140844
141329
  reason.message,
140845
141330
  stackFrames,
@@ -140850,13 +141335,13 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
140850
141335
  span
140851
141336
  }
140852
141337
  );
140853
- normalizeSurfacedSubsetError(error3, budget, stackFrames, span);
140854
- return error3;
141338
+ return normalizeSurfacedSubsetError(error4, budget, stackFrames, span);
140855
141339
  }
140856
- return createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
141340
+ const error3 = createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
140857
141341
  chargeBudget: false,
140858
141342
  span
140859
141343
  });
141344
+ return normalizeSurfacedSubsetError(error3, budget, stackFrames, span);
140860
141345
  }
140861
141346
  function createSubsetErrorValue(name, message2, stackFrames, budget, options = {}) {
140862
141347
  const resumeChecks = options.chargeBudget === false ? budget.suspendChecks() : void 0;
@@ -140865,11 +141350,15 @@ function createSubsetErrorValue(name, message2, stackFrames, budget, options = {
140865
141350
  const errorMessage9 = budget.allocateString(coerceErrorMessage(message2));
140866
141351
  const header = errorMessage9 === "" ? errorName : `${errorName}: ${errorMessage9}`;
140867
141352
  const stack = budget.allocateString([header, ...[...stackFrames].reverse()].join("\n"));
140868
- const error3 = {
140869
- name: errorName,
140870
- message: errorMessage9,
140871
- stack
140872
- };
141353
+ const prototype = options.transport ? void 0 : errorPrototypes.get(budget)?.get(toSandboxErrorName(errorName));
141354
+ const error3 = prototype === void 0 ? { name: errorName, message: errorMessage9, stack } : {};
141355
+ if (prototype !== void 0) {
141356
+ if (message2 !== void 0) Object.defineProperty(error3, "message", { value: errorMessage9, writable: true, configurable: true });
141357
+ if (!errorPrototypes.get(budget).has(errorName))
141358
+ Object.defineProperty(error3, "name", { value: errorName, writable: true, configurable: true });
141359
+ Object.defineProperty(error3, "stack", { value: stack, writable: true, configurable: true });
141360
+ setSandboxPrototype(error3, prototype, budget);
141361
+ }
140873
141362
  sandboxErrorTypes.set(error3, toSandboxErrorName(errorName));
140874
141363
  attachErrorSpan(error3, options.span);
140875
141364
  attachWrappedErrorCause(error3, options.cause);
@@ -140890,6 +141379,7 @@ function isSubsetErrorValue(value) {
140890
141379
  if (typeof value !== "object" || value === null) {
140891
141380
  return false;
140892
141381
  }
141382
+ if (sandboxErrorTypes.has(value)) return true;
140893
141383
  const prototype = Object.getPrototypeOf(value);
140894
141384
  return (prototype === Object.prototype || prototype === null) && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
140895
141385
  }
@@ -140899,21 +141389,37 @@ function normalizeSurfacedSubsetError(error3, budget, stackFrames, span) {
140899
141389
  const name = budget.allocateString(toSandboxErrorName(readErrorName(error3)));
140900
141390
  const message2 = budget.allocateString(readSurfacedErrorMessage(error3, name));
140901
141391
  const frames = readSandboxStackFrames(error3.stack);
141392
+ if (!Object.isExtensible(error3) || ["name", "message", "stack"].some((key3) => {
141393
+ const descriptor = Object.getOwnPropertyDescriptor(error3, key3);
141394
+ return descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable);
141395
+ })) {
141396
+ const original = error3;
141397
+ const descriptors2 = Object.getOwnPropertyDescriptors(original);
141398
+ delete descriptors2.name;
141399
+ delete descriptors2.message;
141400
+ delete descriptors2.stack;
141401
+ error3 = Object.defineProperties({}, descriptors2);
141402
+ const errorType = sandboxErrorTypes.get(original);
141403
+ if (errorType !== void 0) sandboxErrorTypes.set(error3, errorType);
141404
+ }
140902
141405
  error3.name = name;
140903
141406
  error3.message = message2;
140904
141407
  error3.stack = budget.allocateString(
140905
141408
  formatErrorStack(name, message2, frames.length > 0 ? frames : [...stackFrames].reverse())
140906
141409
  );
140907
141410
  attachErrorSpan(error3, readErrorSpan(error3) ?? span);
141411
+ return error3;
140908
141412
  } finally {
140909
141413
  resumeChecks();
140910
141414
  }
140911
141415
  }
140912
141416
  function readErrorName(error3) {
140913
- return typeof error3.name === "string" && error3.name.length > 0 ? error3.name : "Error";
141417
+ const name = getSandboxDataProperty(error3, "name");
141418
+ return typeof name === "string" && name.length > 0 ? name : sandboxErrorTypes.get(error3) ?? "Error";
140914
141419
  }
140915
141420
  function readSurfacedErrorMessage(error3, name) {
140916
- const message2 = typeof error3.message === "string" ? error3.message : "";
141421
+ const value = getSandboxDataProperty(error3, "message");
141422
+ const message2 = typeof value === "string" ? value : "";
140917
141423
  if (message2 === "") {
140918
141424
  return `${name} thrown`;
140919
141425
  }
@@ -141202,6 +141708,7 @@ var init_exceptions = __esm({
141202
141708
  init_object2();
141203
141709
  init_resources();
141204
141710
  init_object_model();
141711
+ init_error_prototypes();
141205
141712
  init_property_key();
141206
141713
  init_internal_symbols();
141207
141714
  init_resume_target();
@@ -142723,9 +143230,12 @@ function measureSandboxData(values, options = {}) {
142723
143230
  seen.add(storage2.buffer);
142724
143231
  usage += storage2.byteLength;
142725
143232
  }
142726
- for (const [key3, descriptor] of float32DataProperties(value)) {
142727
- usage += key3.length + 1;
142728
- visit(descriptor.value, depth + 1);
143233
+ for (const [key3, descriptor] of float32Properties(value)) {
143234
+ usage += 1;
143235
+ if (typeof key3 === "string") usage += key3.length;
143236
+ else visit(key3, depth + 1);
143237
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
143238
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
142729
143239
  }
142730
143240
  return;
142731
143241
  }
@@ -142858,7 +143368,7 @@ function measureSandboxData(values, options = {}) {
142858
143368
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
142859
143369
  if (descriptor !== void 0) descriptors2.push([key3, descriptor]);
142860
143370
  }
142861
- const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
143371
+ const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
142862
143372
  for (const [key3, descriptor] of descriptors2) {
142863
143373
  if (!descriptor.enumerable && !includeNonEnumerable) continue;
142864
143374
  usage += 1 + key3.length;
@@ -143191,6 +143701,53 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
143191
143701
  return options.unwrapHostObject(value);
143192
143702
  }
143193
143703
  if (nodeTypes.isProxy(value)) throw new TypeError("Unsupported proxy sandbox value.");
143704
+ if (sandboxErrorTypes.has(value) && hasExplicitSandboxPrototype(value)) {
143705
+ const prototype = getSandboxPrototype(value);
143706
+ let nativePrototype = null;
143707
+ if (prototype !== null) {
143708
+ const identity = getIntrinsicIdentity(prototype);
143709
+ const nativePrototypes = {
143710
+ Error: Error.prototype,
143711
+ TypeError: TypeError.prototype,
143712
+ RangeError: RangeError.prototype,
143713
+ ReferenceError: ReferenceError.prototype,
143714
+ SyntaxError: SyntaxError.prototype,
143715
+ URIError: URIError.prototype,
143716
+ EvalError: EvalError.prototype,
143717
+ AggregateError: AggregateError.prototype
143718
+ };
143719
+ const path194 = identity === void 0 ? [] : JSON.parse(identity);
143720
+ if (path194.length !== 2 || typeof path194[0] !== "string" || path194[1] !== "prototype" || !Object.hasOwn(nativePrototypes, path194[0]))
143721
+ throw new TypeError("Custom Error prototype links cannot be copied as data.");
143722
+ nativePrototype = nativePrototypes[path194[0]];
143723
+ let current = prototype;
143724
+ let prototypeDepth = 0;
143725
+ while (current !== null) {
143726
+ assertSandboxDataDepth(++prototypeDepth);
143727
+ const objectPrototype = getIntrinsicIdentity(current) === '["Object","prototype"]';
143728
+ const owner = objectPrototype ? Object.getOwnPropertyDescriptor(current, "constructor")?.value : current;
143729
+ if (owner === null || typeof owner !== "object" || objectPrototype && getIntrinsicIdentity(owner) !== '["Object"]' || hasGuestObjectState(owner))
143730
+ throw new TypeError("Modified Error prototype links cannot be copied as data.");
143731
+ current = getSandboxPrototype(current);
143732
+ }
143733
+ }
143734
+ const existing = state.seen.get(value);
143735
+ if (existing !== void 0) return existing;
143736
+ const descriptors2 = Reflect.ownKeys(value).filter((key3) => typeof key3 !== "symbol" || !internalSymbols.has(key3)).map((key3) => [key3, Object.getOwnPropertyDescriptor(value, key3)]);
143737
+ if (descriptors2.some(([, descriptor]) => !("value" in descriptor)))
143738
+ throw new TypeError("Error accessor properties cannot be copied as data.");
143739
+ const copy = new Error();
143740
+ delete copy.stack;
143741
+ Object.setPrototypeOf(copy, nativePrototype);
143742
+ state.seen.set(value, copy);
143743
+ for (const [key3, descriptor] of descriptors2)
143744
+ Object.defineProperty(copy, key3, {
143745
+ ...descriptor,
143746
+ value: copyFromSandbox(descriptor.value, state, joinPath(path193, key3), options, depth + 1)
143747
+ });
143748
+ if (!Object.isExtensible(value)) Object.preventExtensions(copy);
143749
+ return copy;
143750
+ }
143194
143751
  if (!isSandboxClosure(value) && hasGuestObjectState(value)) {
143195
143752
  throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
143196
143753
  }
@@ -143577,6 +144134,7 @@ var init_values = __esm({
143577
144134
  "use strict";
143578
144135
  init_otel2();
143579
144136
  init_internal_symbols();
144137
+ init_intrinsics();
143580
144138
  init_generator_properties();
143581
144139
  init_regexp_properties();
143582
144140
  init_collection_properties();
@@ -143840,8 +144398,14 @@ function captureGuestHeapNode(value, encode) {
143840
144398
  }
143841
144399
  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;
143842
144400
  const prototype = Object.getPrototypeOf(value);
143843
- if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
143844
- return { kind: "guest-object", state: captureObjectState(value, encode) };
144401
+ if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value)) {
144402
+ const errorType = sandboxErrorTypes.get(value);
144403
+ return {
144404
+ kind: "guest-object",
144405
+ state: captureObjectState(value, encode),
144406
+ ...errorType === void 0 ? {} : { errorType }
144407
+ };
144408
+ }
143845
144409
  return void 0;
143846
144410
  }
143847
144411
  if (origin.node.nodeId === void 0) throw new TypeError("Guest closures require an AST node identity.");
@@ -143879,6 +144443,7 @@ var init_guest_heap = __esm({
143879
144443
  "use strict";
143880
144444
  init_closure_origin();
143881
144445
  init_bound_function_state();
144446
+ init_shape();
143882
144447
  init_generator_properties();
143883
144448
  init_intrinsics();
143884
144449
  init_object_model();
@@ -144910,9 +145475,11 @@ function createHostErrorValue(reason, stackFrames, budget, span, state = { seen:
144910
145475
  }
144911
145476
  const error3 = reason instanceof Error ? createSubsetErrorValue(reason.name, reason.message, stackFrames, budget, {
144912
145477
  cause: reason,
144913
- chargeBudget
145478
+ chargeBudget,
145479
+ transport: true
144914
145480
  }) : createSubsetErrorValue("Error", describeThrownReason(reason), stackFrames, budget, {
144915
- chargeBudget: false
145481
+ chargeBudget: false,
145482
+ transport: true
144916
145483
  });
144917
145484
  if (reason instanceof Error) {
144918
145485
  state.seen.set(reason, error3);
@@ -147448,11 +148015,11 @@ function createBuiltinBindings(options) {
147448
148015
  const bindings = {
147449
148016
  ...createConsoleJsonGlobals(options),
147450
148017
  ...createCollectionGlobals(options),
147451
- Float32Array: createFloat32ArrayGlobal(options.budget),
148018
+ Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
147452
148019
  Date: createDateGlobal(options),
147453
148020
  Symbol: createSymbolGlobal(options.budget),
147454
148021
  BigInt: createBigIntGlobal(options.budget),
147455
- ...createErrorGlobals(options),
148022
+ ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
147456
148023
  ...createMathGlobals({ random: options.random, budget: options.budget }),
147457
148024
  ...createObjectArrayGlobals(options),
147458
148025
  ...createMiscGlobals(options),
@@ -147461,6 +148028,8 @@ function createBuiltinBindings(options) {
147461
148028
  ...createRegexGlobals(options)
147462
148029
  };
147463
148030
  createFunctionPrototype(options.budget, options.functionHasInstance);
148031
+ if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
148032
+ if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
147464
148033
  createGeneratorPrototypes(options.budget);
147465
148034
  registerBuiltinIdentities(options.budget, bindings);
147466
148035
  return bindings;
@@ -147600,7 +148169,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
147600
148169
  }
147601
148170
  state(node.state);
147602
148171
  } else if (node.kind === "guest-object" || node.kind === "guest-array") {
147603
- fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
148172
+ fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : ["errorType"]);
148173
+ if (Object.hasOwn(node, "errorType") && !sandboxErrorNames.includes(node.errorType))
148174
+ throw new TypeError("Invalid guest error type.");
147604
148175
  if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
147605
148176
  if (Object.hasOwn(node, "templateNodeId") && integer2(node.templateNodeId) < 1)
147606
148177
  throw new TypeError("Invalid template source identity.");
@@ -147885,6 +148456,7 @@ var init_guest_heap_validation = __esm({
147885
148456
  "packages/safe-js/src/snapshot/guest-heap-validation.ts"() {
147886
148457
  "use strict";
147887
148458
  init_budget2();
148459
+ init_shape();
147888
148460
  init_raw_json();
147889
148461
  init_globals();
147890
148462
  init_intrinsics();
@@ -148204,6 +148776,10 @@ function validateDumpHeap(root, state) {
148204
148776
  if (entry.kind === "float32array") {
148205
148777
  validateFloat32Storage(entry);
148206
148778
  requireRecord3(entry.entries, `${path193}.entries`);
148779
+ if (Object.hasOwn(entry, "state")) {
148780
+ if (Object.keys(entry.entries).length !== 0) fail2("invalidValue", path193, "ambiguous Float32Array property state");
148781
+ validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
148782
+ }
148207
148783
  continue;
148208
148784
  }
148209
148785
  if (entry.kind === "arguments") {
@@ -148432,6 +149008,10 @@ function validateHeapValue(value, path193, state, heap) {
148432
149008
  if (record4.kind === "float32array") {
148433
149009
  validateFloat32Storage(record4);
148434
149010
  requireRecord3(record4.entries, `${path193}.entries`);
149011
+ if (Object.hasOwn(record4, "state")) {
149012
+ if (Object.keys(record4.entries).length !== 0) fail2("invalidValue", path193, "ambiguous Float32Array property state");
149013
+ validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
149014
+ }
148435
149015
  }
148436
149016
  if (record4.kind === "map") {
148437
149017
  const entries = requireArray(record4.entries, `${path193}.entries`, state);
@@ -148564,7 +149144,7 @@ function validateArrayHeap(record4, path193, state) {
148564
149144
  }
148565
149145
  function validateErrorType(record4, path193) {
148566
149146
  if (!Object.hasOwn(record4, "errorType")) return;
148567
- if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
149147
+ if (record4.kind !== "object" && record4.kind !== "guest-object" || !sandboxErrorNames.includes(record4.errorType)) {
148568
149148
  fail2("invalidValue", `${path193}.errorType`, "invalid error metadata");
148569
149149
  }
148570
149150
  }