poe-code 14.0.79 → 14.0.81

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 (47) hide show
  1. package/dist/index.js +772 -341
  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-B3AL4KJ3.js → chunk-2LNBLFJ3.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-BGSPSHLP.js → chunk-ZSYBRZU6.js} +644 -292
  7. package/packages/safe-js/dist/chunks/chunk-ZSYBRZU6.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/graph-depth.js +2 -1
  11. package/packages/safe-js/dist/index.js +2 -2
  12. package/packages/safe-js/dist/interp/async.d.ts +1 -1
  13. package/packages/safe-js/dist/interp/async.js +65 -43
  14. package/packages/safe-js/dist/interp/bound-function-state.d.ts +7 -0
  15. package/packages/safe-js/dist/interp/bound-function-state.js +1 -0
  16. package/packages/safe-js/dist/interp/bound-function.d.ts +4 -0
  17. package/packages/safe-js/dist/interp/bound-function.js +18 -0
  18. package/packages/safe-js/dist/interp/generator-properties.d.ts +3 -0
  19. package/packages/safe-js/dist/interp/generator-properties.js +9 -0
  20. package/packages/safe-js/dist/interp/generator-prototypes.d.ts +6 -0
  21. package/packages/safe-js/dist/interp/generator-prototypes.js +1 -0
  22. package/packages/safe-js/dist/interp/globals/function.d.ts +2 -0
  23. package/packages/safe-js/dist/interp/globals/function.js +32 -0
  24. package/packages/safe-js/dist/interp/globals/generator.d.ts +2 -0
  25. package/packages/safe-js/dist/interp/globals/generator.js +51 -0
  26. package/packages/safe-js/dist/interp/globals/object-array.js +28 -7
  27. package/packages/safe-js/dist/interp/globals/object.js +2 -1
  28. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  29. package/packages/safe-js/dist/interp/globals.js +4 -0
  30. package/packages/safe-js/dist/interp/instanceof.d.ts +4 -0
  31. package/packages/safe-js/dist/interp/instanceof.js +58 -0
  32. package/packages/safe-js/dist/interp/interpreter.js +16 -47
  33. package/packages/safe-js/dist/interp/iteration.js +76 -5
  34. package/packages/safe-js/dist/interp/methods/function.d.ts +5 -2
  35. package/packages/safe-js/dist/interp/methods/function.js +55 -42
  36. package/packages/safe-js/dist/interp/methods/generator.d.ts +4 -1
  37. package/packages/safe-js/dist/interp/methods/generator.js +12 -6
  38. package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
  39. package/packages/safe-js/dist/interp/object-model.js +69 -17
  40. package/packages/safe-js/dist/interp/string-coercion.js +3 -2
  41. package/packages/safe-js/dist/interp/values.js +21 -3
  42. package/packages/safe-js/dist/snapshot/guest-heap-validation.js +27 -3
  43. package/packages/safe-js/dist/snapshot/guest-heap.d.ts +9 -0
  44. package/packages/safe-js/dist/snapshot/guest-heap.js +11 -0
  45. package/packages/safe-js/dist/snapshot/restore.js +61 -7
  46. package/packages/safe-js/dist/chunks/chunk-BGSPSHLP.js.map +0 -7
  47. /package/packages/safe-js/dist/chunks/{chunk-B3AL4KJ3.js.map → chunk-2LNBLFJ3.js.map} +0 -0
