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.
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-C7UCTQDN.js";
25
+ } from "./chunks/chunk-VAYQP2VZ.js";
26
26
  import {
27
27
  Budget,
28
28
  SandboxError,
@@ -34,7 +34,7 @@ import {
34
34
  replaceErrorStack,
35
35
  restore,
36
36
  run
37
- } from "./chunks/chunk-MKJBQPBH.js";
37
+ } from "./chunks/chunk-ZTGKRKQH.js";
38
38
  import "./chunks/chunk-UXMKEUH3.js";
39
39
  import "./chunks/chunk-5DYEOCT5.js";
40
40
  import "./chunks/chunk-4YIDX44G.js";
@@ -5,7 +5,7 @@ import {
5
5
  defineExtension,
6
6
  lint,
7
7
  run
8
- } from "./chunks/chunk-MKJBQPBH.js";
8
+ } from "./chunks/chunk-ZTGKRKQH.js";
9
9
  import "./chunks/chunk-4YIDX44G.js";
10
10
  export {
11
11
  Budget,
@@ -26,7 +26,7 @@ import {
26
26
  runWithSpawnUsageAccumulator,
27
27
  splitFrontmatter,
28
28
  supportsSpawnMode
29
- } from "./chunks/chunk-C7UCTQDN.js";
29
+ } from "./chunks/chunk-VAYQP2VZ.js";
30
30
  import {
31
31
  Budget,
32
32
  FileSnapshotBackend,
@@ -50,7 +50,7 @@ import {
50
50
  registerPendingHostCallPolicy,
51
51
  restore,
52
52
  run
53
- } from "./chunks/chunk-MKJBQPBH.js";
53
+ } from "./chunks/chunk-ZTGKRKQH.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -4,7 +4,8 @@ import { toPropertyKey } from "./property-key.js";
4
4
  import { assertPromiseExecutionAllowed } from "./promise-tracker.js";
5
5
  import { SandboxJobQueue, runAsyncPrefix, suspendJob } from "./jobs.js";
6
6
  import { withCancellationSignal } from "./cancel.js";
7
- import { runResources } from "./resources.js";
7
+ import { retainValues } from "./resources.js";
8
+ import { sandboxString } from "./string-coercion.js";
8
9
  import { attachErrorSpan, formatErrorStack, replaceErrorStack } from "../error/shape.js";
9
10
  import { evaluateArrowFunctionExpression, evaluateFunctionExpression, evaluateAwaitExpression, emitResumeBreakpoint, createInterpretedClosure, normalizeClosureResult } from "./async.js";
10
11
  import { HostCallResumabilityError } from "./host-call.js";
@@ -360,14 +361,18 @@ function isObjectPrototypeSetterProperty(property, key) {
360
361
  }
