poe-code 14.0.80 → 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 (40) hide show
  1. package/dist/index.js +500 -221
  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-34G5WW2O.js → chunk-2LNBLFJ3.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-M4L3EZHL.js → chunk-ZSYBRZU6.js} +431 -206
  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/index.js +2 -2
  11. package/packages/safe-js/dist/interp/async.d.ts +1 -1
  12. package/packages/safe-js/dist/interp/async.js +65 -43
  13. package/packages/safe-js/dist/interp/bound-function-state.d.ts +7 -0
  14. package/packages/safe-js/dist/interp/bound-function-state.js +1 -0
  15. package/packages/safe-js/dist/interp/bound-function.d.ts +4 -0
  16. package/packages/safe-js/dist/interp/bound-function.js +18 -0
  17. package/packages/safe-js/dist/interp/generator-prototypes.d.ts +6 -0
  18. package/packages/safe-js/dist/interp/generator-prototypes.js +1 -0
  19. package/packages/safe-js/dist/interp/globals/function.d.ts +1 -1
  20. package/packages/safe-js/dist/interp/globals/function.js +10 -2
  21. package/packages/safe-js/dist/interp/globals/generator.d.ts +2 -0
  22. package/packages/safe-js/dist/interp/globals/generator.js +51 -0
  23. package/packages/safe-js/dist/interp/globals/object-array.js +19 -1
  24. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  25. package/packages/safe-js/dist/interp/globals.js +3 -1
  26. package/packages/safe-js/dist/interp/instanceof.d.ts +4 -0
  27. package/packages/safe-js/dist/interp/instanceof.js +58 -0
  28. package/packages/safe-js/dist/interp/interpreter.js +3 -40
  29. package/packages/safe-js/dist/interp/iteration.js +44 -6
  30. package/packages/safe-js/dist/interp/methods/function.d.ts +1 -1
  31. package/packages/safe-js/dist/interp/methods/function.js +53 -40
  32. package/packages/safe-js/dist/interp/methods/generator.d.ts +4 -1
  33. package/packages/safe-js/dist/interp/methods/generator.js +12 -6
  34. package/packages/safe-js/dist/interp/object-model.js +2 -0
  35. package/packages/safe-js/dist/snapshot/guest-heap-validation.js +24 -2
  36. package/packages/safe-js/dist/snapshot/guest-heap.d.ts +8 -0
  37. package/packages/safe-js/dist/snapshot/guest-heap.js +7 -0
  38. package/packages/safe-js/dist/snapshot/restore.js +53 -7
  39. package/packages/safe-js/dist/chunks/chunk-M4L3EZHL.js.map +0 -7
  40. /package/packages/safe-js/dist/chunks/{chunk-34G5WW2O.js.map → chunk-2LNBLFJ3.js.map} +0 -0
@@ -7398,6 +7398,9 @@ function graphEntries(value) {
7398
7398
  return entries;
7399
7399
  }
7400
7400
 
7401
+ // packages/safe-js/src/interp/generator-prototypes.ts
7402
+ var generatorPrototypes = /* @__PURE__ */ new WeakMap();
7403
+
7401
7404
  // packages/safe-js/src/interp/resources.ts
7402
7405
  import { AsyncLocalStorage } from "node:async_hooks";
7403
7406
  var runResources = new AsyncLocalStorage();
@@ -8082,6 +8085,7 @@ function releaseObjectPrototype(budget) {
8082
8085
  datePrototypes.delete(budget);
8083
8086
  arrayPrototypes.delete(budget);
8084
8087
  functionPrototypes.delete(budget);
8088
+ generatorPrototypes.delete(budget);
8085
8089
  initialRegexDescriptors.delete(budget);
8086
8090
  intrinsicPrototypes.delete(budget);
8087
8091
  }
@@ -9455,13 +9459,12 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9455
9459
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
9456
9460
  if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9457
