poe-code 14.0.79 → 14.0.80

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 (32) hide show
  1. package/dist/index.js +252 -100
  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-34G5WW2O.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-BGSPSHLP.js → chunk-M4L3EZHL.js} +220 -93
  7. package/packages/safe-js/dist/chunks/chunk-M4L3EZHL.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/generator-properties.d.ts +3 -0
  13. package/packages/safe-js/dist/interp/generator-properties.js +9 -0
  14. package/packages/safe-js/dist/interp/globals/function.d.ts +2 -0
  15. package/packages/safe-js/dist/interp/globals/function.js +24 -0
  16. package/packages/safe-js/dist/interp/globals/object-array.js +9 -6
  17. package/packages/safe-js/dist/interp/globals/object.js +2 -1
  18. package/packages/safe-js/dist/interp/globals.js +2 -0
  19. package/packages/safe-js/dist/interp/interpreter.js +13 -7
  20. package/packages/safe-js/dist/interp/iteration.js +37 -4
  21. package/packages/safe-js/dist/interp/methods/function.d.ts +4 -1
  22. package/packages/safe-js/dist/interp/methods/function.js +2 -2
  23. package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
  24. package/packages/safe-js/dist/interp/object-model.js +67 -17
  25. package/packages/safe-js/dist/interp/string-coercion.js +3 -2
  26. package/packages/safe-js/dist/interp/values.js +21 -3
  27. package/packages/safe-js/dist/snapshot/guest-heap-validation.js +3 -1
  28. package/packages/safe-js/dist/snapshot/guest-heap.d.ts +1 -0
  29. package/packages/safe-js/dist/snapshot/guest-heap.js +4 -0
  30. package/packages/safe-js/dist/snapshot/restore.js +8 -0
  31. package/packages/safe-js/dist/chunks/chunk-BGSPSHLP.js.map +0 -7
  32. /package/packages/safe-js/dist/chunks/{chunk-B3AL4KJ3.js.map → chunk-34G5WW2O.js.map} +0 -0
package/dist/index.js CHANGED
@@ -126512,6 +126512,23 @@ var init_internal_symbols = __esm({
126512
126512
  }
126513
126513
  });
126514
126514
 
126515
+ // packages/safe-js/src/interp/generator-properties.ts
126516
+ function getGeneratorProperties(value) {
126517
+ let properties = generatorGuestProperties.get(value);
126518
+ if (properties === void 0) {
126519
+ properties = /* @__PURE__ */ Object.create(null);
126520
+ generatorGuestProperties.set(value, properties);
126521
+ }
126522
+ return properties;
126523
+ }
126524
+ var generatorGuestProperties;
126525
+ var init_generator_properties = __esm({
126526
+ "packages/safe-js/src/interp/generator-properties.ts"() {
126527
+ "use strict";
126528
+ generatorGuestProperties = /* @__PURE__ */ new WeakMap();
126529
+ }
126530
+ });
126531
+
126515
126532
  // packages/safe-js/src/interp/regexp-properties.ts
126516
126533
  function getRegexProperties(value) {
126517
126534
  const properties = regexGuestProperties.get(value);
@@ -127035,7 +127052,7 @@ function walkGraphDepth(root, rootPath, assertDepth) {
127035
127052
  }
127036
127053
  }
