poe-code 14.0.82 → 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 (34) hide show
  1. package/dist/index.js +543 -156
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-7LGBDF56.js → chunk-37V6Q4K3.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-V6LQP64H.js → chunk-PT7PBLVT.js} +457 -91
  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/float32-prototypes.d.ts +3 -0
  12. package/packages/safe-js/dist/interp/float32-prototypes.js +1 -0
  13. package/packages/safe-js/dist/interp/float32.d.ts +1 -0
  14. package/packages/safe-js/dist/interp/float32.js +12 -4
  15. package/packages/safe-js/dist/interp/globals/float32array.d.ts +3 -2
  16. package/packages/safe-js/dist/interp/globals/float32array.js +371 -65
  17. package/packages/safe-js/dist/interp/globals/object-array.js +3 -3
  18. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  19. package/packages/safe-js/dist/interp/globals.js +4 -2
  20. package/packages/safe-js/dist/interp/instanceof.js +1 -1
  21. package/packages/safe-js/dist/interp/interpreter.js +2 -4
  22. package/packages/safe-js/dist/interp/iteration.js +15 -6
  23. package/packages/safe-js/dist/interp/object-model.js +16 -1
  24. package/packages/safe-js/dist/interp/values.js +12 -4
  25. package/packages/safe-js/dist/parse/parser.js +8 -3
  26. package/packages/safe-js/dist/parse/tokenizer.js +45 -3
  27. package/packages/safe-js/dist/snapshot/float32array.d.ts +3 -0
  28. package/packages/safe-js/dist/snapshot/float32array.js +20 -1
  29. package/packages/safe-js/dist/snapshot/restore.js +17 -2
  30. package/packages/safe-js/dist/snapshot/serialize.d.ts +2 -1
  31. package/packages/safe-js/dist/snapshot/serialize.js +10 -9
  32. package/packages/safe-js/dist/snapshot/validation.js +10 -0
  33. package/packages/safe-js/dist/chunks/chunk-V6LQP64H.js.map +0 -7
  34. /package/packages/safe-js/dist/chunks/{chunk-7LGBDF56.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
  }
@@ -127677,6 +127708,91 @@ var init_error_prototypes = __esm({
127677
127708
  }
127678
127709
  });
127679
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
+
127680
127796
  // packages/safe-js/src/interp/object-model.ts