9461
  if (isSandboxGenerator(value)) {
9458
- if (hasExplicitSandboxPrototype(value)) return void 0;
9459
- if (value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9462
+ if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9460
9463
  return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
9461
9464
  }
9462
9465
  if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
9463
9466
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9464
- if (isSandboxGenerator(value) && value.async)
9467
+ if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
9465
9468
  return getSandboxAsyncIterator(value, budget, context, signal);
9466
9469
  const iterator2 = await acquireSandboxIterator(value, budget, context);
9467
9470
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
@@ -9523,7 +9526,7 @@ async function readIteratorResult(iterator, result, property) {
9523
9526
  }
9524
9527
  function getSandboxAsyncIterator(value, budget, context, signal) {
9525
9528
  if (isSandboxGenerator(value) && value.async) {
9526
- return hasExplicitSandboxPrototype(value) ? void 0 : { ...generatorObjectIterator(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 };
9527
9530
  }
9528
9531
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
9529
9532
  const method = value[Symbol.asyncIterator];
@@ -9673,7 +9676,9 @@ function getSandboxIterator(value, budget, context) {
9673
9676
  return syncIterator(Float32Array.prototype.values.call(value));
9674
9677
  }
9675
9678
  if (isSandboxGenerator(value)) {
9676
- return value.async || hasExplicitSandboxPrototype(value) ? void 0 : generatorObjectIterator(value, budget, context);
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);
9677
9682
  }
9678
9683
  if (typeof value === "string") {
9679
9684
  const iterator2 = value[Symbol.iterator]();
@@ -9750,6 +9755,38 @@ function collectionIterator(collection, value) {
9750
9755
  return adapter;
9751
9756
  }
9752
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
+ }
9753
9790
  function generatorObjectIterator(generator, budget, context) {
9754
9791
  const iterator = generatorIterator(generator, budget, context);
9755
9792
  if (context?.getProperty === void 0) return iterator;
@@ -10225,12 +10262,12 @@ async function evaluateFunctionExpression(node, context, evaluateNode2) {
10225
10262
  value: closure
10226
10263
  };
10227
10264
  }
10228
- function createInterpretedClosure(node, context, evaluateNode2, homeObject) {
10265
+ function createInterpretedClosure(node, context, evaluateNode2, homeObject, initializeGeneratorPrototype = true) {
10229
10266
  if (node.type !== "ArrowFunctionExpression") {
10230
10267
  context = { ...context, functionEnvironment: { homeObject } };
10231
10268
  }
10232
10269
  if (node.type !== "ArrowFunctionExpression" && node.generator) {
10233
- return createGeneratorClosure(node, context, evaluateNode2);
10270
+ return createGeneratorClosure(node, context, evaluateNode2, initializeGeneratorPrototype);
10234
10271
  }
10235
10272
  const construct = node.type !== "ArrowFunctionExpression" && !(node.type === "FunctionExpression" && node.method === true) && !node.async ? async (args, callContext) => {
10236
10273
  const thisValue = {};
@@ -10317,7 +10354,8 @@ function executeAsyncFunction(execute, budget, signal, callContext) {
10317
10354
  });
10318
10355
  return createSandboxPromise(promise, { synchronousPrefix });
10319
10356
  }
10320
- 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);
10321
10359
  const closure = createSandboxClosure({
10322
10360
  sourceRange: functionSources.get(node),
10323
10361
  guest: true,
@@ -10327,54 +10365,69 @@ function createGeneratorClosure(node, context, evaluateNode2) {
10327
10365
  ...node.id === void 0 ? { name: context.inferredName } : { name: node.id.name },
10328
10366
  retainedValues: () => [...context.scope.retainedValues(), context.functionEnvironment?.homeObject, context.functionEnvironment?.newTarget],
10329
10367
  call: async (args, callContext) => {
10330
- const closureContext = {
10331
- ...context,
10332
- compilation: callContext?.compilation ?? context.compilation,
10333
- callStack: [...callContext?.stack ?? context.callStack]
10334
- };
10335
- const scope = await createClosureScope(
10336
- node,
10337
- args,
10338
- callContext?.thisValue,
10339
- closureContext,
10340
- evaluateNode2
10341
- );
10342
- const channel = createGeneratorChannel((generatorYield) => {
10343
- const execute = async () => {
10344
- const result = await evaluateNode2(node.body, {
10345
- ...closureContext,
10346
- functionBody: node.body,
10347
- asyncGenerator: node.async,
10348
- generatorBlockScopes: /* @__PURE__ */ new Map(),
10349
- generatorExpressionStates: /* @__PURE__ */ new Map(),
10350
- captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
10351
- origin.suspendedScope = suspendedScope;
10352
- origin.blockScopes = blocks;
10353
- origin.finallyCompletions = completions;
10354
- origin.expressionStates = expressions;
10355
- },
10356
- generatorYield: (value2, yieldNodeId) => {
10357
- generator.state = "suspended";
10358
- return generatorYield(value2, yieldNodeId);
10359
- },
10360
- scope
10361
- });
10362
- if (result.kind === "error") {
10363
- throw result.error;
10364
- }
10365
- if (result.kind === "throw") {
10366
- throw result.value;
10367
- }
10368
- const value = result.hasValue ? result.value : void 0;
10369
- 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]
10370
10376
  };
10371
- return node.async ? runAsyncPrefix(execute) : execute();
10372
- });
10373
- const generator = createSandboxGenerator(channel, { async: node.async });
10374
- const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
10375
- 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
+ }
10376
10422
  }
10377
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
+ }
10378
10431
  registerClosureOrigin(closure, node, context);
10379
10432
  return closure;
10380
10433
  }
