poe-code 14.0.39 → 14.0.41

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-CSC4EXIV.js";
30
+ } from "./chunk-5J6BX3HD.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-QXSG4XRW.js.map
8248
+ //# sourceMappingURL=chunk-L4NMOY6O.js.map
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-QXSG4XRW.js";
25
+ } from "./chunks/chunk-L4NMOY6O.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-CSC4EXIV.js";
37
+ } from "./chunks/chunk-5J6BX3HD.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-CSC4EXIV.js";
8
+ } from "./chunks/chunk-5J6BX3HD.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-QXSG4XRW.js";
29
+ } from "./chunks/chunk-L4NMOY6O.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-CSC4EXIV.js";
53
+ } from "./chunks/chunk-5J6BX3HD.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -52,6 +52,7 @@ export declare function emitResumeBreakpoint(context: AsyncEvaluationContext, br
52
52
  export declare function evaluateArrowFunctionExpression(node: ArrowFunctionExpression, context: AsyncEvaluationContext, evaluateNode: EvaluateAsyncNode): Promise<AsyncEvaluationResult>;
53
53
  export declare function evaluateFunctionExpression(node: FunctionExpression, context: AsyncEvaluationContext, evaluateNode: EvaluateAsyncNode): Promise<AsyncEvaluationResult>;
54
54
  export declare function createInterpretedClosure(node: ArrowFunctionExpression | FunctionDeclaration | FunctionExpression, context: AsyncEvaluationContext, evaluateNode: EvaluateAsyncNode): import("./values.js").SandboxClosure;
55
+ export declare function executeAsyncFunction(execute: (onSuspend: () => void) => Promise<SandboxValue>, budget: Budget, signal?: AbortSignal): import("./values.js").SandboxPromise;
55
56
  export declare function evaluateAwaitExpression(node: AwaitExpression, context: AsyncEvaluationContext, evaluateNode: EvaluateAsyncNode): Promise<AsyncEvaluationResult>;
56
57
  export declare function normalizeClosureResult(result: SandboxValue | Promise<SandboxValue> | PromiseLike<SandboxValue>, budget?: Budget): SandboxValue;
57
58
  export {};
@@ -81,36 +81,39 @@ export function createInterpretedClosure(node, context, evaluateNode) {
81
81
  };
82
82
  if (!node.async)
83
83
  return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode);
84
- let completePrefix;
85
- const synchronousPrefix = new Promise((resolve) => {
86
- completePrefix = resolve;
87
- });
88
- const promise = new Promise((resolve, reject) => {
89
- runAsyncPrefix(async () => {
90
- try {
91
- const value = await executeClosure(node, args, callContext?.thisValue, { ...invocationContext, onSuspend: completePrefix }, evaluateNode);
92
- resolve(isSandboxPromise(value) || getThenable(value) !== undefined
93
- ? awaitSandboxValue(createSandboxPromise(resolveSandboxValue(value, { budget: context.budget }), {
94
- trackReplay: false
95
- }), context.signal, context.budget)
96
- : allocateProducedSandboxValue(value, context.budget));
97
- }
98
- catch (error) {
99
- reject(error);
100
- }
101
- finally {
102
- completePrefix();
103
- }
104
- }).catch((error) => {
105
- reject(error);
106
- completePrefix();
107
- });
108
- });
109
- return createSandboxPromise(promise, { synchronousPrefix });
84
+ return executeAsyncFunction((onSuspend) => executeClosure(node, args, callContext?.thisValue, { ...invocationContext, onSuspend }, evaluateNode), context.budget, context.signal);
110
85
  }
111
86
  });
112
87
  return closure;
113
88
  }
