poe-code 14.0.43 → 14.0.45

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.
Files changed (36) hide show
  1. package/dist/index.js +50 -26
  2. package/dist/index.js.map +3 -3
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-bash/dist/browser.js +72 -25
  6. package/packages/safe-bash/dist/browser.js.map +3 -3
  7. package/packages/safe-bash/dist/shell/parser.d.ts +3 -2
  8. package/packages/safe-bash/dist/shell/parser.d.ts.map +1 -1
  9. package/packages/safe-bash/dist/shell/parser.js +18 -21
  10. package/packages/safe-bash/dist/shell/parser.js.map +1 -1
  11. package/packages/safe-bash/dist/shell/runtime.d.ts.map +1 -1
  12. package/packages/safe-bash/dist/shell/runtime.js +14 -6
  13. package/packages/safe-bash/dist/shell/runtime.js.map +1 -1
  14. package/packages/safe-bash/dist/shell/shell.d.ts.map +1 -1
  15. package/packages/safe-bash/dist/shell/shell.js +4 -2
  16. package/packages/safe-bash/dist/shell/shell.js.map +1 -1
  17. package/packages/safe-bash/dist/shell/source-line-index.d.ts +10 -0
  18. package/packages/safe-bash/dist/shell/source-line-index.d.ts.map +1 -0
  19. package/packages/safe-bash/dist/shell/source-line-index.js +41 -0
  20. package/packages/safe-bash/dist/shell/source-line-index.js.map +1 -0
  21. package/packages/safe-js/dist/chunks/{chunk-774EXZKX.js → chunk-T3NC5O24.js} +50 -27
  22. package/packages/safe-js/dist/chunks/chunk-T3NC5O24.js.map +7 -0
  23. package/packages/safe-js/dist/chunks/{chunk-RE6OPFUY.js → chunk-WQQANSWB.js} +2 -2
  24. package/packages/safe-js/dist/cli.js +2 -2
  25. package/packages/safe-js/dist/core.js +1 -1
  26. package/packages/safe-js/dist/index.js +2 -2
  27. package/packages/safe-js/dist/interp/exceptions.d.ts +1 -0
  28. package/packages/safe-js/dist/interp/exceptions.js +11 -11
  29. package/packages/safe-js/dist/interp/interpreter.js +4 -3
  30. package/packages/safe-js/dist/interp/methods/number.d.ts +2 -2
  31. package/packages/safe-js/dist/interp/methods/number.js +5 -2
  32. package/packages/safe-js/dist/interp/patterns.js +2 -4
  33. package/packages/safe-js/dist/interp/values.d.ts +1 -1
  34. package/packages/safe-js/dist/interp/values.js +9 -4
  35. package/packages/safe-js/dist/chunks/chunk-774EXZKX.js.map +0 -7
  36. /package/packages/safe-js/dist/chunks/{chunk-RE6OPFUY.js.map → chunk-WQQANSWB.js.map} +0 -0
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-774EXZKX.js";
30
+ } from "./chunk-T3NC5O24.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-RE6OPFUY.js.map
8248
+ //# sourceMappingURL=chunk-WQQANSWB.js.map
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-RE6OPFUY.js";
25
+ } from "./chunks/chunk-WQQANSWB.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-774EXZKX.js";
37
+ } from "./chunks/chunk-T3NC5O24.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-774EXZKX.js";
8
+ } from "./chunks/chunk-T3NC5O24.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-RE6OPFUY.js";
29
+ } from "./chunks/chunk-WQQANSWB.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-774EXZKX.js";
53
+ } from "./chunks/chunk-T3NC5O24.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -30,6 +30,7 @@ type ExceptionContext = {
30
30
  callStack: readonly string[];
31
31
  scope: Scope;
32
32
  toPropertyKey?: (value: SandboxValue) => Promise<string>;
33
+ getProperty?: (value: SandboxValue, key: string | number) => SandboxValue;
33
34
  };
34
35
  type EvaluateExceptionNode<TContext, TError> = (node: ParseResult, context: TContext) => Promise<EvaluationResult<TError>>;
35
36
  export declare function evaluateThrowStatement<TContext extends ExceptionContext, TError>(node: ThrowStatement, context: TContext, evaluateNode: EvaluateExceptionNode<TContext, TError>): Promise<EvaluationResult<TError>>;