@@ -13261,6 +13314,32 @@ function createArrayGlobal(budget) {
13261
13314
  length: 0,
13262
13315
  call: (_args, context) => context?.thisValue
13263
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
+ });
13264
13343
  setSandboxPrototype(iterablePrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
13265
13344
  setSandboxPrototype(iteratorPrototype, iterablePrototype);
13266
13345
  Object.defineProperties(iteratorPrototype, {
@@ -13274,6 +13353,9 @@ function createArrayGlobal(budget) {
13274
13353
  [Symbol.toStringTag]: { value: "Array Iterator", configurable: true }
13275
13354
  });
13276
13355
  registerBuiltinIdentities(budget, { "%ArrayIteratorPrototype%": iteratorPrototype, "%IteratorPrototype%": iterablePrototype });
13356
+ registerIntrinsicFunction(budget, iterablePrototype[Symbol.iterator]);
13357
+ registerIntrinsicFunction(budget, iteratorTagGetter);
13358
+ registerIntrinsicFunction(budget, iteratorTagSetter);
13277
13359
  registerIntrinsicObject(budget, iterablePrototype);
13278
13360
  registerIntrinsicObject(budget, iteratorPrototype);
13279
13361
  for (const method of ["keys", "values", "entries"]) {
@@ -13998,6 +14080,34 @@ function functionString(value) {
13998
14080
  return `function ${name}() { [native code] }`;
13999
14081
  }
14000
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
+
14001
14111
  // packages/safe-js/src/interp/methods/function.ts
14002
14112
  var functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
14003
14113
  function getFunctionMember(target, property, options) {
@@ -14049,28 +14159,11 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
14049
14159
  const thisValue = args[0];
14050
14160
  if (methodName === "bind") {
14051
14161
  const boundArgs = args.slice(1);
14162
+ const explicitPrototype = hasExplicitSandboxPrototype(target);
14163
+ const prototype = getSandboxPrototype(target, options.budget);
14052
14164
  const bind = (length, name) => {
14053
- const bound = createSandboxClosure({
14054
- guest: true,
14055
- sandbox: true,
14056
- name: `bound ${name}`,
14057
- length,
14058
- boundTarget: target,
14059
- retainedValues: () => [target, thisValue, ...boundArgs, bound.name],
14060
- call: (callArgs, context2) => options.callClosure(target, [...boundArgs, ...callArgs], context2?.stack ?? [], thisValue),
14061
- ...target.construct === void 0 ? {} : {
14062
- construct: (callArgs, context2) => options.callClosure(
14063
- target,
14064
- [...boundArgs, ...callArgs],
14065
- context2?.stack ?? [],
14066
- void 0,
14067
- true,
14068
- context2?.newTarget === bound ? target : context2?.newTarget
14069
- )
14070
- }
14071
- });
14072
- if (hasExplicitSandboxPrototype(target))
14073
- 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);
14074
14167
  return bound;
14075
14168
  };
14076
14169
  if (context?.getProperty === void 0)
@@ -14079,15 +14172,20 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
14079
14172
  target.name ?? ""
14080
14173
  );
14081
14174
  return (async () => {
14082
- const properties = target.properties;
14083
- const defaultName = target.name;
14084
- const hasLength = !isGuestClosure(target) || target.properties === void 0 || Object.hasOwn(target.properties, "length");
14085
- const length = hasLength ? await context.getProperty(target, "length") : void 0;
14086
- const name = !isGuestClosure(target) && !Object.hasOwn(properties ?? {}, "name") ? defaultName : await context.getProperty(target, "name");
14087
- return bind(
14088
- typeof length === "number" && !Number.isNaN(length) ? Math.max(0, Math.trunc(length) - boundArgs.length) : 0,
14089
- typeof name === "string" ? name : ""
14090
- );
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
+ }
14091
14189
  })();
14092
14190
  }
14093
14191
  if (methodName === "call") {
@@ -14097,25 +14195,37 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
14097
14195
  if (applyArgs === null || applyArgs === void 0) {
14098
14196
  return options.callClosure(target, [], stack, thisValue);
14099
14197
  }
14100
- if (!Array.isArray(applyArgs)) {
14101
- 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.");
14102
14200
  }
14103
- if (context?.getProperty === void 0)
14201
+ if (context?.getProperty === void 0 && Array.isArray(applyArgs))
14104
14202
  return options.callClosure(target, applyArgs, stack, thisValue);
14105
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
+ };
14106
14216
  const values = [];
14107
- const length = applyArgs.length;
14108
- options.budget?.allocateArrayLength(length);
14109
- const retained = {};
14110
- options.budget?.setRetainedValues(retained, () => values);
14217
+ const release = retainValues(budget, () => [applyArgs, ...values]);
14111
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);
14112
14222
  for (let index = 0; index < length; index++) {
14113
- options.budget?.visitNode();
14114
- values.push(await context.getProperty(applyArgs, index));
14223
+ budget.visitNode();
14224
+ values.push(await read(applyArgs, String(index)));
14115
14225
  }
