@poe-platform/safe-js 0.1.127 → 0.1.128

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-MKJBQPBH.js";
30
+ } from "./chunk-LZEDWYSI.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-23ZKK6SC.js.map
8248
+ //# sourceMappingURL=chunk-EAKCL5OK.js.map
@@ -8267,7 +8267,7 @@ function isCounter(value) {
8267
8267
  }
8268
8268
 
8269
8269
  // packages/safe-js/src/interp/cancel.ts
8270
- import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
8270
+ import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
8271
8271
 
8272
8272
  // packages/safe-js/src/interp/builtin-call.ts
8273
8273
  async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
@@ -8627,6 +8627,55 @@ function toMatchArray(match, input) {
8627
8627
  return result;
8628
8628
  }
8629
8629
 
8630
+ // packages/safe-js/src/interp/resources.ts
8631
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
8632
+ var runResources = new AsyncLocalStorage3();
8633
+ function retainValues(budget, values) {
8634
+ const retained = {};
8635
+ budget.setRetainedValues(retained, values);
8636
+ const pending = runResources.getStore()?.referenceReleases;
8637
+ const release = () => {
8638
+ budget.setRetainedValues(retained, void 0);
8639
+ pending?.delete(release);
8640
+ };
8641
+ pending?.add(release);
8642
+ return release;
8643
+ }
8644
+ async function withRunResources(signal, execute) {
8645
+ const controller = new AbortController();
8646
+ const cancel = () => controller.abort(signal?.reason);
8647
+ const cleanups = /* @__PURE__ */ new Set();
8648
+ const resources = {
8649
+ signal: controller.signal,
8650
+ referenceReleases: /* @__PURE__ */ new Set(),
8651
+ add(close) {
8652
+ cleanups.add(close);
8653
+ }
8654
+ };
8655
+ signal?.addEventListener("abort", cancel, { once: true });
8656
+ if (signal?.aborted) cancel();
8657
+ let result;
8658
+ let failure;
8659
+ let errors = [];
8660
+ try {
8661
+ result = await runResources.run(resources, execute);
8662
+ } catch (error) {
8663
+ failure = { reason: error };
8664
+ } finally {
8665
+ signal?.removeEventListener("abort", cancel);
8666
+ controller.abort(new Error("SafeJS run finished."));
8667
+ for (const release of resources.referenceReleases) release();
8668
+ resources.referenceReleases.clear();
8669
+ const outcomes = await Promise.allSettled(
8670
+ [...cleanups].map((close) => Promise.resolve().then(close))
8671
+ );
8672
+ errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
8673
+ }
8674
+ if (failure !== void 0) throw failure.reason;
8675
+ if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
8676
+ return result;
8677
+ }
8678
+
8630
8679
  // packages/safe-js/src/interp/string-coercion.ts
8631
8680
  var defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
8632
8681
  var defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
@@ -8713,9 +8762,10 @@ async function defaultToString(value, budget, context, joining) {
8713
8762
  }
8714
8763
  if (joining.has(value)) return "";
8715
8764
  joining.add(value);
8765
+ let text = "";
8766
+ const release = retainValues(budget, () => [text]);
8716
8767
  try {
8717
8768
  const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
8718
- let text = "";
8719
8769
  for (let index = 0; index < length; index++) {
8720
8770
  budget.visitNode();
8721
8771
  const element = ownDataValue(value, String(index));
@@ -8724,15 +8774,21 @@ async function defaultToString(value, budget, context, joining) {
8724
8774
  }
8725
8775
  return text;
8726
8776
  } finally {
8777
+ release();
8727
8778
  joining.delete(value);
8728
8779
  }
8729
8780
  }
8730
8781
  if (sandboxErrorTypes.has(value)) {
8731
8782
  const nameValue = ownDataValue(value, "name");
8732
8783
  const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
8733
- const messageValue = ownDataValue(value, "message");
8734
- const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
8735
- return name === "" ? message : message === "" ? name : `${name}: ${message}`;
8784
+ const release = retainValues(budget, () => [name]);
8785
+ try {
8786
+ const messageValue = ownDataValue(value, "message");
8787
+ const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
8788
+ return name === "" ? message : message === "" ? name : `${name}: ${message}`;
8789
+ } finally {
8790
+ release();
8791
+ }
8736
8792
  }
8737
8793
  return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
8738
8794
  }
@@ -9342,8 +9398,8 @@ function syncIterator(iterator) {
9342
9398
  }
