@poe-platform/safe-js 0.1.720 → 0.1.721

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 (66) hide show
  1. package/README.md +15 -2
  2. package/dist/safe-js/chunks/{chunk-APKV5Y6T.js → chunk-4CX3HYRY.js} +2 -2
  3. package/dist/safe-js/chunks/{chunk-NJM2Q74Z.js → chunk-A4L72WXV.js} +4 -4
  4. package/dist/safe-js/chunks/{chunk-B2SQLK4O.js → chunk-B4M6QVUV.js} +2 -2
  5. package/dist/safe-js/chunks/{chunk-A7CADQAD.js → chunk-BEXRQET4.js} +3 -3
  6. package/dist/safe-js/chunks/{chunk-OP3H3ZDN.js → chunk-BHYBD6SY.js} +2 -2
  7. package/dist/safe-js/chunks/{chunk-KP6I45ET.js → chunk-DNA7BMBY.js} +192 -38
  8. package/dist/safe-js/chunks/{chunk-KP6I45ET.js.map → chunk-DNA7BMBY.js.map} +3 -3
  9. package/dist/safe-js/chunks/{chunk-U6KZ2DQ2.js → chunk-GMPZBMPA.js} +3 -3
  10. package/dist/safe-js/chunks/{chunk-IDQ67DY2.js → chunk-ILYJBA2D.js} +24 -3
  11. package/dist/safe-js/chunks/chunk-ILYJBA2D.js.map +7 -0
  12. package/dist/safe-js/chunks/{chunk-NEJ44T4Y.js → chunk-IS7YUCOF.js} +2 -2
  13. package/dist/safe-js/chunks/{chunk-BGJXQN4A.js → chunk-JNLY7IMV.js} +4 -4
  14. package/dist/safe-js/chunks/{chunk-RML35GIF.js → chunk-LPBTSTDG.js} +3 -3
  15. package/dist/safe-js/chunks/{chunk-KK5NCR5R.js → chunk-Q7B6JIMI.js} +110 -46
  16. package/dist/safe-js/chunks/chunk-Q7B6JIMI.js.map +7 -0
  17. package/dist/safe-js/chunks/{chunk-XMA6FOJU.js → chunk-Y4LNCDCP.js} +2 -2
  18. package/dist/safe-js/chunks/{cli-runtime-PO6DQDHP.js → cli-runtime-YK2WE33M.js} +13 -13
  19. package/dist/safe-js/chunks/{dump-TRGFSCJ7.js → dump-ATWBOZWV.js} +4 -4
  20. package/dist/safe-js/chunks/{fs-4T5MZW5J.js → fs-D72Y52I5.js} +4 -4
  21. package/dist/safe-js/chunks/harness-LUYCGWHZ.js +10 -0
  22. package/dist/safe-js/chunks/mcp-IWKZB2R2.js +11 -0
  23. package/dist/safe-js/chunks/migration-file-IXO5MLP4.js +12 -0
  24. package/dist/safe-js/chunks/restore-SI7HOC6C.js +13 -0
  25. package/dist/safe-js/chunks/run-SHI2PYR6.js +17 -0
  26. package/dist/safe-js/chunks/runtime-modules-OO72HTVF.js +10 -0
  27. package/dist/safe-js/cli.js +2 -2
  28. package/dist/safe-js/core.js +7 -7
  29. package/dist/safe-js/extensions.d.ts +3 -1
  30. package/dist/safe-js/index.js +13 -13
  31. package/dist/safe-js/interp/budget.d.ts +3 -0
  32. package/dist/safe-js/interp/scope.d.ts +4 -1
  33. package/dist/safe-js/interp/typed-array.d.ts +3 -0
  34. package/dist/safe-js/parse/dynamic-source.d.ts +1 -1
  35. package/dist/safe-js/parse/parser.d.ts +1 -1
  36. package/dist/safe-js/realm.d.ts +1 -0
  37. package/dist/safe-js/snapshot/guest-heap.d.ts +1 -0
  38. package/dist/toolcraft-design/prompts/primitives/note.d.ts +1 -1
  39. package/package.json +2 -2
  40. package/dist/safe-js/chunks/chunk-IDQ67DY2.js.map +0 -7
  41. package/dist/safe-js/chunks/chunk-KK5NCR5R.js.map +0 -7
  42. package/dist/safe-js/chunks/harness-DLEQ2Z3O.js +0 -10
  43. package/dist/safe-js/chunks/mcp-TNVEFJ6K.js +0 -11
  44. package/dist/safe-js/chunks/migration-file-IDIUFLKY.js +0 -12
  45. package/dist/safe-js/chunks/restore-P27AUZR2.js +0 -13
  46. package/dist/safe-js/chunks/run-KGAEHYMV.js +0 -17
  47. package/dist/safe-js/chunks/runtime-modules-KICK45EE.js +0 -10
  48. /package/dist/safe-js/chunks/{chunk-APKV5Y6T.js.map → chunk-4CX3HYRY.js.map} +0 -0
  49. /package/dist/safe-js/chunks/{chunk-NJM2Q74Z.js.map → chunk-A4L72WXV.js.map} +0 -0
  50. /package/dist/safe-js/chunks/{chunk-B2SQLK4O.js.map → chunk-B4M6QVUV.js.map} +0 -0
  51. /package/dist/safe-js/chunks/{chunk-A7CADQAD.js.map → chunk-BEXRQET4.js.map} +0 -0
  52. /package/dist/safe-js/chunks/{chunk-OP3H3ZDN.js.map → chunk-BHYBD6SY.js.map} +0 -0
  53. /package/dist/safe-js/chunks/{chunk-U6KZ2DQ2.js.map → chunk-GMPZBMPA.js.map} +0 -0
  54. /package/dist/safe-js/chunks/{chunk-NEJ44T4Y.js.map → chunk-IS7YUCOF.js.map} +0 -0
  55. /package/dist/safe-js/chunks/{chunk-BGJXQN4A.js.map → chunk-JNLY7IMV.js.map} +0 -0
  56. /package/dist/safe-js/chunks/{chunk-RML35GIF.js.map → chunk-LPBTSTDG.js.map} +0 -0
  57. /package/dist/safe-js/chunks/{chunk-XMA6FOJU.js.map → chunk-Y4LNCDCP.js.map} +0 -0
  58. /package/dist/safe-js/chunks/{cli-runtime-PO6DQDHP.js.map → cli-runtime-YK2WE33M.js.map} +0 -0
  59. /package/dist/safe-js/chunks/{dump-TRGFSCJ7.js.map → dump-ATWBOZWV.js.map} +0 -0
  60. /package/dist/safe-js/chunks/{fs-4T5MZW5J.js.map → fs-D72Y52I5.js.map} +0 -0
  61. /package/dist/safe-js/chunks/{harness-DLEQ2Z3O.js.map → harness-LUYCGWHZ.js.map} +0 -0
  62. /package/dist/safe-js/chunks/{mcp-TNVEFJ6K.js.map → mcp-IWKZB2R2.js.map} +0 -0
  63. /package/dist/safe-js/chunks/{migration-file-IDIUFLKY.js.map → migration-file-IXO5MLP4.js.map} +0 -0
  64. /package/dist/safe-js/chunks/{restore-P27AUZR2.js.map → restore-SI7HOC6C.js.map} +0 -0
  65. /package/dist/safe-js/chunks/{run-KGAEHYMV.js.map → run-SHI2PYR6.js.map} +0 -0
  66. /package/dist/safe-js/chunks/{runtime-modules-KICK45EE.js.map → runtime-modules-OO72HTVF.js.map} +0 -0
