poe-code 14.0.57 → 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.
package/dist/index.js CHANGED
@@ -144084,6 +144084,50 @@ var init_var_hoist = __esm({
144084
144084
  }
144085
144085
  });
144086
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
+
144087
144131
  // packages/safe-js/src/interp/methods/array.ts
144088
144132
  function getArrayMember(value, property, options) {
144089
144133
  const index = getArrayIndex(property);
@@ -147114,61 +147158,56 @@ async function evaluateMemberAssignmentExpression(node, context) {
147114
147158
  if (node.left.type !== "MemberExpression") {
147115
147159
  throw new TypeError("Expected member assignment target.");
147116
147160
  }
147117
- const member = await evaluateMemberAccess(node.left, context);
147118
- if (member.kind === "error") {
147119
- return member;
147120
- }
147121
- if (member.kind === "completion") {
147122
- return member.result;
147123
- }
147124
- if (member.kind === "nullish") {
147125
- throw new TypeError("Cannot assign properties of null or undefined.");
147126
- }
147127
- let property;
147128
- let current = void 0;
147129
- 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);
147130
147200
  if (member.object === null || member.object === void 0) {
147131
147201
  throw new TypeError("Cannot assign properties of null or undefined.");
147132
147202
  }
147133
- property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147134
- current = getPropertyValue(member.object, property, context);
147135
- }
147136
- if (node.operator === "&&=" && !isTruthy(current)) {
147137
- return {
147138
- kind: "normal",
147139
- hasValue: true,
147140
- value: current
147141
- };
147142
- }
147143
- if (node.operator === "||=" && isTruthy(current)) {
147144
- return {
147145
- kind: "normal",
147146
- hasValue: true,
147147
- value: current
147148
- };
147149
- }
147150
- if (node.operator === "??=" && current !== null && current !== void 0) {
147203
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147204
+ setSandboxProperty(member.object, property, value, context.budget);
147151
147205
  return {
147152
147206
  kind: "normal",
147153
147207
  hasValue: true,
147154
- value: current
147208
+ value
147155
147209
  };
147156
- }
147157
- const right = await evaluateNode2(node.right, context);
147158
- if (right.kind !== "normal") {
147159
- return right;
147160
- }
147161
- const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
147162
- if (member.object === null || member.object === void 0) {
147163
- throw new TypeError("Cannot assign properties of null or undefined.");
147164
- }
147165
- property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147166
- setSandboxProperty(member.object, property, value, context.budget);
147167
- return {
147168
- kind: "normal",
147169
- hasValue: true,
147170
- value
147171
- };
147210
+ });
147172
147211
  }
147173
147212
  async function evaluateLogicalExpression(node, context) {
147174
147213
  const left = await evaluateNode2(node.left, context);
@@ -148147,33 +148186,28 @@ async function evaluateDeleteExpression(node, context) {
148147
148186
  "Unary operator 'delete' requires a member target."
148148
148187
  );
148149
148188
  }
148150
- const member = await evaluateMemberAccess(node.argument, context);
148151
- if (member.kind === "error") {
148152
- return member;
148153
- }
148154
- if (member.kind === "completion") {
148155
- return member.result;
148156
- }
148157
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148158
- if (member.kind === "nullish" && node.argument.optional) {
148159
- return {
148160
- kind: "normal",
148161
- hasValue: true,
148162
- value: true
148163
- };
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.");
148164
148199
  }
148165
- throw new TypeError("Cannot delete properties of null or undefined.");
148166
- }
148167
- if (!isIndexableSandboxValue(member.object)) {
148168
- throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
148169
- }
148170
- const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148171
- const deleted = deleteSandboxProperty(member.object, property);
148172
- return {
148173
- kind: "normal",
148174
- hasValue: true,
148175
- value: deleted
148176
- };
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
+ });
148177
148211
  }