127681
127797
  function registerGuestClosure(closure) {
127682
127798
  guestClosures.add(closure);
@@ -127883,11 +127999,13 @@ function releaseObjectPrototype(budget) {
127883
127999
  functionPrototypes.delete(budget);
127884
128000
  generatorPrototypes.delete(budget);
127885
128001
  errorPrototypes.delete(budget);
128002
+ float32Prototypes.delete(budget);
127886
128003
  initialRegexDescriptors.delete(budget);
127887
128004
  intrinsicPrototypes.delete(budget);
127888
128005
  }
127889
128006
  function getSandboxPrototype(value, budget) {
127890
128007
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
128008
+ if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
127891
128009
  const errorType = sandboxErrorTypes.get(value);
127892
128010
  if (budget !== void 0 && errorType !== void 0) {
127893
128011
  const prototype = errorPrototypes.get(budget)?.get(errorType);
@@ -127920,6 +128038,8 @@ function getSandboxPropertyDescriptor(value, key3, budget) {
127920
128038
  let current = value;
127921
128039
  let depth = 0;
127922
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);
127923
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;
127924
128044
  if (properties === void 0 && isGuestClosure(current) && (key3 === "name" || key3 === "length"))
127925
128045
  return {
@@ -127942,6 +128062,8 @@ function getSandboxDataProperty(value, key3, budget) {
127942
128062
  let current = value;
127943
128063
  let depth = 0;
127944
128064
  while (typeof current === "object" && current !== null) {
128065
+ if (isFloat32Array(current) && typeof key3 !== "symbol" && isFloat32Index(String(key3)))
128066
+ return Object.getOwnPropertyDescriptor(current, key3)?.value;
127945
128067
  if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
127946
128068
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key3)?.value;
127947
128069
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key3)?.value;
@@ -127993,6 +128115,7 @@ function setSandboxPrototype(value, prototype, budget) {
127993
128115
  prototypes.set(value, prototype);
127994
128116
  }
127995
128117
  function isPrototypeRecord(value) {
128118
+ if (isFloat32Array(value)) return true;
127996
128119
  if (isGuestClosure(value)) return true;
127997
128120
  if (isGuestHostObject(value)) return false;
127998
128121
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
@@ -128012,7 +128135,7 @@ function hasGuestObjectState(value) {
128012
128135
  if (isLiveCapability(value)) return true;
128013
128136
  if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
128014
128137
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
128015
- 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(
128016
128139
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
128017
128140
  );
128018
128141
  }
@@ -128030,6 +128153,8 @@ var init_object_model = __esm({
128030
128153
  init_accessors();
128031
128154
  init_host_capabilities();
128032
128155
  init_error_prototypes();
128156
+ init_float32();
128157
+ init_float32_prototypes();
128033
128158
  init_shape();
128034
128159
  init_boxed();
128035
128160
  init_values();
@@ -128079,75 +128204,6 @@ var init_raw_json = __esm({
128079
128204
  }
128080
128205
  });
128081
128206
 
128082
- // packages/safe-js/src/interp/float32.ts
128083
- function isFloat32Array(value) {
128084
- return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
128085
- }
128086
- function float32Storage(value) {
128087
- const buffer = Reflect.apply(readBuffer, value, []);
128088
- if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype || bufferResizable !== void 0 && Reflect.apply(bufferResizable, buffer, [])) {
128089
- throw new TypeError("Float32Array requires a fixed, non-shared ArrayBuffer.");
128090
- }
128091
- return {
128092
- buffer,
128093
- byteOffset: Reflect.apply(readOffset, value, []),
128094
- length: Reflect.apply(readLength, value, []),
128095
- byteLength: Reflect.apply(bufferLength, buffer, [])
128096
- };
128097
- }
128098
- function float32DataProperties(value) {
128099
- if (Object.getOwnPropertySymbols(value).length > 0)
128100
- throw new TypeError("Float32Array symbol properties are not supported.");
128101
- const properties = [];
128102
- for (const key3 of Object.getOwnPropertyNames(value)) {
128103
- if (isFloat32Index(key3)) continue;
128104
- const descriptor = Object.getOwnPropertyDescriptor(value, key3);
128105
- if (!("value" in descriptor))
128106
- throw new TypeError(`Float32Array accessor property '${key3}' is not supported.`);
128107
- properties.push([key3, descriptor]);
128108
- }
128109
- return properties;
128110
- }
128111
- function isFloat32Index(key3) {
128112
- return key3 === "-0" || String(Number(key3)) === key3;
128113
- }
128114
- function float32Number(value) {
128115
- if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
128116
- throw new TypeError(
128117
- "Float32Array numeric arguments must be primitive numeric-coercible values."
128118
- );
128119
- }
128120
- return Number(value);
128121
- }
128122
- function checkFloat32Allocation(length, budget) {
128123
- budget.allocateArrayLength(length);
128124
- budget.provisionDataUsage(length * Float32Array.BYTES_PER_ELEMENT + 1)();
128125
- }
128126
- function copyFloat32Storage(value, state) {
128127
- const storage2 = float32Storage(value);
128128
- state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
128129
- let buffer = state.float32Buffers.get(storage2.buffer);
128130
- if (buffer === void 0) {
128131
- buffer = new ArrayBuffer(storage2.byteLength);
128132
- new Uint8Array(buffer).set(new Uint8Array(storage2.buffer));
128133
- state.float32Buffers.set(storage2.buffer, buffer);
128134
- }
128135
- return new Float32Array(buffer, storage2.byteOffset, storage2.length);
128136
- }
128137
- var typedArrayPrototype, readLength, readOffset, readBuffer, readTag, bufferLength, bufferResizable;
128138
- var init_float32 = __esm({
128139
- "packages/safe-js/src/interp/float32.ts"() {
128140
- "use strict";
128141
- typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
128142
- readLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
128143
- readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
128144
- readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
128145
- readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
128146
- bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
128147
- bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
128148
- }
128149
- });
128150
-
128151
128207
  // packages/safe-js/src/interp/promise-tracker.ts
128152
128208
  import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
128153
128209
  function assertPromiseExecutionAllowed() {
@@ -128817,6 +128873,8 @@ var init_float32array = __esm({
128817
128873
  "packages/safe-js/src/snapshot/float32array.ts"() {
128818
128874
  "use strict";
128819
128875
  init_float32();
128876
+ init_object_model();
128877
+ init_property_descriptors();
128820
128878
  }
128821
128879
  });
128822
128880
 
@@ -131008,6 +131066,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
131008
131066
  const iterator = await invokeBuiltinClosure(factory, [], budget, context, value);
131009
131067
  if (typeof iterator !== "object" && typeof iterator !== "function" || iterator === null)
131010
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);
131011
131071
  const next = await context.getProperty(iterator, "next");
131012
131072
  return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
131013
131073
  }
@@ -131040,7 +131100,7 @@ async function readIteratorResult(iterator, result, property) {
131040
131100
  }
131041
131101
  function getSandboxAsyncIterator(value, budget, context, signal) {
131042
131102
  if (isSandboxGenerator(value) && value.async) {
131043
- 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 };
131044
131104
  }
131045
131105
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
131046
131106
  const method = value[Symbol.asyncIterator];
@@ -131187,11 +131247,15 @@ function getSandboxIterator(value, budget, context) {
131187
131247
  }
131188
131248
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
131189
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
+ }
131190
131254
  return syncIterator(Float32Array.prototype.values.call(value));
131191
131255
  }
131192
131256
  if (isSandboxGenerator(value)) {
131193
131257
  if (value.async) return void 0;
131194
- 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;
131195
131259
  return generatorObjectIterator(value, budget, context);
131196
131260
  }
131197
131261
  if (typeof value === "string") {
@@ -131268,7 +131332,7 @@ function collectionIterator(collection, value) {
131268
131332
  adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
131269
131333
  return adapter;
131270
131334
  }
131271
- function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
131335
+ function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
131272
131336
  const bridge = {
131273
131337
  ...context,
131274
131338
  stack: context?.stack ?? [],
@@ -131282,7 +131346,7 @@ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal)
131282
131346
  let resolved;
131283
131347
  let pending;
131284
131348
  const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
131285
- 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.");
131286
131350
  return resolved = iterator;
131287
131351
  });
