poe-code 14.0.60 → 14.0.61

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
@@ -128613,6 +128613,61 @@ var init_regex = __esm({
128613
128613
  }
128614
128614
  });
128615
128615
 
128616
+ // packages/safe-js/src/interp/resources.ts
128617
+ import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
128618
+ function retainValues(budget, values) {
128619
+ const retained = {};
128620
+ budget.setRetainedValues(retained, values);
128621
+ const pending = runResources.getStore()?.referenceReleases;
128622
+ const release2 = () => {
128623
+ budget.setRetainedValues(retained, void 0);
128624
+ pending?.delete(release2);
128625
+ };
128626
+ pending?.add(release2);
128627
+ return release2;
128628
+ }
128629
+ async function withRunResources(signal, execute2) {
128630
+ const controller = new AbortController();
128631
+ const cancel2 = () => controller.abort(signal?.reason);
128632
+ const cleanups = /* @__PURE__ */ new Set();
128633
+ const resources = {
128634
+ signal: controller.signal,
128635
+ referenceReleases: /* @__PURE__ */ new Set(),
128636
+ add(close) {
128637
+ cleanups.add(close);
128638
+ }
128639
+ };
128640
+ signal?.addEventListener("abort", cancel2, { once: true });
128641
+ if (signal?.aborted) cancel2();
128642
+ let result;
128643
+ let failure;
128644
+ let errors2 = [];
128645
+ try {
128646
+ result = await runResources.run(resources, execute2);
128647
+ } catch (error3) {
128648
+ failure = { reason: error3 };
128649
+ } finally {
128650
+ signal?.removeEventListener("abort", cancel2);
128651
+ controller.abort(new Error("SafeJS run finished."));
128652
+ for (const release2 of resources.referenceReleases) release2();
128653
+ resources.referenceReleases.clear();
128654
+ const outcomes = await Promise.allSettled(
128655
+ [...cleanups].map((close) => Promise.resolve().then(close))
128656
+ );
128657
+ errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
128658
+ }
128659
+ if (failure !== void 0) throw failure.reason;
128660
+ if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
128661
+ return result;
128662
+ }
128663
+ var runResources;
128664
+ var init_resources = __esm({
128665
+ "packages/safe-js/src/interp/resources.ts"() {
128666
+ "use strict";
128667
+ runResources = new AsyncLocalStorage6();
128668
+ }
128669
+ });
128670
+
128616
128671
  // packages/safe-js/src/interp/string-coercion.ts
128617
128672
  function sandboxNumber(value, budget, context) {
128618
128673
  if (value === null || typeof value !== "object") {
@@ -128697,9 +128752,10 @@ async function defaultToString(value, budget, context, joining) {
128697
128752
  }
128698
128753
  if (joining.has(value)) return "";
128699
128754
  joining.add(value);
128755
+ let text5 = "";
128756
+ const release2 = retainValues(budget, () => [text5]);
128700
128757
  try {
128701
128758
  const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
128702
- let text5 = "";
128703
128759
  for (let index = 0; index < length; index++) {
128704
128760
  budget.visitNode();
128705
128761
  const element = ownDataValue(value, String(index));
@@ -128708,15 +128764,21 @@ async function defaultToString(value, budget, context, joining) {
128708
128764
  }
128709
128765
  return text5;
128710
128766
  } finally {
128767
+ release2();
128711
128768
  joining.delete(value);
128712
128769
  }
128713
128770
  }
128714
128771
  if (sandboxErrorTypes.has(value)) {
128715
128772
  const nameValue = ownDataValue(value, "name");
128716
128773
  const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
128717
- const messageValue2 = ownDataValue(value, "message");
128718
- const message2 = messageValue2 === void 0 ? "" : await sandboxString(messageValue2, budget, context, joining);
128719
- return name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`;
128774
+ const release2 = retainValues(budget, () => [name]);
128775
+ try {
128776
+ const messageValue2 = ownDataValue(value, "message");
128777
+ const message2 = messageValue2 === void 0 ? "" : await sandboxString(messageValue2, budget, context, joining);
128778
+ return name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`;
128779
+ } finally {
128780
+ release2();
128781
+ }
128720
128782
  }
128721
128783
  return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
128722
128784
  }