14116
14226
  return await options.callClosure(target, values, stack, thisValue);
14117
14227
  } finally {
14118
- options.budget?.setRetainedValues(retained, void 0);
14228
+ release();
14119
14229
  }
14120
14230
  })();
14121
14231
  }
@@ -14272,16 +14382,19 @@ function getGeneratorMember(target, property, budget) {
14272
14382
  return createSandboxClosure({
14273
14383
  sandbox: true,
14274
14384
  name: property,
14275
- call: ([value], context) => {
14276
- const iterator = generatorIterator(target, budget, context);
14277
- const result = Promise.resolve(iterator[property](value)).then((result2) => allocateProducedSandboxValue(
14278
- { value: result2.value, done: result2.done === true },
14279
- budget
14280
- ));
14281
- return target.async ? createSandboxPromise(result) : result;
14282
- }
14385
+ call: ([value], context) => callGeneratorMethod(target, property, value, budget, context, target.async === true)
14283
14386
  });
14284
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
+ }
14285
14398
 
14286
14399
  // packages/safe-js/src/interp/methods/set.ts
14287
14400
  var setMethodNames = /* @__PURE__ */ new Set([
@@ -14361,74 +14474,6 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14361
14474
  }
14362
14475
  }
14363
14476
 
14364
- // packages/safe-js/src/interp/globals/error.ts
14365
- var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14366
- var errorNames = [
14367
- "Error",
14368
- "TypeError",
14369
- "RangeError",
14370
- "ReferenceError",
14371
- "SyntaxError",
14372
- "URIError",
14373
- "EvalError",
14374
- "AggregateError"
14375
- ];
14376
- function createErrorGlobals(options) {
14377
- return Object.fromEntries(
14378
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14379
- );
14380
- }
14381
- function isSandboxErrorConstructorInstance2(value, constructor) {
14382
- if (!isSandboxClosure(constructor)) {
14383
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14384
- }
14385
- const name = errorConstructorNames.get(constructor);
14386
- if (name === void 0) {
14387
- return false;
14388
- }
14389
- return isSandboxErrorConstructorInstance(value, name);
14390
- }
14391
- function createErrorConstructor(name, budget) {
14392
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14393
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14394
- errorConstructorNames.set(closure, name);
14395
- return closure;
14396
- }
14397
- function createSubsetError(name, args, stackFrames, budget) {
14398
- const message = name === "AggregateError" ? args[1] : args[0];
14399
- const options = name === "AggregateError" ? args[2] : args[1];
14400
- const error = createSubsetErrorValue(name, message, stackFrames, budget);
14401
- if (name === "AggregateError") {
14402
- const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14403
- budget.allocateArrayLength(errors.length);
14404
- error.errors = errors;
14405
- }
14406
- if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14407
- error.cause = options.cause;
14408
- }
14409
- return error;
14410
- }
14411
- function isObjectLike(value) {
14412
- return typeof value === "object" && value !== null;
14413
- }
14414
-
14415
- // packages/safe-js/src/interp/methods/collection-iterator.ts
14416
- function getCollectionIteratorMember(target, property, budget) {
14417
- if (Object.hasOwn(target, property)) return target[property];
14418
- if (property !== "next") return void 0;
14419
- const { collectionKind } = collectionIteratorState(target);
14420
- return createSandboxClosure({
14421
- sandbox: true,
14422
- name: "next",
14423
- call: (_args, context) => {
14424
- const receiver = context?.thisValue;
14425
- if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14426
- throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14427
- return nextCollectionIterator(receiver, budget);
14428
- }
14429
- });
14430
- }
14431
-
14432
14477
  // packages/safe-js/src/interp/globals/float32array.ts