131288
131352
  return {
@@ -131391,6 +131455,7 @@ var init_iteration = __esm({
131391
131455
  init_values();
131392
131456
  init_running_state();
131393
131457
  init_float32();
131458
+ init_float32_prototypes();
131394
131459
  init_boxed();
131395
131460
  init_host_capabilities();
131396
131461
  init_collection_iterator();
@@ -135330,8 +135395,8 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
135330
135395
  }
135331
135396
  function defineDataProperty8(target, key3, descriptor, budget) {
135332
135397
  budget.visitNode();
135333
- if (isFloat32Array(target))
135334
- 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) };
135335
135400
  const properties = objectProperties(target, true);
135336
135401
  if (Array.isArray(properties)) {
135337
135402
  if (key3 === "length" && "value" in descriptor)
@@ -136285,8 +136350,9 @@ var init_set = __esm({
136285
136350
  });
136286
136351
 
136287
136352
  // packages/safe-js/src/interp/globals/float32array.ts
136288
- function createFloat32ArrayGlobal(budget) {
136353
+ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
136289
136354
  const constructor = createSandboxClosure({
136355
+ guest: nativePrototype,
136290
136356
  sandbox: true,
136291
136357
  name: "Float32Array",
136292
136358
  length: 3,
@@ -136294,32 +136360,307 @@ function createFloat32ArrayGlobal(budget) {
136294
136360
  call: () => {
136295
136361
  throw new TypeError("Constructor Float32Array requires 'new'.");
136296
136362
  },
136297
- construct: ([source]) => {
136298
- if (Array.isArray(source) || isFloat32Array(source)) {
136299
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
136300
- checkFloat32Allocation(length2, budget);
136301
- if (isFloat32Array(source)) return new Float32Array(source);
136302
- const result = new Float32Array(length2);
136303
- for (let index = 0; index < length2; index += 1) {
136304
- budget.visitNode();
136305
- const descriptor = Object.getOwnPropertyDescriptor(source, index);
136306
- if (descriptor !== void 0 && !("value" in descriptor))
136307
- throw new TypeError("Float32Array input accessors are not supported.");
136308
- result[index] = float32Number(descriptor?.value);
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();
136309
136376
  }
136310
- return result;
136311
- }
136312
- const number = float32Number(source);
136313
- const length = Number.isNaN(number) ? 0 : Math.trunc(number);
136314
- if (length < 0 || !Number.isSafeInteger(length))
136315
- throw new RangeError("Invalid typed array length.");
136316
- checkFloat32Allocation(length, budget);
136317
- return new Float32Array(length);
136377
+ })();
136318
136378
  }
136319
136379
  });
136320
136380
  constructors.add(constructor);
136321
136381
  return constructor;
136322
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;
136448
+ }
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,
136464
+ sandbox: true,
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();
136539
+ }
136540
+ }
136541
+ })
136542
+ });
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);
136663
+ }
136323
136664
  function isFloat32ArrayConstructor(value) {
136324
136665
  return typeof value === "object" && value !== null && constructors.has(value);
136325
136666
  }