@@ -39,7 +39,7 @@ import {
39
39
  sandboxErrorTypes,
40
40
  syntaxDiagnostics,
41
41
  templateRealms
42
- } from "./chunk-IDQ67DY2.js";
42
+ } from "./chunk-ILYJBA2D.js";
43
43
 
44
44
  // packages/safe-js/src/interp/native-promise-properties.ts
45
45
  import { types } from "node:util";
@@ -1718,7 +1718,7 @@ function createDynamicSource(kind, parameters, body, owner) {
1718
1718
  registerDynamicSource(node, source);
1719
1719
  return { node, source };
1720
1720
  }
1721
- function createEvalSource(body, context, owner) {
1721
+ function createEvalSource(body, context, owner, filename) {
1722
1722
  const source = { kind: "eval", body, nodes: /* @__PURE__ */ new Map(), context: {
1723
1723
  strict: context.strict === true,
1724
1724
  newTarget: context.newTarget === true,
@@ -1727,7 +1727,7 @@ function createEvalSource(body, context, owner) {
1727
1727
  arguments: context.arguments !== false,
1728
1728
  privateNames: [...context.privateNames ?? []]
1729
1729
  } };
1730
- const parsed = parseEvalScript(body, { ...source.context, privateNames: new Set(source.context.privateNames) }, owner);
1730
+ const parsed = parseEvalScript(body, { ...source.context, privateNames: new Set(source.context.privateNames) }, owner, filename);
1731
1731
  registerDynamicSource(parsed.node, source);
1732
1732
  return { ...parsed, source };
1733
1733
  }
@@ -1855,6 +1855,80 @@ var readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").
1855
1855
  var readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
1856
1856
  var createValuesIterator = Object.getOwnPropertyDescriptor(typedArrayPrototype, "values").value;
1857
1857
  var typedArrayViewLayouts = /* @__PURE__ */ new WeakMap();
1858
+ var ownedViews = /* @__PURE__ */ new WeakMap();
1859
+ function createOwnedTypedArray(Native, args) {
1860
+ const view = Reflect.construct(Native, args);
1861
+ const keys = /* @__PURE__ */ new Set();
1862
+ const methods4 = /* @__PURE__ */ new WeakMap();
1863
+ const owned = new Proxy(view, {
1864
+ get(target, key, receiver) {
1865
+ const intrinsic = Object.getOwnPropertyDescriptor(
1866
+ typedArrayPrototype,
1867
+ key
1868
+ );
1869
+ if (!Object.hasOwn(target, key) && intrinsic !== void 0) {
1870
+ if (intrinsic.get !== void 0)
1871
+ return Reflect.get(target, key, target);
1872
+ if (key !== "constructor" && typeof intrinsic.value === "function") {
1873
+ const method = Reflect.get(target, key, target);
1874
+ const cached = methods4.get(method);
1875
+ if (cached !== void 0) return cached;
1876
+ const wrapper = function(...args2) {
1877
+ const native = typeof this === "object" && this !== null ? ownedViews.get(this)?.view ?? this : this;
1878
+ const callbackReceiver = native === target ? receiver : this;
1879
+ if ([
1880
+ "forEach",
1881
+ "map",
1882
+ "filter",
1883
+ "every",
1884
+ "some",
1885
+ "find",
1886
+ "findIndex",
1887
+ "findLast",
1888
+ "findLastIndex",
1889
+ "reduce",
1890
+ "reduceRight"
1891
+ ].includes(String(key)) && typeof args2[0] === "function") {
1892
+ const callback = args2[0];
1893
+ args2[0] = function(...values) {
1894
+ return Reflect.apply(
1895
+ callback,
1896
+ this,
1897
+ values.map(
1898
+ (value) => value === native ? callbackReceiver : value
1899
+ )
1900
+ );
1901
+ };
1902
+ }
1903
+ const result = Reflect.apply(method, native, args2);
1904
+ return result === native ? callbackReceiver : result;
1905
+ };
1906
+ methods4.set(method, wrapper);
1907
+ return wrapper;
1908
+ }
1909
+ }
1910
+ return Reflect.get(target, key, receiver);
1911
+ },
1912
+ defineProperty(target, key, descriptor) {
1913
+ const changed = Reflect.defineProperty(target, key, descriptor);
1914
+ if (changed && !(typeof key === "string" && isTypedArrayIndex(key)))
1915
+ keys.add(key);
1916
+ return changed;
1917
+ },
1918
+ deleteProperty(target, key) {
1919
+ const changed = Reflect.deleteProperty(target, key);
1920
+ if (changed) keys.delete(key);
1921
+ return changed;
1922
+ }
1923
+ });
1924
+ ownedViews.set(owned, { view, keys });
1925
+ const backing = float16BackingViews.get(view);
1926
+ if (backing !== void 0) float16BackingViews.set(owned, backing);
1927
+ return owned;
1928
+ }
1929
+ function nativeTypedArrayView(value) {
1930
+ return ownedViews.get(value)?.view ?? value;
1931
+ }
1858
1932
  var resizeBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
1859
1933
  function restoreTypedArrayView(buffer, byteOffset, length, budget, Native = Float32Array) {
1860
1934
  const originalLength = arrayBufferLength(buffer);
@@ -1879,19 +1953,21 @@ function restoreTypedArrayView(buffer, byteOffset, length, budget, Native = Floa
1879
1953
  function isNumericTypedArray(value) {
1880
1954
  if (typeof value === "object" && value !== null && float16BackingViews.has(value))
1881
1955
  return Object.getPrototypeOf(value) === Float16Array.prototype;
1956
+ if (typeof value === "object" && value !== null && ownedViews.has(value))
1957
+ return isNumericTypedArray(ownedViews.get(value).view);
1882
1958
  if (!ArrayBuffer.isView(value)) return false;
1883
1959
  const tag = Reflect.apply(readTag, value, []);
1884
1960
  return Object.hasOwn(numericTypedArrayConstructors, tag) && Object.getPrototypeOf(value) === numericTypedArrayConstructors[tag].prototype;
1885
1961
  }
1886
1962
  function typedArrayStorage(value, requireInBounds = false) {
1887
1963
  const backingView = float16BackingViews.get(value);
1888
- const view = backingView ?? value;
1964
+ const view = backingView ?? nativeTypedArrayView(value);
1889
1965
  if (requireInBounds) Reflect.apply(createValuesIterator, view, []);
1890
1966
  const buffer = Reflect.apply(readBuffer, view, []);
1891
1967
  if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype && !isSandboxSharedArrayBuffer(buffer)) {
1892
1968
  throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
1893
1969
  }
1894
- const Native = backingView === void 0 ? numericTypedArrayConstructors[Reflect.apply(readTag, value, [])] : Float16Array;
1970
+ const Native = backingView === void 0 ? numericTypedArrayConstructors[Reflect.apply(readTag, view, [])] : Float16Array;
1895
1971
  return {
1896
1972
  Native,
1897
1973
  elementSize: Native.BYTES_PER_ELEMENT,
@@ -1903,14 +1979,23 @@ function typedArrayStorage(value, requireInBounds = false) {
1903
1979
  }
1904
1980
  function typedArrayProperties(value) {
1905
1981
  const properties = [];
1906
- for (const key of Reflect.ownKeys(value)) {
1982
+ const tracked = ownedViews.get(value);
1983
+ const keys = tracked === void 0 ? Reflect.ownKeys(value) : [
1984
+ ...[...tracked.keys].filter((key) => typeof key === "string"),
1985
+ ...[...tracked.keys].filter((key) => typeof key === "symbol")
1986
+ ];
1987
+ for (const key of keys) {
1907
1988
  if (typeof key === "string" && isTypedArrayIndex(key)) continue;
1908
1989
  properties.push([key, Object.getOwnPropertyDescriptor(value, key)]);
1909
1990
  }
1910
1991
  return properties;
1911
1992
  }
1993
+ function typedArraySymbolKeys(value) {
1994
+ const tracked = ownedViews.get(value);
1995
+ return tracked === void 0 ? Object.getOwnPropertySymbols(value) : [...tracked.keys].filter((key) => typeof key === "symbol");
1996
+ }
1912
1997
  function typedArrayDataProperties(value) {
1913
- if (Object.getOwnPropertySymbols(value).length > 0)
1998
+ if (typedArraySymbolKeys(value).length > 0)
1914
1999
  throw new TypeError("Float32Array symbol properties are not supported.");
1915
2000
  const properties = [];
1916
2001
  for (const [key, descriptor] of typedArrayProperties(value)) {
@@ -5457,12 +5542,14 @@ async function suspendAsyncFunctionValue(value, node, context, replayState = con
5457
5542
  driver.suspension = "await";
5458
5543
  origin.awaitPhase = phase;
5459
5544
  }
5545
+ const releaseScope = retainValues(context.budget, () => context.scope.retainedDataRoots());
5460
5546
  try {
5461
5547
  const completion = await context.generatorYield(awaited, node.nodeId);
5462
5548
  if (context.generatorResume !== void 0) context.generatorResume.completed = true;
5463
5549
  if (completion.type === "throw") throw completion.value;
5464
5550
  return completion.value;
5465
5551
  } finally {
5552
+ releaseScope();
5466
5553
  if (origin !== void 0) origin.awaitPhase = void 0;
5467
5554
  leaveAwait();
5468
5555
  }
@@ -15434,7 +15521,7 @@ function hasBigIntContent(Native) {
15434
15521
  }
15435
15522
  function copyTypedArrayElements(target, source, offset, budget) {
15436
15523
  if (!float16BackingViews.has(target) && !float16BackingViews.has(source)) {
15437
- Reflect.apply(Float32Array.prototype.set, target, [source, offset]);
15524
+ Reflect.apply(Float32Array.prototype.set, nativeTypedArrayView(target), [nativeTypedArrayView(source), offset]);
15438
15525
  return;
15439
15526
  }
15440
15527
  const to = typedArrayStorage(target, true);
@@ -15516,7 +15603,7 @@ function createNumericTypedArrayGlobal(budget, nativePrototype = false, Native =
15516
15603
  throw new RangeError("Invalid Float32Array view length.");
15517
15604
  }
15518
15605
  budget.allocateArrayLength(length);
15519
- const result2 = Reflect.construct(Native, [buffer, offset, args[2] === void 0 ? void 0 : length]);
15606
+ const result2 = createOwnedTypedArray(Native, [buffer, offset, args[2] === void 0 ? void 0 : length]);
15520
15607
  if (arrayBufferOptions(buffer) !== void 0)
15521
15608
  typedArrayViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
15522
15609
  setSandboxPrototype(result2, prototype, budget);
@@ -15572,7 +15659,7 @@ async function allocateTypedArrayInput(source, budget, Native, context) {
15572
15659
  length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
15573
15660
  }
15574
15661
  checkTypedArrayAllocation(length, budget, Native.BYTES_PER_ELEMENT);
15575
- result = new Native(length);
15662
+ result = createOwnedTypedArray(Native, [length]);
15576
15663
  checkData(result, 0, true);
15577
15664
  for (let index = 0; index < length; index++) {
15578
15665
  budget.visitNode();
@@ -15590,11 +15677,11 @@ function allocateTypedArray(source, budget, Native) {
15590
15677
  checkTypedArrayAllocation(length2, budget, Native.BYTES_PER_ELEMENT);
15591
15678
  if (isNumericTypedArray(source)) {
15592
15679
  typedArrayStorage(source, true);
15593
- const result2 = new Native(length2);
15680
+ const result2 = createOwnedTypedArray(Native, [length2]);
15594
15681
  copyTypedArrayElements(result2, source, 0, budget);
15595
15682
  return result2;
15596
15683
  }
15597
- const result = new Native(length2);
15684
+ const result = createOwnedTypedArray(Native, [length2]);
15598
15685
  for (let index = 0; index < length2; index += 1) {
15599
15686
  budget.visitNode();
15600
15687
  const descriptor = Object.getOwnPropertyDescriptor(source, index);
@@ -15610,7 +15697,7 @@ function allocateTypedArray(source, budget, Native) {
15610
15697
  if (length < 0 || !Number.isSafeInteger(length))
15611
15698
  throw new RangeError("Invalid typed array length.");
15612
15699
  checkTypedArrayAllocation(length, budget, Native.BYTES_PER_ELEMENT);
15613
- return new Native(length);
15700
+ return createOwnedTypedArray(Native, [length]);
15614
15701
  }
15615
15702
  function createNumericTypedArrayPrototypes(budget, bindings) {
15616
15703
  const shared = createIntrinsicObject();
@@ -15892,7 +15979,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
15892
15979
  const release = retainValues(budget, () => [receiver, result, ...args]);
15893
15980
  try {
15894
15981
  checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15895
- result = new storage2.Native(storage2.length);
15982
+ result = createOwnedTypedArray(storage2.Native, [storage2.length]);
15896
15983
  if (resultPrototype !== void 0) setSandboxPrototype(result, resultPrototype, budget);
15897
15984
  createDataCheckpoint(budget, context)(result, 0, true);
15898
15985
  for (let index = 0; index < storage2.length; index++) {
@@ -15943,7 +16030,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
15943
16030
  const checkData = createDataCheckpoint(budget, bridge);
15944
16031
  try {
15945
16032
  checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15946
- items = new storage2.Native(storage2.length);
16033
+ items = createOwnedTypedArray(storage2.Native, [storage2.length]);
15947
16034
  if (key === "toSorted" && resultPrototype !== void 0) setSandboxPrototype(items, resultPrototype, budget);
15948
16035
  checkData(items, 0, true);
15949
16036
  for (let index = 0; index < storage2.length; index++) {
@@ -15952,7 +16039,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
15952
16039
  }
15953
16040
  if (storage2.length < 2) return items;
15954
16041
  checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
15955
- scratch = new storage2.Native(storage2.length);
16042
+ scratch = createOwnedTypedArray(storage2.Native, [storage2.length]);
15956
16043
  checkData(scratch, 0, true);
15957
16044
  for (let width = 1; width < storage2.length; width *= 2) {
15958
16045
  for (let start = 0; start < storage2.length; start += width * 2) {
@@ -16100,7 +16187,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
16100
16187
  if (index < 0 || index >= typedArrayStorage(receiver).length)
16101
16188
  throw new RangeError("Float32Array#with index is out of bounds.");
16102
16189
  checkTypedArrayAllocation(storage2.length, budget, storage2.elementSize);
16103
- result = new storage2.Native(storage2.length);
16190
+ result = createOwnedTypedArray(storage2.Native, [storage2.length]);
16104
16191
  if (resultPrototype !== void 0) setSandboxPrototype(result, resultPrototype, budget);
16105
16192
  createDataCheckpoint(budget, bridge)(result, 0, true);
16106
16193
  for (let offset = 0; offset < storage2.length; offset++) {
@@ -16258,7 +16345,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
16258
16345
  }
16259
16346
  if (key === "subarray") {
16260
16347
  if (result === void 0) {
16261
- result = Reflect.construct(storage2.Native, [storage2.buffer, offset, tracking ? void 0 : length]);
16348
+ result = createOwnedTypedArray(storage2.Native, [storage2.buffer, offset, tracking ? void 0 : length]);
16262
16349
  if (resultPrototype !== void 0) setSandboxPrototype(result, resultPrototype, budget);
16263
16350
  if (arrayBufferOptions(storage2.buffer) !== void 0)
16264
16351
  typedArrayViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
@@ -16267,7 +16354,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
16267
16354
  }
16268
16355
  if (result === void 0) {
16269
16356
  checkTypedArrayAllocation(length, budget, storage2.elementSize);
16270
- result = new storage2.Native(length);
16357
+ result = createOwnedTypedArray(storage2.Native, [length]);
16271
16358
  if (resultPrototype !== void 0) setSandboxPrototype(result, resultPrototype, budget);
16272
16359
  }
16273
16360
  if (!isNumericTypedArray(result)) throw new TypeError("TypedArray species must return typed storage.");
@@ -18637,6 +18724,8 @@ var Scope = class _Scope {
18637
18724
  #restoredBindings;
18638
18725
  #frameHydrated = false;
18639
18726
  #bindingDataRoots;
18727
+ #globalVarNames;
18728
+ #globalVarNameValues;
18640
18729
  child(bindings = {}, options = {}) {
18641
18730
  return new _Scope(bindings, this, void 0, {
18642
18731
  chargeData: true,
@@ -18649,14 +18738,18 @@ var Scope = class _Scope {
18649
18738
  scope.withEnvironment = true;
18650
18739
  return scope;
18651
18740
  }
18652
- resolveBinding(name, operations) {
18741
+ resolveBinding(name, operations, globalEnvironment) {
18653
18742
  if (this.#bindings.has(name)) return { kind: "binding", name, scope: this };
18654
- if (this.objectEnvironment !== void 0) return this.resolveObjectBinding(name, this.objectEnvironment, operations);
18655
- if (this.parent !== void 0) return this.parent.resolveBinding(name, operations);
18743
+ if (this.objectEnvironment !== void 0) return this.resolveObjectBinding(name, this.objectEnvironment, operations, globalEnvironment);
18744
+ if (this.parent !== void 0) return this.parent.resolveBinding(
18745
+ name,
18746
+ operations,
18747
+ this.options.globalEnvironment === true ? this : void 0
18748
+ );
18656
18749
  if (name === "undefined") return { kind: "binding", name, scope: this };
18657
18750
  return { kind: "unresolvable", name };
18658
18751
  }
18659
- async resolveObjectBinding(name, object, operations) {
18752
+ async resolveObjectBinding(name, object, operations, globalEnvironment) {
18660
18753
  if (await operations.has(object, name)) {
18661
18754
  let blocked = false;
18662
18755
  if (this.withEnvironment) {
@@ -18664,7 +18757,13 @@ var Scope = class _Scope {
18664
18757
  if (typeof unscopables === "object" && unscopables !== null)
18665
18758
  blocked = Boolean(await operations.get(unscopables, name));
18666
18759
  }
18667
- if (!blocked) return { kind: "object", name, object, withEnvironment: this.withEnvironment };
18760
+ if (!blocked) return {
18761
+ kind: "object",
18762
+ name,
18763
+ object,
18764
+ withEnvironment: this.withEnvironment,
18765
+ ...globalEnvironment === void 0 || this.withEnvironment ? {} : { globalEnvironment }
18766
+ };
18668
18767
  }
18669
18768
  if (this.parent !== void 0) return this.parent.resolveBinding(name, operations);
18670
18769
  if (name === "undefined") return { kind: "binding", name, scope: this };
@@ -18714,6 +18813,18 @@ var Scope = class _Scope {
18714
18813
  this.#bindingDataRoots = void 0;
18715
18814
  return true;
18716
18815
  }
18816
+ deleteGlobalBinding(name) {
18817
+ const object = this.parent?.objectEnvironment;
18818
+ if (this.options.globalEnvironment !== true || object === void 0)
18819
+ throw new TypeError("Missing global object environment.");
18820
+ if (!Object.hasOwn(object, name)) return true;
18821
+ const deleted = Reflect.deleteProperty(object, name);
18822
+ if (deleted && this.#globalVarNames?.delete(name)) {
18823
+ if (this.#globalVarNames.size === 0) this.#globalVarNames = void 0;
18824
+ this.#globalVarNameValues = void 0;
18825
+ }
18826
+ return deleted;
18827
+ }
18717
18828
  getOwnBindingKind(name) {
18718
18829
  return this.#bindings.get(name)?.kind;
18719
18830
  }
@@ -18756,6 +18867,7 @@ var Scope = class _Scope {
18756
18867
  }
18757
18868
  retainedValues() {
18758
18869
  const values = this.parent?.retainedValues() ?? [];
18870
+ if (this.#globalVarNames !== void 0) values.push(this.#globalVarNameValues ??= [...this.#globalVarNames]);
18759
18871
  if (this.moduleEnvironment !== void 0) values.push(...Object.values(this.moduleEnvironment.namespaces));
18760
18872
  if (this.resourceState !== void 0) values.push(this.resourceState);
18761
18873
  if (this.options.chargeData !== false) {
@@ -18773,6 +18885,7 @@ var Scope = class _Scope {
18773
18885
  }
18774
18886
  retainedDataRoots() {
18775
18887
  const values = this.parent?.retainedDataRoots() ?? [];
18888
+ if (this.#globalVarNames !== void 0) values.push(this.#globalVarNameValues ??= [...this.#globalVarNames]);
18776
18889
  if (this.withEnvironment && this.objectEnvironment !== void 0) values.push(this.objectEnvironment);
18777
18890
  if (this.moduleEnvironment !== void 0) values.push(...Object.values(this.moduleEnvironment.namespaces));
18778
18891
  if (this.resourceState !== void 0) values.push(this.resourceState);
@@ -18834,9 +18947,14 @@ var Scope = class _Scope {
18834
18947
  const object = this.parent?.objectEnvironment;
18835
18948
  if (object === void 0) throw new TypeError("Missing global object environment.");
18836
18949
  const descriptor = Object.getOwnPropertyDescriptor(object, name);
18837
- if (!definesFunction && descriptor !== void 0) return;
18838
- const attributes = definesFunction && descriptor?.configurable === false ? { value: options.functionValue } : { value: options?.functionValue, writable: true, enumerable: true, configurable: options?.deletable === true };
18839
- if (!Reflect.defineProperty(object, name, attributes)) throw new TypeError(`Cannot declare global '${name}'.`);
18950
+ if (definesFunction || descriptor === void 0) {
18951
+ const attributes = definesFunction && descriptor?.configurable === false ? { value: options.functionValue } : { value: options?.functionValue, writable: true, enumerable: true, configurable: options?.deletable === true };
18952
+ if (!Reflect.defineProperty(object, name, attributes)) throw new TypeError(`Cannot declare global '${name}'.`);
18953
+ }
18954
+ if (!this.#globalVarNames?.has(name)) {
18955
+ (this.#globalVarNames ??= /* @__PURE__ */ new Set()).add(name);
18956
+ this.#globalVarNameValues = void 0;
18957
+ }
18840
18958
  return;
18841
18959
  }
18842
18960
  const boundary = this.options.functionBoundary === true ? this : this.parent;
@@ -18877,7 +18995,7 @@ var Scope = class _Scope {
18877
18995
  throw new TypeError("Script execution requires a global environment.");
18878
18996
  const object = this.parent.objectEnvironment;
18879
18997
  for (const name of lexical) {
18880
- if (this.#bindings.has(name) || Object.getOwnPropertyDescriptor(object, name)?.configurable === false)
18998
+ if (this.#bindings.has(name) || this.#globalVarNames?.has(name) || Object.getOwnPropertyDescriptor(object, name)?.configurable === false)
18881
18999
  throw new SyntaxError(`Cannot redeclare global '${name}'.`);
18882
19000
  }
18883
19001
  for (const name of names) {
@@ -19055,6 +19173,7 @@ var Scope = class _Scope {
19055
19173
  importMeta: this.importMeta,
19056
19174
  functionBoundary: this.isFunctionBoundary(),
19057
19175
  ...this.options.globalEnvironment === true ? { globalEnvironment: true } : {},
19176
+ ...this.#globalVarNames === void 0 ? {} : { globalVarNames: [...this.#globalVarNames] },
19058
19177
  chargeData: this.options.chargeData !== false,
19059
19178
  bindings,
19060
19179
  cells,
@@ -19064,7 +19183,7 @@ var Scope = class _Scope {
19064
19183
  };
19065
19184
  }
19066
19185
  hydrateFrame(frame) {
19067
- if (this.#frameHydrated || this.#bindings.size !== 0 || this.importMeta !== void 0 || this.parent === void 0 && this.#restoredBindings.size !== 0)
19186
+ if (this.#frameHydrated || this.#bindings.size !== 0 || this.#globalVarNames !== void 0 || this.importMeta !== void 0 || this.parent === void 0 && this.#restoredBindings.size !== 0)
19068
19187
  throw new TypeError("Frame hydration requires a fresh scope.");
19069
19188
  if (frame.parent !== this.parent || frame.functionBoundary !== this.isFunctionBoundary() || frame.simpleCatchParameter !== this.options.simpleCatchParameter || frame.globalEnvironment === true !== (this.options.globalEnvironment === true) || frame.chargeData !== (this.options.chargeData !== false))
19070
19189
  throw new TypeError("Scope frame does not match its allocation.");
@@ -19085,6 +19204,17 @@ var Scope = class _Scope {
19085
19204
  referenced.add(id);
19086
19205
  }
19087
19206
  if (referenced.size !== cells.length) throw new TypeError("Unreferenced scope binding cell.");
19207
+ let globalVarNames;
19208
+ if (Object.hasOwn(frame, "globalVarNames")) {
19209
+ if (!Array.isArray(frame.globalVarNames) || frame.globalEnvironment !== true || frame.functionBoundary || frame.parent === void 0 || frame.objectEnvironment !== void 0 || frame.withObject !== void 0)
19210
+ throw new TypeError("Invalid global declaration history.");
19211
+ globalVarNames = /* @__PURE__ */ new Set();
19212
+ for (const name of frame.globalVarNames) {
19213
+ if (typeof name !== "string" || name.length === 0 || globalVarNames.has(name) || bindings.has(name))
19214
+ throw new TypeError("Invalid global declaration name.");
19215
+ globalVarNames.add(name);
19216
+ }
19217
+ }
19088
19218
  const restored = new Map(frame.restoredBindings ?? []);
19089
19219
  if (restored.size !== (frame.restoredBindings?.length ?? 0)) throw new TypeError("Duplicate restored binding.");
19090
19220
  this.importMeta = frame.importMeta;
@@ -19101,6 +19231,8 @@ var Scope = class _Scope {
19101
19231
  }
19102
19232
  if (this.parent === void 0)
19103
19233
  for (const [name, value] of restored) this.#restoredBindings.set(name, value);
19234
+ this.#globalVarNames = globalVarNames?.size ? globalVarNames : void 0;
19235
+ this.#globalVarNameValues = void 0;
19104
19236
  this.#frameHydrated = true;
19105
19237
  this.#bindingDataRoots = void 0;
19106
19238
  }
@@ -19679,6 +19811,7 @@ function captureGuestHeapNode(value, encode, weakEntries = [], weakTarget, final
19679
19811
  chargeData: frame.chargeData,
19680
19812
  ...frame.simpleCatchParameter === void 0 ? {} : { simpleCatchParameter: frame.simpleCatchParameter },
19681
19813
  ...frame.globalEnvironment === true ? { globalEnvironment: true } : {},
19814
+ ...frame.globalVarNames === void 0 ? {} : { globalVarNames: frame.globalVarNames },
19682
19815
  bindings: frame.bindings,
19683
19816
  ...frame.moduleEnvironment === void 0 ? {} : { moduleEnvironment: {
19684
19817
  available: [...frame.moduleEnvironment.available],
@@ -25199,7 +25332,7 @@ async function evaluateUnaryExpression(node, context) {
25199
25332
  async function evaluateDeleteExpression(node, context) {
25200
25333
  if (node.argument.type === "Identifier" && context.strict === false) {
25201
25334
  const reference = await context.scope.resolveBinding(node.argument.name, bindingOperations(context));
25202
- return { kind: "normal", hasValue: true, value: reference.kind === "unresolvable" ? true : reference.kind === "binding" ? reference.scope.deleteBinding(reference.name) : guestProxyStates.has(reference.object) ? await sandboxDeleteProperty(reference.object, reference.name, context.budget, createCoercionContext(context)) : deleteSandboxProperty(reference.object, reference.name, false) };
25335
+ return { kind: "normal", hasValue: true, value: reference.kind === "unresolvable" ? true : reference.kind === "binding" ? reference.scope.deleteBinding(reference.name) : reference.globalEnvironment !== void 0 ? reference.globalEnvironment.deleteGlobalBinding(reference.name) : guestProxyStates.has(reference.object) ? await sandboxDeleteProperty(reference.object, reference.name, context.budget, createCoercionContext(context)) : deleteSandboxProperty(reference.object, reference.name, false) };
25203
25336
  }
25204
25337
  if (node.argument.type !== "MemberExpression") {
25205
25338
  if (node.argument.type !== "Identifier") {
@@ -26496,6 +26629,7 @@ function createFunctionMethodOptions(context) {
26496
26629
  }
26497
26630
  async function invokeSandboxClosure(callee, args, context, stack, span, thisValue = void 0, construct = false, newTarget, directEval = false) {
26498
26631
  const leaveCall = context.budget.enterCall();
26632
+ let releaseScope;
26499
26633
  const realm = functionRealms.get(callee);
26500
26634
  const foreignContext = realm !== void 0 && realm !== activeFunctionRealmPrototypes.get(context.budget) ? intrinsicRealmContexts.get(realm) : void 0;
26501
26635
  const errorBudget = callee.sandbox === true ? foreignContext?.budget : void 0;
@@ -26522,6 +26656,8 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
26522
26656
  ...span === void 0 ? {} : { span }
26523
26657
  }
26524
26658
  ]);
26659
+ if (result instanceof Promise)
26660
+ releaseScope = retainValues(context.budget, () => context.scope.retainedDataRoots());
26525
26661
  if (isSandboxPromise(result) && result.synchronousPrefix !== void 0) {
26526
26662
  await result.synchronousPrefix;
26527
26663
  }
@@ -26535,6 +26671,7 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
26535
26671
  }
26536
26672
  throw captureException(error, stack, callee.sandbox === true, errorBudget);
26537
26673
  } finally {
26674
+ releaseScope?.();
26538
26675
  leaveCall();
26539
26676
  }
26540
26677
  }
@@ -38432,11 +38569,11 @@ async function waitForAtomicValue(view, index, expected, timeout, budget) {
38432
38569
  const resources = runResources.getStore();
38433
38570
  if (resources === void 0) {
38434
38571
  const startedAt = performance.now();
38435
- const result = Reflect.apply(nativeWait, Atomics, [view, index, expected, timeout]);
38572
+ const result = Reflect.apply(nativeWait, Atomics, [nativeTypedArrayView(view), index, expected, timeout]);
38436
38573
  return result.async ? { ...result, startedAt } : result;
38437
38574
  }
38438
38575
  resources.signal.throwIfAborted();
38439
- const immediate = Reflect.apply(nativeWait, Atomics, [view, index, expected, 0]);
38576
+ const immediate = Reflect.apply(nativeWait, Atomics, [nativeTypedArrayView(view), index, expected, 0]);
38440
38577
  if (immediate.value === "not-equal" || timeout <= 0) return immediate;
38441
38578
  let worker = workers.get(resources);
38442
38579
  if (worker === void 0) {
@@ -38501,7 +38638,7 @@ function createAtomicsGlobal(budget) {
38501
38638
  throw new RangeError("Invalid atomic access index.");
38502
38639
  if (name === "notify") {
38503
38640
  const count = args[2] === void 0 ? void 0 : await sandboxNumber(args[2], budget, context);
38504
- return shared ? Reflect.apply(method, Atomics, [view, index, count]) : 0;
38641
+ return shared ? Reflect.apply(method, Atomics, [nativeTypedArrayView(view), index, count]) : 0;
38505
38642
  }
38506
38643
  if (name === "wait" || name === "waitAsync") {
38507
38644
  const expected = storage.Native === BigInt64Array ? await sandboxBigInt(args[2], budget, context) : await sandboxNumber(args[2], budget, context);
@@ -38542,7 +38679,7 @@ function createAtomicsGlobal(budget) {
38542
38679
  for (let offset = 2; offset < method.length; offset++) {
38543
38680
  values.push(storage.Native === BigInt64Array || storage.Native === BigUint64Array ? await sandboxBigInt(args[offset], budget, context) : await sandboxNumber(args[offset], budget, context));
38544
38681
  }
38545
- return Reflect.apply(method, Atomics, [view, index, ...values]);
38682
+ return Reflect.apply(method, Atomics, [nativeTypedArrayView(view), index, ...values]);
38546
38683
  } finally {
38547
38684
  release();
38548
38685
  }
@@ -41514,7 +41651,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
41514
41651
  if (Object.hasOwn(environment, "construction")) reference(environment.construction, ["construction-environment"]);
41515
41652
  }
41516
41653
  } else {
41517
- fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState", "objectEnvironment", "withObject", "moduleEnvironment", "globalEnvironment", "simpleCatchParameter"]);
41654
+ fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState", "objectEnvironment", "withObject", "moduleEnvironment", "globalEnvironment", "globalVarNames", "simpleCatchParameter"]);
41518
41655
  if (node.simpleCatchParameter !== void 0) {
41519
41656
  const bindings = array(node.bindings);
41520
41657
  const cells2 = array(node.cells);
@@ -41581,6 +41718,17 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
41581
41718
  used.add(id);
41582
41719
  }
41583
41720
  if (used.size !== cells.length) throw new TypeError("Unreferenced guest binding cell.");
41721
+ if (Object.hasOwn(node, "globalVarNames")) {
41722
+ const declarations2 = array(node.globalVarNames);
41723
+ if (node.globalEnvironment !== true || node.functionBoundary !== false || absent(node.parent) || node.objectEnvironment !== void 0 || node.withObject !== void 0 || declarations2.length > maxArrayLength)
41724
+ throw new TypeError("Invalid global declaration history.");
41725
+ const declared = /* @__PURE__ */ new Set();
41726
+ for (const name of declarations2) {
41727
+ if (typeof name !== "string" || name.length === 0 || declared.has(name) || names.has(name))
41728
+ throw new TypeError("Invalid global declaration name.");
41729
+ declared.add(name);
41730
+ }
41731
+ }
41584
41732
  if (Object.hasOwn(node, "restoredBindings")) {
41585
41733
  if (!absent(node.parent)) throw new TypeError("Only root scopes own pending restored bindings.");
41586
41734
  const restoredNames = /* @__PURE__ */ new Set();
@@ -44988,7 +45136,7 @@ function ownSandboxSymbolKeys(value) {
44988
45136
  else if (isSandboxPromise(value)) value = getPromiseProperties(value);
44989
45137
  else if (isSandboxGenerator(value)) value = getGeneratorProperties(value);
44990
45138
  else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
44991
- return Object.getOwnPropertySymbols(Object(value)).filter((key) => !internalSymbols.has(key));
45139
+ return (isNumericTypedArray(value) ? typedArraySymbolKeys(value) : Object.getOwnPropertySymbols(Object(value))).filter((key) => !internalSymbols.has(key));
44992
45140
  }
44993
45141
  function ownEnumerableSandboxKeys(value, includeSymbols = false) {
44994
45142
  if (includeSymbols) {
@@ -45453,7 +45601,7 @@ function measureSandboxData(values, options = {}) {
45453
45601
  }
45454
45602
  }
45455
45603
  if (!isGuestHostObject(value)) {
45456
- const symbols = Object.getOwnPropertySymbols(value);
45604
+ const symbols = isNumericTypedArray(value) ? typedArraySymbolKeys(value) : Object.getOwnPropertySymbols(value);
45457
45605
  let descriptors2;
45458
45606
  for (const key of symbols) {
45459
45607
  if (internalSymbols.has(key)) continue;
@@ -47405,6 +47553,7 @@ export {
47405
47553
  isSandboxMap,
47406
47554
  isSandboxSet,
47407
47555
  runResources,
47556
+ retainValues,
47408
47557
  withRunResources,
47409
47558
  readDataRecord,
47410
47559
  readStringList,
@@ -47421,6 +47570,10 @@ export {
47421
47570
  revokeHostObject,
47422
47571
  createHostCallbackContext,
47423
47572
  accessDeniedSystemError,
47573
+ isSandboxArrayBuffer,
47574
+ arrayBufferLength,
47575
+ arrayBufferDetached,
47576
+ arrayBufferOptions,
47424
47577
  releaseObjectPrototype,
47425
47578
  setSandboxPrototype,
47426
47579
  isSandboxModuleNamespace,
@@ -47477,6 +47630,7 @@ export {
47477
47630
  reconcileCompiledValues,
47478
47631
  deepCopyFromSandbox,
47479
47632
  guestProxyStates,
47633
+ getRealmGlobalObject,
47480
47634
  DUMP_FORMAT_VERSION,
47481
47635
  inMemoryRunSnapshots,
47482
47636
  EXECUTION_SEMANTICS,
@@ -47558,4 +47712,4 @@ authorization of the copyright holder.
47558
47712
  SPDX-License-Identifier: Unicode-3.0
47559
47713
 
47560
47714
  */
47561
- //# sourceMappingURL=chunk-KP6I45ET.js.map
47715
+ //# sourceMappingURL=chunk-DNA7BMBY.js.map