14433
14478
  var constructors = /* @__PURE__ */ new WeakSet();
14434
14479
  function createFloat32ArrayGlobal(budget) {
@@ -14554,6 +14599,119 @@ function relativeIndex(value, length, fallback) {
14554
14599
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
14555
14600
  }
14556
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
+
14557
14715
  // packages/safe-js/src/interp/scope.ts
14558
14716
  var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
14559
14717
  var Scope = class _Scope {
@@ -17418,42 +17576,11 @@ function applyBinaryOperator(node, left, right, context) {
17418
17576
  case ">>>":
17419
17577
  return toNumber(left) >>> toNumber(right);
17420
17578
  case "instanceof":
17421
- return evaluateInstanceof(left, right, context);
17579
+ return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
17422
17580
  case "in":
17423
17581
  return hasSandboxProperty(right, left, context);
17424
17582
  }
17425
17583
  }
17426
- async function evaluateInstanceof(left, right, context) {
17427
- while (true) {
17428
- if (right === null || typeof right !== "object" && typeof right !== "function")
17429
- throw new TypeError("Right-hand side of 'instanceof' must be an object.");
17430
- const method = await getPropertyValue(right, Symbol.hasInstance, context);
17431
- if (method !== void 0 && method !== null) {
17432
- if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
17433
- return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
17434
- }
17435
- if (!isSandboxClosure(right))
17436
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
17437
- if (right.boundTarget === void 0) break;
17438
- context.budget.visitNode();
17439
- right = right.boundTarget;
17440
- }
17441
- if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
17442
- if (isSandboxErrorConstructorInstance2(left, right)) return true;
17443
- if (isGuestClosure(right)) {
17444
- if (typeof left !== "object" || left === null) return false;
17445
- const prototype = await getPropertyValue(right, "prototype", context);
17446
- if (typeof prototype !== "object" || prototype === null)
17447
- throw new TypeError("Function has a non-object prototype in instanceof check.");
17448
- let depth = 0;
17449
- for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
17450
- context.budget.visitNode();
17451
- assertSandboxDataDepth(depth++);
17452
- if (current === prototype) return true;
17453
- }
17454
- }
17455
- return false;
17456
- }
17457
17584
  function createCoercionContext(context) {
17458
17585
  return {
17459
17586
  stack: context.callStack,
@@ -20190,6 +20317,18 @@ function captureGuestHeapNode(value, encode) {
20190
20317
  const state2 = captureObjectState(value, encode);
20191
20318
  return { kind: "intrinsic", id: intrinsic, ...state2 === void 0 ? {} : { state: state2 } };
20192
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
+ }
20193
20332
  if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key, entry]) => [encode(key), encode(entry)]), ...serializeCollectionProperties(value, encode) };