89
+ export function executeAsyncFunction(execute, budget, signal) {
90
+ let completePrefix;
91
+ const synchronousPrefix = new Promise((resolve) => {
92
+ completePrefix = resolve;
93
+ });
94
+ const promise = new Promise((resolve, reject) => {
95
+ runAsyncPrefix(async () => {
96
+ try {
97
+ const value = await execute(completePrefix);
98
+ resolve(isSandboxPromise(value) || getThenable(value) !== undefined
99
+ ? awaitSandboxValue(createSandboxPromise(resolveSandboxValue(value, { budget }), {
100
+ trackReplay: false
101
+ }), signal, budget)
102
+ : allocateProducedSandboxValue(value, budget));
103
+ }
104
+ catch (error) {
105
+ reject(error);
106
+ }
107
+ finally {
108
+ completePrefix();
109
+ }
110
+ }).catch((error) => {
111
+ reject(error);
112
+ completePrefix();
113
+ });
114
+ });
115
+ return createSandboxPromise(promise, { synchronousPrefix });
116
+ }
114
117
  function createGeneratorClosure(node, context, evaluateNode) {
115
118
  return createSandboxClosure({
116
119
  guest: true,
@@ -45,6 +45,7 @@ export type InterpreterResult = {
45
45
  };
46
46
  export type InterpretOptions = {
47
47
  assertActive?: () => void;
48
+ onSuspend?: () => void;
48
49
  jobs?: SandboxJobQueue;
49
50
  nested?: boolean;
50
51
  compilation?: CompileScope;
@@ -25,6 +25,7 @@ import { bindPattern } from "./patterns.js";
25
25
  import { callStringMethod, getStringMember, isStringMethodName, validateStringMethodArguments } from "./methods/string.js";
26
26
  import { callSetMethod, getSetMember, isSetMethodName } from "./methods/set.js";
27
27
  import { isSandboxErrorConstructorInstance } from "./globals/error.js";
28
+ import { hasOwnSandboxProperty } from "./globals/object.js";
28
29
  import { isSandboxMapConstructor, isSandboxSetConstructor } from "./globals/collections.js";
29
30
  import { getFloat32Member, isFloat32ArrayConstructor, setFloat32Member } from "./globals/float32array.js";
30
31
  import { isFloat32Array } from "./float32.js";
@@ -110,6 +111,7 @@ export async function interpret(node, options = {}) {
110
111
  budget,
111
112
  callStack: [],
112
113
  onYield: options.onYield,
114
+ onSuspend: options.onSuspend,
113
115
  captureReplayState: options.captureReplayState,
114
116
  rootNode: node,
115
117
  scope,
@@ -437,13 +439,14 @@ async function evaluateBinaryExpression(node, context) {
437
439
  if (right.kind !== "normal") {
438
440
  return right;
439
441
  }
440
- const value = node.operator === "in" && isGuestHostObject(right.value)
441
- ? hasHostObjectMember(right.value, await sandboxString(left.value, context.budget, {
442
- stack: context.callStack,
443
- thisValue: undefined,
444
- invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, undefined, thisValue)
445
- }))
446
- : applyBinaryOperator(node, left.value, right.value, context);
442
+ let leftValue = left.value;
443
+ if (node.operator === "in") {
444
+ if (typeof right.value !== "object" || right.value === null) {
445
+ throw new TypeError("Right-hand side of 'in' must be an object.");
446
+ }
447
+ leftValue = await toPropertyKey(leftValue, context);
448
+ }
449
+ const value = applyBinaryOperator(node, leftValue, right.value, context);
447
450
  return {
448
451
  kind: "normal",
449
452
  hasValue: true,
@@ -2118,9 +2121,49 @@ function applyBinaryOperator(node, left, right, context) {
2118
2121
  }
2119
2122
  return false;
2120
2123
  case "in":
2121
- throw createError("UNSUPPORTED_NODE", node, "Binary operator 'in' is not supported.");
2124
+ return hasSandboxProperty(right, left, context);
2122
2125
  }
2123
2126
  }
2127
+ async function toPropertyKey(value, context) {
2128
+ if (isPlainSandboxObject(value) && !isSandboxDate(value) && !isFloat32Array(value) &&
2129
+ !isSandboxGenerator(value) && !isGuestHostObject(value)) {
2130
+ for (const name of ["toString", "valueOf"]) {
2131
+ const method = getMemberValue(value, name, context);
2132
+ if (!isSandboxClosure(method))
2133
+ continue;
2134
+ const primitive = await invokeSandboxClosure(method, [], context, context.callStack, undefined, value);
2135
+ if (primitive === null || typeof primitive !== "object") {
2136
+ return context.budget.allocateString(String(primitive));
2137
+ }
2138
+ }
2139
+ throw new TypeError("Cannot convert object to primitive value.");
2140
+ }
2141
+ return sandboxString(value, context.budget, {
2142
+ stack: context.callStack,
2143
+ thisValue: undefined,
2144
+ invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, undefined, thisValue)
2145
+ });
2146
+ }
2147
+ function hasSandboxProperty(value, key, context) {
2148
+ let current = value;
2149
+ let depth = 0;
2150
+ while (typeof current === "object" && current !== null) {
2151
+ if (isGuestHostObject(current))
2152
+ return hasHostObjectMember(current, key);
2153
+ if (hasOwnSandboxProperty(current, key, false))
2154
+ return true;
2155
+ if (Array.isArray(current) || !isPlainSandboxObject(current) ||
2156
+ isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current)) {
2157
+ return getPropertyValue(current, key, context) !== undefined;
2158
+ }
2159
+ current = getSandboxPrototype(current, context.budget);
2160
+ if (current !== null) {
2161
+ context.budget.visitNode();
2162
+ assertSandboxDataDepth(++depth);
2163
+ }
2164
+ }
2165
+ return false;
2166
+ }
2124
2167
  async function applyCompoundAssignmentOperator(operator, left, right, context) {
2125
2168
  left = await toNumericPrimitive(left, context);
2126
2169
  right = await toNumericPrimitive(right, context);
@@ -1131,9 +1131,9 @@ class Parser {
1131
1131
  };
1132
1132
  }
1133
1133
  const token = this.currentToken();
1134
- if (token.type === "identifier") {
1134
+ if (token.type === "identifier" || token.type === "keyword") {
1135
1135
  this.index += 1;
1136
- const key = createIdentifier(token);
1136
+ const key = createIdentifierName(token);
1137
1137
  if (this.consumePunctuator(":") !== undefined) {
1138
1138
  const value = this.parseBindingElement();
1139
1139
  if (value.type === "RestElement") {
@@ -1148,6 +1148,8 @@ class Parser {
1148
1148
  span: createSpan(key.span.start, value.span.end)
1149
1149
  };
1150
1150
  }
1151
+ if (!isIdentifierLikeToken(token))
1152
+ throw unexpectedTokenError(token);
1151
1153
  let value = key;
1152
1154
  if (this.consumePunctuator("=") !== undefined) {
1153
1155
  const right = this.parseExpression().node;
@@ -1357,9 +1359,9 @@ class Parser {
1357
1359
  };
1358
1360
  }
1359
1361
  const token = this.currentToken();
1360
- if (token.type === "identifier") {
1362
+ if (token.type === "identifier" || token.type === "keyword") {
1361
1363
  this.index += 1;
1362
- const key = createIdentifier(token);
1364
+ const key = createIdentifierName(token);
1363
1365
  if (this.consumePunctuator(":") !== undefined) {
1364
1366
  const value = this.parseAssignmentPatternElement();
1365
1367
  if (value.type === "RestElement") {
@@ -1374,6 +1376,8 @@ class Parser {
1374
1376
  span: createSpan(key.span.start, value.span.end)
1375
1377
  };
1376
1378
  }
1379
+ if (!isIdentifierLikeToken(token))
1380
+ throw unexpectedTokenError(token);
1377
1381
  let value = key;
1378
1382
  if (this.consumePunctuator("=") !== undefined) {
1379
1383
  const right = this.parseAssignmentExpression().node;
@@ -2027,12 +2031,9 @@ class Parser {
2027
2031
  };
2028
2032
  }
2029
2033
  const token = this.currentToken();
2030
- if (isIdentifierLikeToken(token) ||
2031
- (token.type === "keyword" &&
2032
- this.peekToken(1).type === "punctuator" &&
2033
- this.peekToken(1).value === "(")) {
2034
+ if (token.type === "identifier" || token.type === "keyword") {
2034
2035
  this.index += 1;
2035
- const key = createIdentifier(token);
2036
+ const key = createIdentifierName(token);
2036
2037
  if (this.currentToken().type === "punctuator" && this.currentToken().value === "(") {
2037
2038
  const value = this.parseObjectMethod(asyncToken, key.span.start);
2038
2039
  return {
@@ -2045,6 +2046,8 @@ class Parser {
2045
2046
  };
2046
2047
  }
2047
2048
  if (this.consumePunctuator(":") === undefined) {
2049
+ if (!isIdentifierLikeToken(token))
2050
+ throw unexpectedTokenError(token);
2048
2051
  assertAllowedIdentifierReference(token);
2049
2052
  return {
2050
2053
  type: "Property",
@@ -3484,14 +3487,7 @@ function rebasePosition(position, base) {
3484
3487
  };
3485
3488
  }
3486
3489
  function isLiteralPropertyKey(token) {
3487
- if (token.type === "numeric" || token.type === "string") {
3488
- return true;
3489
- }
3490
- return (token.type === "keyword" &&
3491
- (token.value === "true" ||
3492
- token.value === "false" ||
3493
- token.value === "null" ||
3494
- token.value === "undefined"));
3490
+ return token.type === "numeric" || token.type === "string";
3495
3491
  }
3496
3492
  function isIdentifierLikeToken(token) {
3497
3493
  return token.type === "identifier" || (token.type === "keyword" && token.value === "async");
@@ -1,4 +1,5 @@
1
1
  import { Budget, SandboxError } from "../interp/budget.js";
2
+ import { executeAsyncFunction } from "../interp/async.js";
2
3
  import { CompileScope } from "../interp/regex/compile-guard.js";
3
4
  import { decodeFloat32Storage } from "./float32array.js";
4
5
  import { restoreDateTime } from "../interp/date.js";
@@ -429,7 +430,8 @@ function restoreClosureValue(astNodeId, capturedScopeId, state) {
429
430
  throw new Error(`Snapshot references unknown closure AST node ${astNodeId}.`);
430
431
  }
431
432
  const baseClosure = createSandboxClosure({
432
- async: true,
433
+ async: node.async,
434
+ sandbox: true,
433
435
  length: getFunctionLength(node.params),
434
436
  ...(node.type === "ArrowFunctionExpression" || node.id === undefined ? {} : { name: node.id.name }),
435
437
  ...(node.type !== "ArrowFunctionExpression" &&
@@ -437,18 +439,23 @@ function restoreClosureValue(astNodeId, capturedScopeId, state) {
437
439
  !node.generator &&
438
440
  !node.async
439
441
  ? {
440
- construct: async (args) => {
442
+ construct: async (args, callContext) => {
441
443
  const thisValue = {};
442
444
  const prototype = getGuestFunctionProperty(restoredClosure, "prototype");
443
445
  if (typeof prototype === "object" && prototype !== null) {
444
446
  setSandboxPrototype(thisValue, prototype, state.budget);
445
447
  }
446
- const result = await executeRestoredClosure(node, capturedScopeId, restoredClosure, args, thisValue, state);
448
+ const result = await executeRestoredClosure(node, capturedScopeId, restoredClosure, args, thisValue, state, callContext);
447
449
  return typeof result === "object" && result !== null ? result : thisValue;
448
450
  }
449
451
  }
450
452
  : {}),
451
- call: (args, callContext) => createSandboxPromise(executeRestoredClosure(node, capturedScopeId, restoredClosure, args, callContext?.thisValue, state))
453
+ call: (args, callContext) => {
454
+ if (node.async) {
455
+ return executeAsyncFunction((onSuspend) => executeRestoredClosure(node, capturedScopeId, restoredClosure, args, callContext?.thisValue, state, callContext, onSuspend), state.budget);
456
+ }
457
+ return executeRestoredClosure(node, capturedScopeId, restoredClosure, args, callContext?.thisValue, state, callContext);
458
+ }
452
459
  });
453
460
  const restoredClosure = Object.defineProperties(Object.create(baseClosure), {
454
461
  astNodeId: {
@@ -468,9 +475,10 @@ function restoreClosureValue(astNodeId, capturedScopeId, state) {
468
475
  Object.defineProperty(restoredClosure, "properties", { get: () => getGuestFunctionProperties(restoredClosure) });
469
476
  return restoredClosure;
470
477
  }
471
- async function executeRestoredClosure(node, capturedScopeId, closure, args, thisValue, state) {
472
- const operation = state.budget.acquireCompileOwner(false, state.compilation.owner);
473
- const compilation = new CompileScope(operation.owner);
478
+ async function executeRestoredClosure(node, capturedScopeId, closure, args, thisValue, state, callContext, onSuspend) {
479
+ const parent = callContext?.compilation ?? state.compilation;
480
+ const operation = state.budget.acquireCompileOwner(false, parent.owner);
481
+ const compilation = new CompileScope(operation.owner, parent);
474
482
  state = { ...state, compilation };
475
483
  try {
476
484
  const capturedScope = state.scopeById.get(capturedScopeId) ?? restoreParentScope(capturedScopeId, state);
@@ -499,6 +507,7 @@ async function executeRestoredClosure(node, capturedScopeId, closure, args, this
499
507
  budget: state.budget,
500
508
  compilation,
501
509
  scope,
510
+ nested: true,
502
511
  useScopeDirectly: true
503
512
  });
504
513
  return result.ok
@@ -528,6 +537,7 @@ async function executeRestoredClosure(node, capturedScopeId, closure, args, this
528
537
  budget: state.budget,
529
538
  compilation,
530
539
  scope,
540
+ nested: true,
531
541
  useScopeDirectly: true
532
542
  });
533
543
  return result.ok
@@ -551,12 +561,14 @@ async function executeRestoredClosure(node, capturedScopeId, closure, args, this
551
561
  const result = await interpret(node.body, {
552
562
  budget: state.budget,
553
563
  compilation,
564
+ nested: true,
565
+ onSuspend,
554
566
  scope
555
567
  });
556
568
  if (!result.ok) {
557
569
  throw new Error(result.error.message);
558
570
  }
559
- reconcileCompiledValues(state.budget, [...scope.retainedValues(), ...state.budget.retainedValues(), result.returnValue], compilation);
571
+ reconcileCompiledValues(state.budget, [...scope.retainedValues(), ...state.budget.retainedValues(), result.returnValue], compilation, parent, [result.returnValue]);
560
572
  return result.returnValue;
561
573
  }
562
574
  finally {