poe-code 11.0.22 → 11.0.24
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.
- package/dist/index.js +100 -50
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safejs/dist/chunks/{chunk-IB5DSFBQ.js → chunk-CGS4H4L3.js} +100 -48
- package/packages/safejs/dist/chunks/{chunk-IB5DSFBQ.js.map → chunk-CGS4H4L3.js.map} +4 -4
- package/packages/safejs/dist/chunks/{chunk-K3DCXHEE.js → chunk-I5FH3SKL.js} +2 -2
- package/packages/safejs/dist/cli.js +2 -2
- package/packages/safejs/dist/core.js +1 -1
- package/packages/safejs/dist/index.js +2 -2
- package/packages/safejs/dist/interp/globals/object-array.js +2 -2
- package/packages/safejs/dist/interp/host-bridge.js +1 -1
- package/packages/safejs/dist/interp/interpreter.js +3 -3
- package/packages/safejs/dist/interp/methods/array.d.ts +1 -1
- package/packages/safejs/dist/interp/methods/array.js +32 -32
- package/packages/safejs/dist/interp/methods/map.d.ts +1 -1
- package/packages/safejs/dist/interp/methods/map.js +1 -1
- package/packages/safejs/dist/interp/methods/set.d.ts +1 -1
- package/packages/safejs/dist/interp/methods/set.js +1 -1
- package/packages/safejs/dist/run.js +6 -1
- package/packages/safejs/dist/runner/signal-dump.js +4 -3
- package/packages/safejs/dist/snapshot/dump.d.ts +4 -1
- package/packages/safejs/dist/snapshot/dump.js +11 -6
- /package/packages/safejs/dist/chunks/{chunk-K3DCXHEE.js.map → chunk-I5FH3SKL.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-CGS4H4L3.js";
|
|
31
31
|
|
|
32
32
|
// packages/safejs/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8055,4 +8055,4 @@ export {
|
|
|
8055
8055
|
parseMcpConfig,
|
|
8056
8056
|
makeMcpModule
|
|
8057
8057
|
};
|
|
8058
|
-
//# sourceMappingURL=chunk-
|
|
8058
|
+
//# sourceMappingURL=chunk-I5FH3SKL.js.map
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
parseMcpConfig,
|
|
21
21
|
splitFrontmatter,
|
|
22
22
|
withBrokenPipeGuard
|
|
23
|
-
} from "./chunks/chunk-
|
|
23
|
+
} from "./chunks/chunk-I5FH3SKL.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-
|
|
35
|
+
} from "./chunks/chunk-CGS4H4L3.js";
|
|
36
36
|
import "./chunks/chunk-4YIDX44G.js";
|
|
37
37
|
|
|
38
38
|
// packages/safejs/src/cli.ts
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
runWithSpawnUsageAccumulator,
|
|
28
28
|
splitFrontmatter,
|
|
29
29
|
supportsSpawnMode
|
|
30
|
-
} from "./chunks/chunk-
|
|
30
|
+
} from "./chunks/chunk-I5FH3SKL.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-
|
|
52
|
+
} from "./chunks/chunk-CGS4H4L3.js";
|
|
53
53
|
import "./chunks/chunk-4YIDX44G.js";
|
|
54
54
|
|
|
55
55
|
// packages/safejs/src/runner/run-harness.ts
|
|
@@ -227,7 +227,7 @@ function isAssignableSandboxTarget(value) {
|
|
|
227
227
|
!isSandboxRegex(value));
|
|
228
228
|
}
|
|
229
229
|
async function arrayFromSandboxValues(args, budget) {
|
|
230
|
-
const [items, mapFn] = args;
|
|
230
|
+
const [items, mapFn, thisValue] = args;
|
|
231
231
|
const iterator = getSandboxIterator(items);
|
|
232
232
|
const values = iterator === undefined
|
|
233
233
|
? Reflect.apply(Array.from, Array, [items])
|
|
@@ -240,7 +240,7 @@ async function arrayFromSandboxValues(args, budget) {
|
|
|
240
240
|
}
|
|
241
241
|
const mappedValues = [];
|
|
242
242
|
for (const [index, value] of values.entries()) {
|
|
243
|
-
const result = await mapFn.call([value, index]);
|
|
243
|
+
const result = await mapFn.call([value, index], { stack: [], thisValue });
|
|
244
244
|
if (isSandboxPromise(result) && result.synchronousPrefix !== undefined) {
|
|
245
245
|
await result.synchronousPrefix;
|
|
246
246
|
}
|
|
@@ -150,7 +150,7 @@ function invokeHostCallback(invoke, options) {
|
|
|
150
150
|
}
|
|
151
151
|
lifecycle.hostCallbackDepth += 1;
|
|
152
152
|
try {
|
|
153
|
-
const result = invoke
|
|
153
|
+
const result = lifecycle.hostCallbackContext.run(true, invoke);
|
|
154
154
|
if (isPromiseLike(result)) {
|
|
155
155
|
return Promise.resolve(result).finally(() => {
|
|
156
156
|
lifecycle.hostCallbackDepth -= 1;
|
|
@@ -2286,19 +2286,19 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
|
|
|
2286
2286
|
function createArrayMethodOptions(context) {
|
|
2287
2287
|
return {
|
|
2288
2288
|
budget: context.budget,
|
|
2289
|
-
callClosure: (closure, args, stack) => invokeSandboxClosure(closure, args, context, stack)
|
|
2289
|
+
callClosure: (closure, args, stack, thisValue) => invokeSandboxClosure(closure, args, context, stack, undefined, thisValue)
|
|
2290
2290
|
};
|
|
2291
2291
|
}
|
|
2292
2292
|
function createMapMethodOptions(context) {
|
|
2293
2293
|
return {
|
|
2294
2294
|
budget: context.budget,
|
|
2295
|
-
callClosure: (closure, args, stack) => invokeSandboxClosure(closure, args, context, stack)
|
|
2295
|
+
callClosure: (closure, args, stack, thisValue) => invokeSandboxClosure(closure, args, context, stack, undefined, thisValue)
|
|
2296
2296
|
};
|
|
2297
2297
|
}
|
|
2298
2298
|
function createSetMethodOptions(context) {
|
|
2299
2299
|
return {
|
|
2300
2300
|
budget: context.budget,
|
|
2301
|
-
callClosure: (closure, args, stack) => invokeSandboxClosure(closure, args, context, stack)
|
|
2301
|
+
callClosure: (closure, args, stack, thisValue) => invokeSandboxClosure(closure, args, context, stack, undefined, thisValue)
|
|
2302
2302
|
};
|
|
2303
2303
|
}
|
|
2304
2304
|
function createFunctionMethodOptions(context) {
|
|
@@ -3,7 +3,7 @@ import { type SandboxArray, type SandboxClosure, type SandboxValue } from "../va
|
|
|
3
3
|
export type ArrayMethodName = "map" | "filter" | "find" | "findIndex" | "findLast" | "findLastIndex" | "some" | "every" | "reduce" | "reduceRight" | "forEach" | "flatMap" | "flat" | "includes" | "indexOf" | "lastIndexOf" | "join" | "slice" | "concat" | "splice" | "fill" | "copyWithin" | "at" | "sort" | "reverse" | "toSorted" | "toReversed" | "toSpliced" | "with" | "push" | "pop" | "shift" | "unshift";
|
|
4
4
|
export type ArrayMethodOptions = {
|
|
5
5
|
budget: Budget;
|
|
6
|
-
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[]) => Promise<SandboxValue>;
|
|
6
|
+
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[], thisValue?: SandboxValue) => Promise<SandboxValue>;
|
|
7
7
|
};
|
|
8
8
|
export declare function getArrayMember(value: SandboxArray, property: string | number, options: ArrayMethodOptions): SandboxValue | undefined;
|
|
9
9
|
export declare function isArrayMethodName(property: string | number): property is ArrayMethodName;
|
|
@@ -96,30 +96,30 @@ export async function callArrayMethod(value, methodName, args, options, stack =
|
|
|
96
96
|
async function callArrayMethodUnlocked(value, methodName, args, options, stack) {
|
|
97
97
|
switch (methodName) {
|
|
98
98
|
case "map":
|
|
99
|
-
return budgetProducedValue(await mapArray(value, getRequiredCallback(methodName, args[0]), options, stack), options.budget);
|
|
99
|
+
return budgetProducedValue(await mapArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]), options.budget);
|
|
100
100
|
case "filter":
|
|
101
|
-
return budgetProducedValue(await filterArray(value, getRequiredCallback(methodName, args[0]), options, stack), options.budget);
|
|
101
|
+
return budgetProducedValue(await filterArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]), options.budget);
|
|
102
102
|
case "find":
|
|
103
|
-
return budgetProducedValue(await findInArray(value, getRequiredCallback(methodName, args[0]), options, stack), options.budget);
|
|
103
|
+
return budgetProducedValue(await findInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]), options.budget);
|
|
104
104
|
case "findIndex":
|
|
105
|
-
return await findIndexInArray(value, getRequiredCallback(methodName, args[0]), options, stack);
|
|
105
|
+
return await findIndexInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]);
|
|
106
106
|
case "findLast":
|
|
107
|
-
return budgetProducedValue(await findLastInArray(value, getRequiredCallback(methodName, args[0]), options, stack), options.budget);
|
|
107
|
+
return budgetProducedValue(await findLastInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]), options.budget);
|
|
108
108
|
case "findLastIndex":
|
|
109
|
-
return await findLastIndexInArray(value, getRequiredCallback(methodName, args[0]), options, stack);
|
|
109
|
+
return await findLastIndexInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]);
|
|
110
110
|
case "some":
|
|
111
|
-
return await someInArray(value, getRequiredCallback(methodName, args[0]), options, stack);
|
|
111
|
+
return await someInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]);
|
|
112
112
|
case "every":
|
|
113
|
-
return await everyInArray(value, getRequiredCallback(methodName, args[0]), options, stack);
|
|
113
|
+
return await everyInArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]);
|
|
114
114
|
case "reduce":
|
|
115
115
|
return budgetProducedValue(await reduceArray(value, getRequiredCallback(methodName, args[0]), args.length > 1, args[1], options, stack), options.budget);
|
|
116
116
|
case "reduceRight":
|
|
117
117
|
return budgetProducedValue(await reduceRightArray(value, getRequiredCallback(methodName, args[0]), args.length > 1, args[1], options, stack), options.budget);
|
|
118
118
|
case "forEach":
|
|
119
|
-
await forEachArray(value, getRequiredCallback(methodName, args[0]), options, stack);
|
|
119
|
+
await forEachArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]);
|
|
120
120
|
return undefined;
|
|
121
121
|
case "flatMap":
|
|
122
|
-
return budgetProducedValue(await flatMapArray(value, getRequiredCallback(methodName, args[0]), options, stack), options.budget);
|
|
122
|
+
return budgetProducedValue(await flatMapArray(value, getRequiredCallback(methodName, args[0]), options, stack, args[1]), options.budget);
|
|
123
123
|
case "flat":
|
|
124
124
|
return budgetProducedValue(flattenArray(value, toIntegerOrInfinity(args[0] ?? 1), options.budget), options.budget);
|
|
125
125
|
case "includes":
|
|
@@ -264,83 +264,83 @@ function getRequiredCallback(methodName, value) {
|
|
|
264
264
|
}
|
|
265
265
|
return value;
|
|
266
266
|
}
|
|
267
|
-
async function mapArray(value, callback, options, stack) {
|
|
267
|
+
async function mapArray(value, callback, options, stack, thisValue) {
|
|
268
268
|
const length = value.length;
|
|
269
269
|
const result = new Array(length);
|
|
270
270
|
for (let index = 0; index < length; index += 1) {
|
|
271
271
|
if (!(index in value)) {
|
|
272
272
|
continue;
|
|
273
273
|
}
|
|
274
|
-
result[index] = await callArrayCallback(callback, value[index], index, value, options, stack);
|
|
274
|
+
result[index] = await callArrayCallback(callback, value[index], index, value, options, stack, thisValue);
|
|
275
275
|
}
|
|
276
276
|
return result;
|
|
277
277
|
}
|
|
278
|
-
async function filterArray(value, callback, options, stack) {
|
|
278
|
+
async function filterArray(value, callback, options, stack, thisValue) {
|
|
279
279
|
const length = value.length;
|
|
280
280
|
const result = [];
|
|
281
281
|
for (let index = 0; index < length; index += 1) {
|
|
282
282
|
if (!(index in value)) {
|
|
283
283
|
continue;
|
|
284
284
|
}
|
|
285
|
-
if (await callArrayCallback(callback, value[index], index, value, options, stack)) {
|
|
285
|
+
if (await callArrayCallback(callback, value[index], index, value, options, stack, thisValue)) {
|
|
286
286
|
result.push(value[index]);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
return result;
|
|
290
290
|
}
|
|
291
|
-
async function findInArray(value, callback, options, stack) {
|
|
292
|
-
const index = await findIndexInArray(value, callback, options, stack);
|
|
291
|
+
async function findInArray(value, callback, options, stack, thisValue) {
|
|
292
|
+
const index = await findIndexInArray(value, callback, options, stack, thisValue);
|
|
293
293
|
return index < 0 ? undefined : value[index];
|
|
294
294
|
}
|
|
295
|
-
async function findIndexInArray(value, callback, options, stack) {
|
|
295
|
+
async function findIndexInArray(value, callback, options, stack, thisValue) {
|
|
296
296
|
const length = value.length;
|
|
297
297
|
for (let index = 0; index < length; index += 1) {
|
|
298
298
|
const entry = index in value ? value[index] : undefined;
|
|
299
|
-
if (await callArrayCallback(callback, entry, index, value, options, stack)) {
|
|
299
|
+
if (await callArrayCallback(callback, entry, index, value, options, stack, thisValue)) {
|
|
300
300
|
return index;
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
return -1;
|
|
304
304
|
}
|
|
305
|
-
async function findLastInArray(value, callback, options, stack) {
|
|
305
|
+
async function findLastInArray(value, callback, options, stack, thisValue) {
|
|
306
306
|
const length = value.length;
|
|
307
307
|
for (let index = length - 1; index >= 0; index -= 1) {
|
|
308
308
|
const entry = index in value ? value[index] : undefined;
|
|
309
|
-
if (await callArrayCallback(callback, entry, index, value, options, stack)) {
|
|
309
|
+
if (await callArrayCallback(callback, entry, index, value, options, stack, thisValue)) {
|
|
310
310
|
return entry;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
return undefined;
|
|
314
314
|
}
|
|
315
|
-
async function findLastIndexInArray(value, callback, options, stack) {
|
|
315
|
+
async function findLastIndexInArray(value, callback, options, stack, thisValue) {
|
|
316
316
|
const length = value.length;
|
|
317
317
|
for (let index = length - 1; index >= 0; index -= 1) {
|
|
318
318
|
const entry = index in value ? value[index] : undefined;
|
|
319
|
-
if (await callArrayCallback(callback, entry, index, value, options, stack)) {
|
|
319
|
+
if (await callArrayCallback(callback, entry, index, value, options, stack, thisValue)) {
|
|
320
320
|
return index;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
return -1;
|
|
324
324
|
}
|
|
325
|
-
async function someInArray(value, callback, options, stack) {
|
|
325
|
+
async function someInArray(value, callback, options, stack, thisValue) {
|
|
326
326
|
const length = value.length;
|
|
327
327
|
for (let index = 0; index < length; index += 1) {
|
|
328
328
|
if (!(index in value)) {
|
|
329
329
|
continue;
|
|
330
330
|
}
|
|
331
|
-
if (await callArrayCallback(callback, value[index], index, value, options, stack)) {
|
|
331
|
+
if (await callArrayCallback(callback, value[index], index, value, options, stack, thisValue)) {
|
|
332
332
|
return true;
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
return false;
|
|
336
336
|
}
|
|
337
|
-
async function everyInArray(value, callback, options, stack) {
|
|
337
|
+
async function everyInArray(value, callback, options, stack, thisValue) {
|
|
338
338
|
const length = value.length;
|
|
339
339
|
for (let index = 0; index < length; index += 1) {
|
|
340
340
|
if (!(index in value)) {
|
|
341
341
|
continue;
|
|
342
342
|
}
|
|
343
|
-
if (!(await callArrayCallback(callback, value[index], index, value, options, stack))) {
|
|
343
|
+
if (!(await callArrayCallback(callback, value[index], index, value, options, stack, thisValue))) {
|
|
344
344
|
return false;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
@@ -388,23 +388,23 @@ async function reduceFromRight(value, callback, accumulator, startIndex, length,
|
|
|
388
388
|
}
|
|
389
389
|
return current;
|
|
390
390
|
}
|
|
391
|
-
async function forEachArray(value, callback, options, stack) {
|
|
391
|
+
async function forEachArray(value, callback, options, stack, thisValue) {
|
|
392
392
|
const length = value.length;
|
|
393
393
|
for (let index = 0; index < length; index += 1) {
|
|
394
394
|
if (!(index in value)) {
|
|
395
395
|
continue;
|
|
396
396
|
}
|
|
397
|
-
await callArrayCallback(callback, value[index], index, value, options, stack);
|
|
397
|
+
await callArrayCallback(callback, value[index], index, value, options, stack, thisValue);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
async function flatMapArray(value, callback, options, stack) {
|
|
400
|
+
async function flatMapArray(value, callback, options, stack, thisValue) {
|
|
401
401
|
const length = value.length;
|
|
402
402
|
const result = [];
|
|
403
403
|
for (let index = 0; index < length; index += 1) {
|
|
404
404
|
if (!(index in value)) {
|
|
405
405
|
continue;
|
|
406
406
|
}
|
|
407
|
-
const mapped = await callArrayCallback(callback, value[index], index, value, options, stack);
|
|
407
|
+
const mapped = await callArrayCallback(callback, value[index], index, value, options, stack, thisValue);
|
|
408
408
|
if (Array.isArray(mapped)) {
|
|
409
409
|
for (let mappedIndex = 0; mappedIndex < mapped.length; mappedIndex += 1) {
|
|
410
410
|
if (!(mappedIndex in mapped)) {
|
|
@@ -477,8 +477,8 @@ async function compareEntries(left, right, comparator, options, stack) {
|
|
|
477
477
|
const result = Number(await options.callClosure(comparator, [left, right], stack));
|
|
478
478
|
return Number.isNaN(result) ? 0 : result;
|
|
479
479
|
}
|
|
480
|
-
async function callArrayCallback(callback, value, index, array, options, stack) {
|
|
481
|
-
return options.callClosure(callback, [value, index, array], stack);
|
|
480
|
+
async function callArrayCallback(callback, value, index, array, options, stack, thisValue) {
|
|
481
|
+
return options.callClosure(callback, [value, index, array], stack, thisValue);
|
|
482
482
|
}
|
|
483
483
|
function findNextDefinedIndex(value, startIndex, direction, length) {
|
|
484
484
|
for (let index = startIndex; direction > 0 ? index < length : index >= 0; index += direction) {
|
|
@@ -3,7 +3,7 @@ import { type SandboxClosure, type SandboxMap, type SandboxValue } from "../valu
|
|
|
3
3
|
export type MapMethodName = "get" | "set" | "has" | "delete" | "clear" | "forEach" | "keys" | "values" | "entries";
|
|
4
4
|
export type MapMethodOptions = {
|
|
5
5
|
budget: Budget;
|
|
6
|
-
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[]) => Promise<SandboxValue>;
|
|
6
|
+
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[], thisValue?: SandboxValue) => Promise<SandboxValue>;
|
|
7
7
|
};
|
|
8
8
|
export declare function isMapMethodName(value: string | number): value is MapMethodName;
|
|
9
9
|
export declare function getMapMember(target: SandboxMap, property: string | number, options: MapMethodOptions): SandboxValue | undefined;
|
|
@@ -57,7 +57,7 @@ export async function callMapMethod(target, methodName, args, options, stack = [
|
|
|
57
57
|
const entries = [...target.entries];
|
|
58
58
|
for (let index = 0; index < entries.length; index += 1) {
|
|
59
59
|
const [key, value] = entries[index];
|
|
60
|
-
await options.callClosure(callback, [value, key, target], stack);
|
|
60
|
+
await options.callClosure(callback, [value, key, target], stack, args[1]);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
finally {
|
|
@@ -3,7 +3,7 @@ import { type SandboxClosure, type SandboxSet, type SandboxValue } from "../valu
|
|
|
3
3
|
export type SetMethodName = "add" | "has" | "delete" | "clear" | "forEach" | "keys" | "values" | "entries";
|
|
4
4
|
export type SetMethodOptions = {
|
|
5
5
|
budget: Budget;
|
|
6
|
-
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[]) => Promise<SandboxValue>;
|
|
6
|
+
callClosure: (closure: SandboxClosure, args: readonly SandboxValue[], stack: readonly string[], thisValue?: SandboxValue) => Promise<SandboxValue>;
|
|
7
7
|
};
|
|
8
8
|
export declare function isSetMethodName(value: string | number): value is SetMethodName;
|
|
9
9
|
export declare function getSetMember(target: SandboxSet, property: string | number, options: SetMethodOptions): SandboxValue | undefined;
|
|
@@ -54,7 +54,7 @@ export async function callSetMethod(target, methodName, args, options, stack = [
|
|
|
54
54
|
const values = [...target.values];
|
|
55
55
|
for (let index = 0; index < values.length; index += 1) {
|
|
56
56
|
const value = values[index];
|
|
57
|
-
await options.callClosure(callback, [value, value, target], stack);
|
|
57
|
+
await options.callClosure(callback, [value, value, target], stack, args[1]);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
finally {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import { hashSource } from "./parse/hash.js";
|
|
2
3
|
import { withRunResources } from "./interp/resources.js";
|
|
3
4
|
import { createReplayableRandom } from "./random.js";
|
|
@@ -41,7 +42,10 @@ export class UnhandledRejectionError extends Error {
|
|
|
41
42
|
}
|
|
42
43
|
const DEFAULT_MAX_CALL_DEPTH = 1_000;
|
|
43
44
|
export function run(source, options = {}) {
|
|
44
|
-
const lifecycle = {
|
|
45
|
+
const lifecycle = {
|
|
46
|
+
hostCallbackDepth: 0,
|
|
47
|
+
hostCallbackContext: new AsyncLocalStorage()
|
|
48
|
+
};
|
|
45
49
|
const dumpController = createDumpController(lifecycle);
|
|
46
50
|
const promiseTracker = createSandboxPromiseRejectionTracker();
|
|
47
51
|
let completedSnapshot;
|
|
@@ -335,6 +339,7 @@ export function run(source, options = {}) {
|
|
|
335
339
|
throw error;
|
|
336
340
|
}
|
|
337
341
|
finally {
|
|
342
|
+
lifecycle.hostCallbackContext.disable();
|
|
338
343
|
options.signal?.removeEventListener("abort", captureCancellationSnapshot);
|
|
339
344
|
leaveInputReplay?.();
|
|
340
345
|
leaveHostReplay?.();
|
|
@@ -2,9 +2,8 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { mkdir, rename, rm, writeFile as nodeWriteFile } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
4
|
import { hasOwnErrorCode } from "../error-codes.js";
|
|
5
|
-
import {
|
|
5
|
+
import { dump } from "../snapshot/dump.js";
|
|
6
6
|
export function attachSignalDumpHandler(result, options = {}) {
|
|
7
|
-
const dumpResult = options.dumpResult ?? dumpCurrent;
|
|
8
7
|
const signalProcess = options.process ?? process;
|
|
9
8
|
const stderr = options.stderr ?? process.stderr;
|
|
10
9
|
const writeDumpFile = options.writeFile ?? nodeWriteFile;
|
|
@@ -19,7 +18,9 @@ export function attachSignalDumpHandler(result, options = {}) {
|
|
|
19
18
|
}
|
|
20
19
|
async function writeDump(signal) {
|
|
21
20
|
try {
|
|
22
|
-
const snapshot =
|
|
21
|
+
const snapshot = options.dumpResult === undefined
|
|
22
|
+
? await dump(result, { mode: "replay" })
|
|
23
|
+
: await options.dumpResult(result);
|
|
23
24
|
if (options.dumpPath !== undefined) {
|
|
24
25
|
const parentPath = dirname(options.dumpPath);
|
|
25
26
|
const tempPath = join(parentPath, `.${basename(options.dumpPath)}.${randomUUID()}.tmp`);
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import type { RunResult, RunSnapshot } from "../run.js";
|
|
2
3
|
export type DumpOptions = {
|
|
4
|
+
mode?: "capture" | "replay";
|
|
3
5
|
onFailure?: "throw" | "checkpoint";
|
|
4
6
|
};
|
|
5
7
|
type DumpController = {
|
|
6
8
|
fail(error: unknown): void;
|
|
7
9
|
finalize(snapshot: RunSnapshot): void;
|
|
8
10
|
onYield(createSnapshot: () => RunSnapshot): void;
|
|
9
|
-
requestCurrentSnapshot(): Promise<string>;
|
|
11
|
+
requestCurrentSnapshot(options?: DumpOptions): Promise<string>;
|
|
10
12
|
requestSnapshot(options?: DumpOptions): Promise<string>;
|
|
11
13
|
};
|
|
12
14
|
export type RunLifecycle = {
|
|
15
|
+
hostCallbackContext: AsyncLocalStorage<boolean>;
|
|
13
16
|
hostCallbackDepth: number;
|
|
14
17
|
};
|
|
15
18
|
export declare function attachDumpController(result: Promise<RunResult>, controller: DumpController): Promise<RunResult>;
|
|
@@ -46,8 +46,8 @@ export function createDumpController(lifecycle) {
|
|
|
46
46
|
}
|
|
47
47
|
settlePendingSnapshot(createSnapshot());
|
|
48
48
|
},
|
|
49
|
-
requestCurrentSnapshot() {
|
|
50
|
-
assertDumpAllowed();
|
|
49
|
+
requestCurrentSnapshot(options = {}) {
|
|
50
|
+
assertDumpAllowed(options);
|
|
51
51
|
if (failed !== undefined) {
|
|
52
52
|
return Promise.reject(failed.error);
|
|
53
53
|
}
|
|
@@ -59,10 +59,10 @@ export function createDumpController(lifecycle) {
|
|
|
59
59
|
return Promise.reject(error);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
return this.requestSnapshot();
|
|
62
|
+
return this.requestSnapshot(options);
|
|
63
63
|
},
|
|
64
64
|
requestSnapshot(options = {}) {
|
|
65
|
-
assertDumpAllowed();
|
|
65
|
+
assertDumpAllowed(options);
|
|
66
66
|
if (failed !== undefined) {
|
|
67
67
|
if ((options.onFailure === "checkpoint" ||
|
|
68
68
|
(options.onFailure === undefined && isDataBudgetError(failed.error))) &&
|
|
@@ -88,6 +88,10 @@ export function createDumpController(lifecycle) {
|
|
|
88
88
|
return Promise.reject(error);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
if (options.mode === "replay" &&
|
|
92
|
+
(latestSnapshot !== undefined || latestSnapshotFactory !== undefined)) {
|
|
93
|
+
return this.requestCurrentSnapshot(options);
|
|
94
|
+
}
|
|
91
95
|
if (pendingRequest !== undefined) {
|
|
92
96
|
return pendingRequest.promise;
|
|
93
97
|
}
|
|
@@ -105,8 +109,9 @@ export function createDumpController(lifecycle) {
|
|
|
105
109
|
return promise;
|
|
106
110
|
}
|
|
107
111
|
};
|
|
108
|
-
function assertDumpAllowed() {
|
|
109
|
-
if ((lifecycle?.hostCallbackDepth ?? 0) > 0
|
|
112
|
+
function assertDumpAllowed(options) {
|
|
113
|
+
if ((lifecycle?.hostCallbackDepth ?? 0) > 0 &&
|
|
114
|
+
(options.mode !== "replay" || lifecycle?.hostCallbackContext.getStore() === true)) {
|
|
110
115
|
throw new SandboxError("reentry");
|
|
111
116
|
}
|
|
112
117
|
}
|
|
File without changes
|