@@ -2,7 +2,8 @@ import { attachErrorSpan, attachWrappedErrorCause, describeThrownValue, formatEr
2
2
  import { SandboxError } from "./budget.js";
3
3
  import { HostCallResumabilityError } from "./host-call.js";
4
4
  import { withFatalPromiseCleanup } from "./promise-tracker.js";
5
- import { deepCopyToSandbox } from "./values.js";
5
+ import { deepCopyToSandbox, ownEnumerableSandboxEntries } from "./values.js";
6
+ import { getSandboxDataProperty } from "./object-model.js";
6
7
  import { toPropertyKey } from "./property-key.js";
7
8
  const capturedExceptionBrand = Symbol("CapturedException");
8
9
  export async function evaluateThrowStatement(node, context, evaluateNode) {
@@ -240,6 +241,9 @@ async function evaluateCatchClause(node, thrownValue, context, evaluateNode) {
240
241
  scope
241
242
  };
242
243
  if (node.param !== undefined) {
244
+ for (const name of getPatternBindingNames(node.param)) {
245
+ scope.predeclare(name, "let");
246
+ }
243
247
  const binding = await bindPattern(node.param, thrownValue, catchContext, evaluateNode);
244
248
  if (!binding.ok) {
245
249
  return binding.result;
@@ -351,8 +355,8 @@ async function bindArrayPattern(pattern, value, context, evaluateNode) {
351
355
  return { ok: true };
352
356
  }
353
357
  async function bindObjectPattern(pattern, value, context, evaluateNode) {
354
- if ((typeof value !== "object" && !Array.isArray(value)) || value === null) {
355
- throw new TypeError("Object catch bindings require a non-null object value.");
358
+ if (value === null || value === undefined) {
359
+ throw new TypeError("Object catch bindings require a non-nullish value.");
356
360
  }
357
361
  const excludedKeys = new Set();
358
362
  for (const property of pattern.properties) {
@@ -369,7 +373,9 @@ async function bindObjectPattern(pattern, value, context, evaluateNode) {
369
373
  return key;
370
374
  }
371
375
  excludedKeys.add(String(key.value));
372
- const binding = await bindPattern(property.value, getObjectPatternValue(value, key.value), context, evaluateNode);
376
+ const binding = await bindPattern(property.value, context.getProperty === undefined
377
+ ? getSandboxDataProperty(value, key.value, context.budget)
378
+ : context.getProperty(value, key.value), context, evaluateNode);
373
379
  if (!binding.ok) {
374
380
  return binding;
375
381
  }
@@ -406,15 +412,9 @@ function getStaticPropertyKey(property) {
406
412
  throw new TypeError(`Unsupported catch binding property key '${property.type}'.`);
407
413
  }
408
414
  }
409
- function getObjectPatternValue(value, key) {
410
- return value[key];
411
- }
412
415
  function copyObjectRest(value, excludedKeys) {
413
416
  const rest = Object.create(null);
414
- for (const [key, entryValue] of Object.entries(value)) {
415
- if (excludedKeys.has(key)) {
416
- continue;
417
- }
417
+ for (const [key, entryValue] of ownEnumerableSandboxEntries(value, excludedKeys)) {
418
418
  rest[key] = entryValue;
419
419
  }
420
420
  return rest;
@@ -1537,7 +1537,8 @@ async function evaluateThrowStatement(node, context) {
1537
1537
  async function evaluateTryStatement(node, context) {
1538
1538
  return evaluateTryStatementResult(node, {
1539
1539
  ...context,
1540
- toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context))
1540
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context)),
1541
+ getProperty: (value, key) => getPropertyValue(value, key, context)
1541
1542
  }, evaluateNode);
1542
1543
  }
1543
1544
  async function evaluateUnaryExpression(node, context) {
@@ -1675,7 +1676,7 @@ function getPropertyValue(target, property, context) {
1675
1676
  if (typeof target === "string")
1676
1677
  return getStringMember(target, property, context.budget);
1677
1678
  if (typeof target === "number")
1678
- return getNumberMember(target, property, context.budget);
1679
+ return getNumberMember(property, context.budget);
1679
1680
  if (typeof target === "boolean")
1680
1681
  return undefined;
1681
1682
  if (isFloat32Array(target))
@@ -1878,7 +1879,7 @@ async function evaluateMemberCallExpression(node, context) {
1878
1879
  return evaluatePrimitiveMemberCall(node, "String", member.property, getStringMember(member.object, member.property, context.budget), context);
1879
1880
  }
1880
1881
  if (typeof member.object === "number") {
1881
- return evaluatePrimitiveMemberCall(node, "Number", member.property, getNumberMember(member.object, member.property, context.budget), context);
1882
+ return evaluatePrimitiveMemberCall(node, "Number", member.property, getNumberMember(member.property, context.budget), context);
1882
1883
  }
1883
1884
  if (Array.isArray(member.object) && !Object.hasOwn(member.object, member.property)) {
1884
1885
  return evaluatePrimitiveMemberCall(node, "Array", member.property, getArrayMemberValue(member.object, member.property, context), context);
@@ -1,6 +1,6 @@
1
1
  import { Budget } from "../budget.js";
2
2
  import { type SandboxValue } from "../values.js";
3
3
  export type NumberMethodName = "toExponential" | "toFixed" | "toPrecision" | "toString";
4
- export declare function getNumberMember(value: number, property: string | number, budget: Budget): SandboxValue | undefined;
4
+ export declare function getNumberMember(property: string | number, budget: Budget): SandboxValue | undefined;
5
5
  export declare function isNumberMethodName(property: string | number): property is NumberMethodName;
6
- export declare function callNumberMethod(value: number, methodName: NumberMethodName, args: readonly SandboxValue[], budget: Budget): string;
6
+ export declare function callNumberMethod(value: SandboxValue, methodName: NumberMethodName, args: readonly SandboxValue[], budget: Budget): string;
@@ -5,20 +5,23 @@ const numberMethodNames = new Set([
5
5
  "toPrecision",
6
6
  "toString"
7
7
  ]);
8
- export function getNumberMember(value, property, budget) {
8
+ export function getNumberMember(property, budget) {
9
9
  if (!isNumberMethodName(property)) {
10
10
  return undefined;
11
11
  }
12
12
  return createSandboxClosure({
13
13
  sandbox: true,
14
14
  name: `Number#${property}`,
15
- call: (args) => callNumberMethod(value, property, args, budget)
15
+ call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget)
16
16
  });
17
17
  }
18
18
  export function isNumberMethodName(property) {
19
19
  return typeof property === "string" && numberMethodNames.has(property);
20
20
  }
21
21
  export function callNumberMethod(value, methodName, args, budget) {
22
+ if (typeof value !== "number") {
23
+ throw new TypeError(`Number#${methodName} requires a number receiver.`);
24
+ }
22
25
  return budget.allocateString(callNativeNumberMethod(value, methodName, args));
23
26
  }
24
27
  function callNativeNumberMethod(value, methodName, args) {
@@ -161,10 +161,8 @@ function describeRuntimeValue(value) {
161
161
  }
162
162
  function copyObjectRestValue(value, excludedKeys) {
163
163
  const rest = Object.create(null);
164
- for (const [key, entryValue] of ownEnumerableSandboxEntries(value)) {
165
- if (!excludedKeys.has(key)) {
166
- defineProperty(rest, key, entryValue);
167
- }
164
+ for (const [key, entryValue] of ownEnumerableSandboxEntries(value, excludedKeys)) {
165
+ defineProperty(rest, key, entryValue);
168
166
  }
169
167
  return rest;
170
168
  }
@@ -104,7 +104,7 @@ export declare function createSandboxClosure(input: {
104
104
  properties?: SandboxObject | ((closure: SandboxClosure) => SandboxObject);
105
105
  retainedValues?: () => Iterable<SandboxValue>;
106
106
  }): SandboxClosure;
107
- export declare function ownEnumerableSandboxEntries(value: SandboxValue): Array<[string, SandboxValue]>;
107
+ export declare function ownEnumerableSandboxEntries(value: SandboxValue, excludedKeys?: ReadonlySet<string>): Array<[string, SandboxValue]>;
108
108
  export declare function createSandboxPromise(promise: Promise<SandboxValue>, metadata?: {
109
109
  trackReplay?: boolean;
110
110
  synchronousPrefix?: Promise<void>;
@@ -73,10 +73,12 @@ export function createSandboxClosure(input) {
73
73
  }
74
74
  return Object.freeze(closure);
75
75
  }
76
- export function ownEnumerableSandboxEntries(value) {
76
+ export function ownEnumerableSandboxEntries(value, excludedKeys) {
77
77
  if (isGuestHostObject(value)) {
78
78
  const entries = [];
79
79
  for (const key of getHostObjectKeys(value)) {
80
+ if (excludedKeys?.has(key))
81
+ continue;
80
82
  if (hasHostObjectMember(value, key, true))
81
83
  entries.push([key, getHostObjectMember(value, key)]);
82
84
  }
@@ -84,11 +86,14 @@ export function ownEnumerableSandboxEntries(value) {
84
86
  }
85
87
  if (value === null || value === undefined)
86
88
  throw new TypeError("Cannot convert undefined or null to object.");
89
+ let entries;
87
90
  if (isGuestClosure(value))
88
- return Object.entries(value.properties ?? {});
89
- if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value))
91
+ entries = Object.entries(value.properties ?? {});
92
+ else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value))
90
93
  return [];
91
- return Object.entries(Object(value));
94
+ else
95
+ entries = Object.entries(Object(value));
96
+ return excludedKeys === undefined ? entries : entries.filter(([key]) => !excludedKeys.has(key));
92
97
  }
93
98
  export function createSandboxPromise(promise, metadata = {}) {
94
99
  const original = metadata.trackReplay === false