poe-code 14.0.45 → 14.0.47

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 (26) hide show
  1. package/dist/index.js +53 -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 +15 -5
  6. package/packages/safe-bash/dist/browser.js.map +2 -2
  7. package/packages/safe-bash/dist/commands/network/authorizer.d.ts.map +1 -1
  8. package/packages/safe-bash/dist/commands/network/authorizer.js +4 -1
  9. package/packages/safe-bash/dist/commands/network/authorizer.js.map +1 -1
  10. package/packages/safe-bash/dist/contracts/filesystem-output.d.ts.map +1 -1
  11. package/packages/safe-bash/dist/contracts/filesystem-output.js +12 -4
  12. package/packages/safe-bash/dist/contracts/filesystem-output.js.map +1 -1
  13. package/packages/safe-js/dist/chunks/{chunk-WQQANSWB.js → chunk-WQY27BRL.js} +2 -2
  14. package/packages/safe-js/dist/chunks/{chunk-T3NC5O24.js → chunk-XC53RECY.js} +54 -27
  15. package/packages/safe-js/dist/chunks/chunk-XC53RECY.js.map +7 -0
  16. package/packages/safe-js/dist/cli.js +2 -2
  17. package/packages/safe-js/dist/core.js +1 -1
  18. package/packages/safe-js/dist/index.js +2 -2
  19. package/packages/safe-js/dist/interp/budget.d.ts +1 -0
  20. package/packages/safe-js/dist/interp/budget.js +3 -0
  21. package/packages/safe-js/dist/interp/exceptions.d.ts +3 -0
  22. package/packages/safe-js/dist/interp/exceptions.js +57 -12
  23. package/packages/safe-js/dist/interp/interpreter.js +6 -29
  24. package/packages/safe-js/dist/interp/methods/function.js +5 -2
  25. package/packages/safe-js/dist/chunks/chunk-T3NC5O24.js.map +0 -7
  26. /package/packages/safe-js/dist/chunks/{chunk-WQQANSWB.js.map → chunk-WQY27BRL.js.map} +0 -0
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-WQQANSWB.js";
25
+ } from "./chunks/chunk-WQY27BRL.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-T3NC5O24.js";
37
+ } from "./chunks/chunk-XC53RECY.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-T3NC5O24.js";
8
+ } from "./chunks/chunk-XC53RECY.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-WQQANSWB.js";
29
+ } from "./chunks/chunk-WQY27BRL.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-T3NC5O24.js";
53
+ } from "./chunks/chunk-XC53RECY.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -34,6 +34,7 @@ type BudgetLimits = {
34
34
  arrayLength?: number;
35
35
  dataSize?: number;
36
36
  };
37
+ export declare function isFatalSandboxError(error: unknown): error is SandboxError;
37
38
  export type CompileOwner = {
38
39
  readonly budget: Budget;
39
40
  readonly generation: number;
@@ -34,6 +34,9 @@ export class SandboxError extends Error {
34
34
  this.limit = input.limit;
35
35
  }
36
36
  }
