poe-code 14.0.56 → 14.0.58

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 (30) hide show
  1. package/dist/index.js +401 -341
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-SRYQTOX4.js → chunk-3VTLNK4E.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-XI33TU4X.js → chunk-DHD453E5.js} +393 -336
  7. package/packages/safe-js/dist/chunks/chunk-DHD453E5.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/globals/misc.js +20 -7
  12. package/packages/safe-js/dist/interp/interpreter.js +194 -213
  13. package/packages/safe-js/dist/interp/methods/regex.d.ts +1 -1
  14. package/packages/safe-js/dist/interp/methods/regex.js +18 -6
  15. package/packages/safe-js/dist/interp/methods/string.js +59 -26
  16. package/packages/safe-js/dist/interp/regex/engine.d.ts +1 -0
  17. package/packages/safe-js/dist/interp/regex/engine.js +3 -3
  18. package/packages/safe-js/dist/interp/resources.d.ts +1 -0
  19. package/packages/safe-js/dist/interp/resources.js +4 -0
  20. package/packages/safe-js/dist/interp/values.d.ts +6 -3
  21. package/packages/safe-js/dist/interp/values.js +19 -6
  22. package/packages/safe-js/dist/realm.js +6 -2
  23. package/packages/safe-js/dist/snapshot/replay-data.d.ts +1 -1
  24. package/packages/safe-js/dist/snapshot/replay-data.js +4 -4
  25. package/packages/safe-js/dist/snapshot/restore.js +8 -0
  26. package/packages/safe-js/dist/snapshot/serialize.d.ts +6 -1
  27. package/packages/safe-js/dist/snapshot/serialize.js +14 -1
  28. package/packages/safe-js/dist/snapshot/validation.js +8 -2
  29. package/packages/safe-js/dist/chunks/chunk-XI33TU4X.js.map +0 -7
  30. /package/packages/safe-js/dist/chunks/{chunk-SRYQTOX4.js.map → chunk-3VTLNK4E.js.map} +0 -0
package/dist/index.js CHANGED
@@ -127268,7 +127268,7 @@ function encodeReplayData(value, options = {}) {
127268
127268
  kind: "regex",
127269
127269
  source: entry.source,
127270
127270
  flags: entry.flags,
127271
- lastIndex: entry.lastIndex
127271
+ lastIndex: child(entry.lastIndex, "lastIndex")
127272
127272
  };