@@ -136330,6 +136671,7 @@ function getFloat32Member(value, property, budget) {
136330
136671
  if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
136331
136672
  return descriptor.value;
136332
136673
  }
136674
+ if (float32Prototypes.has(budget)) return void 0;
136333
136675
  const storage2 = float32Storage(value);
136334
136676
  if (key3 === "length") return storage2.length;
136335
136677
  if (key3 === "byteLength") return storage2.length * 4;
@@ -136337,6 +136679,7 @@ function getFloat32Member(value, property, budget) {
136337
136679
  if (key3 === "BYTES_PER_ELEMENT") return 4;
136338
136680
  if (!["set", "slice", "subarray"].includes(key3)) return void 0;
136339
136681
  return createSandboxClosure({
136682
+ guest: true,
136340
136683
  sandbox: true,
136341
136684
  name: key3,
136342
136685
  length: key3 === "set" ? 1 : 2,
@@ -136345,65 +136688,88 @@ function getFloat32Member(value, property, budget) {
136345
136688
  if (!isFloat32Array(receiver))
136346
136689
  throw new TypeError(`Float32Array#${key3} requires a Float32Array receiver.`);
136347
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
+ };
136348
136701
  if (key3 === "set") {
136349
- const [source, offsetValue = 0] = args;
136350
- if (!Array.isArray(source) && !isFloat32Array(source))
136351
- throw new TypeError("Float32Array#set requires an array or Float32Array.");
136352
- const number = float32Number(offsetValue);
136353
- const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
136354
- const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
136355
- if (offset < 0 || !Number.isSafeInteger(offset) || offset + length2 > storage3.length)
136356
- throw new RangeError("Float32Array#set source is out of bounds.");
136357
- if (isFloat32Array(source)) {
136358
- Float32Array.prototype.set.call(receiver, source, offset);
136359
- return void 0;
136360
- }
136361
- checkFloat32Allocation(length2, budget);
136362
- const copied = new Float32Array(length2);
136363
- for (let index = 0; index < length2; index += 1) {
136364
- budget.visitNode();
136365
- const entry = Object.getOwnPropertyDescriptor(source, index);
136366
- if (entry !== void 0 && !("value" in entry))
136367
- throw new TypeError("Float32Array input accessors are not supported.");
136368
- copied[index] = float32Number(entry?.value);
136369
- }
136370
- Float32Array.prototype.set.call(receiver, copied, offset);
136371
- 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
+ })();
136372
136732
  }
136373
- const start = relativeIndex(args[0], storage3.length, 0);
136374
- const end = relativeIndex(args[1], storage3.length, storage3.length);
136375
- const length = Math.max(end - start, 0);
136376
- if (key3 === "subarray")
136377
- return new Float32Array(storage3.buffer, storage3.byteOffset + start * 4, length);
136378
- checkFloat32Allocation(length, budget);
136379
- const result = new Float32Array(length);
136380
- new Uint8Array(result.buffer).set(
136381
- new Uint8Array(storage3.buffer, storage3.byteOffset + start * 4, length * 4)
136382
- );
136383
- 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
+ })();
136384
136751
  }
136385
136752
  });
136386
136753
  }
136387
- function setFloat32Member(value, property, entry) {
136388
- const key3 = String(property);
136389
- 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)) {
136390
136757
  Reflect.set(value, key3, float32Number(entry));
136391
136758
  return;
136392
136759
  }
