@poe-platform/safe-js 0.1.127 → 0.1.129

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-OM5W7AYB.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-EH4VQYKL.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();
@@ -26689,14 +26707,18 @@ function isObjectPrototypeSetterProperty(property, key) {
26689
26707
  }
26690
26708
  async function evaluateTemplateLiteral(node, context) {
26691
26709
  let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
26692
- const release = retainValues(context.budget, () => [value]);
26710
+ let input = void 0;
26711
+ const release = retainValues(context.budget, () => [value, input]);
26693
26712
  try {
26694
26713
  for (let index = 0; index < node.expressions.length; index += 1) {
26695
26714
  const expression = await evaluateNode(node.expressions[index], context);
26696
26715
  if (expression.kind !== "normal") {
26697
26716
  return expression;
26698
26717
  }
26699
- const expressionText = context.budget.allocateString(String(expression.value));
26718
+ input = expression.value;
26719
+ const text = sandboxString(input, context.budget, createCoercionContext(context));
26720
+ const expressionText = typeof text === "string" ? text : await text;
26721
+ input = void 0;
26700
26722
  value = context.budget.allocateString(value + expressionText);
26701
26723
  const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
26702
26724
  value = context.budget.allocateString(value + quasiText);
@@ -28143,17 +28165,6 @@ async function evaluateMemberAccess(node, context, consume) {
28143
28165
  release();
28144
28166
  }
28145
28167
  }
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
28168
  async function evaluateMemberProperty(node, context) {
28158
28169
  const property = await evaluateNode(node, context);
28159
28170
  if (property.kind !== "normal") {
@@ -33445,6 +33456,7 @@ export {
33445
33456
  HostOperationResumePolicyError,
33446
33457
  registerPendingHostCallPolicy,
33447
33458
  HostCallResumabilityError,
33459
+ runResources,
33448
33460
  assertSnapshotInactive,
33449
33461
  isSandboxClosure,
33450
33462
  deepCopyToSandbox,
@@ -33461,7 +33473,6 @@ export {
33461
33473
  validateSnapshotMigration,
33462
33474
  restore,
33463
33475
  lint,
33464
- runResources,
33465
33476
  declareHostOperation,
33466
33477
  createSeededRandom,
33467
33478
  createReplayableRandom,
@@ -33473,4 +33484,4 @@ export {
33473
33484
  FileSnapshotBackend,
33474
33485
  run
33475
33486
  };
33476
- //# sourceMappingURL=chunk-MKJBQPBH.js.map
33487
+ //# sourceMappingURL=chunk-OM5W7AYB.js.map