127037
127054
  function graphEntries(value) {
127038
- const properties = regexGuestProperties.get(value);
127055
+ const properties = regexGuestProperties.get(value) ?? generatorGuestProperties.get(value);
127039
127056
  if (properties !== void 0) return Reflect.ownKeys(properties).flatMap((key3) => {
127040
127057
  const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
127041
127058
  return "value" in descriptor ? [[`.${String(key3)}`, descriptor.value]] : [];
@@ -127079,6 +127096,7 @@ var init_graph_depth = __esm({
127079
127096
  init_collection_brands();
127080
127097
  init_boxed();
127081
127098
  init_regexp_properties();
127099
+ init_generator_properties();
127082
127100
  MAX_DATA_DEPTH = 1024;
127083
127101
  SnapshotBudgetError = class extends Error {
127084
127102
  code = "budgetExceeded";
@@ -127098,6 +127116,61 @@ var init_graph_depth = __esm({
127098
127116
  }
127099
127117
  });
127100
127118
 
127119
+ // packages/safe-js/src/interp/resources.ts
127120
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
127121
+ function retainValues(budget, values) {
127122
+ const retained = {};
127123
+ budget.setRetainedValues(retained, values);
127124
+ const pending = runResources.getStore()?.referenceReleases;
127125
+ const release2 = () => {
127126
+ budget.setRetainedValues(retained, void 0);
127127
+ pending?.delete(release2);
127128
+ };
127129
+ pending?.add(release2);
127130
+ return release2;
127131
+ }
127132
+ async function withRunResources(signal, execute2) {
127133
+ const controller = new AbortController();
127134
+ const cancel2 = () => controller.abort(signal?.reason);
127135
+ const cleanups = /* @__PURE__ */ new Set();
127136
+ const resources = {
127137
+ signal: controller.signal,
127138
+ referenceReleases: /* @__PURE__ */ new Set(),
127139
+ add(close) {
127140
+ cleanups.add(close);
127141
+ }
127142
+ };
127143
+ signal?.addEventListener("abort", cancel2, { once: true });
127144
+ if (signal?.aborted) cancel2();
127145
+ let result;
127146
+ let failure;
127147
+ let errors2 = [];
127148
+ try {
127149
+ result = await runResources.run(resources, execute2);
127150
+ } catch (error3) {
127151
+ failure = { reason: error3 };
127152
+ } finally {
127153
+ signal?.removeEventListener("abort", cancel2);
127154
+ controller.abort(new Error("SafeJS run finished."));
127155
+ for (const release2 of resources.referenceReleases) release2();
127156
+ resources.referenceReleases.clear();
127157
+ const outcomes = await Promise.allSettled(
127158
+ [...cleanups].map((close) => Promise.resolve().then(close))
127159
+ );
127160
+ errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
127161
+ }
127162
+ if (failure !== void 0) throw failure.reason;
127163
+ if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
127164
+ return result;
127165
+ }
127166
+ var runResources;
127167
+ var init_resources = __esm({
127168
+ "packages/safe-js/src/interp/resources.ts"() {
127169
+ "use strict";
127170
+ runResources = new AsyncLocalStorage4();
127171
+ }
127172
+ });
127173
+
127101
127174
  // packages/safe-js/src/interp/symbols.ts
127102
127175
  var wellKnownSymbols;
127103
127176
  var init_symbols2 = __esm({
@@ -127615,9 +127688,23 @@ function materializeFunctionProperties(closure) {
127615
127688
  descriptorObjects.add(prototype);
127616
127689
  Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
127617
127690
  }
127618
- descriptorObjects.add(properties);
127619
- functionProperties.set(closure, properties);
127620
- return properties;
127691
+ const state = { revision: 0 };
127692
+ const tracked = new Proxy(properties, {
127693
+ defineProperty(target, key3, descriptor) {
127694
+ const changed = Reflect.defineProperty(target, key3, descriptor);
127695
+ if (changed) state.revision++;
127696
+ return changed;
127697
+ },
127698
+ deleteProperty(target, key3) {
127699
+ const changed = Reflect.deleteProperty(target, key3);
127700
+ if (changed) state.revision++;
127701
+ return changed;
127702
+ }
127703
+ });
127704
+ functionPropertyRevisions.set(tracked, state);
127705
+ descriptorObjects.add(tracked);
127706
+ functionProperties.set(closure, tracked);
127707
+ return tracked;
127621
127708
  }
127622
127709
  function getGuestFunctionProperty(closure, key3) {
127623
127710
  let properties = functionProperties.get(closure);
@@ -127635,6 +127722,12 @@ function installObjectPrototype(budget, prototype, constructor) {
127635
127722
  intrinsicPrototypes.set(budget, prototype);
127636
127723
  registerIntrinsicPrototype(budget, prototype, constructor);
127637
127724
  }
127725
+ function installFunctionPrototype(budget, prototype) {
127726
+ functionPrototypes.set(budget, prototype);
127727
+ registerBuiltinIdentities(budget, { "%FunctionPrototype%": prototype });
127728
+ registerIntrinsicFunction(budget, prototype);
127729
+ registerIntrinsicObject(budget, materializeFunctionProperties(prototype));
127730
+ }
127638
127731
  function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
127639
127732
  let state = boxedPrototypes.get(budget);
127640
127733
  if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
@@ -127721,6 +127814,9 @@ function trackIntrinsicState(budget, root, owner, targets) {
127721
127814
  explicit: hasExplicitSandboxPrototype(target)
127722
127815
  })).map((record4) => ({
127723
127816
  ...record4,
127817
+ revision: functionPropertyRevisions.get(record4.value),
127818
+ capturedRevision: -1,
127819
+ captured: [],
127724
127820
  extensible: Object.isExtensible(record4.value),
127725
127821
  descriptors: new Map(Reflect.ownKeys(record4.value).map((key3) => [key3, Object.getOwnPropertyDescriptor(record4.value, key3)]))
127726
127822
  }));
@@ -127736,14 +127832,21 @@ function trackIntrinsicState(budget, root, owner, targets) {
127736
127832
  );
127737
127833
  budget.setRetainedValues(root, () => {
127738
127834
  const retained = [];
127739
- for (const { target, value, descriptors: descriptors2, prototype: parent } of records) {
127835
+ for (const record4 of records) {
127836
+ const { target, value, descriptors: descriptors2, prototype: parent, revision: revision2 } = record4;
127740
127837
  const currentPrototype = getSandboxPrototype(target);
127741
127838
  if (currentPrototype !== parent) retained.push(currentPrototype);
127742
- for (const key3 of Reflect.ownKeys(value)) {
127743
- const descriptor = Object.getOwnPropertyDescriptor(value, key3);
127744
- if (unchanged(descriptors2.get(key3), descriptor)) continue;
127745
- retained.push(key3, descriptor.value, ...retainedAccessorClosures(descriptor));
127839
+ if (revision2 === void 0 || revision2.revision !== record4.capturedRevision) {
127840
+ const captured = [];
127841
+ for (const key3 of Reflect.ownKeys(value)) {
127842
+ const descriptor = Object.getOwnPropertyDescriptor(value, key3);
127843
+ if (unchanged(descriptors2.get(key3), descriptor)) continue;
127844
+ captured.push(key3, descriptor.value, ...retainedAccessorClosures(descriptor));
127845
+ }
127846
+ record4.captured = captured;
127847
+ record4.capturedRevision = revision2?.revision ?? -1;
127746
127848
  }
127849
+ for (const item of record4.captured) retained.push(item);
127747
127850
  }
127748
127851
  return retained;
127749
127852
  });
@@ -127759,11 +127862,14 @@ function releaseObjectPrototype(budget) {
127759
127862
  promisePrototypes.delete(budget);
127760
127863
  datePrototypes.delete(budget);
127761
127864
  arrayPrototypes.delete(budget);
127865
+ functionPrototypes.delete(budget);
127762
127866
  initialRegexDescriptors.delete(budget);
127763
127867
  intrinsicPrototypes.delete(budget);
127764
127868
  }
127765
127869
  function getSandboxPrototype(value, budget) {
127766
127870
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
127871
+ if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
127872
+ return functionPrototypes.get(budget) ?? null;
127767
127873
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
127768
127874
  if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
127769
127875
  if (budget !== void 0 && isSandboxPromise(value)) return promisePrototypes.get(budget) ?? null;
@@ -127788,8 +127894,15 @@ function getSandboxPropertyDescriptor(value, key3, budget) {
127788
127894
  return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key3);
127789
127895
  let current = value;
127790
127896
  let depth = 0;
127791
- while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
127792
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
127897
+ while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
127898
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key3 === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
127899
+ if (properties === void 0 && isGuestClosure(current) && (key3 === "name" || key3 === "length"))
127900
+ return {
127901
+ value: key3 === "name" ? current.name ?? "" : current.length ?? 0,
127902
+ writable: false,
127903
+ enumerable: false,
127904
+ configurable: true
127905
+ };
127793
127906
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
127794
127907
  if (descriptor !== void 0) return descriptor;
127795
127908
  current = getSandboxPrototype(current, budget);
@@ -127807,6 +127920,10 @@ function getSandboxDataProperty(value, key3, budget) {
127807
127920
  if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
127808
127921
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key3)?.value;
127809
127922
  if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key3)?.value;
127923
+ if (isSandboxGenerator(current)) {
127924
+ const descriptor = Object.getOwnPropertyDescriptor(getGeneratorProperties(current), key3);
127925
+ if (descriptor !== void 0) return descriptor.value;
127926
+ }
127810
127927
  if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key3)?.value;
127811
127928
  if (isGuestClosure(current)) {
127812
127929
  const entry = getGuestFunctionProperty(current, key3);
@@ -127815,9 +127932,9 @@ function getSandboxDataProperty(value, key3, budget) {
127815
127932
  const properties = current.properties;
127816
127933
  return properties !== void 0 && Object.hasOwn(properties, key3) ? properties[key3] : void 0;
127817
127934
  }
127818
- if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
127935
+ if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current))
127819
127936
  return void 0;
127820
- if (!isSandboxClosure(current) && Object.hasOwn(current, key3)) return current[key3];
127937
+ if (!isSandboxClosure(current) && !isSandboxGenerator(current) && Object.hasOwn(current, key3)) return current[key3];
127821
127938
  current = getSandboxPrototype(current, budget);
127822
127939
  if (current !== null) {
127823
127940
  budget?.visitNode();
@@ -127830,7 +127947,7 @@ function setSandboxPrototype(value, prototype, budget) {
127830
127947
  if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
127831
127948
  throw new TypeError("Object.prototype has an immutable null prototype.");
127832
127949
  }
127833
- 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)) {
127950
+ 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)) {
127834
127951
  throw new TypeError(
127835
127952
  "Prototype links require supported sandbox objects."
127836
127953
  );
@@ -127839,7 +127956,7 @@ function setSandboxPrototype(value, prototype, budget) {
127839
127956
  if (prototype === null) prototypes.set(value, null);
127840
127957
  return;
127841
127958
  }
127842
- if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
127959
+ 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)) {
127843
127960
  throw new TypeError("Cannot change the prototype of a non-extensible object.");
127844
127961
  }
127845
127962
  let depth = 0;
@@ -127874,11 +127991,13 @@ function hasGuestObjectState(value) {
127874
127991
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
127875
127992
  );
127876
127993
  }
127877
- var guestClosures, functionProperties, prototypes, intrinsicPrototypes, boxedPrototypes, regexPrototypes, collectionPrototypes, promisePrototypes, datePrototypes, arrayPrototypes, initialArrayMethods, initialRegexDescriptors, intrinsicPrototypeRoots, intrinsicConstructors, intrinsicFunctions, initialBoxedMethods, descriptorObjects;
127994
+ var guestClosures, functionProperties, functionPropertyRevisions, prototypes, intrinsicPrototypes, boxedPrototypes, regexPrototypes, collectionPrototypes, promisePrototypes, datePrototypes, arrayPrototypes, functionPrototypes, initialArrayMethods, initialRegexDescriptors, intrinsicPrototypeRoots, intrinsicConstructors, intrinsicFunctions, initialBoxedMethods, descriptorObjects;
127878
127995
  var init_object_model = __esm({
127879
127996
  "packages/safe-js/src/interp/object-model.ts"() {
127880
127997
  "use strict";
127881
127998
  init_graph_depth();
127999
+ init_generator_properties();
128000
+ init_resources();
127882
128001
  init_intrinsics();
127883
128002
  init_template_objects();
127884
128003
  init_date();
@@ -127888,6 +128007,7 @@ var init_object_model = __esm({
127888
128007
  init_values();
127889
128008
  guestClosures = /* @__PURE__ */ new WeakSet();
127890
128009
  functionProperties = /* @__PURE__ */ new WeakMap();
128010
+ functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
127891
128011
  prototypes = /* @__PURE__ */ new WeakMap();
127892
128012
  intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
127893
128013
  boxedPrototypes = /* @__PURE__ */ new WeakMap();
@@ -127896,6 +128016,7 @@ var init_object_model = __esm({
127896
128016
  promisePrototypes = /* @__PURE__ */ new WeakMap();
127897
128017
  datePrototypes = /* @__PURE__ */ new WeakMap();
127898
128018
  arrayPrototypes = /* @__PURE__ */ new WeakMap();
128019
+ functionPrototypes = /* @__PURE__ */ new WeakMap();
127899
128020
  initialArrayMethods = /* @__PURE__ */ new WeakMap();
127900
128021
  initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
127901
128022
  intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
@@ -128000,7 +128121,7 @@ var init_float32 = __esm({
128000
128121
  });
128001
128122
 
128002
128123
  // packages/safe-js/src/interp/promise-tracker.ts
128003
- import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
128124
+ import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
128004
128125
  function assertPromiseExecutionAllowed() {
128005
128126
  const failure = activePromiseTracker.getStore()?.failure;
128006
128127
  if (failure !== void 0 && fatalRejectionCleanup.getStore() !== true) throw failure;
@@ -128114,13 +128235,13 @@ var init_promise_tracker = __esm({
128114
128235
  return void 0;
128115
128236
  }
128116
128237
  };
128117
- activePromiseTracker = new AsyncLocalStorage4();
128118
- fatalRejectionCleanup = new AsyncLocalStorage4();
128238
+ activePromiseTracker = new AsyncLocalStorage5();
128239
+ fatalRejectionCleanup = new AsyncLocalStorage5();
128119
128240
  }
128120
128241
  });
128121
128242
 
128122
128243
  // packages/safe-js/src/interp/promise-replay.ts
128123
- import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
128244
+ import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
128124
128245
  function validateReplay(value) {
128125
128246
  validateSnapshotData(value);
128126
128247
  if (value === null || typeof value !== "object" || !("version" in value) || value.version !== 1 || !("steps" in value) || !isCounter(value.steps) || !("promises" in value) || !isCounter(value.promises) || !("settlements" in value) || !Array.isArray(value.settlements)) {
@@ -128469,7 +128590,7 @@ var init_promise_replay = __esm({
128469
128590
  this.liveWaiters.clear();
128470
128591
  }
128471
128592
  };
128472
- promiseReplayContext = new AsyncLocalStorage5();
128593
+ promiseReplayContext = new AsyncLocalStorage6();
128473
128594
  }
128474
128595
  });
128475
128596
 
@@ -130389,61 +130510,6 @@ var init_engine2 = __esm({
130389
130510
  }
130390
130511
  });
130391
130512
 
130392
- // packages/safe-js/src/interp/resources.ts
130393
- import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
130394
- function retainValues(budget, values) {
130395
- const retained = {};
130396
- budget.setRetainedValues(retained, values);
130397
- const pending = runResources.getStore()?.referenceReleases;
130398
- const release2 = () => {
130399
- budget.setRetainedValues(retained, void 0);
130400
- pending?.delete(release2);
130401
- };
130402
- pending?.add(release2);
130403
- return release2;
130404
- }
130405
- async function withRunResources(signal, execute2) {
130406
- const controller = new AbortController();
130407
- const cancel2 = () => controller.abort(signal?.reason);
130408
- const cleanups = /* @__PURE__ */ new Set();
130409
- const resources = {
130410
- signal: controller.signal,
130411
- referenceReleases: /* @__PURE__ */ new Set(),
130412
- add(close) {
130413
- cleanups.add(close);
130414
- }
130415
- };
130416
- signal?.addEventListener("abort", cancel2, { once: true });
130417
- if (signal?.aborted) cancel2();
130418
- let result;
130419
- let failure;
130420
- let errors2 = [];
130421
- try {
130422
- result = await runResources.run(resources, execute2);
130423
- } catch (error3) {
130424
- failure = { reason: error3 };
130425
- } finally {
130426
- signal?.removeEventListener("abort", cancel2);
130427
- controller.abort(new Error("SafeJS run finished."));
130428
- for (const release2 of resources.referenceReleases) release2();
130429
- resources.referenceReleases.clear();
130430
- const outcomes = await Promise.allSettled(
130431
- [...cleanups].map((close) => Promise.resolve().then(close))
130432
- );
130433
- errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
130434
- }
130435
- if (failure !== void 0) throw failure.reason;
130436
- if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
130437
- return result;
130438
- }
130439
- var runResources;
130440
- var init_resources = __esm({
130441
- "packages/safe-js/src/interp/resources.ts"() {
130442
- "use strict";
130443
- runResources = new AsyncLocalStorage6();
130444
- }
130445
- });
130446
-
130447
130513
  // packages/safe-js/src/interp/bigint-operators.ts
130448
130514
  function bigIntOperation(operator, left, right, budget) {
130449
130515
  if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
@@ -130865,7 +130931,10 @@ async function restoreSandboxIterator(snapshot2, budget, context, signal) {
130865
130931
  if (snapshot2.kind === "guest") return guestIterator(snapshot2.value, snapshot2.next, snapshot2.async, budget, context, signal);
130866
130932
  if (snapshot2.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot2.inner, budget, context, signal), budget, signal, context);
130867
130933
  if (Array.isArray(snapshot2.value)) return arrayIterator(snapshot2.value, context, budget, snapshot2.index);
130868
- const iterator = isSandboxGenerator(snapshot2.value) && snapshot2.value.async ? getSandboxAsyncIterator(snapshot2.value, budget, context, signal) : getSandboxIterator(snapshot2.value, budget, context);
130934
+ const iterator = isSandboxGenerator(snapshot2.value) ? {
130935
+ ...generatorObjectIterator(snapshot2.value, budget, context),
130936
+ ...snapshot2.value.async ? { asyncProtocol: true } : {}
130937
+ } : getSandboxIterator(snapshot2.value, budget, context);
130869
130938
  if (iterator === void 0) throw new TypeError("Invalid builtin iterator snapshot.");
130870
130939
  for (let index = 0; index < snapshot2.index; index++) await iterator.next();
130871
130940
  return iterator;
@@ -130875,6 +130944,11 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
130875
130944
  if (context.getProperty === void 0 || isGuestHostObject(value))
130876
130945
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
130877
130946
  if (getSandboxPropertyDescriptor(value, key3, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
130947
+ if (isSandboxGenerator(value)) {
130948
+ if (hasExplicitSandboxPrototype(value)) return void 0;
130949
+ if (value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
130950
+ return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
130951
+ }
130878
130952
  if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
130879
130953
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
130880
130954
  if (isSandboxGenerator(value) && value.async)
@@ -130939,7 +131013,7 @@ async function readIteratorResult(iterator, result, property) {
130939
131013
  }
130940
131014
  function getSandboxAsyncIterator(value, budget, context, signal) {
130941
131015
  if (isSandboxGenerator(value) && value.async) {
130942
- return { ...generatorIterator(value, budget, context), asyncProtocol: true };
131016
+ return hasExplicitSandboxPrototype(value) ? void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
130943
131017
  }
130944
131018
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
130945
131019
  const method = value[Symbol.asyncIterator];
@@ -131089,7 +131163,7 @@ function getSandboxIterator(value, budget, context) {
131089
131163
  return syncIterator(Float32Array.prototype.values.call(value));
131090
131164
  }
131091
131165
  if (isSandboxGenerator(value)) {
131092
- return value.async ? void 0 : generatorIterator(value);
131166
+ return value.async || hasExplicitSandboxPrototype(value) ? void 0 : generatorObjectIterator(value, budget, context);
131093
131167
  }
131094
131168
  if (typeof value === "string") {
131095
131169
  const iterator2 = value[Symbol.iterator]();
@@ -131165,6 +131239,26 @@ function collectionIterator(collection, value) {
131165
131239
  adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
131166
131240
  return adapter;
131167
131241
  }
131242
+ function generatorObjectIterator(generator, budget, context) {
131243
+ const iterator = generatorIterator(generator, budget, context);
131244
+ if (context?.getProperty === void 0) return iterator;
131245
+ return {
131246
+ ...iterator,
131247
+ getOperation: async (method) => {
131248
+ if (method === "next" || !hasExplicitSandboxPrototype(generator) && getSandboxPropertyDescriptor(generator, method, budget) === void 0) return iterator[method];
131249
+ const operation = await context.getProperty(generator, method);
131250
+ if (operation === void 0 || operation === null) return void 0;
131251
+ if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
131252
+ return async (...args) => {
131253
+ const result = await invokeBuiltinClosure(operation, args, budget ?? new Budget(), context, generator);
131254
+ return generator.async ? await awaitSandboxValue(result, void 0, budget, context) : result;
131255
+ };
131256
+ },
131257
+ readResultProperty: async (result, property) => ({
131258
+ value: await context.getProperty(result, property)
131259
+ })
131260
+ };
131261
+ }
131168
131262
  function generatorIterator(generator, budget, context) {
131169
131263
  const invoke2 = async (method, value) => {
131170
131264
  const leaveRunning = enterRunningState(generator);
@@ -134660,14 +134754,14 @@ function createObjectArrayGlobals(options) {
134660
134754
  call: ([value]) => {
134661
134755
  if (isGuestHostObject(value))
134662
134756
  throw new TypeError("Live host objects cannot be made non-extensible.");
134663
- Object.preventExtensions(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
134757
+ 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);
134664
134758
  return value;
134665
134759
  },
134666
134760
  name: "preventExtensions"
134667
134761
  }),
134668
134762
  isExtensible: createSandboxClosure({
134669
134763
  sandbox: true,
134670
- call: ([value]) => Object.isExtensible(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
134764
+ 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),
134671
134765
  name: "isExtensible"
134672
134766
  }),
134673
134767
  seal: createSandboxClosure({
@@ -134675,14 +134769,14 @@ function createObjectArrayGlobals(options) {
134675
134769
  call: ([value]) => {
134676
134770
  if (isGuestHostObject(value))
134677
134771
  throw new TypeError("Live host objects cannot be sealed.");
134678
- Object.seal(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
134772
+ 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);
134679
134773
  return value;
134680
134774
  },
134681
134775
  name: "seal"
134682
134776
  }),
134683
134777
  isSealed: createSandboxClosure({
134684
134778
  sandbox: true,
134685
- call: ([value]) => Object.isSealed(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
134779
+ 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),
134686
134780
  name: "isSealed"
134687
134781
  }),
134688
134782
  freeze: createSandboxClosure({
@@ -134691,7 +134785,7 @@ function createObjectArrayGlobals(options) {
134691
134785
  if (isGuestHostObject(value))
134692
134786
  throw new TypeError("Live host objects cannot be frozen.");
134693
134787
  if (typeof value === "object" && value !== null) {
134694
- Object.freeze(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
134788
+ 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);
134695
134789
  }
134696
134790
  return value;
134697
134791
  },
@@ -134699,7 +134793,7 @@ function createObjectArrayGlobals(options) {
134699
134793
  }),
134700
134794
  isFrozen: createSandboxClosure({
134701
134795
  sandbox: true,
134702
- call: ([value]) => Object.isFrozen(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
134796
+ 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),
134703
134797
  name: "isFrozen"
134704
134798
  }),
134705
134799
  assign: createSandboxClosure({
@@ -135042,6 +135136,7 @@ function reflectionProperties(value) {
135042
135136
  return objectProperties(value);
135043
135137
  }
135044
135138
  function objectProperties(value, mutable = false) {
135139
+ if (isSandboxGenerator(value)) return getGeneratorProperties(value);
135045
135140
  if (isSandboxPromise(value)) return getPromiseProperties(value);
135046
135141
  if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
135047
135142
  if (isSandboxRegex(value)) return getRegexProperties(value);
@@ -135360,6 +135455,7 @@ var init_object_array = __esm({
135360
135455
  "packages/safe-js/src/interp/globals/object-array.ts"() {
135361
135456
  "use strict";
135362
135457
  init_budget2();
135458
+ init_generator_properties();
135363
135459
  init_accessors();
135364
135460
  init_builtin_call();
135365
135461
  init_data_checkpoint();
@@ -135638,7 +135734,7 @@ function getFunctionMember(target, property, options) {
135638
135734
  } else if (Object.hasOwn(current, String(property))) {
135639
135735
  return current[String(property)];
135640
135736
  }
135641
- if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current)) break;
135737
+ if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current) && getSandboxPrototype(current, options.budget) === null) break;
135642
135738
  current = getSandboxPrototype(current, options.budget);
135643
135739
  if (current !== null) {
135644
135740
  options.budget?.visitNode();
@@ -137911,7 +138007,7 @@ function forInKeys(object, budget) {
137911
138007
  for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
137912
138008
  if (depth > 0) budget.visitNode();
137913
138009
  assertSandboxDataDepth(depth++);
137914
- 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;
138010
+ 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;
137915
138011
  for (const key3 of Object.getOwnPropertyNames(properties)) {
137916
138012
  if (seen.has(key3)) continue;
137917
138013
  seen.add(key3);
@@ -137927,7 +138023,7 @@ function hasForInProperty(object, key3, budget) {
137927
138023
  for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
137928
138024
  if (depth > 0) budget.visitNode();
137929
138025
  assertSandboxDataDepth(depth++);
137930
- 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;
138026
+ 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;
137931
138027
  if (Object.hasOwn(properties, key3)) return true;
137932
138028
  }
137933
138029
  return false;
@@ -138483,7 +138579,7 @@ function getPropertyValue(target, property, context, receiver = target) {
138483
138579
  if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
138484
138580
  if (isSandboxCollectionIterator(target))
138485
138581
  return getCollectionIteratorMember(target, property, context.budget);
138486
- if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
138582
+ if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
138487
138583
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
138488
138584
  if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
138489
138585
  if (isSandboxRegex(target)) return hasExplicitSandboxPrototype(target) || getSandboxPrototype(target, context.budget) !== null ? void 0 : getRegexMember(target, property, context.budget, createCoercionContext(context));
@@ -138799,7 +138895,7 @@ async function evaluateMemberCallExpression(node, context) {
138799
138895
  );
138800
138896
  }
138801
138897
  if (isSandboxGenerator(member.object)) {
138802
- const memberValue = getGeneratorMember(member.object, member.property, context.budget);
138898
+ const memberValue = await getPropertyValue(member.object, member.property, context);
138803
138899
  if (memberValue === void 0) {
138804
138900
  throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
138805
138901
  }
@@ -139103,7 +139199,7 @@ function hasSandboxProperty(value, key3, context) {
139103
139199
  while (typeof current === "object" && current !== null) {
139104
139200
  if (isGuestHostObject(current)) return typeof key3 === "symbol" ? false : hasHostObjectMember(current, String(key3));
139105
139201
  if (hasOwnSandboxProperty(current, key3, false)) return true;
139106
- 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))) {
139202
+ 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))) {
139107
139203
  return getPropertyValue(current, key3, context) !== void 0;
139108
139204
  }
139109
139205
  current = getSandboxPrototype(current, context.budget);
@@ -139349,6 +139445,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
139349
139445
  }
139350
139446
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
139351
139447
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
139448
+ if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
139352
139449
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
139353
139450
  if (isFloat32Array(target)) {
139354
139451
  if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
@@ -139382,7 +139479,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
139382
139479
  for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
139383
139480
  budget.visitNode();
139384
139481
  assertSandboxDataDepth(depth++);
139385
- const properties = isSandboxClosure(prototype) ? prototype.properties : prototype;
139482
+ const properties = isSandboxGenerator(prototype) ? getGeneratorProperties(prototype) : isSandboxClosure(prototype) ? prototype.properties : prototype;
139386
139483
  const inherited = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
139387
139484
  if (inherited === void 0) continue;
139388
139485
  if (inherited.writable !== true)
@@ -139401,7 +139498,7 @@ function setSuperProperty(base, receiver, key3, value, context) {
139401
139498
  for (let current = base; current !== null; current = getSandboxPrototype(current, budget)) {
139402
139499
  budget.visitNode();
139403
139500
  assertSandboxDataDepth(depth++);
139404
- const properties = isSandboxClosure(current) ? current.properties : current;
139501
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxClosure(current) ? current.properties : current;
139405
139502
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
139406
139503
  if (descriptor === void 0) continue;
139407
139504
  if (!("value" in descriptor))
@@ -139419,6 +139516,7 @@ function deleteSandboxProperty(target, property) {
139419
139516
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
139420
139517
  if (isSandboxRegex(target)) target = getRegexProperties(target);
139421
139518
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
139519
+ if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
139422
139520
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
139423
139521
  if (Array.isArray(target)) {
139424
139522
  assertCollectionMutable(target);
@@ -139741,6 +139839,7 @@ var init_interpreter = __esm({
139741
139839
  init_iteration();
139742
139840
  init_running_state();
139743
139841
  init_generator2();
139842
+ init_generator_properties();
139744
139843
  init_regex();
139745
139844
  init_patterns();
139746
139845
  init_string();
@@ -140116,11 +140215,11 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
140116
140215
  }
140117
140216
  }
140118
140217
  function conversionHook(value, name, budget, context) {
140119
- 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));
140218
+ 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));
140120
140219
  let current = value;
140121
140220
  let depth = 0;
140122
140221
  while (current !== null) {
140123
- const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
140222
+ 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;
140124
140223
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, name);
140125
140224
  if (descriptor !== void 0) {
140126
140225
  return readPropertyDescriptor(descriptor, value, context);
@@ -140183,6 +140282,7 @@ var init_string_coercion = __esm({
140183
140282
  "packages/safe-js/src/interp/string-coercion.ts"() {
140184
140283
  "use strict";
140185
140284
  init_shape();
140285
+ init_generator_properties();
140186
140286
  init_accessors();
140187
140287
  init_date();
140188
140288
  init_builtin_call();
@@ -140363,8 +140463,7 @@ function hasOwnSandboxProperty(value, key3, enumerable) {
140363
140463
  properties = value.properties ?? /* @__PURE__ */ Object.create(null);
140364
140464
  } else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
140365
140465
  else if (isSandboxPromise(value)) properties = getPromiseProperties(value);
140366
- else if (isSandboxGenerator(value))
140367
- return false;
140466
+ else if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
140368
140467
  else if (isSandboxRegex(value)) properties = getRegexProperties(value);
140369
140468
  else properties = Object(value);
140370
140469
  const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
@@ -140401,6 +140500,7 @@ var init_object2 = __esm({
140401
140500
  "packages/safe-js/src/interp/globals/object.ts"() {
140402
140501
  "use strict";
140403
140502
  init_graph_depth();
140503
+ init_generator_properties();
140404
140504
  init_accessors();
140405
140505
  init_arguments();
140406
140506
  init_date();
@@ -142206,6 +142306,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
142206
142306
  if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
142207
142307
  else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
142208
142308
  else if (isSandboxPromise(value)) entries = Object.entries(getPromiseProperties(value));
142309
+ else if (isSandboxGenerator(value)) entries = Object.entries(getGeneratorProperties(value));
142209
142310
  else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
142210
142311
  else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
142211
142312
  else entries = Object.entries(Object(value));
@@ -142217,19 +142318,20 @@ function ownSandboxSymbolKeys(value) {
142217
142318
  if (isSandboxClosure(value)) value = value.properties ?? {};
142218
142319
  else if (isSandboxRegex(value)) value = getRegexProperties(value);
142219
142320
  else if (isSandboxPromise(value)) value = getPromiseProperties(value);
142321
+ else if (isSandboxGenerator(value)) value = getGeneratorProperties(value);
142220
142322
  else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
142221
- else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
142222
142323
  return Object.getOwnPropertySymbols(Object(value)).filter((key3) => !internalSymbols.has(key3));
142223
142324
  }
142224
142325
  function ownEnumerableSandboxKeys(value, includeSymbols = false) {
142225
142326
  if (includeSymbols) {
142226
- const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
142327
+ 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);
142227
142328
  return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key3) => Object.getOwnPropertyDescriptor(properties, key3)?.enumerable === true)];
142228
142329
  }
142229
142330
  if (isGuestHostObject(value)) return getHostObjectKeys(value);
142230
142331
  if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
142231
142332
  if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
142232
142333
  if (isSandboxPromise(value)) return Object.keys(getPromiseProperties(value));
142334
+ if (isSandboxGenerator(value)) return Object.keys(getGeneratorProperties(value));
142233
142335
  if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
142234
142336
  if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
142235
142337
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
@@ -142281,6 +142383,7 @@ function createSandboxGenerator(channel, metadata = void 0) {
142281
142383
  enumerable: false,
142282
142384
  value: true
142283
142385
  });
142386
+ getGeneratorProperties(generator);
142284
142387
  return generator;
142285
142388
  }
142286
142389
  function createSandboxMap(entries = []) {
@@ -142535,6 +142638,14 @@ function measureSandboxData(values, options = {}) {
142535
142638
  return;
142536
142639
  }
142537
142640
  if (isSandboxGenerator(value)) {
142641
+ const descriptors3 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
142642
+ for (const key3 of Reflect.ownKeys(descriptors3)) {
142643
+ const descriptor = descriptors3[key3];
142644
+ usage += typeof key3 === "string" ? key3.length + 1 : 1;
142645
+ if (typeof key3 === "symbol") visit(key3, depth + 1);
142646
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
142647
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
142648
+ }
142538
142649
  const snapshot2 = value.channel.snapshot();
142539
142650
  usage += snapshot2.sent.length;
142540
142651
  for (const completion of snapshot2.sent) visit(completion.value, depth + 1);
@@ -143299,6 +143410,7 @@ var init_values = __esm({
143299
143410
  "use strict";
143300
143411
  init_otel2();
143301
143412
  init_internal_symbols();
143413
+ init_generator_properties();
143302
143414
  init_regexp_properties();
143303
143415
  init_collection_properties();
143304
143416
  init_collection_properties();
@@ -143456,6 +143568,7 @@ function captureGuestHeapNode(value, encode) {
143456
143568
  state: value.state,
143457
143569
  astNodeId: origin2.node.nodeId,
143458
143570
  async: value.async === true,
143571
+ objectState: captureObjectState(value, encode),
143459
143572
  scope: encode(origin2.scope),
143460
143573
  closureScope: encode(origin2.closureScope),
143461
143574
  ...value.state !== "suspended" || origin2.suspendedScope === void 0 ? {} : { suspendedScope: encode(origin2.suspendedScope) },
@@ -143571,6 +143684,7 @@ function captureGuestHeapNode(value, encode) {
143571
143684
  }
143572
143685
  function captureObjectState(value, encode) {
143573
143686
  let properties = value;
143687
+ if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
143574
143688
  if (isSandboxClosure(value)) {
143575
143689
  properties = value.properties;
143576
143690
  if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
@@ -143585,6 +143699,7 @@ var init_guest_heap = __esm({
143585
143699
  "packages/safe-js/src/snapshot/guest-heap.ts"() {
143586
143700
  "use strict";
143587
143701
  init_closure_origin();
143702
+ init_generator_properties();
143588
143703
  init_intrinsics();
143589
143704
  init_object_model();
143590
143705
  init_host_capabilities();
@@ -146799,6 +146914,40 @@ var init_uri = __esm({
146799
146914
  }
146800
146915
  });
146801
146916
 
146917
+ // packages/safe-js/src/interp/globals/function.ts
146918
+ function createFunctionPrototype(budget) {
146919
+ const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
146920
+ const properties = materializeFunctionProperties(prototype);
146921
+ Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
146922
+ for (const [name, length] of [["call", 1], ["apply", 2], ["bind", 1], ["toString", 0]]) {
146923
+ Object.defineProperty(properties, name, {
146924
+ writable: true,
146925
+ configurable: true,
146926
+ value: createSandboxClosure({
146927
+ guest: true,
146928
+ sandbox: true,
146929
+ name,
146930
+ length,
146931
+ call: (args, context) => callFunctionMethod(context?.thisValue, name, args, {
146932
+ budget,
146933
+ 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)
146934
+ }, context?.stack ?? [], context)
146935
+ })
146936
+ });
146937
+ }
146938
+ setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
146939
+ installFunctionPrototype(budget, prototype);
146940
+ }
146941
+ var init_function2 = __esm({
146942
+ "packages/safe-js/src/interp/globals/function.ts"() {
146943
+ "use strict";
146944
+ init_builtin_call();
146945
+ init_function();
146946
+ init_object_model();
146947
+ init_values();
146948
+ }
146949
+ });
146950
+
146802
146951
  // packages/safe-js/src/interp/globals/symbol.ts
146803
146952
  function createSymbolGlobal(budget) {
146804
146953
  let registry = registries.get(budget);
@@ -147051,6 +147200,7 @@ function createBuiltinBindings(options) {
147051
147200
  ...createPromiseGlobals(options),
147052
147201
  ...createRegexGlobals(options)
147053
147202
  };
147203
+ createFunctionPrototype(options.budget);
147054
147204
  registerBuiltinIdentities(options.budget, bindings);
147055
147205
  return bindings;
147056
147206
  }
@@ -147066,6 +147216,7 @@ var init_globals = __esm({
147066
147216
  init_misc();
147067
147217
  init_uri();
147068
147218
  init_object_array();
147219
+ init_function2();
147069
147220
  init_promise();
147070
147221
  init_date2();
147071
147222
  init_symbol();
@@ -147239,7 +147390,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
147239
147390
  }
147240
147391
  state(node.state);
147241
147392
  } else if (node.kind === "guest-generator") {
147242
- fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates"]);
147393
+ fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
147394
+ if (Object.hasOwn(node, "objectState")) state(node.objectState);
147243
147395
  if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer2(node.astNodeId) < 1)
147244
147396
  throw new TypeError("Invalid generator state.");
147245
147397
  reference(node.scope, ["scope-frame"]);