poe-code 12.0.0 → 12.0.2

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.
@@ -20,7 +20,7 @@ import {
20
20
  parseMcpConfig,
21
21
  splitFrontmatter,
22
22
  withBrokenPipeGuard
23
- } from "./chunks/chunk-6EXLQKE5.js";
23
+ } from "./chunks/chunk-T55OILHA.js";
24
24
  import {
25
25
  Budget,
26
26
  SandboxError,
@@ -32,7 +32,7 @@ import {
32
32
  replaceErrorStack,
33
33
  restore,
34
34
  run
35
- } from "./chunks/chunk-YE6I5W6O.js";
35
+ } from "./chunks/chunk-Z3ZMLYCK.js";
36
36
  import "./chunks/chunk-4YIDX44G.js";
37
37
 
38
38
  // packages/safejs/src/cli.ts
@@ -3,7 +3,7 @@ import {
3
3
  createReplayableRandom,
4
4
  lint,
5
5
  run
6
- } from "./chunks/chunk-YE6I5W6O.js";
6
+ } from "./chunks/chunk-Z3ZMLYCK.js";
7
7
  import "./chunks/chunk-4YIDX44G.js";
8
8
  export {
9
9
  Budget,
@@ -27,7 +27,7 @@ import {
27
27
  runWithSpawnUsageAccumulator,
28
28
  splitFrontmatter,
29
29
  supportsSpawnMode
30
- } from "./chunks/chunk-6EXLQKE5.js";
30
+ } from "./chunks/chunk-T55OILHA.js";
31
31
  import {
32
32
  Budget,
33
33
  FileSnapshotBackend,
@@ -49,7 +49,7 @@ import {
49
49
  registerPendingHostCallPolicy,
50
50
  restore,
51
51
  run
52
- } from "./chunks/chunk-YE6I5W6O.js";
52
+ } from "./chunks/chunk-Z3ZMLYCK.js";
53
53
  import "./chunks/chunk-4YIDX44G.js";
54
54
 
55
55
  // packages/safejs/src/runner/run-harness.ts
@@ -1,3 +1,4 @@
1
+ import { sandboxErrorTypes } from "../../error/shape.js";
1
2
  import { getSandboxIterator } from "../iteration.js";
2
3
  import { allocateProducedSandboxValue, createSandboxClosure, deepCopyToSandbox, isSandboxClosure, isSandboxMap, isSandboxPromise, isSandboxRegex, isSandboxSet } from "../values.js";
3
4
  export function createObjectArrayGlobals(options) {
@@ -88,7 +89,12 @@ export function createObjectArrayGlobals(options) {
88
89
  }),
89
90
  String: createSandboxClosure({
90
91
  sandbox: true,
91
- call: ([value]) => options.budget.allocateString(String(value)),
92
+ call: ([value]) => options.budget.allocateString(typeof value === "object" &&
93
+ value !== null &&
94
+ sandboxErrorTypes.has(value) &&
95
+ !Object.hasOwn(value, "toString")
96
+ ? Error.prototype.toString.call(value)
97
+ : String(value)),
92
98
  name: "String",
93
99
  properties: {
94
100
  raw: createSandboxClosure({
@@ -1,7 +1,7 @@
1
1
  import type { Expression } from "../../parse.js";
2
2
  import { Budget } from "../budget.js";
3
3
  import { type SandboxClosure, type SandboxValue } from "../values.js";
4
- type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "lastIndexOf" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "trim" | "trimEnd" | "trimStart";
4
+ type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "trim" | "trimEnd" | "trimStart";
5
5
  export declare function getStringMember(value: string, property: string | number, budget: Budget): SandboxValue | undefined;
6
6
  export declare function isStringMethodName(property: string | number): property is StringMethodName;
7
7
  export declare function validateStringMethodArguments(_methodName: StringMethodName, _args: readonly Expression[]): void;
@@ -1,4 +1,4 @@
1
- import { createSandboxClosure, createSandboxRegex, isSandboxClosure, isSandboxRegex } from "../values.js";
1
+ import { createSandboxClosure, createSandboxRegex, deepCopyFromSandbox, isSandboxClosure, isSandboxRegex } from "../values.js";
2
2
  import { executeRegex, toMatchArray } from "./regex.js";
3
3
  const SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
4
4
  const stringMethodNames = new Set([
@@ -11,6 +11,7 @@ const stringMethodNames = new Set([
11
11
  "includes",
12
12
  "indexOf",
13
13
  "lastIndexOf",
14
+ "localeCompare",
14
15
  "match",
15
16
  "matchAll",
16
17
  "normalize",
@@ -45,6 +46,7 @@ export function getStringMember(value, property, budget) {
45
46
  return createSandboxClosure({
46
47
  sandbox: true,
47
48
  name: `String#${property}`,
49
+ ...(property === "localeCompare" ? { length: 1 } : {}),
48
50
  call: (args) => callStringMethod(value, property, args, budget)
49
51
  });
50
52
  }
@@ -69,6 +71,46 @@ export function callStringMethod(value, methodName, args, budget, callClosure =
69
71
  if (methodName === "match" || methodName === "matchAll" || methodName === "search") {
70
72
  return callMatchLikeMethod(value, methodName, args);
71
73
  }
74
+ if (methodName === "localeCompare") {
75
+ if (isSandboxClosure(args[0])) {
76
+ throw new TypeError("String#localeCompare does not support function comparison values.");
77
+ }
78
+ const comparison = budget.allocateString(String(deepCopyFromSandbox(args[0])));
79
+ const locales = Reflect.apply(Intl.getCanonicalLocales, Intl, [
80
+ deepCopyFromSandbox(args[1])
81
+ ]);
82
+ const options = args[2];
83
+ const nativeOptions = options === undefined || options === null
84
+ ? options
85
+ : Object.fromEntries([
86
+ "usage",
87
+ "localeMatcher",
88
+ "collation",
89
+ "numeric",
90
+ "caseFirst",
91
+ "sensitivity",
92
+ "ignorePunctuation"
93
+ ].map((property) => {
94
+ const descriptor = Object.getOwnPropertyDescriptor(options, property);
95
+ if (descriptor !== undefined && !("value" in descriptor)) {
96
+ throw new TypeError("String#localeCompare only supports data option properties.");
97
+ }
98
+ const option = descriptor?.value;
99
+ return [
100
+ property,
101
+ option === undefined
102
+ ? undefined
103
+ : property === "numeric" || property === "ignorePunctuation"
104
+ ? Boolean(option)
105
+ : deepCopyFromSandbox(option)
106
+ ];
107
+ }));
108
+ return Reflect.apply(String.prototype.localeCompare, value, [
109
+ comparison,
110
+ locales,
111
+ nativeOptions
112
+ ]);
113
+ }
72
114
  if (args.some(isSandboxClosure)) {
73
115
  throw new TypeError(`String#${methodName} does not support function arguments.`);
74
116
  }