148178
148212
  async function evaluateUpdateExpression(node, context) {
148179
148213
  if (node.argument.type === "Identifier") {
@@ -148209,41 +148243,35 @@ async function evaluateMemberUpdateExpression(node, context) {
148209
148243
  if (node.argument.type !== "MemberExpression") {
148210
148244
  throw new TypeError("Expected member update target.");
148211
148245
  }
148212
- const member = await evaluateMemberAccess(node.argument, context);
148213
- if (member.kind === "error") {
148214
- return member;
148215
- }
148216
- if (member.kind === "completion") {
148217
- return member.result;
148218
- }
148219
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148220
- throw new TypeError("Cannot update properties of null or undefined.");
148221
- }
148222
- const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
148223
- const current = toNumber(
148224
- await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
148225
- );
148226
- const next = node.operator === "++" ? current + 1 : current - 1;
148227
- setSandboxProperty(member.object, property, next, context.budget);
148228
- return {
148229
- kind: "normal",
148230
- hasValue: true,
148231
- value: node.prefix ? next : current
148232
- };
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
+ });
148233
148262
  }
148234
148263
  async function evaluateMemberExpression(node, context) {
148235
- const member = await evaluateMemberAccess(node, context);
148236
- if (member.kind === "error") return member;
148237
- if (member.kind === "completion") return member.result;
148238
- if (member.kind === "nullish" || member.object === null || member.object === void 0) {
148239
- if (member.kind === "nullish" && node.optional) return { kind: "normal", hasValue: true, value: void 0 };
148240
- throw new TypeError("Cannot read properties of null or undefined.");
148241
- }
148242
- return {
148243
- kind: "normal",
148244
- hasValue: true,
148245
- value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
148246
- };
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
+ });
148247
148275
  }