20194
20333
  if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
20195
20334
  if (isSandboxArrayIterator(value)) {
@@ -23944,7 +24083,7 @@ function createUriGlobals(budget) {
23944
24083
  }
23945
24084
 
23946
24085
  // packages/safe-js/src/interp/globals/function.ts
23947
- function createFunctionPrototype(budget) {
24086
+ function createFunctionPrototype(budget, installHasInstance = true) {
23948
24087
  const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
23949
24088
  const properties = materializeFunctionProperties(prototype);
23950
24089
  Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
@@ -23964,8 +24103,77 @@ function createFunctionPrototype(budget) {
23964
24103
  })
23965
24104
  });
23966
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 });
23967
24114
  setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
23968
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);
23969
24177
  }
23970
24178
 
23971
24179
  // packages/safe-js/src/interp/globals/symbol.ts
@@ -24198,7 +24406,8 @@ function createBuiltinBindings(options) {
24198
24406
  ...createPromiseGlobals(options),
24199
24407
  ...createRegexGlobals(options)
24200
24408
  };
24201
- createFunctionPrototype(options.budget);
24409
+ createFunctionPrototype(options.budget, options.functionHasInstance);
24410
+ createGeneratorPrototypes(options.budget);
24202
24411
  registerBuiltinIdentities(options.budget, bindings);
24203
24412
  return bindings;
24204
24413
  }
@@ -24249,7 +24458,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24249
24458
  createRawJson(node.text);
24250
24459
  return true;
24251
24460
  }
24252
- 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;
24253
24462
  const reference = (value, kinds) => {
24254
24463
  const ref = record3(value);
24255
24464
  fields(ref, ["kind", "id"]);
@@ -24260,7 +24469,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24260
24469
  };
24261
24470
  const callable = (value) => {
24262
24471
  if (absent(value)) return;
24263
- const target = reference(value, ["intrinsic", "guest-function", "guest-class"]);
24472
+ const target = reference(value, ["intrinsic", "bound-function", "guest-function", "guest-class"]);
24264
24473
  if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
24265
24474
  throw new TypeError("Guest accessor reference is not callable.");
24266
24475
  };
@@ -24356,6 +24565,22 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24356
24565
  if (descriptor.kind !== "data" || descriptor.writable !== false || descriptor.enumerable !== false || descriptor.configurable !== false)
24357
24566
  throw new TypeError("Invalid class prototype descriptor.");
24358
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);
24359
24584
  } else if (node.kind === "guest-function") {
24360
24585
  fields(node, ["kind", "astNodeId", "scope", "state"], ["name", "environment"]);
24361
24586
  if (integer(node.astNodeId) < 1) throw new TypeError("Invalid guest AST identity.");
@@ -41049,4 +41274,4 @@ export {
41049
41274
  FileSnapshotBackend,
41050
41275
  run
41051
41276
  };
41052
- //# sourceMappingURL=chunk-M4L3EZHL.js.map
41277
+ //# sourceMappingURL=chunk-ZSYBRZU6.js.map