136393
136760
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
136394
- if (descriptor === void 0 && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key3))
136395
- throw new TypeError(`Cannot assign to read only property '${key3}'.`);
136396
- if (descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable))
136397
- 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)}'.`);
136398
136766
  Object.defineProperty(
136399
136767
  value,
136400
136768
  key3,
136401
136769
  descriptor === void 0 ? { value: entry, configurable: true, enumerable: true, writable: true } : { value: entry }
136402
136770
  );
136403
136771
  }
136404
- function relativeIndex(value, length, fallback) {
136405
- if (value === void 0) return fallback;
136406
- const numeric = float32Number(value);
136772
+ function relativeIndex(numeric, length) {
136407
136773
  const integer3 = Number.isNaN(numeric) ? 0 : Math.trunc(numeric);
136408
136774
  return integer3 < 0 ? Math.max(length + integer3, 0) : Math.min(integer3, length);
136409
136775
  }
@@ -136413,6 +136779,16 @@ var init_float32array2 = __esm({
136413
136779
  "use strict";
136414
136780
  init_float32();
136415
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();
136416
136792
  constructors = /* @__PURE__ */ new WeakSet();
136417
136793
  }
136418
136794
  });
@@ -136590,7 +136966,7 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
136590
136966
  budget.visitNode();
136591
136967
  return evaluateInstanceof(value, constructor.boundTarget, budget, context);
136592
136968
  }
136593
- if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
136969
+ if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
136594
136970
  if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
136595
136971
  if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
136596
136972
  const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
@@ -139190,7 +139566,7 @@ async function evaluateMemberCallExpression(node, context) {
139190
139566
  if (isFloat32Array(member.object)) {
139191
139567
  return evaluateResolvedCallExpression(
139192
139568
  node,
139193
- getFloat32Member(member.object, member.property, context.budget),
139569
+ await getPropertyValue(member.object, member.property, context),
139194
139570
  context,
139195
139571
  member.object
139196
139572
  );
@@ -139727,8 +140103,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
139727
140103
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
139728
140104
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
139729
140105
  if (isFloat32Array(target)) {
139730
- if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
139731
- setFloat32Member(target, property, value);
140106
+ setFloat32Member(target, property, value, budget);
139732
140107
  return;
139733
140108
  }
139734
140109
  if (isSandboxRegex(target)) {
@@ -142855,9 +143230,12 @@ function measureSandboxData(values, options = {}) {
142855
143230
  seen.add(storage2.buffer);
142856
143231
  usage += storage2.byteLength;
142857
143232
  }
142858
- for (const [key3, descriptor] of float32DataProperties(value)) {
142859
- usage += key3.length + 1;
142860
- 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);
142861
143239
  }
142862
143240
  return;
142863
143241
  }
@@ -147637,7 +148015,7 @@ function createBuiltinBindings(options) {
147637
148015
  const bindings = {
147638
148016
  ...createConsoleJsonGlobals(options),
147639
148017
  ...createCollectionGlobals(options),
147640
- Float32Array: createFloat32ArrayGlobal(options.budget),
148018
+ Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
147641
148019
  Date: createDateGlobal(options),
147642
148020
  Symbol: createSymbolGlobal(options.budget),
147643
148021
  BigInt: createBigIntGlobal(options.budget),
@@ -147650,6 +148028,7 @@ function createBuiltinBindings(options) {
147650
148028
  ...createRegexGlobals(options)
147651
148029
  };
147652
148030
  createFunctionPrototype(options.budget, options.functionHasInstance);
148031
+ if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
147653
148032
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
147654
148033
  createGeneratorPrototypes(options.budget);
147655
148034
  registerBuiltinIdentities(options.budget, bindings);
@@ -148397,6 +148776,10 @@ function validateDumpHeap(root, state) {
148397
148776
  if (entry.kind === "float32array") {
148398
148777
  validateFloat32Storage(entry);
148399
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
+ }
148400
148783
  continue;
148401
148784
  }
148402
148785
  if (entry.kind === "arguments") {
@@ -148625,6 +149008,10 @@ function validateHeapValue(value, path193, state, heap) {
148625
149008
  if (record4.kind === "float32array") {
148626
149009
  validateFloat32Storage(record4);
148627
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
+ }
148628
149015
  }
148629
149016
  if (record4.kind === "map") {
148630
149017
  const entries = requireArray(record4.entries, `${path193}.entries`, state);