148248
148276
  function getPropertyValue(target, property, context) {
148249
148277
  if (isGuestHostObject(target)) return getHostObjectMember(target, String(property));
@@ -148351,26 +148379,27 @@ function attachFatalSandboxErrorContext(error3, node, stackFrames) {
148351
148379
  attachErrorSpan(error3, node.span);
148352
148380
  replaceErrorStack(error3, stackFrames);
148353
148381
  }
148354
- async function evaluateMemberAccess(node, context) {
148382
+ async function evaluateMemberAccess(node, context, consume) {
148355
148383
  const object = await evaluateNode2(node.object, context);
148356
- if (object.kind !== "normal") {
148357
- return {
148358
- kind: "completion",
148359
- result: object
148360
- };
148361
- }
148384
+ if (object.kind !== "normal") return object;
148362
148385
  if ((object.value === null || object.value === void 0) && node.optional) {
148363
- return {
148364
- kind: "nullish"
148365
- };
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);
148366
148402
  }
148367
- const property = node.computed ? await evaluateNode2(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
148368
- if (property.kind !== "normal") return { kind: "completion", result: property };
148369
- return {
148370
- kind: "resolved",
148371
- object: object.value,
148372
- property: property.value
148373
- };
148374
148403
  }
148375
148404
  async function evaluateMemberProperty(node, context) {
148376
148405
  const property = await evaluateNode2(node, context);
@@ -148407,137 +148436,132 @@ async function evaluateMemberCallExpression(node, context) {
148407
148436
  if (node.callee.type !== "MemberExpression") {
148408
148437
  throw new TypeError("Expected member call expression.");
148409
148438
  }
148410
- const reference = await evaluateMemberAccess(node.callee, context);
148411
- if (reference.kind === "error") {
148412
- return reference;
148413
- }
148414
- if (reference.kind === "completion") {
148415
- return reference.result;
148416
- }
148417
- if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
148418
- if (reference.kind === "nullish") {
148419
- return {
148420
- kind: "normal",
148421
- hasValue: true,
148422
- value: void 0
148423
- };
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.");
148424
148449
  }
148425
- throw new TypeError("Cannot read properties of null or undefined.");
148426
- }
148427
- const member = {
148428
- ...reference,
148429
- property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
148430
- };
148431
- if (typeof member.object === "string" && isStringMethodName(member.property)) {
148432
- return evaluateStringMethodCall(node, member.object, member.property, context);
148433
- }
148434
- if (typeof member.object === "number" && isNumberMethodName(member.property)) {
148435
- return evaluateNumberMethodCall(node, member.object, member.property, context);
148436
- }
148437
- if (Array.isArray(member.object) && isArrayMethodName(member.property) && !Object.hasOwn(member.object, member.property)) {
148438
- return evaluateArrayMethodCall(node, member.object, member.property, context);
148439
- }
148440
- if (isSandboxMap(member.object) && isMapMethodName(member.property)) {
148441
- return evaluateMapMethodCall(node, member.object, member.property, context);
148442
- }
148443
- if (isSandboxSet(member.object) && isSetMethodName(member.property)) {
148444
- return evaluateSetMethodCall(node, member.object, member.property, context);
148445
- }
148446
- if (typeof member.object === "string") {
148447
- return evaluatePrimitiveMemberCall(
148448
- node,
148449
- "String",
148450
- member.property,
148451
- getStringMember(member.object, member.property, context.budget),
148452
- context
148453
- );
148454
- }
148455
- if (typeof member.object === "number") {
148456
- return evaluatePrimitiveMemberCall(
148457
- node,
148458
- "Number",
148459
- member.property,
148460
- getNumberMember(member.property, context.budget),
148461
- context
148462
- );
148463
- }
148464
- if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
148465
- return evaluatePrimitiveMemberCall(
148466
- node,
148467
- "Array",
148468
- member.property,
148469
- getArrayMemberValue(member.object, member.property, context),
148470
- context
148471
- );
148472
- }
148473
- if (isSandboxMap(member.object)) {
148474
- return evaluatePrimitiveMemberCall(
148475
- node,
148476
- "Map",
148477
- member.property,
148478
- getMapMember(member.object, member.property, createMapMethodOptions(context)),
148479
- context
148480
- );
148481
- }
148482
- if (isSandboxDate(member.object)) {
148483
- return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
148484
- }
148485
- if (isFloat32Array(member.object)) {
148486
- return evaluateResolvedCallExpression(
148487
- node,
148488
- getFloat32Member(member.object, member.property, context.budget),
148489
- context,
148490
- member.object
148491
- );
148492
- }
148493
- if (isSandboxSet(member.object)) {
148494
- return evaluatePrimitiveMemberCall(
148495
- node,
148496
- "Set",
148497
- member.property,
148498
- getSetMember(member.object, member.property, createSetMethodOptions(context)),
148499
- context
148500
- );
148501
- }
148502
- if (isSandboxGenerator(member.object)) {
148503
- const memberValue = getGeneratorMember(member.object, member.property, context.budget);
148504
- if (memberValue === void 0) {
148505
- 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);
148506
148456
  }
148507
- return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148508
- }
148509
- if (isSandboxClosure(member.object)) {
148510
- const memberValue = getClosureMemberValue(member.object, member.property, context);
148511
- if (memberValue === void 0) {
148512
- 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.");
148513
148557
  }
148514
- return evaluateResolvedCallExpression(node, memberValue, context, member.object);
148515
- }
148516
- if (isSandboxPromise(member.object)) {
148517
- return evaluateResolvedCallExpression(
148518
- node,
148519
- getPromiseMember(member.property, context.budget),
148520
- context,
148521
- member.object
148522
- );
148523
- }
148524
- if (isSandboxRegex(member.object) && isRegexMethodName(member.property)) {
148525
148558
  return evaluateResolvedCallExpression(
148526
148559
  node,
148527
- getRegexMember(member.object, member.property, context.budget),
148560
+ getMemberValue(member.object, member.property, context),
148528
148561
  context,
148529
148562
  member.object
148530
148563
  );
148531
- }
148532
- if (!isIndexableSandboxValue(member.object)) {
148533
- throw new TypeError("Attempted to read a property from a non-object value.");
148534
- }
148535
- return evaluateResolvedCallExpression(
148536
- node,
148537
- getMemberValue(member.object, member.property, context),
148538
- context,
148539
- member.object
148540
- );
148564
+ });
148541
148565
  }
