poe-code 5.0.4 → 7.0.0
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 +3457 -3542
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safejs/dist/interp/async.d.ts +2 -1
- package/packages/safejs/dist/interp/async.js +56 -33
- package/packages/safejs/dist/interp/cancel.d.ts +7 -2
- package/packages/safejs/dist/interp/cancel.js +128 -92
- package/packages/safejs/dist/interp/exceptions.js +7 -3
- package/packages/safejs/dist/interp/globals/collections.js +2 -0
- package/packages/safejs/dist/interp/globals/console-json.js +4 -0
- package/packages/safejs/dist/interp/globals/error.js +1 -5
- package/packages/safejs/dist/interp/globals/math.js +2 -4
- package/packages/safejs/dist/interp/globals/misc.js +5 -0
- package/packages/safejs/dist/interp/globals/object-array.js +25 -0
- package/packages/safejs/dist/interp/globals/regex.js +1 -1
- package/packages/safejs/dist/interp/host-bridge.js +8 -5
- package/packages/safejs/dist/interp/interpreter.js +33 -37
- package/packages/safejs/dist/interp/iteration.d.ts +3 -3
- package/packages/safejs/dist/interp/iteration.js +20 -9
- package/packages/safejs/dist/interp/methods/array.js +1 -0
- package/packages/safejs/dist/interp/methods/function.d.ts +1 -1
- package/packages/safejs/dist/interp/methods/function.js +17 -1
- package/packages/safejs/dist/interp/methods/generator.js +1 -0
- package/packages/safejs/dist/interp/methods/map.js +1 -0
- package/packages/safejs/dist/interp/methods/number.js +1 -0
- package/packages/safejs/dist/interp/methods/regex.js +1 -0
- package/packages/safejs/dist/interp/methods/set.js +1 -0
- package/packages/safejs/dist/interp/methods/string.js +1 -0
- package/packages/safejs/dist/interp/patterns.d.ts +1 -0
- package/packages/safejs/dist/interp/patterns.js +1 -1
- package/packages/safejs/dist/interp/promise-tracker.d.ts +12 -2
- package/packages/safejs/dist/interp/promise-tracker.js +65 -7
- package/packages/safejs/dist/interp/promise.d.ts +7 -5
- package/packages/safejs/dist/interp/promise.js +531 -148
- package/packages/safejs/dist/interp/values.d.ts +6 -0
- package/packages/safejs/dist/interp/values.js +25 -5
- package/packages/safejs/dist/interp/var-hoist.js +5 -135
- package/packages/safejs/dist/lint/index.js +0 -4
- package/packages/safejs/dist/lint/rules/AS001.js +4 -9
- package/packages/safejs/dist/lint/rules/AS003.js +47 -7
- package/packages/safejs/dist/lint/rules/AS006-007.js +48 -7
- package/packages/safejs/dist/parse/bindings.d.ts +6 -0
- package/packages/safejs/dist/parse/bindings.js +90 -0
- package/packages/safejs/dist/parse/parser.js +70 -37
- package/packages/safejs/dist/snapshot/dump-format.d.ts +1 -1
- package/packages/safejs/dist/snapshot/dump-format.js +1 -1
- package/packages/safejs/dist/snapshot/replay-data.js +3 -0
- package/packages/safejs/dist/lint/rules/AS-await-non-promise.d.ts +0 -13
- package/packages/safejs/dist/lint/rules/AS-await-non-promise.js +0 -301
- package/packages/safejs/dist/lint/rules/AS008.d.ts +0 -13
- package/packages/safejs/dist/lint/rules/AS008.js +0 -386
|
@@ -1,32 +1,71 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { SandboxError } from "./budget.js";
|
|
2
3
|
export class SandboxPromiseRejectionTracker {
|
|
3
4
|
records = new Set();
|
|
4
5
|
recordsByPromise = new WeakMap();
|
|
6
|
+
fatalRejection;
|
|
7
|
+
fatalWaiters = new Set();
|
|
8
|
+
get failure() {
|
|
9
|
+
return this.fatalRejection;
|
|
10
|
+
}
|
|
11
|
+
onFatalRejection(interrupt) {
|
|
12
|
+
if (this.fatalRejection === undefined)
|
|
13
|
+
this.fatalWaiters.add(interrupt);
|
|
14
|
+
else
|
|
15
|
+
interrupt(this.fatalRejection);
|
|
16
|
+
return () => this.fatalWaiters.delete(interrupt);
|
|
17
|
+
}
|
|
18
|
+
interruptOnFatalRejection(pending) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const detach = this.onFatalRejection(reject);
|
|
21
|
+
pending.then((value) => {
|
|
22
|
+
detach();
|
|
23
|
+
resolve(value);
|
|
24
|
+
}, (reason) => {
|
|
25
|
+
detach();
|
|
26
|
+
reject(reason);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
5
30
|
observe(promise) {
|
|
6
31
|
const record = this.recordsByPromise.get(promise);
|
|
7
32
|
if (record !== undefined) {
|
|
8
33
|
record.observed = true;
|
|
9
34
|
}
|
|
10
35
|
}
|
|
11
|
-
track(promise) {
|
|
12
|
-
|
|
36
|
+
track(promise, outcome) {
|
|
37
|
+
const existing = this.recordsByPromise.get(promise);
|
|
38
|
+
if (existing !== undefined && outcome === undefined) {
|
|
13
39
|
return;
|
|
14
40
|
}
|
|
15
|
-
const record = {
|
|
41
|
+
const record = existing ?? {
|
|
16
42
|
observed: false,
|
|
17
43
|
promise,
|
|
18
44
|
rejected: false
|
|
19
45
|
};
|
|
20
46
|
this.records.add(record);
|
|
21
47
|
this.recordsByPromise.set(promise, record);
|
|
22
|
-
|
|
48
|
+
const pending = outcome ?? promise.promise;
|
|
49
|
+
pending.then(() => undefined, (reason) => {
|
|
50
|
+
if (this.fatalRejection === undefined &&
|
|
51
|
+
reason instanceof SandboxError &&
|
|
52
|
+
(reason.code === "budgetExceeded" || reason.code === "reentry")) {
|
|
53
|
+
this.fatalRejection = reason;
|
|
54
|
+
for (const interrupt of this.fatalWaiters)
|
|
55
|
+
interrupt(reason);
|
|
56
|
+
this.fatalWaiters.clear();
|
|
57
|
+
}
|
|
58
|
+
if (record.rejected)
|
|
59
|
+
return;
|
|
23
60
|
record.rejected = true;
|
|
24
61
|
record.rejectionReason = reason;
|
|
25
62
|
});
|
|
26
|
-
|
|
63
|
+
pending.catch(() => undefined);
|
|
27
64
|
}
|
|
28
65
|
async findUnhandledRejection() {
|
|
29
66
|
await flushPromiseJobs();
|
|
67
|
+
if (this.fatalRejection !== undefined)
|
|
68
|
+
throw this.fatalRejection;
|
|
30
69
|
for (const record of this.records) {
|
|
31
70
|
if (record.rejected && !record.observed) {
|
|
32
71
|
return {
|
|
@@ -39,14 +78,33 @@ export class SandboxPromiseRejectionTracker {
|
|
|
39
78
|
}
|
|
40
79
|
}
|
|
41
80
|
const activePromiseTracker = new AsyncLocalStorage();
|
|
81
|
+
const fatalRejectionCleanup = new AsyncLocalStorage();
|
|
82
|
+
export function assertPromiseExecutionAllowed() {
|
|
83
|
+
const failure = activePromiseTracker.getStore()?.failure;
|
|
84
|
+
if (failure !== undefined && fatalRejectionCleanup.getStore() !== true)
|
|
85
|
+
throw failure;
|
|
86
|
+
}
|
|
87
|
+
export function onFatalPromiseRejection(interrupt) {
|
|
88
|
+
if (fatalRejectionCleanup.getStore() === true)
|
|
89
|
+
return undefined;
|
|
90
|
+
return activePromiseTracker.getStore()?.onFatalRejection(interrupt);
|
|
91
|
+
}
|
|
92
|
+
export function interruptOnFatalPromiseRejection(pending) {
|
|
93
|
+
if (fatalRejectionCleanup.getStore() === true)
|
|
94
|
+
return pending;
|
|
95
|
+
return activePromiseTracker.getStore()?.interruptOnFatalRejection(pending) ?? pending;
|
|
96
|
+
}
|
|
97
|
+
export function withFatalPromiseCleanup(callback) {
|
|
98
|
+
return fatalRejectionCleanup.run(true, callback);
|
|
99
|
+
}
|
|
42
100
|
export function createSandboxPromiseRejectionTracker() {
|
|
43
101
|
return new SandboxPromiseRejectionTracker();
|
|
44
102
|
}
|
|
45
103
|
export function observeSandboxPromise(promise) {
|
|
46
104
|
activePromiseTracker.getStore()?.observe(promise);
|
|
47
105
|
}
|
|
48
|
-
export function trackSandboxPromise(promise) {
|
|
49
|
-
activePromiseTracker.getStore()?.track(promise);
|
|
106
|
+
export function trackSandboxPromise(promise, outcome) {
|
|
107
|
+
activePromiseTracker.getStore()?.track(promise, outcome);
|
|
50
108
|
}
|
|
51
109
|
export function withSandboxPromiseRejectionTracker(tracker, callback) {
|
|
52
110
|
return activePromiseTracker.run(tracker, callback);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type SandboxClosure, type
|
|
1
|
+
import { type Budget } from "./budget.js";
|
|
2
|
+
import { type SandboxClosure, type SandboxPromise, type SandboxValue } from "./values.js";
|
|
3
3
|
export type PromiseGlobals = {
|
|
4
|
-
Promise:
|
|
4
|
+
Promise: SandboxClosure;
|
|
5
5
|
};
|
|
6
|
+
export declare function isSandboxPromiseConstructor(value: unknown): value is SandboxClosure;
|
|
6
7
|
export declare function createPromiseGlobals(options: {
|
|
7
8
|
budget: Budget;
|
|
8
9
|
}): PromiseGlobals;
|
|
9
|
-
export declare function getPromiseMember(
|
|
10
|
+
export declare function getPromiseMember(property: string | number, budget: Budget): SandboxValue;
|
|
10
11
|
export declare function resolveSandboxValue(value: SandboxValue | Promise<SandboxValue> | PromiseLike<SandboxValue>, options?: {
|
|
11
12
|
budget?: Budget;
|
|
13
|
+
self?: SandboxPromise;
|
|
12
14
|
}): Promise<SandboxValue>;
|
|
13
|
-
export declare function consumeSettledHostCall(value: SandboxPromise):
|
|
15
|
+
export declare function consumeSettledHostCall(value: SandboxPromise): undefined;
|
|
14
16
|
export declare function getThenable(value: SandboxValue): SandboxClosure | undefined;
|