361
362
  async function evaluateTemplateLiteral(node, context) {
362
363
  let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
363
- const release = retainValues(context.budget, () => [value]);
364
+ let input = undefined;
365
+ const release = retainValues(context.budget, () => [value, input]);
364
366
  try {
365
367
  for (let index = 0; index < node.expressions.length; index += 1) {
366
368
  const expression = await evaluateNode(node.expressions[index], context);
367
369
  if (expression.kind !== "normal") {
368
370
  return expression;
369
371
  }
370
- const expressionText = context.budget.allocateString(String(expression.value));
372
+ input = expression.value;
373
+ const text = sandboxString(input, context.budget, createCoercionContext(context));
374
+ const expressionText = typeof text === "string" ? text : await text;
375
+ input = undefined;
371
376
  value = context.budget.allocateString(value + expressionText);
372
377
  const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
373
378
  value = context.budget.allocateString(value + quasiText);
@@ -1831,17 +1836,6 @@ async function evaluateMemberAccess(node, context, consume) {
1831
1836
  release();
1832
1837
  }
1833
1838
  }
1834
- function retainValues(budget, values) {
1835
- const retained = {};
1836
- budget.setRetainedValues(retained, values);
1837
- const pending = runResources.getStore()?.referenceReleases;
1838
- const release = () => {
1839
- budget.setRetainedValues(retained, undefined);
1840
- pending?.delete(release);
1841
- };
1842
- pending?.add(release);
1843
- return release;
1844
- }
1845
1839
  async function evaluateMemberProperty(node, context) {
1846
1840
  const property = await evaluateNode(node, context);
1847
1841
  if (property.kind !== "normal") {
@@ -2,6 +2,7 @@ import { invokeBuiltinClosure } from "../builtin-call.js";
2
2
  import { CompileScope } from "../regex/compile-guard.js";
3
3
  import { normalizeLastIndex } from "../regex/engine.js";
4
4
  import { sandboxNumber, sandboxString } from "../string-coercion.js";
5
+ import { retainValues } from "../resources.js";
5
6
  import { createSandboxClosure, createSandboxRegex, deepCopyFromSandbox, isSandboxClosure, isSandboxRegex } from "../values.js";
6
7
  import { executeRegex, toMatchArray } from "./regex.js";
7
8
  const SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
@@ -83,6 +84,9 @@ export function isStringMethodName(property) {
83
84
  }
84
85
  export function validateStringMethodArguments(_methodName, _args) { }
85
86
  export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
87
+ if (methodName === "concat" && args.some(argument => argument !== null && typeof argument === "object")) {
88
+ return callConcat(value, args, budget, context);
89
+ }
86
90
  if (methodName === "isWellFormed") {
87
91
  for (let index = 0; index < value.length; index++) {
88
92
  const codeUnit = value.charCodeAt(index);
@@ -239,6 +243,20 @@ export function callStringMethod(value, methodName, args, budget, callClosure =
239
243
  operation.release();
240
244
  }
241
245
  }
246
+ async function callConcat(value, args, budget, context) {
247
+ let result = budget.allocateString(value);
248
+ const release = retainValues(budget, () => [result]);
249
+ try {
250
+ for (const argument of args) {
251
+ const text = sandboxString(argument, budget, context);
252
+ result = budget.allocateString(result + (typeof text === "string" ? text : await text));
253
+ }
254
+ return result;
255
+ }
256
+ finally {
257
+ release();
258
+ }
259
+ }
242
260
  function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
243
261
  const search = args[0];
244
262
  const replacement = args[1];
@@ -1,8 +1,10 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import type { Budget } from "./budget.js";
2
3
  export type RunResources = {
3
4
  signal: AbortSignal;
4
5
  referenceReleases: Set<() => void>;
5
6
  add(close: () => Promise<void>): void;
6
7
  };
7
8
  export declare const runResources: AsyncLocalStorage<RunResources>;
9
+ export declare function retainValues(budget: Budget, values: () => Iterable<unknown>): () => void;
8
10
  export declare function withRunResources<Result>(signal: AbortSignal | undefined, execute: () => Promise<Result>): Promise<Result>;
@@ -1,5 +1,16 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  export const runResources = new AsyncLocalStorage();
3
+ export function retainValues(budget, values) {
4
+ const retained = {};
5
+ budget.setRetainedValues(retained, values);
6
+ const pending = runResources.getStore()?.referenceReleases;
7
+ const release = () => {
8
+ budget.setRetainedValues(retained, undefined);
9
+ pending?.delete(release);
10
+ };
11
+ pending?.add(release);
12
+ return release;
13
+ }
3
14
  export async function withRunResources(signal, execute) {
4
15
  const controller = new AbortController();
5
16
  const cancel = () => controller.abort(signal?.reason);
@@ -7,6 +7,7 @@ import { isGuestHostObject } from "./host-capabilities.js";
7
7
  import { collectionIteratorState, isSandboxCollectionIterator } from "./collection-iterator.js";
8
8
  import { getGuestFunctionProperties, getSandboxPrototype, hasExplicitSandboxPrototype, isGuestClosure } from "./object-model.js";
9
9
  import { getRegexMember } from "./methods/regex.js";
10
+ import { retainValues } from "./resources.js";
10
11
  import { isSandboxClosure, isSandboxPromise, isSandboxMap, isSandboxSet, isSandboxRegex, isSandboxGenerator } from "./values.js";
11
12
  const defaultStringHook = Symbol("defaultStringHook");
12
13
  const defaultValueHook = Symbol("defaultValueHook");
@@ -118,9 +119,10 @@ async function defaultToString(value, budget, context, joining) {
118
119
  if (joining.has(value))
119
120
  return "";
120
121
  joining.add(value);
122
+ let text = "";
123
+ const release = retainValues(budget, () => [text]);
121
124
  try {
122
125
  const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
123
- let text = "";
124
126
  for (let index = 0; index < length; index++) {
125
127
  budget.visitNode();
126
128
  const element = ownDataValue(value, String(index));
@@ -132,15 +134,22 @@ async function defaultToString(value, budget, context, joining) {
132
134
  return text;
133
135
  }
134
136
  finally {
137
+ release();
135
138
  joining.delete(value);
136
139
  }
137
140
  }
138
141
  if (sandboxErrorTypes.has(value)) {
139
142
  const nameValue = ownDataValue(value, "name");
140
143
  const name = nameValue === undefined ? "Error" : await sandboxString(nameValue, budget, context, joining);
141
- const messageValue = ownDataValue(value, "message");
142
- const message = messageValue === undefined ? "" : await sandboxString(messageValue, budget, context, joining);
143
- return name === "" ? message : message === "" ? name : `${name}: ${message}`;
144
+ const release = retainValues(budget, () => [name]);
145
+ try {
146
+ const messageValue = ownDataValue(value, "message");
147
+ const message = messageValue === undefined ? "" : await sandboxString(messageValue, budget, context, joining);
148
+ return name === "" ? message : message === "" ? name : `${name}: ${message}`;
149
+ }
150
+ finally {
151
+ release();
152
+ }
144
153
  }
145
154
  return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
146
155
  }