148542
148566
  function evaluatePrimitiveMemberCall(node, receiverType, property, value, context) {
148543
148567
  if (value === void 0) {
@@ -149315,6 +149339,7 @@ var init_interpreter = __esm({
149315
149339
  init_promise_tracker();
149316
149340
  init_jobs4();
149317
149341
  init_cancel2();
149342
+ init_resources();
149318
149343
  init_shape();
149319
149344
  init_async();
149320
149345
  init_host_call();
@@ -151779,47 +151804,6 @@ var init_globals = __esm({
151779
151804
  }
151780
151805
  });
151781
151806
 
151782
- // packages/safe-js/src/interp/resources.ts
151783
- import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
151784
- async function withRunResources(signal, execute2) {
151785
- const controller = new AbortController();
151786
- const cancel2 = () => controller.abort(signal?.reason);
151787
- const cleanups = /* @__PURE__ */ new Set();
151788
- const resources = {
151789
- signal: controller.signal,
151790
- add(close) {
151791
- cleanups.add(close);
151792
- }
151793
- };
151794
- signal?.addEventListener("abort", cancel2, { once: true });
151795
- if (signal?.aborted) cancel2();
151796
- let result;
151797
- let failure;
151798
- let errors2 = [];
151799
- try {
151800
- result = await runResources.run(resources, execute2);
151801
- } catch (error3) {
151802
- failure = { reason: error3 };
151803
- } finally {
151804
- signal?.removeEventListener("abort", cancel2);
151805
- controller.abort(new Error("SafeJS run finished."));
151806
- const outcomes = await Promise.allSettled(
151807
- [...cleanups].map((close) => Promise.resolve().then(close))
151808
- );
151809
- errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
151810
- }
151811
- if (failure !== void 0) throw failure.reason;
151812
- if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
151813
- return result;
151814
- }
151815
- var runResources;
151816
- var init_resources = __esm({
151817
- "packages/safe-js/src/interp/resources.ts"() {
151818
- "use strict";
151819
- runResources = new AsyncLocalStorage8();
151820
- }
151821
- });
151822
-
151823
151807
  // packages/safe-js/src/modules/registry.ts
151824
151808
  function createUnknownModuleMessage2(moduleName, moduleNames) {
151825
151809
  if (moduleNames.length === 0) {
@@ -152192,6 +152176,7 @@ var init_realm = __esm({
152192
152176
  extensions;
152193
152177
  consoleExtension;
152194
152178
  cleanups = [];
152179
+ referenceReleases = /* @__PURE__ */ new Set();
152195
152180
  callbacks = /* @__PURE__ */ new Map();
152196
152181
  pendingCallbacks = /* @__PURE__ */ new Set();
152197
152182
  callbackCache = /* @__PURE__ */ new WeakMap();
@@ -152518,7 +152503,7 @@ var init_realm = __esm({
152518
152503
  const pending = withSandboxPromiseRejectionTracker(
152519
152504
  this.tracker,
152520
152505
  () => runResources.run(
152521
- { signal: this.controller.signal, add: this.onCleanup },
152506
+ { signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
152522
152507
  () => withCancellationSignal(
152523
152508
  this.controller.signal,
152524
152509
  () => active && this.phase.getStore()?.active ? runAsyncPrefix(invoke2) : this.queue.run(invoke2)
@@ -152713,7 +152698,7 @@ var init_realm = __esm({
152713
152698
  () => withSandboxPromiseRejectionTracker(
152714
152699
  this.tracker,
152715
152700
  () => runResources.run(
152716
- { signal: this.controller.signal, add: this.onCleanup },
152701
+ { signal: this.controller.signal, referenceReleases: this.referenceReleases, add: this.onCleanup },
152717
152702
  () => withCancellationSignal(this.controller.signal, task)
152718
152703
  )
152719
152704
  )
@@ -152770,6 +152755,8 @@ var init_realm = __esm({
152770
152755
  this.hostObjects.clear();
152771
152756
  for (const reference of this.guestReferences.keys()) revokeGuestReference(reference, this);
152772
152757
  this.guestReferences.clear();
152758
+ for (const release2 of this.referenceReleases) release2();
152759
+ this.referenceReleases.clear();
152773
152760
  this.budget.setRetainedValues(this, void 0);
152774
152761
  releaseObjectPrototype(this.budget);
152775
152762
  this.disposal = (async () => {