37
+ export function isFatalSandboxError(error) {
38
+ return (error instanceof SandboxError && (error.code === "budgetExceeded" || error.code === "reentry"));
39
+ }
37
40
  export class Budget {
38
41
  deadline;
39
42
  limits;
@@ -2,6 +2,7 @@ import type { BreakStatement, ContinueStatement, ParseResult, ThrowStatement, Tr
2
2
  import { type SandboxErrorName, type ErrorSourceSpan } from "../error/shape.js";
3
3
  import { type Budget } from "./budget.js";
4
4
  import type { Scope } from "./scope.js";
5
+ import type { InterpreterError } from "./interpreter.js";
5
6
  import { type SandboxObject, type SandboxValue } from "./values.js";
6
7
  declare const capturedExceptionBrand: unique symbol;
7
8
  export type { SandboxErrorName } from "../error/shape.js";
@@ -35,6 +36,8 @@ type ExceptionContext = {
35
36
  type EvaluateExceptionNode<TContext, TError> = (node: ParseResult, context: TContext) => Promise<EvaluationResult<TError>>;
36
37
  export declare function evaluateThrowStatement<TContext extends ExceptionContext, TError>(node: ThrowStatement, context: TContext, evaluateNode: EvaluateExceptionNode<TContext, TError>): Promise<EvaluationResult<TError>>;
37
38
  export declare function evaluateTryStatement<TContext extends ExceptionContext, TError>(node: TryStatement, context: TContext, evaluateNode: EvaluateExceptionNode<TContext, TError>): Promise<EvaluationResult<TError>>;
39
+ export declare function createThrowCompletion(error: unknown, budget: Budget, stackFrames: readonly string[], span?: ErrorSourceSpan): CompletionResult;
40
+ export declare function isInterpreterError(value: unknown): value is InterpreterError;
38
41
  export declare function createCapturedException(reason: unknown, stackFrames: readonly string[], sandbox?: boolean): CapturedException;
39
42
  export declare function isCapturedException(value: unknown): value is CapturedException;
40
43
  export declare function coerceThrownValue(reason: unknown, budget: Budget, stackFrames: readonly string[], span?: ErrorSourceSpan, sandbox?: boolean): SandboxValue;
@@ -1,5 +1,5 @@
1
1
  import { attachErrorSpan, attachWrappedErrorCause, describeThrownValue, formatErrorStack, readErrorCause, readErrorSpan, sandboxErrorNames, sandboxErrorTypes } from "../error/shape.js";
2
- import { SandboxError } from "./budget.js";
2
+ import { isFatalSandboxError, SandboxError } from "./budget.js";
3
3
  import { HostCallResumabilityError } from "./host-call.js";
4
4
  import { withFatalPromiseCleanup } from "./promise-tracker.js";
5
5
  import { deepCopyToSandbox, ownEnumerableSandboxEntries } from "./values.js";
@@ -36,25 +36,70 @@ export async function evaluateTryStatement(node, context, evaluateNode) {
36
36
  value: undefined
37
37
  };
38
38
  }
39
- const tryOrCatchResult = fatalBudgetError === undefined && tryResult.kind === "throw" && node.handler !== undefined
40
- ? await evaluateCatchClause(node.handler, tryResult.value, context, evaluateNode)
41
- : tryResult;
39
+ let tryOrCatchResult = tryResult;
40
+ let catchFailure;
41
+ if (fatalBudgetError === undefined && tryResult.kind === "throw" && node.handler !== undefined) {
42
+ try {
43
+ tryOrCatchResult = await evaluateCatchClause(node.handler, tryResult.value, context, evaluateNode);
44
+ }
45
+ catch (error) {
46
+ if (isFatalSandboxError(error) || isInterpreterError(error) || error instanceof HostCallResumabilityError) {
47
+ throw error;
48
+ }
49
+ catchFailure = createThrowCompletion(error, context.budget, context.callStack, node.span);
50
+ tryOrCatchResult = catchFailure;
51
+ }
52
+ }
42
53
  if (node.finalizer === undefined || tryOrCatchResult.kind === "error") {
43
54
  return tryOrCatchResult;
44
55
  }
45
56
  const evaluateFinalizer = () => fatalBudgetError?.budget === "deadline"
46
57
  ? evaluateWithoutDeadlineChecks(context, () => evaluateBlockCompletion(node.finalizer, context, evaluateNode))
47
58
  : evaluateBlockCompletion(node.finalizer, context, evaluateNode);
48
- const finalizerResult = await (fatalBudgetError === undefined
49
- ? evaluateFinalizer()
50
- : withFatalPromiseCleanup(evaluateFinalizer));
51
- if (fatalBudgetError !== undefined) {
52
- throw fatalBudgetError;
59
+ if (catchFailure !== undefined) {
60
+ const value = catchFailure.value;
61
+ context.budget.setRetainedValues(catchFailure, () => [value]);
53
62
  }
54
- if (finalizerResult.kind === "normal") {
55
- return tryOrCatchResult;
63
+ try {
64
+ const finalizerResult = await (fatalBudgetError === undefined
65
+ ? evaluateFinalizer()
66
+ : withFatalPromiseCleanup(evaluateFinalizer));
67
+ if (fatalBudgetError !== undefined) {
68
+ throw fatalBudgetError;
69
+ }
70
+ if (finalizerResult.kind === "normal") {
71
+ return tryOrCatchResult;
72
+ }
73
+ return finalizerResult;
74
+ }
75
+ finally {
76
+ if (catchFailure !== undefined)
77
+ context.budget.setRetainedValues(catchFailure, undefined);
56
78
  }
57
- return finalizerResult;
79
+ }
80
+ export function createThrowCompletion(error, budget, stackFrames, span) {
81
+ const value = isCapturedException(error)
82
+ ? coerceThrownValue(error.reason, budget, error.stackFrames, span, error.sandbox)
83
+ : coerceThrownValue(error, budget, stackFrames, span, true);
84
+ return {
85
+ kind: "throw",
86
+ hasValue: true,
87
+ span: readErrorSpan(value) ?? span,
88
+ stackFrames: isCapturedException(error) ? error.stackFrames : stackFrames,
89
+ value
90
+ };
91
+ }
92
+ export function isInterpreterError(value) {
93
+ return (typeof value === "object" &&
94
+ value !== null &&
95
+ hasOwnProperty(value, "code") &&
96
+ hasOwnProperty(value, "message") &&
97
+ hasOwnProperty(value, "nodeType") &&
98
+ hasOwnProperty(value, "span") &&
99
+ (value.code === "UNBOUND_IDENTIFIER" || value.code === "UNSUPPORTED_NODE"));
100
+ }
101
+ function hasOwnProperty(value, name) {
102
+ return Object.prototype.hasOwnProperty.call(value, name);
58
103
  }
59
104
  export function createCapturedException(reason, stackFrames, sandbox = false) {
60
105
  return {
@@ -4,12 +4,12 @@ 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 { attachErrorSpan, formatErrorStack, readErrorSpan, replaceErrorStack } from "../error/shape.js";
7
+ import { attachErrorSpan, formatErrorStack, replaceErrorStack } from "../error/shape.js";
8
8
  import { evaluateArrowFunctionExpression, evaluateFunctionExpression, evaluateAwaitExpression, emitResumeBreakpoint, createInterpretedClosure, normalizeClosureResult } from "./async.js";
9
9
  import { HostCallResumabilityError } from "./host-call.js";
10
- import { Budget, SandboxError } from "./budget.js";
10
+ import { Budget, isFatalSandboxError, SandboxError } from "./budget.js";
11
11
  import { CompileScope, RegexCompileGuard } from "./regex/compile-guard.js";
12
- import { coerceThrownValue, createCapturedException, evaluateThrowStatement as evaluateThrowStatementResult, evaluateTryStatement as evaluateTryStatementResult, isCapturedException, surfaceThrownValue } from "./exceptions.js";
12
+ import { createCapturedException, createThrowCompletion, evaluateThrowStatement as evaluateThrowStatementResult, evaluateTryStatement as evaluateTryStatementResult, isCapturedException, isInterpreterError, surfaceThrownValue } from "./exceptions.js";
13
13
  import { callArrayMethod, getArrayMember, isArrayMethodName } from "./methods/array.js";
14
14
  import { getFunctionMember } from "./methods/function.js";
15
15
  import { getGuestFunctionProperty, getSandboxPrototype, isGuestClosure, materializeFunctionProperties, setSandboxPrototype } from "./object-model.js";
@@ -222,17 +222,9 @@ async function evaluateNode(node, context) {
222
222
  error
223
223
  };
224
224
  }
225
- const exception = isCapturedException(error)
226
- ? coerceThrownValue(error.reason, context.budget, error.stackFrames, node.span, error.sandbox)
227
- : coerceThrownValue(error, context.budget, context.callStack, node.span, true);
228
- reconcileDataBudget(context.budget, context.stats, context.scope, exception, compilation, context.compilation);
229
- return {
230
- kind: "throw",
231
- hasValue: true,
232
- span: readErrorSpan(exception) ?? node.span,
233
- stackFrames: isCapturedException(error) ? error.stackFrames : context.callStack,
234
- value: exception
235
- };
225
+ const completion = createThrowCompletion(error, context.budget, context.callStack, node.span);
226
+ reconcileDataBudget(context.budget, context.stats, context.scope, completion.value, compilation, context.compilation);
227
+ return completion;
236
228
  }
237
229
  finally {
238
230
  compilation.dispose();
@@ -2667,18 +2659,6 @@ function defineSandboxProperty(target, key, value) {
2667
2659
  writable: true
2668
2660
  });
2669
2661
  }
2670
- function isInterpreterError(value) {
2671
- return (typeof value === "object" &&
2672
- value !== null &&
2673
- hasOwnProperty(value, "code") &&
2674
- hasOwnProperty(value, "message") &&
2675
- hasOwnProperty(value, "nodeType") &&
2676
- hasOwnProperty(value, "span") &&
2677
- (value.code === "UNBOUND_IDENTIFIER" || value.code === "UNSUPPORTED_NODE"));
2678
- }
2679
- function hasOwnProperty(value, name) {
2680
- return Object.prototype.hasOwnProperty.call(value, name);
2681
- }
2682
2662
  function wrapHostResult(result, stack, sandbox) {
2683
2663
  if (!isPromiseLikeResult(result)) {
2684
2664
  return result;
@@ -2690,9 +2670,6 @@ function wrapHostResult(result, stack, sandbox) {
2690
2670
  function captureException(error, stack, sandbox) {
2691
2671
  return isCapturedException(error) ? error : createCapturedException(error, stack, sandbox);
2692
2672
  }
2693
- function isFatalSandboxError(error) {
2694
- return (error instanceof SandboxError && (error.code === "budgetExceeded" || error.code === "reentry"));
2695
- }
2696
2673
  function isPromiseLikeResult(value) {
2697
2674
  return typeof value === "object" && value !== null && "then" in value;
2698
2675
  }
@@ -1,4 +1,4 @@
1
- import { createSandboxClosure } from "../values.js";
1
+ import { createSandboxClosure, isSandboxClosure } from "../values.js";
2
2
  import { getGuestFunctionProperty, isGuestClosure } from "../object-model.js";
3
3
  const functionMethodNames = new Set(["apply", "bind", "call"]);
4
4
  export function getFunctionMember(target, property, options) {
@@ -22,13 +22,16 @@ export function getFunctionMember(target, property, options) {
22
22
  return createSandboxClosure({
23
23
  sandbox: true,
24
24
  name: `Function#${property}`,
25
- call: (args, context) => callFunctionMethod(target, property, args, options, context?.stack ?? [])
25
+ call: (args, context) => callFunctionMethod(context?.thisValue, property, args, options, context?.stack ?? [])
26
26
  });
27
27
  }
28
28
  function isFunctionMethodName(property) {
29
29
  return typeof property === "string" && functionMethodNames.has(property);
30
30
  }
31
31
  function callFunctionMethod(target, methodName, args, options, stack) {
32
+ if (!isSandboxClosure(target)) {
33
+ throw new TypeError(`Function#${methodName} requires a callable receiver.`);
34
+ }
32
35
  const thisValue = args[0];
33
36
  if (methodName === "bind") {
34
37
  const boundArgs = args.slice(1);