@@ -7013,6 +7013,17 @@ function serializedDateTime(value) {
7013
7013
  // packages/safe-js/src/interp/internal-symbols.ts
7014
7014
  var internalSymbols = /* @__PURE__ */ new Set();
7015
7015
 
7016
+ // packages/safe-js/src/interp/generator-properties.ts
7017
+ var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
7018
+ function getGeneratorProperties(value) {
7019
+ let properties = generatorGuestProperties.get(value);
7020
+ if (properties === void 0) {
7021
+ properties = /* @__PURE__ */ Object.create(null);
7022
+ generatorGuestProperties.set(value, properties);
7023
+ }
7024
+ return properties;
7025
+ }
7026
+
7016
7027
  // packages/safe-js/src/interp/regexp-properties.ts
7017
7028
  var regexGuestProperties = /* @__PURE__ */ new WeakMap();
7018
7029
  function getRegexProperties(value) {
@@ -7355,7 +7366,7 @@ function walkGraphDepth(root, rootPath, assertDepth) {
7355
7366
  }
7356
7367
  }
7357
7368
  function graphEntries(value) {
7358
- const properties = regexGuestProperties.get(value);
7369
+ const properties = regexGuestProperties.get(value) ?? generatorGuestProperties.get(value);
7359
7370
  if (properties !== void 0) return Reflect.ownKeys(properties).flatMap((key) => {
7360
7371
  const descriptor = Object.getOwnPropertyDescriptor(properties, key);
7361
7372
  return "value" in descriptor ? [[`.${String(key)}`, descriptor.value]] : [];
@@ -7387,6 +7398,58 @@ function graphEntries(value) {
7387
7398
  return entries;
7388
7399
  }
7389
7400
 
7401
+ // packages/safe-js/src/interp/generator-prototypes.ts
7402
+ var generatorPrototypes = /* @__PURE__ */ new WeakMap();
7403
+
7404
+ // packages/safe-js/src/interp/resources.ts
7405
+ import { AsyncLocalStorage } from "node:async_hooks";
7406
+ var runResources = new AsyncLocalStorage();
7407
+ function retainValues(budget, values) {
7408
+ const retained = {};
7409
+ budget.setRetainedValues(retained, values);
7410
+ const pending = runResources.getStore()?.referenceReleases;
7411
+ const release = () => {
7412
+ budget.setRetainedValues(retained, void 0);
7413
+ pending?.delete(release);
7414
+ };
7415
+ pending?.add(release);
7416
+ return release;
7417
+ }
7418
+ async function withRunResources(signal, execute) {
7419
+ const controller = new AbortController();
7420
+ const cancel = () => controller.abort(signal?.reason);
7421
+ const cleanups = /* @__PURE__ */ new Set();
7422
+ const resources = {
7423
+ signal: controller.signal,
7424
+ referenceReleases: /* @__PURE__ */ new Set(),
7425
+ add(close) {
7426
+ cleanups.add(close);
7427
+ }
7428
+ };
7429
+ signal?.addEventListener("abort", cancel, { once: true });
7430
+ if (signal?.aborted) cancel();
7431
+ let result;
7432
+ let failure;
7433
+ let errors = [];
7434
+ try {
7435
+ result = await runResources.run(resources, execute);
7436
+ } catch (error) {
7437
+ failure = { reason: error };
7438
+ } finally {
7439
+ signal?.removeEventListener("abort", cancel);
7440
+ controller.abort(new Error("SafeJS run finished."));
7441
+ for (const release of resources.referenceReleases) release();
7442
+ resources.referenceReleases.clear();
7443
+ const outcomes = await Promise.allSettled(
7444
+ [...cleanups].map((close) => Promise.resolve().then(close))
7445
+ );
7446
+ errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
7447
+ }
7448
+ if (failure !== void 0) throw failure.reason;
7449
+ if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
7450
+ return result;
7451
+ }
7452
+
7390
7453
  // packages/safe-js/src/interp/symbols.ts
7391
7454
  var wellKnownSymbols = Object.freeze({
7392
7455
  iterator: Symbol.iterator,
@@ -7802,6 +7865,7 @@ function namedKeys(state) {
7802
7865
  // packages/safe-js/src/interp/object-model.ts
7803
7866
  var guestClosures = /* @__PURE__ */ new WeakSet();
7804
7867
  var functionProperties = /* @__PURE__ */ new WeakMap();
7868
+ var functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
7805
7869
  var prototypes = /* @__PURE__ */ new WeakMap();
7806
7870
  var intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
7807
7871
  var boxedPrototypes = /* @__PURE__ */ new WeakMap();
@@ -7810,6 +7874,7 @@ var collectionPrototypes = /* @__PURE__ */ new WeakMap();
7810
7874
  var promisePrototypes = /* @__PURE__ */ new WeakMap();
7811
7875
  var datePrototypes = /* @__PURE__ */ new WeakMap();
7812
7876
  var arrayPrototypes = /* @__PURE__ */ new WeakMap();
7877
+ var functionPrototypes = /* @__PURE__ */ new WeakMap();
7813
7878
  var initialArrayMethods = /* @__PURE__ */ new WeakMap();
7814
7879
  var initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
7815
7880
  var intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
@@ -7845,9 +7910,23 @@ function materializeFunctionProperties(closure) {
7845
7910
  descriptorObjects.add(prototype);
7846
7911
  Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
7847
7912
  }
7848
- descriptorObjects.add(properties);
7849
- functionProperties.set(closure, properties);
7850
- return properties;
7913
+ const state = { revision: 0 };
7914
+ const tracked = new Proxy(properties, {
7915
+ defineProperty(target, key, descriptor) {
7916
+ const changed = Reflect.defineProperty(target, key, descriptor);
7917
+ if (changed) state.revision++;
7918
+ return changed;
7919
+ },
7920
+ deleteProperty(target, key) {
7921
+ const changed = Reflect.deleteProperty(target, key);
7922
+ if (changed) state.revision++;
7923
+ return changed;
7924
+ }
7925
+ });
7926
+ functionPropertyRevisions.set(tracked, state);
7927
+ descriptorObjects.add(tracked);
7928
+ functionProperties.set(closure, tracked);
7929
+ return tracked;
7851
7930
  }
7852
7931
  function getGuestFunctionProperty(closure, key) {
7853
7932
  let properties = functionProperties.get(closure);
@@ -7865,6 +7944,12 @@ function installObjectPrototype(budget, prototype, constructor) {
7865
7944
  intrinsicPrototypes.set(budget, prototype);
7866
7945
  registerIntrinsicPrototype(budget, prototype, constructor);
7867
7946
  }
7947
+ function installFunctionPrototype(budget, prototype) {
7948
+ functionPrototypes.set(budget, prototype);
7949
+ registerBuiltinIdentities(budget, { "%FunctionPrototype%": prototype });
7950
+ registerIntrinsicFunction(budget, prototype);
7951
+ registerIntrinsicObject(budget, materializeFunctionProperties(prototype));
7952
+ }
7868
7953
  function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
7869
7954
  let state = boxedPrototypes.get(budget);
7870
7955
  if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
@@ -7951,6 +8036,9 @@ function trackIntrinsicState(budget, root, owner, targets) {
7951
8036
  explicit: hasExplicitSandboxPrototype(target)
7952
8037
  })).map((record4) => ({
7953
8038
  ...record4,
8039
+ revision: functionPropertyRevisions.get(record4.value),
8040
+ capturedRevision: -1,
8041
+ captured: [],
7954
8042
  extensible: Object.isExtensible(record4.value),
7955
8043
  descriptors: new Map(Reflect.ownKeys(record4.value).map((key) => [key, Object.getOwnPropertyDescriptor(record4.value, key)]))
7956
8044
  }));
@@ -7966,14 +8054,21 @@ function trackIntrinsicState(budget, root, owner, targets) {
7966
8054
  );
7967
8055
  budget.setRetainedValues(root, () => {
7968
8056
  const retained = [];
7969
- for (const { target, value, descriptors: descriptors2, prototype: parent } of records) {
8057
+ for (const record4 of records) {
8058
+ const { target, value, descriptors: descriptors2, prototype: parent, revision } = record4;
7970
8059
  const currentPrototype = getSandboxPrototype(target);
7971
8060
  if (currentPrototype !== parent) retained.push(currentPrototype);
7972
- for (const key of Reflect.ownKeys(value)) {
7973
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
7974
- if (unchanged(descriptors2.get(key), descriptor)) continue;
7975
- retained.push(key, descriptor.value, ...retainedAccessorClosures(descriptor));
8061
+ if (revision === void 0 || revision.revision !== record4.capturedRevision) {
8062
+ const captured = [];
8063
+ for (const key of Reflect.ownKeys(value)) {
8064
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
8065
+ if (unchanged(descriptors2.get(key), descriptor)) continue;
8066
+ captured.push(key, descriptor.value, ...retainedAccessorClosures(descriptor));
8067
+ }
8068
+ record4.captured = captured;
8069
+ record4.capturedRevision = revision?.revision ?? -1;
7976
8070
  }
8071
+ for (const item of record4.captured) retained.push(item);
7977
8072
  }
7978
8073
  return retained;
7979
8074
  });
@@ -7989,11 +8084,15 @@ function releaseObjectPrototype(budget) {
7989
8084
  promisePrototypes.delete(budget);
7990
8085
  datePrototypes.delete(budget);
7991
8086
  arrayPrototypes.delete(budget);
8087
+ functionPrototypes.delete(budget);
8088
+ generatorPrototypes.delete(budget);
7992
8089
  initialRegexDescriptors.delete(budget);
7993
8090
  intrinsicPrototypes.delete(budget);
7994
8091
  }
7995
8092
  function getSandboxPrototype(value, budget) {
7996
8093
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
8094
+ if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
8095
+ return functionPrototypes.get(budget) ?? null;
7997
8096
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
7998
8097
  if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
7999
8098
  if (budget !== void 0 && isSandboxPromise(value)) return promisePrototypes.get(budget) ?? null;
@@ -8018,8 +8117,15 @@ function getSandboxPropertyDescriptor(value, key, budget) {
8018
8117
  return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key);
8019
8118
  let current = value;
8020
8119
  let depth = 0;
8021
- while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8022
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8120
+ while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8121
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8122
+ if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
8123
+ return {
8124
+ value: key === "name" ? current.name ?? "" : current.length ?? 0,
8125
+ writable: false,
8126
+ enumerable: false,
8127
+ configurable: true
8128
+ };
8023
8129
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
8024
8130
  if (descriptor !== void 0) return descriptor;
8025
8131
  current = getSandboxPrototype(current, budget);
@@ -8037,6 +8143,10 @@ function getSandboxDataProperty(value, key, budget) {
8037
8143
  if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
8038
8144
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
8039
8145
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key)?.value;
8146
+ if (isSandboxGenerator(current)) {
8147
+ const descriptor = Object.getOwnPropertyDescriptor(getGeneratorProperties(current), key);
8148
+ if (descriptor !== void 0) return descriptor.value;
8149
+ }
8040
8150
  if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key)?.value;
8041
8151
  if (isGuestClosure(current)) {
8042
8152
  const entry = getGuestFunctionProperty(current, key);
@@ -8045,9 +8155,9 @@ function getSandboxDataProperty(value, key, budget) {
8045
8155
  const properties = current.properties;
8046
8156
  return properties !== void 0 && Object.hasOwn(properties, key) ? properties[key] : void 0;
8047
8157
  }
8048
- if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
8158
+ if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current))
8049
8159
  return void 0;
8050
- if (!isSandboxClosure(current) && Object.hasOwn(current, key)) return current[key];
8160
+ if (!isSandboxClosure(current) && !isSandboxGenerator(current) && Object.hasOwn(current, key)) return current[key];
8051
8161
  current = getSandboxPrototype(current, budget);
8052
8162
  if (current !== null) {
8053
8163
  budget?.visitNode();
@@ -8060,7 +8170,7 @@ function setSandboxPrototype(value, prototype, budget) {
8060
8170
  if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
8061
8171
  throw new TypeError("Object.prototype has an immutable null prototype.");
8062
8172
  }
8063
- if (!Array.isArray(value) && !isSandboxDate(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isSandboxDate(prototype) && !isSandboxPromise(prototype) && !isSandboxRegex(prototype) && !isSandboxMap(prototype) && !isSandboxSet(prototype) && !isPrototypeRecord(prototype)) {
8173
+ if (!Array.isArray(value) && !isSandboxGenerator(value) && !isSandboxDate(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isSandboxGenerator(prototype) && !isSandboxDate(prototype) && !isSandboxPromise(prototype) && !isSandboxRegex(prototype) && !isSandboxMap(prototype) && !isSandboxSet(prototype) && !isPrototypeRecord(prototype)) {
8064
8174
  throw new TypeError(
8065
8175
  "Prototype links require supported sandbox objects."
8066
8176
  );
@@ -8069,7 +8179,7 @@ function setSandboxPrototype(value, prototype, budget) {
8069
8179
  if (prototype === null) prototypes.set(value, null);
8070
8180
  return;
8071
8181
  }
8072
- if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
8182
+ if (!Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
8073
8183
  throw new TypeError("Cannot change the prototype of a non-extensible object.");
8074
8184
  }
8075
8185
  let depth = 0;
@@ -8126,7 +8236,7 @@ function isRawJson(value) {
8126
8236
  import { types as nodeTypes } from "node:util";
8127
8237
 
8128
8238
  // packages/safe-js/src/interp/promise-tracker.ts
8129
- import { AsyncLocalStorage } from "node:async_hooks";
8239
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
8130
8240
  var SandboxPromiseRejectionTracker = class {
8131
8241
  records = /* @__PURE__ */ new Set();
8132
8242
  recordsByPromise = /* @__PURE__ */ new WeakMap();
@@ -8203,8 +8313,8 @@ var SandboxPromiseRejectionTracker = class {
8203
8313
  return void 0;
8204
8314
  }
8205
8315
  };
8206
- var activePromiseTracker = new AsyncLocalStorage();
8207
- var fatalRejectionCleanup = new AsyncLocalStorage();
8316
+ var activePromiseTracker = new AsyncLocalStorage2();
8317
+ var fatalRejectionCleanup = new AsyncLocalStorage2();
8208
8318
  function assertPromiseExecutionAllowed() {
8209
8319
  const failure = activePromiseTracker.getStore()?.failure;
8210
8320
  if (failure !== void 0 && fatalRejectionCleanup.getStore() !== true) throw failure;
@@ -8766,55 +8876,6 @@ function isLineTerminator(character) {
8766
8876
  return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
8767
8877
  }
8768
8878
 
8769
- // packages/safe-js/src/interp/resources.ts
8770
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
8771
- var runResources = new AsyncLocalStorage2();
8772
- function retainValues(budget, values) {
8773
- const retained = {};
8774
- budget.setRetainedValues(retained, values);
8775
- const pending = runResources.getStore()?.referenceReleases;
8776
- const release = () => {
8777
- budget.setRetainedValues(retained, void 0);
8778
- pending?.delete(release);
8779
- };
8780
- pending?.add(release);
8781
- return release;
8782
- }
8783
- async function withRunResources(signal, execute) {
8784
- const controller = new AbortController();
8785
- const cancel = () => controller.abort(signal?.reason);
8786
- const cleanups = /* @__PURE__ */ new Set();
8787
- const resources = {
8788
- signal: controller.signal,
8789
- referenceReleases: /* @__PURE__ */ new Set(),
8790
- add(close) {
8791
- cleanups.add(close);
8792
- }
8793
- };
8794
- signal?.addEventListener("abort", cancel, { once: true });
8795
- if (signal?.aborted) cancel();
8796
- let result;
8797
- let failure;
8798
- let errors = [];
8799
- try {
8800
- result = await runResources.run(resources, execute);
8801
- } catch (error) {
8802
- failure = { reason: error };
8803
- } finally {
8804
- signal?.removeEventListener("abort", cancel);
8805
- controller.abort(new Error("SafeJS run finished."));
8806
- for (const release of resources.referenceReleases) release();
8807
- resources.referenceReleases.clear();
8808
- const outcomes = await Promise.allSettled(
8809
- [...cleanups].map((close) => Promise.resolve().then(close))
8810
- );
8811
- errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
8812
- }
8813
- if (failure !== void 0) throw failure.reason;
8814
- if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
8815
- return result;
8816
- }
8817
-
8818
8879
  // packages/safe-js/src/interp/bigint-operators.ts
8819
8880
  function bigIntOperation(operator, left, right, budget) {
8820
8881
  if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
@@ -9384,7 +9445,10 @@ async function restoreSandboxIterator(snapshot, budget, context, signal) {
9384
9445
  if (snapshot.kind === "guest") return guestIterator(snapshot.value, snapshot.next, snapshot.async, budget, context, signal);
9385
9446
  if (snapshot.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot.inner, budget, context, signal), budget, signal, context);
9386
9447
  if (Array.isArray(snapshot.value)) return arrayIterator(snapshot.value, context, budget, snapshot.index);
9387
- const iterator = isSandboxGenerator(snapshot.value) && snapshot.value.async ? getSandboxAsyncIterator(snapshot.value, budget, context, signal) : getSandboxIterator(snapshot.value, budget, context);
9448
+ const iterator = isSandboxGenerator(snapshot.value) ? {
9449
+ ...generatorObjectIterator(snapshot.value, budget, context),
9450
+ ...snapshot.value.async ? { asyncProtocol: true } : {}
9451
+ } : getSandboxIterator(snapshot.value, budget, context);
9388
9452
  if (iterator === void 0) throw new TypeError("Invalid builtin iterator snapshot.");
9389
9453
  for (let index = 0; index < snapshot.index; index++) await iterator.next();
9390
9454
  return iterator;
@@ -9394,9 +9458,13 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9394
9458
  if (context.getProperty === void 0 || isGuestHostObject(value))
9395
9459
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
9396
9460
  if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9461
+ if (isSandboxGenerator(value)) {
9462
+ if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9463
+ return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
9464
+ }
9397
9465
  if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
9398
9466
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9399
- if (isSandboxGenerator(value) && value.async)
9467
+ if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
9400
9468
  return getSandboxAsyncIterator(value, budget, context, signal);
9401
9469
  const iterator2 = await acquireSandboxIterator(value, budget, context);
9402
9470
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
@@ -9458,7 +9526,7 @@ async function readIteratorResult(iterator, result, property) {
9458
9526
  }
9459
9527
  function getSandboxAsyncIterator(value, budget, context, signal) {
9460
9528
  if (isSandboxGenerator(value) && value.async) {
9461
- return { ...generatorIterator(value, budget, context), asyncProtocol: true };
9529
+ return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
9462
9530
  }
9463
9531
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
9464
9532
  const method = value[Symbol.asyncIterator];
@@ -9608,7 +9676,9 @@ function getSandboxIterator(value, budget, context) {
9608
9676
  return syncIterator(Float32Array.prototype.values.call(value));
9609
9677
  }
9610
9678
  if (isSandboxGenerator(value)) {
9611
- return value.async ? void 0 : generatorIterator(value);
9679
+ if (value.async) return void 0;
9680
+ if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9681
+ return generatorObjectIterator(value, budget, context);
9612
9682
  }
9613
9683
  if (typeof value === "string") {
9614
9684
  const iterator2 = value[Symbol.iterator]();
@@ -9685,6 +9755,58 @@ function collectionIterator(collection, value) {
9685
9755
  return adapter;
9686
9756
  }
9687
9757
  var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
9758
+ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
9759
+ const bridge = {
9760
+ ...context,
9761
+ stack: context?.stack ?? [],
9762
+ thisValue: value,
9763
+ invokeClosure: (closure, args, receiver, construct) => invokeBuiltinClosure(closure, args, budget, context, receiver, construct),
9764
+ getProperty: (target, key) => {
9765
+ const descriptor = getSandboxPropertyDescriptor(target, key, budget);
9766
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, target, bridge, true);
9767
+ }
9768
+ };
9769
+ let resolved;
9770
+ let pending;
9771
+ const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
9772
+ if (iterator === void 0) throw new TypeError("Generator does not provide an iterator protocol.");
9773
+ return resolved = iterator;
9774
+ });
9775
+ return {
9776
+ asynchronous: true,
9777
+ ...asyncProtocol ? { asyncProtocol: true } : {},
9778
+ get retainedValue() {
9779
+ return [value, resolved?.retainedValue];
9780
+ },
9781
+ snapshot: () => resolved?.snapshot?.() ?? { kind: "unsupported" },
9782
+ next: async (...args) => (await initialize()).next(...args),
9783
+ getOperation: async (method) => {
9784
+ const iterator = await initialize();
9785
+ return iterator.getOperation === void 0 ? iterator[method] : iterator.getOperation(method);
9786
+ },
9787
+ readResultProperty: async (result, property) => readIteratorResult(await initialize(), result, property)
9788
+ };
9789
+ }
9790
+ function generatorObjectIterator(generator, budget, context) {
9791
+ const iterator = generatorIterator(generator, budget, context);
9792
+ if (context?.getProperty === void 0) return iterator;
9793
+ return {
9794
+ ...iterator,
9795
+ getOperation: async (method) => {
9796
+ if (method === "next" || !hasExplicitSandboxPrototype(generator) && getSandboxPropertyDescriptor(generator, method, budget) === void 0) return iterator[method];
9797
+ const operation = await context.getProperty(generator, method);
9798
+ if (operation === void 0 || operation === null) return void 0;
9799
+ if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
9800
+ return async (...args) => {
9801
+ const result = await invokeBuiltinClosure(operation, args, budget ?? new Budget(), context, generator);
9802
+ return generator.async ? await awaitSandboxValue(result, void 0, budget, context) : result;
9803
+ };
9804
+ },
9805
+ readResultProperty: async (result, property) => ({
9806
+ value: await context.getProperty(result, property)
9807
+ })
9808
+ };
9809
+ }
9688
9810
  function generatorIterator(generator, budget, context) {
9689
9811
  const invoke = async (method, value) => {
9690
9812
  const leaveRunning = enterRunningState(generator);
@@ -10140,12 +10262,12 @@ async function evaluateFunctionExpression(node, context, evaluateNode2) {
10140
10262
  value: closure
10141
10263
  };
10142
10264
  }
10143
- function createInterpretedClosure(node, context, evaluateNode2, homeObject) {
10265
+ function createInterpretedClosure(node, context, evaluateNode2, homeObject, initializeGeneratorPrototype = true) {
10144
10266
  if (node.type !== "ArrowFunctionExpression") {
10145
10267
  context = { ...context, functionEnvironment: { homeObject } };
10146
10268
  }
10147
10269
  if (node.type !== "ArrowFunctionExpression" && node.generator) {
10148
- return createGeneratorClosure(node, context, evaluateNode2);
10270
+ return createGeneratorClosure(node, context, evaluateNode2, initializeGeneratorPrototype);
10149
10271
  }
10150
10272
  const construct = node.type !== "ArrowFunctionExpression" && !(node.type === "FunctionExpression" && node.method === true) && !node.async ? async (args, callContext) => {
10151
10273
  const thisValue = {};
@@ -10232,7 +10354,8 @@ function executeAsyncFunction(execute, budget, signal, callContext) {
10232
10354
  });
10233
10355
  return createSandboxPromise(promise, { synchronousPrefix });
10234
10356
  }
10235
- function createGeneratorClosure(node, context, evaluateNode2) {
10357
+ function createGeneratorClosure(node, context, evaluateNode2, initializePrototype) {
10358
+ const prototypes2 = !initializePrototype || runResources.getStore()?.functionSourceText === false ? void 0 : generatorPrototypes.get(context.budget)?.get(node.async === true);
10236
10359
  const closure = createSandboxClosure({
10237
10360
  sourceRange: functionSources.get(node),
10238
10361
  guest: true,
@@ -10242,54 +10365,69 @@ function createGeneratorClosure(node, context, evaluateNode2) {
10242
10365
  ...node.id === void 0 ? { name: context.inferredName } : { name: node.id.name },
10243
10366
  retainedValues: () => [...context.scope.retainedValues(), context.functionEnvironment?.homeObject, context.functionEnvironment?.newTarget],
10244
10367
  call: async (args, callContext) => {
10245
- const closureContext = {
10246
- ...context,
10247
- compilation: callContext?.compilation ?? context.compilation,
10248
- callStack: [...callContext?.stack ?? context.callStack]
10249
- };
10250
- const scope = await createClosureScope(
10251
- node,
10252
- args,
10253
- callContext?.thisValue,
10254
- closureContext,
10255
- evaluateNode2
10256
- );
10257
- const channel = createGeneratorChannel((generatorYield) => {
10258
- const execute = async () => {
10259
- const result = await evaluateNode2(node.body, {
10260
- ...closureContext,
10261
- functionBody: node.body,
10262
- asyncGenerator: node.async,
10263
- generatorBlockScopes: /* @__PURE__ */ new Map(),
10264
- generatorExpressionStates: /* @__PURE__ */ new Map(),
10265
- captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
10266
- origin.suspendedScope = suspendedScope;
10267
- origin.blockScopes = blocks;
10268
- origin.finallyCompletions = completions;
10269
- origin.expressionStates = expressions;
10270
- },
10271
- generatorYield: (value2, yieldNodeId) => {
10272
- generator.state = "suspended";
10273
- return generatorYield(value2, yieldNodeId);
10274
- },
10275
- scope
10276
- });
10277
- if (result.kind === "error") {
10278
- throw result.error;
10279
- }
10280
- if (result.kind === "throw") {
10281
- throw result.value;
10282
- }
10283
- const value = result.hasValue ? result.value : void 0;
10284
- return node.async ? awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)) : value;
10368
+ const candidate = prototypes2 === void 0 ? void 0 : getGuestFunctionProperty(closure, "prototype");
10369
+ const prototype = typeof candidate === "object" && candidate !== null ? candidate : prototypes2?.instancePrototype;
10370
+ const releasePrototype = prototype === void 0 ? void 0 : retainValues(context.budget, () => [prototype]);
10371
+ try {
10372
+ const closureContext = {
10373
+ ...context,
10374
+ compilation: callContext?.compilation ?? context.compilation,
10375
+ callStack: [...callContext?.stack ?? context.callStack]
10285
10376
  };
10286
- return node.async ? runAsyncPrefix(execute) : execute();
10287
- });
10288
- const generator = createSandboxGenerator(channel, { async: node.async });
10289
- const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
10290
- return generator;
10377
+ const scope = await createClosureScope(
10378
+ node,
10379
+ args,
10380
+ callContext?.thisValue,
10381
+ closureContext,
10382
+ evaluateNode2
10383
+ );
10384
+ const channel = createGeneratorChannel((generatorYield) => {
10385
+ const execute = async () => {
10386
+ const result = await evaluateNode2(node.body, {
10387
+ ...closureContext,
10388
+ functionBody: node.body,
10389
+ asyncGenerator: node.async,
10390
+ generatorBlockScopes: /* @__PURE__ */ new Map(),
10391
+ generatorExpressionStates: /* @__PURE__ */ new Map(),
10392
+ captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
10393
+ origin.suspendedScope = suspendedScope;
10394
+ origin.blockScopes = blocks;
10395
+ origin.finallyCompletions = completions;
10396
+ origin.expressionStates = expressions;
10397
+ },
10398
+ generatorYield: (value2, yieldNodeId) => {
10399
+ generator.state = "suspended";
10400
+ return generatorYield(value2, yieldNodeId);
10401
+ },
10402
+ scope
10403
+ });
10404
+ if (result.kind === "error") {
10405
+ throw result.error;
10406
+ }
10407
+ if (result.kind === "throw") {
10408
+ throw result.value;
10409
+ }
10410
+ const value = result.hasValue ? result.value : void 0;
10411
+ return node.async ? awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)) : value;
10412
+ };
10413
+ return node.async ? runAsyncPrefix(execute) : execute();
10414
+ });
10415
+ const generator = createSandboxGenerator(channel, { async: node.async });
10416
+ if (prototype !== void 0) setSandboxPrototype(generator, prototype, context.budget);
10417
+ const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
10418
+ return generator;
10419
+ } finally {
10420
+ releasePrototype?.();
10421
+ }
10291
10422
  }
10292
10423
  });
10424
+ if (prototypes2 !== void 0) {
10425
+ const prototype = /* @__PURE__ */ Object.create(null);
10426
+ markDescriptorObject(prototype);
10427
+ setSandboxPrototype(prototype, prototypes2.instancePrototype);
10428
+ Object.defineProperty(materializeFunctionProperties(closure), "prototype", { value: prototype, writable: true });
10429
+ setSandboxPrototype(closure, prototypes2.functionPrototype);
10430
+ }
10293
10431
  registerClosureOrigin(closure, node, context);
10294
10432
  return closure;
10295
10433
  }
@@ -13006,14 +13144,14 @@ function createObjectArrayGlobals(options) {
13006
13144
  call: ([value]) => {
13007
13145
  if (isGuestHostObject(value))
13008
13146
  throw new TypeError("Live host objects cannot be made non-extensible.");
13009
- Object.preventExtensions(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13147
+ Object.preventExtensions(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13010
13148
  return value;
13011
13149
  },
13012
13150
  name: "preventExtensions"
13013
13151
  }),
13014
13152
  isExtensible: createSandboxClosure({
13015
13153
  sandbox: true,
13016
- call: ([value]) => Object.isExtensible(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13154
+ call: ([value]) => Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13017
13155
  name: "isExtensible"
13018
13156
  }),
13019
13157
  seal: createSandboxClosure({
@@ -13021,14 +13159,14 @@ function createObjectArrayGlobals(options) {
13021
13159
  call: ([value]) => {
13022
13160
  if (isGuestHostObject(value))
13023
13161
  throw new TypeError("Live host objects cannot be sealed.");
13024
- Object.seal(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13162
+ Object.seal(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13025
13163
  return value;
13026
13164
  },
13027
13165
  name: "seal"
13028
13166
  }),
13029
13167
  isSealed: createSandboxClosure({
13030
13168
  sandbox: true,
13031
- call: ([value]) => Object.isSealed(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13169
+ call: ([value]) => Object.isSealed(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13032
13170
  name: "isSealed"
13033
13171
  }),
13034
13172
  freeze: createSandboxClosure({
@@ -13037,7 +13175,7 @@ function createObjectArrayGlobals(options) {
13037
13175
  if (isGuestHostObject(value))
13038
13176
  throw new TypeError("Live host objects cannot be frozen.");
13039
13177
  if (typeof value === "object" && value !== null) {
13040
- Object.freeze(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13178
+ Object.freeze(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
13041
13179
  }
13042
13180
  return value;
13043
13181
  },
@@ -13045,7 +13183,7 @@ function createObjectArrayGlobals(options) {
13045
13183
  }),
13046
13184
  isFrozen: createSandboxClosure({
13047
13185
  sandbox: true,
13048
- call: ([value]) => Object.isFrozen(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13186
+ call: ([value]) => Object.isFrozen(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
13049
13187
  name: "isFrozen"
13050
13188
  }),
13051
13189
  assign: createSandboxClosure({
@@ -13176,6 +13314,32 @@ function createArrayGlobal(budget) {
13176
13314
  length: 0,
13177
13315
  call: (_args, context) => context?.thisValue
13178
13316
  }), writable: true, configurable: true });
13317
+ const iteratorTagGetter = createSandboxClosure({
13318
+ guest: true,
13319
+ sandbox: true,
13320
+ name: "get [Symbol.toStringTag]",
13321
+ length: 0,
13322
+ call: () => "Iterator"
13323
+ });
13324
+ const iteratorTagSetter = createSandboxClosure({
13325
+ guest: true,
13326
+ sandbox: true,
13327
+ name: "set [Symbol.toStringTag]",
13328
+ length: 1,
13329
+ call: ([value], context) => {
13330
+ const receiver = context?.thisValue;
13331
+ if (receiver === iterablePrototype || receiver === null || typeof receiver !== "object")
13332
+ throw new TypeError("Iterator tag setter requires a distinct object receiver.");
13333
+ defineOwnDataProperty(objectProperties(receiver, true), Symbol.toStringTag, value);
13334
+ createDataCheckpoint(budget, context)(receiver, 0, true);
13335
+ return void 0;
13336
+ }
13337
+ });
13338
+ Object.defineProperty(iterablePrototype, Symbol.toStringTag, {
13339
+ get: accessorAdapter(iteratorTagGetter, "get"),
13340
+ set: accessorAdapter(iteratorTagSetter, "set"),
13341
+ configurable: true
13342
+ });
13179
13343
  setSandboxPrototype(iterablePrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
13180
13344
  setSandboxPrototype(iteratorPrototype, iterablePrototype);
13181
13345
  Object.defineProperties(iteratorPrototype, {
@@ -13189,6 +13353,9 @@ function createArrayGlobal(budget) {
13189
13353
  [Symbol.toStringTag]: { value: "Array Iterator", configurable: true }
13190
13354
  });
13191
13355
  registerBuiltinIdentities(budget, { "%ArrayIteratorPrototype%": iteratorPrototype, "%IteratorPrototype%": iterablePrototype });
13356
+ registerIntrinsicFunction(budget, iterablePrototype[Symbol.iterator]);
13357
+ registerIntrinsicFunction(budget, iteratorTagGetter);
13358
+ registerIntrinsicFunction(budget, iteratorTagSetter);
13192
13359
  registerIntrinsicObject(budget, iterablePrototype);
13193
13360
  registerIntrinsicObject(budget, iteratorPrototype);
13194
13361
  for (const method of ["keys", "values", "entries"]) {
@@ -13388,6 +13555,7 @@ function reflectionProperties(value) {
13388
13555
  return objectProperties(value);
13389
13556
  }
13390
13557
  function objectProperties(value, mutable = false) {
13558
+ if (isSandboxGenerator(value)) return getGeneratorProperties(value);
13391
13559
  if (isSandboxPromise(value)) return getPromiseProperties(value);
13392
13560
  if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
13393
13561
  if (isSandboxRegex(value)) return getRegexProperties(value);
@@ -13912,6 +14080,34 @@ function functionString(value) {
13912
14080
  return `function ${name}() { [native code] }`;
13913
14081
  }
13914
14082
 
14083
+ // packages/safe-js/src/interp/bound-function-state.ts
14084
+ var boundFunctionStates = /* @__PURE__ */ new WeakMap();
14085
+
14086
+ // packages/safe-js/src/interp/bound-function.ts
14087
+ function createBoundFunction(state, name, length, callClosure) {
14088
+ const bound = createSandboxClosure({
14089
+ guest: true,
14090
+ sandbox: true,
14091
+ name,
14092
+ length,
14093
+ boundTarget: state.target,
14094
+ retainedValues: () => [state.target, state.thisValue, ...state.args, bound.name],
14095
+ call: (args, context) => callClosure(state.target, [...state.args, ...args], context?.stack ?? [], state.thisValue),
14096
+ ...state.target.construct === void 0 ? {} : {
14097
+ construct: (args, context) => callClosure(
14098
+ state.target,
14099
+ [...state.args, ...args],
14100
+ context?.stack ?? [],
14101
+ void 0,
14102
+ true,
14103
+ context?.newTarget === bound ? state.target : context?.newTarget
14104
+ )
14105
+ }
14106
+ });
14107
+ boundFunctionStates.set(bound, state);
14108
+ return bound;
14109
+ }
14110
+
13915
14111
  // packages/safe-js/src/interp/methods/function.ts
13916
14112
  var functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
13917
14113
  function getFunctionMember(target, property, options) {
@@ -13929,7 +14125,7 @@ function getFunctionMember(target, property, options) {
13929
14125
  } else if (Object.hasOwn(current, String(property))) {
13930
14126
  return current[String(property)];
13931
14127
  }
13932
- if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current)) break;
14128
+ if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current) && getSandboxPrototype(current, options.budget) === null) break;
13933
14129
  current = getSandboxPrototype(current, options.budget);
13934
14130
  if (current !== null) {
13935
14131
  options.budget?.visitNode();
@@ -13963,28 +14159,11 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
13963
14159
  const thisValue = args[0];
13964
14160
  if (methodName === "bind") {
13965
14161
  const boundArgs = args.slice(1);
14162
+ const explicitPrototype = hasExplicitSandboxPrototype(target);
14163
+ const prototype = getSandboxPrototype(target, options.budget);
13966
14164
  const bind = (length, name) => {
13967
- const bound = createSandboxClosure({
13968
- guest: true,
13969
- sandbox: true,
13970
- name: `bound ${name}`,
13971
- length,
13972
- boundTarget: target,
13973
- retainedValues: () => [target, thisValue, ...boundArgs, bound.name],
13974
- call: (callArgs, context2) => options.callClosure(target, [...boundArgs, ...callArgs], context2?.stack ?? [], thisValue),
13975
- ...target.construct === void 0 ? {} : {
13976
- construct: (callArgs, context2) => options.callClosure(
13977
- target,
13978
- [...boundArgs, ...callArgs],
13979
- context2?.stack ?? [],
13980
- void 0,
13981
- true,
13982
- context2?.newTarget === bound ? target : context2?.newTarget
13983
- )
13984
- }
13985
- });
13986
- if (hasExplicitSandboxPrototype(target))
13987
- setSandboxPrototype(bound, getSandboxPrototype(target, options.budget), options.budget);
14165
+ const bound = createBoundFunction({ target, thisValue, args: boundArgs }, `bound ${name}`, length, options.callClosure);
14166
+ if (explicitPrototype) setSandboxPrototype(bound, prototype, options.budget);
13988
14167
  return bound;
13989
14168
  };
13990
14169
  if (context?.getProperty === void 0)
@@ -13993,15 +14172,20 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
13993
14172
  target.name ?? ""
13994
14173
  );
13995
14174
  return (async () => {
13996
- const properties = target.properties;
13997
- const defaultName = target.name;
13998
- const hasLength = !isGuestClosure(target) || target.properties === void 0 || Object.hasOwn(target.properties, "length");
13999
- const length = hasLength ? await context.getProperty(target, "length") : void 0;
14000
- const name = !isGuestClosure(target) && !Object.hasOwn(properties ?? {}, "name") ? defaultName : await context.getProperty(target, "name");
14001
- return bind(
14002
- typeof length === "number" && !Number.isNaN(length) ? Math.max(0, Math.trunc(length) - boundArgs.length) : 0,
14003
- typeof name === "string" ? name : ""
14004
- );
14175
+ const release = options.budget !== void 0 && explicitPrototype && prototype !== null ? retainValues(options.budget, () => [prototype]) : void 0;
14176
+ try {
14177
+ const properties = target.properties;
14178
+ const defaultName = target.name;
14179
+ const hasLength = !isGuestClosure(target) || target.properties === void 0 || Object.hasOwn(target.properties, "length");
14180
+ const length = hasLength ? await context.getProperty(target, "length") : void 0;
14181
+ const name = !isGuestClosure(target) && !Object.hasOwn(properties ?? {}, "name") ? defaultName : await context.getProperty(target, "name");
14182
+ return bind(
14183
+ typeof length === "number" && !Number.isNaN(length) ? Math.max(0, Math.trunc(length) - boundArgs.length) : 0,
14184
+ typeof name === "string" ? name : ""
14185
+ );
14186
+ } finally {
14187
+ release?.();
14188
+ }
14005
14189
  })();
14006
14190
  }
14007
14191
  if (methodName === "call") {
@@ -14011,25 +14195,37 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
14011
14195
  if (applyArgs === null || applyArgs === void 0) {
14012
14196
  return options.callClosure(target, [], stack, thisValue);
14013
14197
  }
14014
- if (!Array.isArray(applyArgs)) {
14015
- throw new TypeError("Function#apply requires an array or nullish arguments value.");
14198
+ if (typeof applyArgs !== "object") {
14199
+ throw new TypeError("Function#apply requires an object or nullish arguments value.");
14016
14200
  }
14017
- if (context?.getProperty === void 0)
14201
+ if (context?.getProperty === void 0 && Array.isArray(applyArgs))
14018
14202
  return options.callClosure(target, applyArgs, stack, thisValue);
14019
14203
  return (async () => {
14204
+ const budget = options.budget ?? new Budget();
14205
+ const invocationContext = {
14206
+ ...context,
14207
+ stack,
14208
+ thisValue: context?.thisValue,
14209
+ invokeClosure: context?.invokeClosure ?? ((callee, values2, receiver) => Promise.resolve(options.callClosure(callee, values2, stack, receiver)))
14210
+ };
14211
+ const read = (value, key) => {
14212
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
14213
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14214
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, invocationContext);
14215
+ };
14020
14216
  const values = [];
14021
- const length = applyArgs.length;
14022
- options.budget?.allocateArrayLength(length);
14023
- const retained = {};
14024
- options.budget?.setRetainedValues(retained, () => values);
14217
+ const release = retainValues(budget, () => [applyArgs, ...values]);
14025
14218
  try {
14219
+ const number = await sandboxNumber(await read(applyArgs, "length"), budget, invocationContext);
14220
+ const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14221
+ budget.allocateArrayLength(length);
14026
14222
  for (let index = 0; index < length; index++) {
14027
- options.budget?.visitNode();
14028
- values.push(await context.getProperty(applyArgs, index));
14223
+ budget.visitNode();
14224
+ values.push(await read(applyArgs, String(index)));
14029
14225
  }
14030
14226
  return await options.callClosure(target, values, stack, thisValue);
14031
14227
  } finally {
14032
- options.budget?.setRetainedValues(retained, void 0);
14228
+ release();
14033
14229
  }
14034
14230
  })();
14035
14231
  }
@@ -14186,16 +14382,19 @@ function getGeneratorMember(target, property, budget) {
14186
14382
  return createSandboxClosure({
14187
14383
  sandbox: true,
14188
14384
  name: property,
14189
- call: ([value], context) => {
14190
- const iterator = generatorIterator(target, budget, context);
14191
- const result = Promise.resolve(iterator[property](value)).then((result2) => allocateProducedSandboxValue(
14192
- { value: result2.value, done: result2.done === true },
14193
- budget
14194
- ));
14195
- return target.async ? createSandboxPromise(result) : result;
14196
- }
14385
+ call: ([value], context) => callGeneratorMethod(target, property, value, budget, context, target.async === true)
14197
14386
  });
14198
14387
  }
14388
+ function callGeneratorMethod(target, method, value, budget, context, async) {
14389
+ const result = (async () => {
14390
+ if (!isSandboxGenerator(target) || target.async === true !== async)
14391
+ throw new TypeError(`${async ? "AsyncGenerator" : "Generator"}.${method} requires a matching generator receiver.`);
14392
+ const iterator = generatorIterator(target, budget, context);
14393
+ const result2 = await iterator[method](value);
14394
+ return allocateProducedSandboxValue({ value: result2.value, done: result2.done === true }, budget);
14395
+ })();
14396
+ return async ? createSandboxPromise(result) : result;
14397
+ }
14199
14398
 
14200
14399
  // packages/safe-js/src/interp/methods/set.ts
14201
14400
  var setMethodNames = /* @__PURE__ */ new Set([
@@ -14275,74 +14474,6 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14275
14474
  }
14276
14475
  }
14277
14476
 
14278
- // packages/safe-js/src/interp/globals/error.ts
14279
- var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14280
- var errorNames = [
14281
- "Error",
14282
- "TypeError",
14283
- "RangeError",
14284
- "ReferenceError",
14285
- "SyntaxError",
14286
- "URIError",
14287
- "EvalError",
14288
- "AggregateError"
14289
- ];
14290
- function createErrorGlobals(options) {
14291
- return Object.fromEntries(
14292
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14293
- );
14294
- }
14295
- function isSandboxErrorConstructorInstance2(value, constructor) {
14296
- if (!isSandboxClosure(constructor)) {
14297
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14298
- }
14299
- const name = errorConstructorNames.get(constructor);
14300
- if (name === void 0) {
14301
- return false;
14302
- }
14303
- return isSandboxErrorConstructorInstance(value, name);
14304
- }
14305
- function createErrorConstructor(name, budget) {
14306
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14307
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14308
- errorConstructorNames.set(closure, name);
14309
- return closure;
14310
- }
14311
- function createSubsetError(name, args, stackFrames, budget) {
14312
- const message = name === "AggregateError" ? args[1] : args[0];
14313
- const options = name === "AggregateError" ? args[2] : args[1];
14314
- const error = createSubsetErrorValue(name, message, stackFrames, budget);
14315
- if (name === "AggregateError") {
14316
- const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14317
- budget.allocateArrayLength(errors.length);
14318
- error.errors = errors;
14319
- }
14320
- if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14321
- error.cause = options.cause;
14322
- }
14323
- return error;
14324
- }
14325
- function isObjectLike(value) {
14326
- return typeof value === "object" && value !== null;
14327
- }
14328
-
14329
- // packages/safe-js/src/interp/methods/collection-iterator.ts
14330
- function getCollectionIteratorMember(target, property, budget) {
14331
- if (Object.hasOwn(target, property)) return target[property];
14332
- if (property !== "next") return void 0;
14333
- const { collectionKind } = collectionIteratorState(target);
14334
- return createSandboxClosure({
14335
- sandbox: true,
14336
- name: "next",
14337
- call: (_args, context) => {
14338
- const receiver = context?.thisValue;
14339
- if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14340
- throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14341
- return nextCollectionIterator(receiver, budget);
14342
- }
14343
- });
14344
- }
14345
-
14346
14477
  // packages/safe-js/src/interp/globals/float32array.ts
14347
14478
  var constructors = /* @__PURE__ */ new WeakSet();
14348
14479
  function createFloat32ArrayGlobal(budget) {
@@ -14468,6 +14599,119 @@ function relativeIndex(value, length, fallback) {
14468
14599
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
14469
14600
  }
14470
14601
 
14602
+ // packages/safe-js/src/interp/globals/error.ts
14603
+ var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14604
+ var errorNames = [
14605
+ "Error",
14606
+ "TypeError",
14607
+ "RangeError",
14608
+ "ReferenceError",
14609
+ "SyntaxError",
14610
+ "URIError",
14611
+ "EvalError",
14612
+ "AggregateError"
14613
+ ];
14614
+ function createErrorGlobals(options) {
14615
+ return Object.fromEntries(
14616
+ errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14617
+ );
14618
+ }
14619
+ function isSandboxErrorConstructorInstance2(value, constructor) {
14620
+ if (!isSandboxClosure(constructor)) {
14621
+ throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14622
+ }
14623
+ const name = errorConstructorNames.get(constructor);
14624
+ if (name === void 0) {
14625
+ return false;
14626
+ }
14627
+ return isSandboxErrorConstructorInstance(value, name);
14628
+ }
14629
+ function createErrorConstructor(name, budget) {
14630
+ const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14631
+ const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14632
+ errorConstructorNames.set(closure, name);
14633
+ return closure;
14634
+ }
14635
+ function createSubsetError(name, args, stackFrames, budget) {
14636
+ const message = name === "AggregateError" ? args[1] : args[0];
14637
+ const options = name === "AggregateError" ? args[2] : args[1];
14638
+ const error = createSubsetErrorValue(name, message, stackFrames, budget);
14639
+ if (name === "AggregateError") {
14640
+ const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14641
+ budget.allocateArrayLength(errors.length);
14642
+ error.errors = errors;
14643
+ }
14644
+ if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14645
+ error.cause = options.cause;
14646
+ }
14647
+ return error;
14648
+ }
14649
+ function isObjectLike(value) {
14650
+ return typeof value === "object" && value !== null;
14651
+ }
14652
+
14653
+ // packages/safe-js/src/interp/instanceof.ts
14654
+ async function evaluateInstanceof(value, constructor, budget, context) {
14655
+ if (constructor === null || typeof constructor !== "object")
14656
+ throw new TypeError("Right-hand side of 'instanceof' must be an object.");
14657
+ const method = await readInstanceProperty(constructor, Symbol.hasInstance, budget, context);
14658
+ if (method !== void 0 && method !== null) {
14659
+ if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
14660
+ return Boolean(await invokeBuiltinClosure(method, [value], budget, context, constructor));
14661
+ }
14662
+ if (!isSandboxClosure(constructor))
14663
+ throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14664
+ return ordinaryHasInstance(value, constructor, budget, context);
14665
+ }
14666
+ async function ordinaryHasInstance(value, constructor, budget, context) {
14667
+ if (!isSandboxClosure(constructor)) return false;
14668
+ if (constructor.boundTarget !== void 0) {
14669
+ budget.visitNode();
14670
+ return evaluateInstanceof(value, constructor.boundTarget, budget, context);
14671
+ }
14672
+ if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
14673
+ if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
14674
+ if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
14675
+ const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
14676
+ if (typeof prototype !== "object" || prototype === null)
14677
+ throw new TypeError("Function has a non-object prototype in instanceof check.");
14678
+ let depth = 0;
14679
+ for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
14680
+ budget.visitNode();
14681
+ assertSandboxDataDepth(depth++);
14682
+ if (current === prototype) return true;
14683
+ }
14684
+ return false;
14685
+ }
14686
+ async function readInstanceProperty(value, key, budget, context) {
14687
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
14688
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14689
+ if (descriptor === void 0) return void 0;
14690
+ return readPropertyDescriptor(descriptor, value, {
14691
+ ...context,
14692
+ stack: context?.stack ?? [],
14693
+ thisValue: value,
14694
+ invokeClosure: context?.invokeClosure ?? ((closure, args, receiver) => invokeBuiltinClosure(closure, args, budget, context, receiver))
14695
+ });
14696
+ }
14697
+
14698
+ // packages/safe-js/src/interp/methods/collection-iterator.ts
14699
+ function getCollectionIteratorMember(target, property, budget) {
14700
+ if (Object.hasOwn(target, property)) return target[property];
14701
+ if (property !== "next") return void 0;
14702
+ const { collectionKind } = collectionIteratorState(target);
14703
+ return createSandboxClosure({
14704
+ sandbox: true,
14705
+ name: "next",
14706
+ call: (_args, context) => {
14707
+ const receiver = context?.thisValue;
14708
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14709
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14710
+ return nextCollectionIterator(receiver, budget);
14711
+ }
14712
+ });
14713
+ }
14714
+
14471
14715
  // packages/safe-js/src/interp/scope.ts
14472
14716
  var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
14473
14717
  var Scope = class _Scope {
@@ -16192,7 +16436,7 @@ function forInKeys(object, budget) {
16192
16436
  for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
16193
16437
  if (depth > 0) budget.visitNode();
16194
16438
  assertSandboxDataDepth(depth++);
16195
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
16439
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
16196
16440
  for (const key of Object.getOwnPropertyNames(properties)) {
16197
16441
  if (seen.has(key)) continue;
16198
16442
  seen.add(key);
@@ -16208,7 +16452,7 @@ function hasForInProperty(object, key, budget) {
16208
16452
  for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
16209
16453
  if (depth > 0) budget.visitNode();
16210
16454
  assertSandboxDataDepth(depth++);
16211
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
16455
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
16212
16456
  if (Object.hasOwn(properties, key)) return true;
16213
16457
  }
16214
16458
  return false;
@@ -16764,7 +17008,7 @@ function getPropertyValue(target, property, context, receiver = target) {
16764
17008
  if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
16765
17009
  if (isSandboxCollectionIterator(target))
16766
17010
  return getCollectionIteratorMember(target, property, context.budget);
16767
- if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
17011
+ if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
16768
17012
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
16769
17013
  if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
16770
17014
  if (isSandboxRegex(target)) return hasExplicitSandboxPrototype(target) || getSandboxPrototype(target, context.budget) !== null ? void 0 : getRegexMember(target, property, context.budget, createCoercionContext(context));
@@ -17080,7 +17324,7 @@ async function evaluateMemberCallExpression(node, context) {
17080
17324
  );
17081
17325
  }
17082
17326
  if (isSandboxGenerator(member.object)) {
17083
- const memberValue = getGeneratorMember(member.object, member.property, context.budget);
17327
+ const memberValue = await getPropertyValue(member.object, member.property, context);
17084
17328
  if (memberValue === void 0) {
17085
17329
  throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
17086
17330
  }
@@ -17332,42 +17576,11 @@ function applyBinaryOperator(node, left, right, context) {
17332
17576
  case ">>>":
17333
17577
  return toNumber(left) >>> toNumber(right);
17334
17578
  case "instanceof":
17335
- return evaluateInstanceof(left, right, context);
17579
+ return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
17336
17580
  case "in":
17337
17581
  return hasSandboxProperty(right, left, context);
17338
17582
  }
17339
17583
  }
17340
- async function evaluateInstanceof(left, right, context) {
17341
- while (true) {
17342
- if (right === null || typeof right !== "object" && typeof right !== "function")
17343
- throw new TypeError("Right-hand side of 'instanceof' must be an object.");
17344
- const method = await getPropertyValue(right, Symbol.hasInstance, context);
17345
- if (method !== void 0 && method !== null) {
17346
- if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
17347
- return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
17348
- }
17349
- if (!isSandboxClosure(right))
17350
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
17351
- if (right.boundTarget === void 0) break;
17352
- context.budget.visitNode();
17353
- right = right.boundTarget;
17354
- }
17355
- if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
17356
- if (isSandboxErrorConstructorInstance2(left, right)) return true;
17357
- if (isGuestClosure(right)) {
17358
- if (typeof left !== "object" || left === null) return false;
17359
- const prototype = await getPropertyValue(right, "prototype", context);
17360
- if (typeof prototype !== "object" || prototype === null)
17361
- throw new TypeError("Function has a non-object prototype in instanceof check.");
17362
- let depth = 0;
17363
- for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
17364
- context.budget.visitNode();
17365
- assertSandboxDataDepth(depth++);
17366
- if (current === prototype) return true;
17367
- }
17368
- }
17369
- return false;
17370
- }
17371
17584
  function createCoercionContext(context) {
17372
17585
  return {
17373
17586
  stack: context.callStack,
@@ -17384,7 +17597,7 @@ function hasSandboxProperty(value, key, context) {
17384
17597
  while (typeof current === "object" && current !== null) {
17385
17598
  if (isGuestHostObject(current)) return typeof key === "symbol" ? false : hasHostObjectMember(current, String(key));
17386
17599
  if (hasOwnSandboxProperty(current, key, false)) return true;
17387
- if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
17600
+ if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || isSandboxGenerator(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
17388
17601
  return getPropertyValue(current, key, context) !== void 0;
17389
17602
  }
17390
17603
  current = getSandboxPrototype(current, context.budget);
@@ -17630,6 +17843,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
17630
17843
  }
17631
17844
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
17632
17845
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
17846
+ if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
17633
17847
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
17634
17848
  if (isFloat32Array(target)) {
17635
17849
  if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
@@ -17663,7 +17877,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
17663
17877
  for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
17664
17878
  budget.visitNode();
17665
17879
  assertSandboxDataDepth(depth++);
17666
- const properties = isSandboxClosure(prototype) ? prototype.properties : prototype;
17880
+ const properties = isSandboxGenerator(prototype) ? getGeneratorProperties(prototype) : isSandboxClosure(prototype) ? prototype.properties : prototype;
17667
17881
  const inherited = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
17668
17882
  if (inherited === void 0) continue;
17669
17883
  if (inherited.writable !== true)
@@ -17682,7 +17896,7 @@ function setSuperProperty(base, receiver, key, value, context) {
17682
17896
  for (let current = base; current !== null; current = getSandboxPrototype(current, budget)) {
17683
17897
  budget.visitNode();
17684
17898
  assertSandboxDataDepth(depth++);
17685
- const properties = isSandboxClosure(current) ? current.properties : current;
17899
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxClosure(current) ? current.properties : current;
17686
17900
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
17687
17901
  if (descriptor === void 0) continue;
17688
17902
  if (!("value" in descriptor))
@@ -17700,6 +17914,7 @@ function deleteSandboxProperty(target, property) {
17700
17914
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
17701
17915
  if (isSandboxRegex(target)) target = getRegexProperties(target);
17702
17916
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
17917
+ if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
17703
17918
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
17704
17919
  if (Array.isArray(target)) {
17705
17920
  assertCollectionMutable(target);
@@ -18266,11 +18481,11 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
18266
18481
  }
18267
18482
  }
18268
18483
  function conversionHook(value, name, budget, context) {
18269
- const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
18484
+ const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) && getSandboxPrototype(value, budget) === null || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
18270
18485
  let current = value;
18271
18486
  let depth = 0;
18272
18487
  while (current !== null) {
18273
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
18488
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
18274
18489
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, name);
18275
18490
  if (descriptor !== void 0) {
18276
18491
  return readPropertyDescriptor(descriptor, value, context);
@@ -18483,8 +18698,7 @@ function hasOwnSandboxProperty(value, key, enumerable) {
18483
18698
  properties = value.properties ?? /* @__PURE__ */ Object.create(null);
18484
18699
  } else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
18485
18700
  else if (isSandboxPromise(value)) properties = getPromiseProperties(value);
18486
- else if (isSandboxGenerator(value))
18487
- return false;
18701
+ else if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
18488
18702
  else if (isSandboxRegex(value)) properties = getRegexProperties(value);
18489
18703
  else properties = Object(value);
18490
18704
  const descriptor = Object.getOwnPropertyDescriptor(properties, key);
@@ -20103,6 +20317,18 @@ function captureGuestHeapNode(value, encode) {
20103
20317
  const state2 = captureObjectState(value, encode);
20104
20318
  return { kind: "intrinsic", id: intrinsic, ...state2 === void 0 ? {} : { state: state2 } };
20105
20319
  }
20320
+ const bound = boundFunctionStates.get(value);
20321
+ if (bound !== void 0 && isSandboxClosure(value)) {
20322
+ return {
20323
+ kind: "bound-function",
20324
+ target: encode(bound.target),
20325
+ thisValue: encode(bound.thisValue),
20326
+ args: bound.args.map(encode),
20327
+ length: encode(value.length),
20328
+ ...value.name === void 0 ? {} : { name: value.name },
20329
+ state: captureObjectState(value, encode)
20330
+ };
20331
+ }
20106
20332
  if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key, entry]) => [encode(key), encode(entry)]), ...serializeCollectionProperties(value, encode) };
20107
20333
  if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
20108
20334
  if (isSandboxArrayIterator(value)) {
@@ -20153,6 +20379,7 @@ function captureGuestHeapNode(value, encode) {
20153
20379
  state: value.state,
20154
20380
  astNodeId: origin2.node.nodeId,
20155
20381
  async: value.async === true,
20382
+ objectState: captureObjectState(value, encode),
20156
20383
  scope: encode(origin2.scope),
20157
20384
  closureScope: encode(origin2.closureScope),
20158
20385
  ...value.state !== "suspended" || origin2.suspendedScope === void 0 ? {} : { suspendedScope: encode(origin2.suspendedScope) },
@@ -20268,6 +20495,7 @@ function captureGuestHeapNode(value, encode) {
20268
20495
  }
20269
20496
  function captureObjectState(value, encode) {
20270
20497
  let properties = value;
20498
+ if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
20271
20499
  if (isSandboxClosure(value)) {
20272
20500
  properties = value.properties;
20273
20501
  if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
@@ -23854,6 +24082,100 @@ function createUriGlobals(budget) {
23854
24082
  }));
23855
24083
  }
23856
24084
 
24085
+ // packages/safe-js/src/interp/globals/function.ts
24086
+ function createFunctionPrototype(budget, installHasInstance = true) {
24087
+ const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
24088
+ const properties = materializeFunctionProperties(prototype);
24089
+ Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
24090
+ for (const [name, length] of [["call", 1], ["apply", 2], ["bind", 1], ["toString", 0]]) {
24091
+ Object.defineProperty(properties, name, {
24092
+ writable: true,
24093
+ configurable: true,
24094
+ value: createSandboxClosure({
24095
+ guest: true,
24096
+ sandbox: true,
24097
+ name,
24098
+ length,
24099
+ call: (args, context) => callFunctionMethod(context?.thisValue, name, args, {
24100
+ budget,
24101
+ callClosure: (target, values, stack, thisValue, construct, newTarget) => context?.invokeClosure !== void 0 ? context.invokeClosure(target, values, thisValue, construct, newTarget) : invokeBuiltinClosure(target, values, budget, { ...context, stack, thisValue, newTarget }, thisValue, construct)
24102
+ }, context?.stack ?? [], context)
24103
+ })
24104
+ });
24105
+ }
24106
+ const hasInstance = installHasInstance ? createSandboxClosure({
24107
+ guest: true,
24108
+ sandbox: true,
24109
+ name: "[Symbol.hasInstance]",
24110
+ length: 1,
24111
+ call: ([value], context) => ordinaryHasInstance(value, context?.thisValue, budget, context)
24112
+ }) : void 0;
24113
+ if (hasInstance !== void 0) Object.defineProperty(properties, Symbol.hasInstance, { value: hasInstance });
24114
+ setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
24115
+ installFunctionPrototype(budget, prototype);
24116
+ if (hasInstance !== void 0) registerIntrinsicFunction(budget, hasInstance);
24117
+ }
24118
+
24119
+ // packages/safe-js/src/interp/globals/generator.ts
24120
+ function createGeneratorPrototypes(budget) {
24121
+ const asyncIteratorPrototype = /* @__PURE__ */ Object.create(null);
24122
+ const asyncIterator = createSandboxClosure({
24123
+ guest: true,
24124
+ sandbox: true,
24125
+ name: "[Symbol.asyncIterator]",
24126
+ length: 0,
24127
+ call: (_args, context) => context?.thisValue
24128
+ });
24129
+ Object.defineProperty(asyncIteratorPrototype, Symbol.asyncIterator, {
24130
+ value: asyncIterator,
24131
+ writable: true,
24132
+ configurable: true
24133
+ });
24134
+ setSandboxPrototype(asyncIteratorPrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
24135
+ registerBuiltinIdentities(budget, { "%AsyncIteratorPrototype%": asyncIteratorPrototype });
24136
+ registerIntrinsicObject(budget, asyncIteratorPrototype);
24137
+ registerIntrinsicFunction(budget, asyncIterator);
24138
+ const state = /* @__PURE__ */ new Map();
24139
+ for (const async of [false, true]) {
24140
+ const tag = async ? "AsyncGenerator" : "Generator";
24141
+ const functionPrototype = /* @__PURE__ */ Object.create(null);
24142
+ const instancePrototype = /* @__PURE__ */ Object.create(null);
24143
+ setSandboxPrototype(functionPrototype, resolveIntrinsicIdentity(budget, JSON.stringify(["%FunctionPrototype%"])));
24144
+ setSandboxPrototype(instancePrototype, async ? asyncIteratorPrototype : resolveIntrinsicIdentity(budget, JSON.stringify(["%IteratorPrototype%"])));
24145
+ Object.defineProperties(functionPrototype, {
24146
+ prototype: { value: instancePrototype, configurable: true },
24147
+ // Do not expose native dynamic-source constructors through this graph.
24148
+ constructor: { value: void 0, configurable: true },
24149
+ [Symbol.toStringTag]: { value: `${tag}Function`, configurable: true }
24150
+ });
24151
+ Object.defineProperties(instancePrototype, {
24152
+ constructor: { value: functionPrototype, configurable: true },
24153
+ [Symbol.toStringTag]: { value: tag, configurable: true }
24154
+ });
24155
+ for (const method of ["next", "return", "throw"]) {
24156
+ Object.defineProperty(instancePrototype, method, {
24157
+ writable: true,
24158
+ configurable: true,
24159
+ value: createSandboxClosure({
24160
+ guest: true,
24161
+ sandbox: true,
24162
+ name: method,
24163
+ length: 1,
24164
+ call: ([value], context) => callGeneratorMethod(context?.thisValue, method, value, budget, context, async)
24165
+ })
24166
+ });
24167
+ }
24168
+ registerBuiltinIdentities(budget, {
24169
+ [`%${tag}Prototype%`]: instancePrototype,
24170
+ [`%${tag}FunctionPrototype%`]: functionPrototype
24171
+ });
24172
+ registerIntrinsicObject(budget, functionPrototype);
24173
+ registerIntrinsicObject(budget, instancePrototype);
24174
+ state.set(async, { functionPrototype, instancePrototype });
24175
+ }
24176
+ generatorPrototypes.set(budget, state);
24177
+ }
24178
+
23857
24179
  // packages/safe-js/src/interp/globals/symbol.ts
23858
24180
  var registries = /* @__PURE__ */ new WeakMap();
23859
24181
  function createSymbolGlobal(budget) {
@@ -24084,6 +24406,8 @@ function createBuiltinBindings(options) {
24084
24406
  ...createPromiseGlobals(options),
24085
24407
  ...createRegexGlobals(options)
24086
24408
  };
24409
+ createFunctionPrototype(options.budget, options.functionHasInstance);
24410
+ createGeneratorPrototypes(options.budget);
24087
24411
  registerBuiltinIdentities(options.budget, bindings);
24088
24412
  return bindings;
24089
24413
  }
@@ -24134,7 +24458,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24134
24458
  createRawJson(node.text);
24135
24459
  return true;
24136
24460
  }
24137
- if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
24461
+ if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
24138
24462
  const reference = (value, kinds) => {
24139
24463
  const ref = record3(value);
24140
24464
  fields(ref, ["kind", "id"]);
@@ -24145,7 +24469,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24145
24469
  };
24146
24470
  const callable = (value) => {
24147
24471
  if (absent(value)) return;
24148
- const target = reference(value, ["intrinsic", "guest-function", "guest-class"]);
24472
+ const target = reference(value, ["intrinsic", "bound-function", "guest-function", "guest-class"]);
24149
24473
  if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
24150
24474
  throw new TypeError("Guest accessor reference is not callable.");
24151
24475
  };
@@ -24241,6 +24565,22 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24241
24565
  if (descriptor.kind !== "data" || descriptor.writable !== false || descriptor.enumerable !== false || descriptor.configurable !== false)
24242
24566
  throw new TypeError("Invalid class prototype descriptor.");
24243
24567
  reference(descriptor.value, ["object", "guest-object"]);
24568
+ } else if (node.kind === "bound-function") {
24569
+ fields(node, ["kind", "target", "thisValue", "args", "length", "state"], ["name"]);
24570
+ if (Object.hasOwn(node, "name") && typeof node.name !== "string") throw new TypeError("Invalid bound function name.");
24571
+ if (array(node.args).length > maxArrayLength) throw new TypeError("Bound arguments exceed allocation limit.");
24572
+ if (!absent(node.length) && !(typeof node.length === "number" && node.length >= 0) && !(record3(node.length).kind === "number" && record3(node.length).value === "Infinity"))
24573
+ throw new TypeError("Invalid bound function length.");
24574
+ const visited = /* @__PURE__ */ new Set([raw]);
24575
+ let current = node;
24576
+ while (current.kind === "bound-function") {
24577
+ assertSnapshotDataDepth(visited.size, "<bound-target>");
24578
+ callable(current.target);
24579
+ current = reference(current.target);
24580
+ if (visited.has(current)) throw new TypeError("Cyclic bound function target.");
24581
+ visited.add(current);
24582
+ }
24583
+ state(node.state);
24244
24584
  } else if (node.kind === "guest-function") {
24245
24585
  fields(node, ["kind", "astNodeId", "scope", "state"], ["name", "environment"]);
24246
24586
  if (integer(node.astNodeId) < 1) throw new TypeError("Invalid guest AST identity.");
@@ -24254,7 +24594,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24254
24594
  }
24255
24595
  state(node.state);
24256
24596
  } else if (node.kind === "guest-generator") {
24257
- fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates"]);
24597
+ fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
24598
+ if (Object.hasOwn(node, "objectState")) state(node.objectState);
24258
24599
  if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer(node.astNodeId) < 1)
24259
24600
  throw new TypeError("Invalid generator state.");
24260
24601
  reference(node.scope, ["scope-frame"]);
@@ -25767,6 +26108,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
25767
26108
  if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
25768
26109
  else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
25769
26110
  else if (isSandboxPromise(value)) entries = Object.entries(getPromiseProperties(value));
26111
+ else if (isSandboxGenerator(value)) entries = Object.entries(getGeneratorProperties(value));
25770
26112
  else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
25771
26113
  else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
25772
26114
  else entries = Object.entries(Object(value));
@@ -25778,19 +26120,20 @@ function ownSandboxSymbolKeys(value) {
25778
26120
  if (isSandboxClosure(value)) value = value.properties ?? {};
25779
26121
  else if (isSandboxRegex(value)) value = getRegexProperties(value);
25780
26122
  else if (isSandboxPromise(value)) value = getPromiseProperties(value);
26123
+ else if (isSandboxGenerator(value)) value = getGeneratorProperties(value);
25781
26124
  else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
25782
- else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
25783
26125
  return Object.getOwnPropertySymbols(Object(value)).filter((key) => !internalSymbols.has(key));
25784
26126
  }
25785
26127
  function ownEnumerableSandboxKeys(value, includeSymbols = false) {
25786
26128
  if (includeSymbols) {
25787
- const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
26129
+ const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
25788
26130
  return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key) => Object.getOwnPropertyDescriptor(properties, key)?.enumerable === true)];
25789
26131
  }
25790
26132
  if (isGuestHostObject(value)) return getHostObjectKeys(value);
25791
26133
  if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
25792
26134
  if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
25793
26135
  if (isSandboxPromise(value)) return Object.keys(getPromiseProperties(value));
26136
+ if (isSandboxGenerator(value)) return Object.keys(getGeneratorProperties(value));
25794
26137
  if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
25795
26138
  if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
25796
26139
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
@@ -25842,6 +26185,7 @@ function createSandboxGenerator(channel, metadata = void 0) {
25842
26185
  enumerable: false,
25843
26186
  value: true
25844
26187
  });
26188
+ getGeneratorProperties(generator);
25845
26189
  return generator;
25846
26190
  }
25847
26191
  function createSandboxMap(entries = []) {
@@ -26096,6 +26440,14 @@ function measureSandboxData(values, options = {}) {
26096
26440
  return;
26097
26441
  }
26098
26442
  if (isSandboxGenerator(value)) {
26443
+ const descriptors3 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
26444
+ for (const key of Reflect.ownKeys(descriptors3)) {
26445
+ const descriptor = descriptors3[key];
26446
+ usage += typeof key === "string" ? key.length + 1 : 1;
26447
+ if (typeof key === "symbol") visit(key, depth + 1);
26448
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
26449
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
26450
+ }
26099
26451
  const snapshot = value.channel.snapshot();
26100
26452
  usage += snapshot.sent.length;
26101
26453
  for (const completion of snapshot.sent) visit(completion.value, depth + 1);
@@ -40889,12 +41241,12 @@ export {
40889
41241
  safeAddEvent,
40890
41242
  safeRecordException,
40891
41243
  safeEndSpan,
41244
+ runResources,
40892
41245
  defineExtension,
40893
41246
  encodeReplayData,
40894
41247
  HostOperationResumePolicyError,
40895
41248
  registerPendingHostCallPolicy,
40896
41249
  HostCallResumabilityError,
40897
- runResources,
40898
41250
  assertSnapshotInactive,
40899
41251
  isSandboxClosure,
40900
41252
  deepCopyToSandbox,
@@ -40922,4 +41274,4 @@ export {
40922
41274
  FileSnapshotBackend,
40923
41275
  run
40924
41276
  };
40925
- //# sourceMappingURL=chunk-BGSPSHLP.js.map
41277
+ //# sourceMappingURL=chunk-ZSYBRZU6.js.map