poe-code 14.0.54 → 14.0.55

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-L7PHF62H.js";
30
+ } from "./chunk-6LFWVA64.js";
31
31
  import {
32
32
  createFileSystem,
33
33
  createNodeFileSystemAdapterRegistry,
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-Z55VACOY.js.map
8248
+ //# sourceMappingURL=chunk-G5LQ37D4.js.map
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-Z55VACOY.js";
25
+ } from "./chunks/chunk-G5LQ37D4.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-L7PHF62H.js";
37
+ } from "./chunks/chunk-6LFWVA64.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-L7PHF62H.js";
8
+ } from "./chunks/chunk-6LFWVA64.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-Z55VACOY.js";
29
+ } from "./chunks/chunk-G5LQ37D4.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-L7PHF62H.js";
53
+ } from "./chunks/chunk-6LFWVA64.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -1,5 +1,8 @@
1
1
  import { type SandboxClosure } from "../values.js";
2
- import { type CompileOwner } from "../budget.js";
3
- export declare function createRegexGlobals(owner?: CompileOwner): {
2
+ import { type Budget, type CompileOwner } from "../budget.js";
3
+ export declare function createRegexGlobals(options: {
4
+ budget: Budget;
5
+ compileOwner?: CompileOwner;
6
+ }): {
4
7
  RegExp: SandboxClosure;
5
8
  };
@@ -1,28 +1,42 @@
1
- import { createSandboxClosure, createSandboxRegex, reconcileCompiledValues } from "../values.js";
1
+ import { createSandboxClosure, createSandboxRegex, isSandboxRegex, reconcileCompiledValues } from "../values.js";
2
2
  import { CompileScope } from "../regex/compile-guard.js";
3
3
  import { SandboxError } from "../budget.js";
4
- export function createRegexGlobals(owner) {
5
- const construct = (args, context) => {
6
- const selected = owner ?? context?.compilation?.owner;
4
+ import { sandboxString } from "../string-coercion.js";
5
+ export function createRegexGlobals(options) {
6
+ const invoke = (construct) => async (args, context) => {
7
+ const selected = options.compileOwner ?? context?.compilation?.owner;
7
8
  if (context?.compilation?.owner !== undefined && selected !== context.compilation.owner) {
8
9
  throw new SandboxError("reentry");
9
10
  }
10
- const operation = selected?.budget.acquireCompileOwner(false, selected);
11
- const compilation = context?.compilation ?? new CompileScope(selected);
11
+ const operation = options.budget.acquireCompileOwner(false, selected);
12
+ const compilation = context?.compilation?.owner === operation.owner
13
+ ? context.compilation : new CompileScope(operation.owner);
14
+ let source = "";
15
+ const retained = {};
16
+ options.budget.setRetainedValues(retained, () => [...args, source]);
12
17
  try {
13
- const regex = createSandboxRegex(String(args[0] ?? ""), String(args[1] ?? ""), 0, compilation);
14
- if (context?.compilation === undefined && selected !== undefined) {
15
- reconcileCompiledValues(selected.budget, [regex], compilation);
18
+ const pattern = args[0];
19
+ const flags = args[1];
20
+ if (!construct && isSandboxRegex(pattern) && flags === undefined)
21
+ return pattern;
22
+ const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
23
+ const flagsValue = isSandboxRegex(pattern) && flags === undefined ? pattern.flags : flags;
24
+ source = sourceValue === undefined ? "" : await sandboxString(sourceValue, options.budget, context);
25
+ const flagText = flagsValue === undefined ? "" : await sandboxString(flagsValue, options.budget, context);
26
+ const regex = createSandboxRegex(source, flagText, 0, compilation);
27
+ if (compilation !== context?.compilation) {
28
+ reconcileCompiledValues(options.budget, [regex], compilation);
16
29
  }
17
30
  return regex;
18
31
  }
19
32
  finally {
20
- if (context?.compilation === undefined)
33
+ options.budget.setRetainedValues(retained, undefined);
34
+ if (compilation !== context?.compilation)
21
35
  compilation.dispose();
22
- operation?.release();
36
+ operation.release();
23
37
  }
24
38
  };
25
39
  return {
26
- RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: construct, construct })
40
+ RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke(false), construct: invoke(true) })
27
41
  };
28
42
  }
@@ -19,6 +19,6 @@ export function createBuiltinBindings(options) {
19
19
  ...createObjectArrayGlobals(options),
20
20
  ...createMiscGlobals(options),
21
21
  ...createPromiseGlobals(options),
22
- ...createRegexGlobals(options.compileOwner)
22
+ ...createRegexGlobals(options)
23
23
  };
24
24
  }
@@ -1938,7 +1938,7 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
1938
1938
  return {
1939
1939
  kind: "normal",
1940
1940
  hasValue: true,
1941
- value: await callStringMethod(target, methodName, args.value, context.budget, (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack), context.compilation)
1941
+ value: await callStringMethod(target, methodName, args.value, context.budget, (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack), context.compilation, createCoercionContext(context))
1942
1942
  };