9343
9399
 
9344
9400
  // packages/safe-js/src/interp/jobs.ts
9345
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
9346
- var activeJob = new AsyncLocalStorage3();
9401
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
9402
+ var activeJob = new AsyncLocalStorage4();
9347
9403
  var SandboxJobQueue = class {
9348
9404
  running = false;
9349
9405
  pending = [];
@@ -10172,7 +10228,7 @@ function isPromiseLike(value) {
10172
10228
  }
10173
10229
 
10174
10230
  // packages/safe-js/src/interp/cancel.ts
10175
- var activeCancellation = new AsyncLocalStorage4();
10231
+ var activeCancellation = new AsyncLocalStorage5();
10176
10232
  var sandboxPromises = /* @__PURE__ */ new WeakSet();
10177
10233
  var cancelableOutcomes = /* @__PURE__ */ new WeakMap();
10178
10234
  function withCancellationSignal(signal, task) {
@@ -23890,44 +23946,6 @@ function hoistVarDeclarations(node, scope) {
23890
23946
  }
23891
23947
  }
23892
23948
 
23893
- // packages/safe-js/src/interp/resources.ts
23894
- import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
23895
- var runResources = new AsyncLocalStorage5();
23896
- async function withRunResources(signal, execute) {
23897
- const controller = new AbortController();
23898
- const cancel = () => controller.abort(signal?.reason);
23899
- const cleanups = /* @__PURE__ */ new Set();
23900
- const resources = {
23901
- signal: controller.signal,
23902
- referenceReleases: /* @__PURE__ */ new Set(),
23903
- add(close) {
23904
- cleanups.add(close);
23905
- }
23906
- };
23907
- signal?.addEventListener("abort", cancel, { once: true });
23908
- if (signal?.aborted) cancel();
23909
- let result;
23910
- let failure;
23911
- let errors = [];
23912
- try {
23913
- result = await runResources.run(resources, execute);
23914
- } catch (error) {
23915
- failure = { reason: error };
23916
- } finally {
23917
- signal?.removeEventListener("abort", cancel);
23918
- controller.abort(new Error("SafeJS run finished."));
23919
- for (const release of resources.referenceReleases) release();
23920
- resources.referenceReleases.clear();
23921
- const outcomes = await Promise.allSettled(
23922
- [...cleanups].map((close) => Promise.resolve().then(close))
23923
- );
23924
- errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
23925
- }
23926
- if (failure !== void 0) throw failure.reason;
23927
- if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
23928
- return result;
23929
- }
23930
-
23931
23949
  // packages/safe-js/src/interp/methods/array.ts
23932
23950
  var arrayLikeSources = /* @__PURE__ */ new WeakMap();
23933
23951
  var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
@@ -28143,17 +28161,6 @@ async function evaluateMemberAccess(node, context, consume) {
28143
28161
  release();
28144
28162
  }
28145
28163
  }
28146
- function retainValues(budget, values) {
28147
- const retained = {};
28148
- budget.setRetainedValues(retained, values);
28149
- const pending = runResources.getStore()?.referenceReleases;
28150
- const release = () => {
28151
- budget.setRetainedValues(retained, void 0);
28152
- pending?.delete(release);
28153
- };
28154
- pending?.add(release);
28155
- return release;
28156
- }
28157
28164
  async function evaluateMemberProperty(node, context) {
28158
28165
  const property = await evaluateNode(node, context);
28159
28166
  if (property.kind !== "normal") {
@@ -33445,6 +33452,7 @@ export {
33445
33452
  HostOperationResumePolicyError,
33446
33453
  registerPendingHostCallPolicy,
33447
33454
  HostCallResumabilityError,
33455
+ runResources,
33448
33456
  assertSnapshotInactive,
33449
33457
  isSandboxClosure,
33450
33458
  deepCopyToSandbox,
@@ -33461,7 +33469,6 @@ export {
33461
33469
  validateSnapshotMigration,
33462
33470
  restore,
33463
33471
  lint,
33464
- runResources,
33465
33472
  declareHostOperation,
33466
33473
  createSeededRandom,
33467
33474
  createReplayableRandom,
@@ -33473,4 +33480,4 @@ export {
33473
33480
  FileSnapshotBackend,
33474
33481
  run
33475
33482
  };
33476
- //# sourceMappingURL=chunk-MKJBQPBH.js.map
33483
+ //# sourceMappingURL=chunk-LZEDWYSI.js.map