@@ -128740,6 +128802,7 @@ var init_string_coercion = __esm({
128740
128802
  init_collection_iterator();
128741
128803
  init_object_model();
128742
128804
  init_regex();
128805
+ init_resources();
128743
128806
  init_values();
128744
128807
  defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
128745
128808
  defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
@@ -129380,7 +129443,7 @@ var init_iteration = __esm({
129380
129443
  });
129381
129444
 
129382
129445
  // packages/safe-js/src/interp/jobs.ts
129383
- import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
129446
+ import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
129384
129447
  function runPromiseJob(task) {
129385
129448
  const job = activeJob.getStore();
129386
129449
  return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
@@ -129414,7 +129477,7 @@ var activeJob, SandboxJobQueue;
129414
129477
  var init_jobs4 = __esm({
129415
129478
  "packages/safe-js/src/interp/jobs.ts"() {
129416
129479
  "use strict";
129417
- activeJob = new AsyncLocalStorage6();
129480
+ activeJob = new AsyncLocalStorage7();
129418
129481
  SandboxJobQueue = class {
129419
129482
  running = false;
129420
129483
  pending = [];
@@ -130228,7 +130291,7 @@ var init_promise = __esm({
130228
130291
  });
130229
130292
 
130230
130293
  // packages/safe-js/src/interp/cancel.ts
130231
- import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
130294
+ import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
130232
130295
  function withCancellationSignal(signal, task) {
130233
130296
  return activeCancellation.run({ signal, host: false }, task);
130234
130297
  }
@@ -130413,7 +130476,7 @@ var init_cancel2 = __esm({
130413
130476
  init_promise_tracker();
130414
130477
  init_shape();
130415
130478
  init_promise();
130416
- activeCancellation = new AsyncLocalStorage7();
130479
+ activeCancellation = new AsyncLocalStorage8();
130417
130480
  sandboxPromises = /* @__PURE__ */ new WeakSet();
130418
130481
  cancelableOutcomes = /* @__PURE__ */ new WeakMap();
130419
130482
  }
@@ -144094,50 +144157,6 @@ var init_var_hoist = __esm({
144094
144157
  }
144095
144158
  });
144096
144159
 
144097
- // packages/safe-js/src/interp/resources.ts
144098
- import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
144099
- async function withRunResources(signal, execute2) {
144100
- const controller = new AbortController();
144101
- const cancel2 = () => controller.abort(signal?.reason);
144102
- const cleanups = /* @__PURE__ */ new Set();
144103
- const resources = {
144104
- signal: controller.signal,
144105
- referenceReleases: /* @__PURE__ */ new Set(),
144106
- add(close) {
144107
- cleanups.add(close);
144108
- }
144109
- };
144110
- signal?.addEventListener("abort", cancel2, { once: true });
144111
- if (signal?.aborted) cancel2();
144112
- let result;
144113
- let failure;
144114
- let errors2 = [];
144115
- try {
144116
- result = await runResources.run(resources, execute2);
144117
- } catch (error3) {
144118
- failure = { reason: error3 };
144119
- } finally {
144120
- signal?.removeEventListener("abort", cancel2);
144121
- controller.abort(new Error("SafeJS run finished."));
144122
- for (const release2 of resources.referenceReleases) release2();
144123
- resources.referenceReleases.clear();
144124
- const outcomes = await Promise.allSettled(
144125
- [...cleanups].map((close) => Promise.resolve().then(close))
144126
- );
144127
- errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
144128
- }
144129
- if (failure !== void 0) throw failure.reason;
144130
- if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
144131
- return result;
144132
- }
144133
- var runResources;
144134
- var init_resources = __esm({
144135
- "packages/safe-js/src/interp/resources.ts"() {
144136
- "use strict";
144137
- runResources = new AsyncLocalStorage8();
144138
- }
144139
- });
144140
-
144141
144160
  // packages/safe-js/src/interp/methods/array.ts
144142
144161
  function getArrayMember(value, property, options) {
144143
144162
  const index = getArrayIndex(property);
@@ -145301,6 +145320,9 @@ function isStringMethodName(property) {
145301
145320
  function validateStringMethodArguments(_methodName, _args) {
145302
145321
  }
145303
145322
  function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
145323
+ if (methodName === "concat" && args.some((argument) => argument !== null && typeof argument === "object")) {
145324
+ return callConcat(value, args, budget, context);
145325
+ }
145304
145326
  if (methodName === "isWellFormed") {
145305
145327
  for (let index = 0; index < value.length; index++) {
145306
145328
  const codeUnit = value.charCodeAt(index);
@@ -145456,6 +145478,19 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
145456
145478
  operation.release();
145457
145479
  }
145458
145480
  }
145481
+ async function callConcat(value, args, budget, context) {
145482
+ let result = budget.allocateString(value);
145483
+ const release2 = retainValues(budget, () => [result]);
145484
+ try {
145485
+ for (const argument of args) {
145486
+ const text5 = sandboxString(argument, budget, context);
145487
+ result = budget.allocateString(result + (typeof text5 === "string" ? text5 : await text5));
145488
+ }
145489
+ return result;
145490
+ } finally {
145491
+ release2();
145492
+ }
145493
+ }
145459
145494
  function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
145460
145495
  const search = args[0];
145461
145496
  const replacement = args[1];
@@ -145709,6 +145744,7 @@ var init_string = __esm({
145709
145744
  init_compile_guard();
145710
145745
  init_engine2();
145711
145746
  init_string_coercion();
145747
+ init_resources();
145712
145748
  init_values();
145713
145749
  init_regex();
145714
145750
  SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
@@ -146993,14 +147029,18 @@ function isObjectPrototypeSetterProperty(property, key3) {
146993
147029
  }
146994
147030
  async function evaluateTemplateLiteral(node, context) {
146995
147031
  let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
146996
- const release2 = retainValues(context.budget, () => [value]);
147032
+ let input = void 0;
147033
+ const release2 = retainValues(context.budget, () => [value, input]);
146997
147034
  try {
146998
147035
  for (let index = 0; index < node.expressions.length; index += 1) {
146999
147036
  const expression = await evaluateNode2(node.expressions[index], context);
147000
147037
  if (expression.kind !== "normal") {
147001
147038
  return expression;
147002
147039
  }
147003
- const expressionText = context.budget.allocateString(String(expression.value));
147040
+ input = expression.value;
147041
+ const text5 = sandboxString(input, context.budget, createCoercionContext(context));
147042
+ const expressionText = typeof text5 === "string" ? text5 : await text5;
147043
+ input = void 0;
147004
147044
  value = context.budget.allocateString(value + expressionText);
147005
147045
  const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
147006
147046
  value = context.budget.allocateString(value + quasiText);
@@ -148447,17 +148487,6 @@ async function evaluateMemberAccess(node, context, consume) {
148447
148487
  release2();
148448
148488
  }
148449
148489
  }
148450
- function retainValues(budget, values) {
148451
- const retained = {};
148452
- budget.setRetainedValues(retained, values);
148453
- const pending = runResources.getStore()?.referenceReleases;
148454
- const release2 = () => {
148455
- budget.setRetainedValues(retained, void 0);
148456
- pending?.delete(release2);
148457
- };
148458
- pending?.add(release2);
148459
- return release2;
148460
- }
148461
148490
  async function evaluateMemberProperty(node, context) {
148462
148491
  const property = await evaluateNode2(node, context);
148463
148492
  if (property.kind !== "normal") {
@@ -149407,6 +149436,7 @@ var init_interpreter = __esm({
149407
149436
  init_jobs4();
149408
149437
  init_cancel2();
149409
149438
  init_resources();
149439
+ init_string_coercion();
149410
149440
  init_shape();
149411
149441
  init_async();
149412
149442
  init_host_call();