1943
1943
  }
1944
1944
  catch (error) {
@@ -1,10 +1,10 @@
1
1
  import type { Expression } from "../../parse.js";
2
2
  import { Budget } from "../budget.js";
3
3
  import { CompileScope } from "../regex/compile-guard.js";
4
- import { type SandboxClosure, type SandboxValue } from "../values.js";
4
+ import { type SandboxCallContext, type SandboxClosure, type SandboxValue } from "../values.js";
5
5
  type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "isWellFormed" | "lastIndexOf" | "localeCompare" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "toWellFormed" | "trim" | "trimEnd" | "trimStart";
6
6
  export declare function getStringMember(value: string, property: string | number, budget: Budget): SandboxValue | undefined;
7
7
  export declare function isStringMethodName(property: string | number): property is StringMethodName;
8
8
  export declare function validateStringMethodArguments(_methodName: StringMethodName, _args: readonly Expression[]): void;
9
- export declare function callStringMethod(value: string, methodName: StringMethodName, args: readonly SandboxValue[], budget: Budget, callClosure?: (closure: SandboxClosure, args: readonly SandboxValue[]) => Promise<SandboxValue>, parent?: CompileScope): SandboxValue | Promise<SandboxValue>;
9
+ export declare function callStringMethod(value: string, methodName: StringMethodName, args: readonly SandboxValue[], budget: Budget, callClosure?: (closure: SandboxClosure, args: readonly SandboxValue[]) => Promise<SandboxValue>, parent?: CompileScope, context?: SandboxCallContext): SandboxValue | Promise<SandboxValue>;
10
10
  export {};
@@ -62,7 +62,7 @@ export function getStringMember(value, property, budget) {
62
62
  budget.setRetainedValues(retainedReceiver, () => [receiver]);
63
63
  try {
64
64
  const string = await sandboxString(receiver, budget, context);
65
- return await callStringMethod(string, property, args, budget, (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, undefined), context?.compilation);
65
+ return await callStringMethod(string, property, args, budget, (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, undefined), context?.compilation, context);
66
66
  }
67
67
  finally {
68
68
  budget.setRetainedValues(retainedReceiver, undefined);
@@ -81,7 +81,7 @@ export function isStringMethodName(property) {
81
81
  return typeof property === "string" && stringMethodNames.has(property);
82
82
  }
83
83
  export function validateStringMethodArguments(_methodName, _args) { }
84
- export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
84
+ export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
85
85
  if (methodName === "isWellFormed") {
86
86
  for (let index = 0; index < value.length; index++) {
87
87
  const codeUnit = value.charCodeAt(index);
@@ -122,6 +122,9 @@ export function callStringMethod(value, methodName, args, budget, callClosure =
122
122
  if (methodName === "replace" || methodName === "replaceAll") {
123
123
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
124
124
  }
125
+ if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
126
+ return callStringPattern(value, methodName, args[0], budget, parent, context);
127
+ }
125
128
  const operation = budget.acquireCompileOwner(false, parent?.owner);
126
129
  const compilation = new CompileScope(operation.owner);
127
130
  try {
@@ -379,6 +382,22 @@ function callSplit(value, args, budget, compilation) {
379
382
  budget.allocateArrayLength(result.length);
380
383
  return result;
381
384
  }
385
+ async function callStringPattern(value, methodName, pattern, budget, parent, context) {
386
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
387
+ const compilation = new CompileScope(operation.owner);
388
+ const retainedPattern = {};
389
+ budget.setRetainedValues(retainedPattern, () => [pattern]);
390
+ try {
391
+ const source = pattern === undefined ? "" : await sandboxString(pattern, budget, context);
392
+ const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
393
+ return callMatchLikeMethod(value, methodName, [regex], compilation);
394
+ }
395
+ finally {
396
+ budget.setRetainedValues(retainedPattern, undefined);
397
+ compilation.dispose();
398
+ operation.release();
399
+ }
400
+ }
382
401
  function callMatchLikeMethod(value, methodName, args, compilation) {
383
402
  const regex = args[0];
384
403
  if (!isSandboxRegex(regex))
@@ -401,19 +420,20 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
401
420
  const matcher = methodName === "matchAll"
402
421
  ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation)
403
422
  : regex;
404
- const matches = collectRegexMatches(matcher, value, true);
423
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
405
424
  if (methodName === "match" && matches.length === 0)
406
425
  return null;
407
426
  return methodName === "match"
408
427
  ? matches.map((match) => match.text)
409
428
  : matches.map((match) => toMatchArray(match, value));
410
429
  }
411
- function collectRegexMatches(regex, value, all) {
430
+ function collectRegexMatches(regex, value, all, budget) {
412
431
  const matches = [];
413
432
  do {
414
433
  const match = executeRegex(regex, value);
415
434
  if (match === null)
416
435
  break;
436
+ budget?.allocateArrayLength(matches.length + 1);
417
437
  matches.push(match);
418
438
  if (all && match.text.length === 0)
419
439
  regex.lastIndex += 1;