127273
127273
  } else if (isSandboxArguments(entry)) {
127274
127274
  nodes[id] = { kind: "arguments", data: serializeArguments(entry, child) };
@@ -127435,11 +127435,12 @@ function decodeReplayData(input, options = {}, parent) {
127435
127435
  return result3;
127436
127436
  }
127437
127437
  if (kind === "regex") {
127438
- if (typeof node.source !== "string" || typeof node.flags !== "string" || typeof node.lastIndex !== "number" || !Number.isFinite(node.lastIndex)) {
127438
+ if (typeof node.source !== "string" || typeof node.flags !== "string" || !Object.hasOwn(node, "lastIndex")) {
127439
127439
  throw new TypeError("Invalid replay regular expression.");
127440
127440
  }
127441
- const result3 = createSandboxRegex(node.source, node.flags, node.lastIndex, compilation);
127441
+ const result3 = createSandboxRegex(node.source, node.flags, 0, compilation);
127442
127442
  restored.set(id, result3);
127443
+ result3.lastIndex = child(own(node, "lastIndex"));
127443
127444
  return result3;
127444
127445
  }
127445
127446
  if (kind === "arguments") {
@@ -128445,10 +128446,10 @@ function charge(context) {
128445
128446
  allocateRegexSteps(context.steps);
128446
128447
  }
128447
128448
  function normalizeLastIndex(lastIndex) {
128448
- if (!Number.isFinite(lastIndex) || lastIndex <= 0) {
128449
+ if (Number.isNaN(lastIndex) || lastIndex <= 0) {
128449
128450
  return 0;
128450
128451
  }
128451
- return Math.floor(lastIndex);
128452
+ return Math.min(Math.floor(lastIndex), Number.MAX_SAFE_INTEGER);
128452
128453
  }
128453
128454
  function charactersEqual(left, right, ignoreCase) {
128454
128455
  return left !== void 0 && foldCharacter(left, ignoreCase) === foldCharacter(right, ignoreCase);
@@ -128496,6 +128497,7 @@ function getRegexMember(target, property, budget) {
128496
128497
  return budget === void 0 ? flags : budget.allocateString(flags);
128497
128498
  }
128498
128499
  if (property === "lastIndex") return target.lastIndex;
128500
+ if (Object.hasOwn(regexFlagProperties, property)) return target.flags.includes(regexFlagProperties[property]);
128499
128501
  if (!isRegexMethodName(property)) {
128500
128502
  return void 0;
128501
128503
  }
@@ -128530,14 +128532,16 @@ function setRegexMember(target, property, value) {
128530
128532
  if (property !== "lastIndex") {
128531
128533
  throw new TypeError(`RegExp#${String(property)} is not writable.`);
128532
128534
  }
128533
- target.lastIndex = Number(value);
128535
+ target.lastIndex = value;
128534
128536
  }
128535
128537
  async function callRegexMethod(target, methodName, args, budget, context) {
128536
128538
  if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
128537
128539
  throw new TypeError(`RegExp#${methodName} requires ${methodName === "exec" ? "a regex" : "an object"} receiver.`);
128538
128540
  }
128539
128541
  const retained = {};
128540
- budget.setRetainedValues(retained, () => [target, ...args]);
128542
+ let cursor2;
128543
+ let convertedInput;
128544
+ budget.setRetainedValues(retained, () => [target, ...args, cursor2, convertedInput]);
128541
128545
  try {
128542
128546
  const input = await sandboxString(args[0], budget, context);
128543
128547
  if (methodName === "test") {
@@ -128551,15 +128555,18 @@ async function callRegexMethod(target, methodName, args, budget, context) {
128551
128555
  }
128552
128556
  }
128553
128557
  if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
128554
- const match = executeRegex(target, input);
128558
+ if (typeof args[0] !== "string") convertedInput = input;
128559
+ cursor2 = target.lastIndex;
128560
+ const lastIndex = await sandboxNumber(cursor2, budget, context);
128561
+ const match = executeRegex(target, input, lastIndex);
128555
128562
  return methodName === "test" ? match !== null : toMatchArray(match, input);
128556
128563
  } finally {
128557
128564
  budget.setRetainedValues(retained, void 0);
128558
128565
  }
128559
128566
  }
128560
- function executeRegex(target, input) {
128567
+ function executeRegex(target, input, lastIndex) {
128561
128568
  const pattern = getSandboxRegexPattern(target);
128562
- const match = matchRegex(pattern, input, target.lastIndex);
128569
+ const match = matchRegex(pattern, input, lastIndex);
128563
128570
  if (pattern.flags.global) {
128564
128571
  target.lastIndex = match === null ? 0 : match.index + match.text.length;
128565
128572
  }
@@ -128573,7 +128580,7 @@ function toMatchArray(match, input) {
128573
128580
  Object.assign(result, { index: match.index, input, groups: void 0 });
128574
128581
  return result;
128575
128582
  }
128576
- var regexMethodNames;
128583
+ var regexMethodNames, regexFlagProperties;
128577
128584
  var init_regex = __esm({
128578
128585
  "packages/safe-js/src/interp/methods/regex.ts"() {
128579
128586
  "use strict";
@@ -128583,6 +128590,16 @@ var init_regex = __esm({
128583
128590
  init_object_model();
128584
128591
  init_string_coercion();
128585
128592
  regexMethodNames = /* @__PURE__ */ new Set(["exec", "test"]);
128593
+ regexFlagProperties = {
128594
+ hasIndices: "d",
128595
+ global: "g",
128596
+ ignoreCase: "i",
128597
+ multiline: "m",
128598
+ dotAll: "s",
128599
+ unicode: "u",
128600
+ unicodeSets: "v",
128601
+ sticky: "y"
128602
+ };
128586
128603
  }
128587
128604
  });
128588
128605
 
@@ -130573,13 +130590,14 @@ function deepCopyToSandbox(value) {
130573
130590
  seen: /* @__PURE__ */ new WeakMap()
130574
130591
  });
130575
130592
  }
130576
- function cloneSandboxValue(value) {
130593
+ function cloneSandboxValue(value, options = {}) {
130577
130594
  const initializeIterators = [];
130578
130595
  const copy = copyToSandbox(
130579
130596
  value,
130580
130597
  {
130581
130598
  seen: /* @__PURE__ */ new WeakMap(),
130582
- initializeIterators
130599
+ initializeIterators,
130600
+ ...options
130583
130601
  },
130584
130602
  "<root>",
130585
130603
  true
@@ -130678,11 +130696,12 @@ function measureSandboxData(values, options = {}) {
130678
130696
  }
130679
130697
  if (isSandboxPromise(value)) return;
130680
130698
  if (isSandboxRegex(value)) {
130681
- const { source, flags } = captureRegexData(value);
130699
+ const { source, flags, lastIndex } = captureRegexData(value);
130682
130700
  const compiled = regexCompiledData(getSandboxRegexPattern(value));
130683
130701
  const staged = compiled.ticket === void 0 ? 0 : compiled.ticket.owner.budget.compileTicketUsage(compiled.ticket);
130684
130702
  usage += Math.max(6 + source.length + flags.length + compiled.units, staged - 1);
130685
130703
  if (compiled.ticket !== void 0) options.compileTickets?.add(compiled.ticket);
130704
+ visit(lastIndex, depth + 1);
130686
130705
  return;
130687
130706
  }
130688
130707
  if (isSandboxArguments(value)) {
@@ -130763,7 +130782,16 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
130763
130782
  return value;
130764
130783
  }
130765
130784
  if (isLiveCapability(value)) throw new TypeError("Live capabilities require their owning realm bridge.");
130766
- if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxRegex(value) || isSandboxPromise(value)) {
130785
+ if (isSandboxRegex(value)) {
130786
+ if (!cloneSandboxCollections) return value;
130787
+ const existing = state.seen.get(value);
130788
+ if (existing !== void 0) return existing;
130789
+ const copy = createSandboxRegex(value.source, value.flags, 0, state.compilation);
130790
+ state.seen.set(value, copy);
130791
+ if (!state.resetRegexLastIndex) copy.lastIndex = copyToSandbox(value.lastIndex, state, `${path193}.lastIndex`, true, depth + 1);
130792
+ return copy;
130793
+ }
130794
+ if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
130767
130795
  return value;
130768
130796
  }
130769
130797
  if (isSandboxCollectionIterator(value)) {
@@ -130972,9 +131000,9 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
130972
131000
  if (existing !== void 0) return existing;
130973
131001
  guard.allocate(1 + source.length + flags.length);
130974
131002
  const regex = new RegExp(source, flags);
130975
- regex.lastIndex = lastIndex;
130976
- guard.retainScratch();
130977
131003
  state.seen.set(value, regex);
131004
+ Reflect.set(regex, "lastIndex", copyFromSandbox(lastIndex, state, `${path193}.lastIndex`, options, depth + 1));
131005
+ guard.retainScratch();
130978
131006
  return regex;
130979
131007
  } finally {
130980
131008
  guard.close();
@@ -131856,7 +131884,7 @@ function validateTaggedValue(record2, path193, state) {
131856
131884
  case "undefined":
131857
131885
  return;
131858
131886
  case "number":
131859
- if (!["-Infinity", "Infinity", "NaN"].includes(String(record2.value))) {
131887
+ if (!["-Infinity", "Infinity", "NaN", "-0"].includes(String(record2.value))) {
131860
131888
  fail2("invalidValue", `${path193}.value`, "unknown non-finite number value");
131861
131889
  }
131862
131890
  return;
@@ -131878,6 +131906,11 @@ function validateTaggedValue(record2, path193, state) {
131878
131906
  requireString2(record2.flags, `${path193}.flags`, state.limits);
131879
131907
  requireSafeInteger(record2.lastIndex, `${path193}.lastIndex`, 0);
131880
131908
  return;
131909
+ case "regex-object":
131910
+ requireString2(record2.source, `${path193}.source`, state.limits);
131911
+ requireString2(record2.flags, `${path193}.flags`, state.limits);
131912
+ if (!Object.hasOwn(record2, "lastIndex")) fail2("invalidValue", `${path193}.lastIndex`, "missing regex cursor");
131913
+ return;
131881
131914
  case "array":
131882
131915
  case "arguments":
131883
131916
  case "object":
@@ -144051,6 +144084,50 @@ var init_var_hoist = __esm({
144051
144084
  }
144052
144085
  });
144053
144086
 
144087
+ // packages/safe-js/src/interp/resources.ts
144088
+ import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
144089
+ async function withRunResources(signal, execute2) {
144090
+ const controller = new AbortController();
144091
+ const cancel2 = () => controller.abort(signal?.reason);
144092
+ const cleanups = /* @__PURE__ */ new Set();
144093
+ const resources = {
144094
+ signal: controller.signal,
144095
+ referenceReleases: /* @__PURE__ */ new Set(),
144096
+ add(close) {
144097
+ cleanups.add(close);
144098
+ }
144099
+ };
144100
+ signal?.addEventListener("abort", cancel2, { once: true });
144101
+ if (signal?.aborted) cancel2();
144102
+ let result;
144103
+ let failure;
144104
+ let errors2 = [];
144105
+ try {
144106
+ result = await runResources.run(resources, execute2);
144107
+ } catch (error3) {
144108
+ failure = { reason: error3 };
144109
+ } finally {
144110
+ signal?.removeEventListener("abort", cancel2);
144111
+ controller.abort(new Error("SafeJS run finished."));
144112
+ for (const release2 of resources.referenceReleases) release2();
144113
+ resources.referenceReleases.clear();
144114
+ const outcomes = await Promise.allSettled(
144115
+ [...cleanups].map((close) => Promise.resolve().then(close))
144116
+ );
144117
+ errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
144118
+ }
144119
+ if (failure !== void 0) throw failure.reason;
144120
+ if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
144121
+ return result;
144122
+ }
144123
+ var runResources;
144124
+ var init_resources = __esm({
144125
+ "packages/safe-js/src/interp/resources.ts"() {
144126
+ "use strict";
144127
+ runResources = new AsyncLocalStorage8();
144128
+ }
144129
+ });
144130
+
144054
144131
  // packages/safe-js/src/interp/methods/array.ts
144055
144132
  function getArrayMember(value, property, options) {
144056
144133
  const index = getArrayIndex(property);
@@ -145250,7 +145327,11 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
145250
145327
  return budget.allocateString(result + value.slice(spanStart));
145251
145328
  }
145252
145329
  if (methodName === "replace" || methodName === "replaceAll") {
145253
- return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
145330
+ return callReplaceLikeMethod(value, methodName, args, budget, callClosure, context);
145331
+ }
145332
+ const regex = args[0];
145333
+ if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll" && regex.flags.includes("g"))) {
145334
+ return callStringRegexCursor(value, methodName, regex, budget, parent, context);
145254
145335
  }
145255
145336
  if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
145256
145337
  return callStringPattern(value, methodName, args[0], budget, parent, context);
@@ -145365,7 +145446,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
145365
145446
  operation.release();
145366
145447
  }
145367
145448
  }
145368
- function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
145449
+ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
145369
145450
  const search = args[0];
145370
145451
  const replacement = args[1];
145371
145452
  if (!isSandboxRegex(search) && typeof search !== "string" || typeof replacement !== "string" && !isSandboxClosure(replacement)) {
@@ -145383,7 +145464,8 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
145383
145464
  replacement,
145384
145465
  methodName === "replaceAll",
145385
145466
  budget,
145386
- callClosure
145467
+ callClosure,
145468
+ context
145387
145469
  );
145388
145470
  }
145389
145471
  if (typeof replacement === "string") {
@@ -145400,20 +145482,28 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
145400
145482
  callClosure
145401
145483
  );
145402
145484
  }
145403
- async function replaceRegex(value, regex, replacement, replaceAll2, budget, callClosure) {
145485
+ async function replaceRegex(value, regex, replacement, replaceAll2, budget, callClosure, context) {
145404
145486
  if (regex.flags.includes("g")) regex.lastIndex = 0;
145405
- const matches = collectRegexMatches(regex, value, replaceAll2 || regex.flags.includes("g"));
145406
- let result = "";
145407
- let copiedThrough = 0;
145408
- for (const match of matches) {
145409
- result += value.slice(copiedThrough, match.index);
145410
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
145411
- await callClosure(replacement, [match.text, ...match.captures, match.index, value])
145412
- );
145413
- copiedThrough = match.index + match.text.length;
145487
+ const cursor2 = regex.lastIndex;
145488
+ const retained = {};
145489
+ budget.setRetainedValues(retained, () => [value, regex, cursor2, replacement]);
145490
+ try {
145491
+ const lastIndex = await sandboxNumber(cursor2, budget, context);
145492
+ const matches = collectRegexMatches(regex, value, replaceAll2 || regex.flags.includes("g"), void 0, lastIndex);
145493
+ let result = "";
145494
+ let copiedThrough = 0;
145495
+ for (const match of matches) {
145496
+ result += value.slice(copiedThrough, match.index);
145497
+ result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
145498
+ await callClosure(replacement, [match.text, ...match.captures, match.index, value])
145499
+ );
145500
+ copiedThrough = match.index + match.text.length;
145501
+ }
145502
+ result += value.slice(copiedThrough);
145503
+ return budget.allocateString(result);
145504
+ } finally {
145505
+ budget.setRetainedValues(retained, void 0);
145414
145506
  }
145415
- result += value.slice(copiedThrough);
145416
- return budget.allocateString(result);
145417
145507
  }
145418
145508
  function expandReplacement(replacement, match, captures, input, matchIndex) {
145419
145509
  let result = "";
@@ -145529,7 +145619,7 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
145529
145619
  const operation = budget.acquireCompileOwner(false, parent?.owner);
145530
145620
  const compilation = new CompileScope(operation.owner);
145531
145621
  const retainedPattern = {};
145532
- budget.setRetainedValues(retainedPattern, () => [pattern]);
145622
+ budget.setRetainedValues(retainedPattern, () => [value, pattern]);
145533
145623
  try {
145534
145624
  const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
145535
145625
  const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
@@ -145540,35 +145630,51 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
145540
145630
  operation.release();
145541
145631
  }
145542
145632
  }
145543
- function callMatchLikeMethod(value, methodName, args, compilation) {
145633
+ async function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
145634
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
145635
+ const compilation = new CompileScope(operation.owner);
145636
+ const cursor2 = regex.lastIndex;
145637
+ const retained = {};
145638
+ budget.setRetainedValues(retained, () => [value, regex, cursor2]);
145639
+ try {
145640
+ const lastIndex = await sandboxNumber(cursor2, budget, context);
145641
+ return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex);
145642
+ } finally {
145643
+ budget.setRetainedValues(retained, void 0);
145644
+ compilation.dispose();
145645
+ operation.release();
145646
+ }
145647
+ }
145648
+ function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
145544
145649
  const regex = args[0];
145545
145650
  if (!isSandboxRegex(regex))
145546
145651
  throw new TypeError(`String#${methodName} requires a regex argument.`);
145547
145652
  if (methodName === "search") {
145548
- const lastIndex = regex.lastIndex;
145549
- if (!Object.is(lastIndex, 0)) regex.lastIndex = 0;
145550
- const match = executeRegex(regex, value);
145551
- if (!Object.is(regex.lastIndex, lastIndex)) regex.lastIndex = lastIndex;
145653
+ const lastIndex2 = regex.lastIndex;
145654
+ if (!Object.is(lastIndex2, 0)) regex.lastIndex = 0;
145655
+ const match = executeRegex(regex, value, 0);
145656
+ if (!Object.is(regex.lastIndex, lastIndex2)) regex.lastIndex = lastIndex2;
145552
145657
  return match?.index ?? -1;
145553
145658
  }
145554
145659
  if (methodName === "matchAll" && !regex.flags.includes("g"))
145555
145660
  throw new TypeError("String#matchAll requires a global regex.");
145556
145661
  if (methodName === "match" && !regex.flags.includes("g"))
145557
- return toMatchArray(executeRegex(regex, value), value);
145662
+ return toMatchArray(executeRegex(regex, value, lastIndex ?? Number(regex.lastIndex)), value);
145558
145663
  if (methodName === "match") regex.lastIndex = 0;
145559
- const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
145560
- const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
145664
+ const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
145665
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget, Number(matcher.lastIndex));
145561
145666
  if (methodName === "match" && matches.length === 0) return null;
145562
145667
  return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
145563
145668
  }
145564
- function collectRegexMatches(regex, value, all, budget) {
145669
+ function collectRegexMatches(regex, value, all, budget, lastIndex = 0) {
145565
145670
  const matches = [];
145566
145671
  do {
145567
- const match = executeRegex(regex, value);
145672
+ const match = executeRegex(regex, value, lastIndex);
145568
145673
  if (match === null) break;
145569
145674
  budget?.allocateArrayLength(matches.length + 1);
145570
145675
  matches.push(match);
145571
- if (all && match.text.length === 0) regex.lastIndex += 1;
145676
+ lastIndex = match.index + match.text.length;
145677
+ if (all && match.text.length === 0) regex.lastIndex = ++lastIndex;
145572
145678
  } while (all);
145573
145679
  return matches;
145574
145680
  }
@@ -145591,6 +145697,7 @@ var init_string = __esm({
145591
145697
  "use strict";
145592
145698
  init_builtin_call();
145593
145699
  init_compile_guard();
145700
+ init_engine2();
145594
145701
  init_string_coercion();
145595
145702
  init_values();
145596
145703
  init_regex();
@@ -147051,61 +147158,56 @@ async function evaluateMemberAssignmentExpression(node, context) {
147051
147158
  if (node.left.type !== "MemberExpression") {
147052
147159
  throw new TypeError("Expected member assignment target.");
147053
147160
  }
147054
- const member = await evaluateMemberAccess(node.left, context);
147055
- if (member.kind === "error") {
147056
- return member;
147057
- }
147058
- if (member.kind === "completion") {
147059
- return member.result;
147060
- }
147061
- if (member.kind === "nullish") {
147062
- throw new TypeError("Cannot assign properties of null or undefined.");
147063
- }
147064
- let property;
147065
- let current = void 0;
147066
- if (node.operator !== "=") {
147161
+ return evaluateMemberAccess(node.left, context, async (member) => {
147162
+ if (member.kind === "nullish") {
147163
+ throw new TypeError("Cannot assign properties of null or undefined.");
147164
+ }
147165
+ let property;
147166
+ let current = void 0;
147167
+ if (node.operator !== "=") {
147168
+ if (member.object === null || member.object === void 0) {
147169
+ throw new TypeError("Cannot assign properties of null or undefined.");
147170
+ }
147171
+ property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147172
+ current = getPropertyValue(member.object, property, context);
147173
+ }
147174
+ if (node.operator === "&&=" && !isTruthy(current)) {
147175
+ return {
147176
+ kind: "normal",
147177
+ hasValue: true,
147178
+ value: current
147179
+ };
147180
+ }
147181
+ if (node.operator === "||=" && isTruthy(current)) {
147182
+ return {
147183
+ kind: "normal",
147184
+ hasValue: true,
147185
+ value: current
147186
+ };
147187
+ }
147188
+ if (node.operator === "??=" && current !== null && current !== void 0) {
147189
+ return {
147190
+ kind: "normal",
147191
+ hasValue: true,
147192
+ value: current
147193
+ };
147194
+ }
147195
+ const right = await evaluateNode2(node.right, context);
147196
+ if (right.kind !== "normal") {
147197
+ return right;
147198
+ }
147199
+ const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
147067
147200
  if (member.object === null || member.object === void 0) {
147068
147201
  throw new TypeError("Cannot assign properties of null or undefined.");
147069
147202
  }
147070
- property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147071
- current = getPropertyValue(member.object, property, context);
147072
- }
147073
- if (node.operator === "&&=" && !isTruthy(current)) {
147203
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147204
+ setSandboxProperty(member.object, property, value, context.budget);
147074
147205
  return {
147075
147206
  kind: "normal",
147076
147207
  hasValue: true,
147077
- value: current
147078
- };
147079
- }
147080
- if (node.operator === "||=" && isTruthy(current)) {
147081
- return {
147082
- kind: "normal",
147083
- hasValue: true,
147084
- value: current
147085
- };
147086
- }
147087
- if (node.operator === "??=" && current !== null && current !== void 0) {
147088
- return {
147089
- kind: "normal",
147090
- hasValue: true,
147091
- value: current
147208
+ value
147092
147209
  };
147093
- }
147094
- const right = await evaluateNode2(node.right, context);
147095
- if (right.kind !== "normal") {
147096
- return right;
147097
- }
147098
- const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
147099
- if (member.object === null || member.object === void 0) {
147100
- throw new TypeError("Cannot assign properties of null or undefined.");
147101
- }
147102
- property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147103
- setSandboxProperty(member.object, property, value, context.budget);
147104
- return {
147105
- kind: "normal",
147106
- hasValue: true,
147107
- value
147108
- };
147210
+ });
147109
147211
  }
147110
147212
  async function evaluateLogicalExpression(node, context) {
147111
147213
  const left = await evaluateNode2(node.left, context);
@@ -148084,33 +148186,28 @@ async function evaluateDeleteExpression(node, context) {
148084
148186
  "Unary operator 'delete' requires a member target."
148085
148187
  );
148086
148188
  }
148087
- const member = await evaluateMemberAccess(node.argument, context);
148088
- if (member.kind === "error") {
148089
- return member;
148090
- }
148091
- if (member.kind === "completion") {
148092
- return member.result;
148093
- }
148094
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148095
- if (member.kind === "nullish" && node.argument.optional) {
148096
- return {
148097
- kind: "normal",
148098
- hasValue: true,
148099
- value: true
148100
- };
148189
+ return evaluateMemberAccess(node.argument, context, async (member) => {
148190
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148191
+ if (member.kind === "nullish") {
148192
+ return {
148193
+ kind: "normal",
148194
+ hasValue: true,
148195
+ value: true
148196
+ };
148197
+ }
148198
+ throw new TypeError("Cannot delete properties of null or undefined.");
148101
148199
  }
148102
- throw new TypeError("Cannot delete properties of null or undefined.");
148103
- }
148104
- if (!isIndexableSandboxValue(member.object)) {
148105
- throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
148106
- }
148107
- const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148108
- const deleted = deleteSandboxProperty(member.object, property);
148109
- return {
148110
- kind: "normal",
148111
- hasValue: true,
148112
- value: deleted
148113
- };
148200
+ if (!isIndexableSandboxValue(member.object)) {
148201
+ throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
148202
+ }
148203
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148204
+ const deleted = deleteSandboxProperty(member.object, property);
148205
+ return {
148206
+ kind: "normal",
148207
+ hasValue: true,
148208
+ value: deleted
148209
+ };
148210
+ });
148114
148211
  }
148115
148212
  async function evaluateUpdateExpression(node, context) {
148116
148213
  if (node.argument.type === "Identifier") {
@@ -148146,41 +148243,35 @@ async function evaluateMemberUpdateExpression(node, context) {
148146
148243
  if (node.argument.type !== "MemberExpression") {
148147
148244
  throw new TypeError("Expected member update target.");
148148
148245
  }
148149
- const member = await evaluateMemberAccess(node.argument, context);
148150
- if (member.kind === "error") {
148151
- return member;
148152
- }
148153
- if (member.kind === "completion") {
148154
- return member.result;
148155
- }
148156
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148157
- throw new TypeError("Cannot update properties of null or undefined.");
148158
- }
148159
- const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148160
- const current = toNumber(
148161
- await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
148162
- );
148163
- const next = node.operator === "++" ? current + 1 : current - 1;
148164
- setSandboxProperty(member.object, property, next, context.budget);
148165
- return {
148166
- kind: "normal",
148167
- hasValue: true,
148168
- value: node.prefix ? next : current
148169
- };
148246
+ return evaluateMemberAccess(node.argument, context, async (member) => {
148247
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148248
+ throw new TypeError("Cannot update properties of null or undefined.");
148249
+ }
148250
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148251
+ const current = toNumber(
148252
+ await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
148253
+ );
148254
+ const next = node.operator === "++" ? current + 1 : current - 1;
148255
+ setSandboxProperty(member.object, property, next, context.budget);
148256
+ return {
148257
+ kind: "normal",
148258
+ hasValue: true,
148259
+ value: node.prefix ? next : current
148260
+ };
148261
+ });
148170
148262
  }
148171
148263
  async function evaluateMemberExpression(node, context) {
148172
- const member = await evaluateMemberAccess(node, context);
148173
- if (member.kind === "error") return member;
148174
- if (member.kind === "completion") return member.result;
148175
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148176
- if (member.kind === "nullish" && node.optional) return { kind: "normal", hasValue: true, value: void 0 };
148177
- throw new TypeError("Cannot read properties of null or undefined.");
148178
- }
148179
- return {
148180
- kind: "normal",
148181
- hasValue: true,
148182
- value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
148183
- };
148264
+ return evaluateMemberAccess(node, context, async (member) => {
148265
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148266
+ if (member.kind === "nullish") return { kind: "normal", hasValue: true, value: void 0 };
148267
+ throw new TypeError("Cannot read properties of null or undefined.");
148268
+ }
148269
+ return {
148270
+ kind: "normal",
148271
+ hasValue: true,
148272
+ value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
148273
+ };
148274
+ });
148184
148275
  }
148185
148276
  function getPropertyValue(target, property, context) {
148186
148277
  if (isGuestHostObject(target)) return getHostObjectMember(target, String(property));
@@ -148288,26 +148379,27 @@ function attachFatalSandboxErrorContext(error3, node, stackFrames) {
148288
148379
  attachErrorSpan(error3, node.span);
148289
148380
  replaceErrorStack(error3, stackFrames);
148290
148381
  }
148291
- async function evaluateMemberAccess(node, context) {
148382
+ async function evaluateMemberAccess(node, context, consume) {
148292
148383
  const object = await evaluateNode2(node.object, context);
148293
- if (object.kind !== "normal") {
148294
- return {
148295
- kind: "completion",
148296
- result: object
148297
- };
148298
- }
148384
+ if (object.kind !== "normal") return object;
148299
148385
  if ((object.value === null || object.value === void 0) && node.optional) {
148300
- return {
148301
- kind: "nullish"
148302
- };
148386
+ return consume({ kind: "nullish" });
148387
+ }
148388
+ const retained = {};
148389
+ let property;
148390
+ context.budget.setRetainedValues(retained, () => [object.value, property]);
148391
+ const release2 = () => context.budget.setRetainedValues(retained, void 0);
148392
+ const pending = runResources.getStore()?.referenceReleases;
148393
+ pending?.add(release2);
148394
+ try {
148395
+ const result = node.computed ? await evaluateNode2(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
148396
+ if (result.kind !== "normal") return result;
148397
+ property = result.value;
148398
+ return await consume({ kind: "resolved", object: object.value, property });
148399
+ } finally {
148400
+ release2();
148401
+ pending?.delete(release2);
148303
148402
  }
148304
- const property = node.computed ? await evaluateNode2(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
148305
- if (property.kind !== "normal") return { kind: "completion", result: property };
148306
- return {
148307
- kind: "resolved",
148308
- object: object.value,
148309
- property: property.value
148310
- };
148311
148403
  }
148312
148404
  async function evaluateMemberProperty(node, context) {
148313
148405
  const property = await evaluateNode2(node, context);
@@ -148344,137 +148436,132 @@ async function evaluateMemberCallExpression(node, context) {
148344
148436
  if (node.callee.type !== "MemberExpression") {
148345
148437
  throw new TypeError("Expected member call expression.");
148346
148438
  }
148347
- const reference = await evaluateMemberAccess(node.callee, context);
148348
- if (reference.kind === "error") {
148349
- return reference;
148350
- }
148351
- if (reference.kind === "completion") {
148352
- return reference.result;
148353
- }
148354
- if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
148355
- if (reference.kind === "nullish") {
148356
- return {
148357
- kind: "normal",
148358
- hasValue: true,
148359
- value: void 0
148360
- };
148439
+ return evaluateMemberAccess(node.callee, context, async (reference) => {
148440
+ if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
148441
+ if (reference.kind === "nullish") {
148442
+ return {
148443
+ kind: "normal",
148444
+ hasValue: true,
148445
+ value: void 0
148446
+ };
148447
+ }
148448
+ throw new TypeError("Cannot read properties of null or undefined.");
148361
148449
  }
148362
- throw new TypeError("Cannot read properties of null or undefined.");
148363
- }
148364
- const member = {
148365
- ...reference,
148366
- property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
148367
- };
148368
- if (typeof member.object === "string" && isStringMethodName(member.property)) {
148369
- return evaluateStringMethodCall(node, member.object, member.property, context);
148370
- }
148371
- if (typeof member.object === "number" && isNumberMethodName(member.property)) {
148372
- return evaluateNumberMethodCall(node, member.object, member.property, context);
148373
- }
148374
- if (Array.isArray(member.object) && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property)) {
148375
- return evaluateArrayMethodCall(node, member.object, member.property, context);
148376
- }
148377
- if (isSandboxMap(member.object) && isMapMethodName(member.property)) {
148378
- return evaluateMapMethodCall(node, member.object, member.property, context);
148379
- }
148380
- if (isSandboxSet(member.object) && isSetMethodName(member.property)) {
148381
- return evaluateSetMethodCall(node, member.object, member.property, context);
148382
- }
148383
- if (typeof member.object === "string") {
148384
- return evaluatePrimitiveMemberCall(
148385
- node,
148386
- "String",
148387
- member.property,
148388
- getStringMember(member.object, member.property, context.budget),
148389
- context
148390
- );
148391
- }
148392
- if (typeof member.object === "number") {
148393
- return evaluatePrimitiveMemberCall(
148394
- node,
148395
- "Number",
148396
- member.property,
148397
- getNumberMember(member.property, context.budget),
148398
- context
148399
- );
148400
- }
148401
- if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
148402
- return evaluatePrimitiveMemberCall(
148403
- node,
148404
- "Array",
148405
- member.property,
148406
- getArrayMemberValue(member.object, member.property, context),
148407
- context
148408
- );
148409
- }
148410
- if (isSandboxMap(member.object)) {
148411
- return evaluatePrimitiveMemberCall(
148412
- node,
148413
- "Map",
148414
- member.property,
148415
- getMapMember(member.object, member.property, createMapMethodOptions(context)),
148416
- context
148417
- );
148418
- }
148419
- if (isSandboxDate(member.object)) {
148420
- return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
148421
- }
148422
- if (isFloat32Array(member.object)) {
148423
- return evaluateResolvedCallExpression(
148424
- node,
148425
- getFloat32Member(member.object, member.property, context.budget),
148426
- context,
148427
- member.object
148428
- );
148429
- }
148430
- if (isSandboxSet(member.object)) {
148431
- return evaluatePrimitiveMemberCall(
148432
- node,
148433
- "Set",
148434
- member.property,
148435
- getSetMember(member.object, member.property, createSetMethodOptions(context)),
148436
- context
148437
- );
148438
- }
148439
- if (isSandboxGenerator(member.object)) {
148440
- const memberValue = getGeneratorMember(member.object, member.property, context.budget);
148441
- if (memberValue === void 0) {
148442
- throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
148450
+ const member = {
148451
+ ...reference,
148452
+ property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
148453
+ };
148454
+ if (typeof member.object === "string" && isStringMethodName(member.property)) {
148455
+ return evaluateStringMethodCall(node, member.object, member.property, context);
148443
148456
  }
148444
- return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148445
- }
148446
- if (isSandboxClosure(member.object)) {
148447
- const memberValue = getClosureMemberValue(member.object, member.property, context);
148448
- if (memberValue === void 0) {
148449
- throw new TypeError(`Function#${String(member.property)} is not a supported method.`);
148457
+ if (typeof member.object === "number" && isNumberMethodName(member.property)) {
148458
+ return evaluateNumberMethodCall(node, member.object, member.property, context);
148459
+ }
148460
+ if (Array.isArray(member.object) && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property)) {
148461
+ return evaluateArrayMethodCall(node, member.object, member.property, context);
148462
+ }
148463
+ if (isSandboxMap(member.object) && isMapMethodName(member.property)) {
148464
+ return evaluateMapMethodCall(node, member.object, member.property, context);
148465
+ }
148466
+ if (isSandboxSet(member.object) && isSetMethodName(member.property)) {
148467
+ return evaluateSetMethodCall(node, member.object, member.property, context);
148468
+ }
148469
+ if (typeof member.object === "string") {
148470
+ return evaluatePrimitiveMemberCall(
148471
+ node,
148472
+ "String",
148473
+ member.property,
148474
+ getStringMember(member.object, member.property, context.budget),
148475
+ context
148476
+ );
148477
+ }
148478
+ if (typeof member.object === "number") {
148479
+ return evaluatePrimitiveMemberCall(
148480
+ node,
148481
+ "Number",
148482
+ member.property,
148483
+ getNumberMember(member.property, context.budget),
148484
+ context
148485
+ );
148486
+ }
148487
+ if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
148488
+ return evaluatePrimitiveMemberCall(
148489
+ node,
148490
+ "Array",
148491
+ member.property,
148492
+ getArrayMemberValue(member.object, member.property, context),
148493
+ context
148494
+ );
148495
+ }
148496
+ if (isSandboxMap(member.object)) {
148497
+ return evaluatePrimitiveMemberCall(
148498
+ node,
148499
+ "Map",
148500
+ member.property,
148501
+ getMapMember(member.object, member.property, createMapMethodOptions(context)),
148502
+ context
148503
+ );
148504
+ }
148505
+ if (isSandboxDate(member.object)) {
148506
+ return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
148507
+ }
148508
+ if (isFloat32Array(member.object)) {
148509
+ return evaluateResolvedCallExpression(
148510
+ node,
148511
+ getFloat32Member(member.object, member.property, context.budget),
148512
+ context,
148513
+ member.object
148514
+ );
148515
+ }
148516
+ if (isSandboxSet(member.object)) {
148517
+ return evaluatePrimitiveMemberCall(
148518
+ node,
148519
+ "Set",
148520
+ member.property,
148521
+ getSetMember(member.object, member.property, createSetMethodOptions(context)),
148522
+ context
148523
+ );
148524
+ }
148525
+ if (isSandboxGenerator(member.object)) {
148526
+ const memberValue = getGeneratorMember(member.object, member.property, context.budget);
148527
+ if (memberValue === void 0) {
148528
+ throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
148529
+ }
148530
+ return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148531
+ }
148532
+ if (isSandboxClosure(member.object)) {
148533
+ const memberValue = getClosureMemberValue(member.object, member.property, context);
148534
+ if (memberValue === void 0) {
148535
+ throw new TypeError(`Function#${String(member.property)} is not a supported method.`);
148536
+ }
148537
+ return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148538
+ }
148539
+ if (isSandboxPromise(member.object)) {
148540
+ return evaluateResolvedCallExpression(
148541
+ node,
148542
+ getPromiseMember(member.property, context.budget),
148543
+ context,
148544
+ member.object
148545
+ );
148546
+ }
148547
+ if (isSandboxRegex(member.object) && isRegexMethodName(member.property)) {
148548
+ return evaluateResolvedCallExpression(
148549
+ node,
148550
+ getRegexMember(member.object, member.property, context.budget),
148551
+ context,
148552
+ member.object
148553
+ );
148554
+ }
148555
+ if (!isIndexableSandboxValue(member.object)) {
148556
+ throw new TypeError("Attempted to read a property from a non-object value.");
148450
148557
  }
148451
- return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148452
- }
148453
- if (isSandboxPromise(member.object)) {
148454
- return evaluateResolvedCallExpression(
148455
- node,
148456
- getPromiseMember(member.property, context.budget),
148457
- context,
148458
- member.object
148459
- );
148460
- }
148461
- if (isSandboxRegex(member.object) && isRegexMethodName(member.property)) {
148462
148558
  return evaluateResolvedCallExpression(
148463
148559
  node,
148464
- getRegexMember(member.object, member.property, context.budget),
148560
+ getMemberValue(member.object, member.property, context),
148465
148561
  context,
148466
148562
  member.object
148467
148563
  );
148468
- }
148469
- if (!isIndexableSandboxValue(member.object)) {
148470
- throw new TypeError("Attempted to read a property from a non-object value.");
148471
- }
148472
- return evaluateResolvedCallExpression(
148473
- node,
148474
- getMemberValue(member.object, member.property, context),
148475
- context,
148476
- member.object
148477
- );
148564
+ });
148478
148565
  }
148479
148566
  function evaluatePrimitiveMemberCall(node, receiverType, property, value, context) {
148480
148567
  if (value === void 0) {
@@ -149252,6 +149339,7 @@ var init_interpreter = __esm({
149252
149339
  init_promise_tracker();
149253
149340
  init_jobs4();
149254
149341
  init_cancel2();
149342
+ init_resources();
149255
149343
  init_shape();
149256
149344
  init_async();
149257
149345
  init_host_call();
@@ -151112,7 +151200,7 @@ function createMiscGlobals(options) {
151112
151200
  return {
151113
151201
  structuredClone: createSandboxClosure({
151114
151202
  sandbox: true,
151115
- call: ([value]) => structuredCloneSandboxValue(value, options.budget),
151203
+ call: ([value], context) => structuredCloneSandboxValue(value, options.budget, context?.compilation),
151116
151204
  name: "structuredClone"
151117
151205
  }),
151118
151206
  parseInt: createSandboxClosure({
@@ -151137,11 +151225,20 @@ function createMiscGlobals(options) {
151137
151225
  })
151138
151226
  };
151139
151227
  }
151140
- function structuredCloneSandboxValue(value, budget) {
151141
- assertSandboxGraphDepth(value);
151142
- const clone = cloneSandboxValue(value);
151143
- assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
151144
- return allocateProducedSandboxValue(clone, budget);
151228
+ function structuredCloneSandboxValue(value, budget, parent) {
151229
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
151230
+ const compilation = parent?.owner === operation.owner ? parent : new CompileScope(operation.owner);
151231
+ try {
151232
+ const clone = cloneSandboxValue(value, { compilation, resetRegexLastIndex: true });
151233
+ assertSandboxGraphDepth(clone);
151234
+ assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
151235
+ allocateProducedSandboxValue(clone, budget);
151236
+ if (compilation !== parent) reconcileCompiledValues(budget, [clone], compilation);
151237
+ return clone;
151238
+ } finally {
151239
+ if (compilation !== parent) compilation.dispose();
151240
+ operation.release();
151241
+ }
151145
151242
  }
151146
151243
  function assertStructuredCloneable(value, seen) {
151147
151244
  if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value)) {
@@ -151173,6 +151270,7 @@ var init_misc = __esm({
151173
151270
  "use strict";
151174
151271
  init_collection_iterator();
151175
151272
  init_graph_depth();
151273
+ init_compile_guard();
151176
151274
  init_values();
151177
151275
  }
151178
151276
  });
@@ -151706,47 +151804,6 @@ var init_globals = __esm({
151706
151804
  }
151707
151805
  });
151708
151806
 
151709
- // packages/safe-js/src/interp/resources.ts
151710
- import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
151711
- async function withRunResources(signal, execute2) {
151712
- const controller = new AbortController();
151713
- const cancel2 = () => controller.abort(signal?.reason);
151714
- const cleanups = /* @__PURE__ */ new Set();
151715
- const resources = {
151716
- signal: controller.signal,
151717
- add(close) {
151718
- cleanups.add(close);
151719
- }
151720
- };
151721
- signal?.addEventListener("abort", cancel2, { once: true });
151722
- if (signal?.aborted) cancel2();
151723
- let result;
151724
- let failure;
151725
- let errors2 = [];
151726
- try {
151727
- result = await runResources.run(resources, execute2);
151728
- } catch (error3) {
151729
- failure = { reason: error3 };
151730
- } finally {
151731
- signal?.removeEventListener("abort", cancel2);
151732
- controller.abort(new Error("SafeJS run finished."));
151733
- const outcomes = await Promise.allSettled(
151734
- [...cleanups].map((close) => Promise.resolve().then(close))
151735
- );
151736
- errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
151737
- }
151738
- if (failure !== void 0) throw failure.reason;
151739
- if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
151740
- return result;
151741
- }
151742
- var runResources;
151743
- var init_resources = __esm({
151744
- "packages/safe-js/src/interp/resources.ts"() {
151745
- "use strict";
151746
- runResources = new AsyncLocalStorage8();
151747
- }
151748
- });
151749
-
151750
151807
  // packages/safe-js/src/modules/registry.ts
151751
151808
  function createUnknownModuleMessage2(moduleName, moduleNames) {
151752
151809
  if (moduleNames.length === 0) {
@@ -152119,6 +152176,7 @@ var init_realm = __esm({
152119
152176
  extensions;
152120
152177
  consoleExtension;
152121
152178
  cleanups = [];
152179
+ referenceReleases = /* @__PURE__ */ new Set();
152122
152180
  callbacks = /* @__PURE__ */ new Map();
152123
152181
  pendingCallbacks = /* @__PURE__ */ new Set();
152124
152182
  callbackCache = /* @__PURE__ */ new WeakMap();
@@ -152445,7 +152503,7 @@ var init_realm = __esm({
152445
152503
  const pending = withSandboxPromiseRejectionTracker(
152446
152504
  this.tracker,
152447
152505
  () => runResources.run(
152448
- { signal: this.controller.signal, add: this.onCleanup },
152506
+ { signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
152449
152507
  () => withCancellationSignal(
152450
152508
  this.controller.signal,
152451
152509
  () => active && this.phase.getStore()?.active ? runAsyncPrefix(invoke2) : this.queue.run(invoke2)
@@ -152640,7 +152698,7 @@ var init_realm = __esm({
152640
152698
  () => withSandboxPromiseRejectionTracker(
152641
152699
  this.tracker,
152642
152700
  () => runResources.run(
152643
- { signal: this.controller.signal, add: this.onCleanup },
152701
+ { signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
152644
152702
  () => withCancellationSignal(this.controller.signal, task)
152645
152703
  )
152646
152704
  )
@@ -152697,6 +152755,8 @@ var init_realm = __esm({
152697
152755
  this.hostObjects.clear();
152698
152756
  for (const reference of this.guestReferences.keys()) revokeGuestReference(reference, this);
152699
152757
  this.guestReferences.clear();
152758
+ for (const release2 of this.referenceReleases) release2();
152759
+ this.referenceReleases.clear();
152700
152760
  this.budget.setRetainedValues(this, void 0);
152701
152761
  releaseObjectPrototype(this.budget);
152702
152762
  this.disposal = (async () => {