@cuxt/sandboxjs 0.1.0 → 0.1.3
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/LICENSE +21 -21
- package/README.md +198 -185
- package/{build → dist/cjs}/Sandbox.d.ts +15 -6
- package/dist/cjs/Sandbox.js +126 -0
- package/dist/{SandboxExec.d.ts → cjs/SandboxExec.d.ts} +8 -17
- package/dist/cjs/SandboxExec.js +227 -0
- package/{build/eval.d.ts → dist/cjs/eval/index.d.ts} +10 -2
- package/dist/cjs/eval/index.js +233 -0
- package/dist/cjs/executor/executorUtils.d.ts +161 -0
- package/dist/cjs/executor/executorUtils.js +930 -0
- package/dist/cjs/executor/index.d.ts +1 -0
- package/dist/cjs/executor/index.js +2 -0
- package/dist/cjs/executor/ops/assignment.d.ts +1 -0
- package/dist/cjs/executor/ops/assignment.js +88 -0
- package/dist/cjs/executor/ops/call.d.ts +1 -0
- package/dist/cjs/executor/ops/call.js +160 -0
- package/dist/cjs/executor/ops/comparison.d.ts +1 -0
- package/dist/cjs/executor/ops/comparison.js +36 -0
- package/dist/cjs/executor/ops/control.d.ts +1 -0
- package/dist/cjs/executor/ops/control.js +203 -0
- package/dist/cjs/executor/ops/functions.d.ts +1 -0
- package/dist/cjs/executor/ops/functions.js +55 -0
- package/dist/cjs/executor/ops/index.d.ts +0 -0
- package/dist/cjs/executor/ops/index.js +11 -0
- package/dist/cjs/executor/ops/literals.d.ts +1 -0
- package/dist/cjs/executor/ops/literals.js +45 -0
- package/dist/cjs/executor/ops/misc.d.ts +1 -0
- package/dist/cjs/executor/ops/misc.js +25 -0
- package/dist/cjs/executor/ops/object.d.ts +1 -0
- package/dist/cjs/executor/ops/object.js +51 -0
- package/dist/cjs/executor/ops/prop.d.ts +1 -0
- package/dist/cjs/executor/ops/prop.js +70 -0
- package/dist/cjs/executor/ops/unary.d.ts +1 -0
- package/dist/cjs/executor/ops/unary.js +48 -0
- package/dist/cjs/executor/ops/variables.d.ts +1 -0
- package/dist/cjs/executor/ops/variables.js +16 -0
- package/dist/cjs/executor/opsRegistry.d.ts +33 -0
- package/dist/cjs/executor/opsRegistry.js +8 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/parser/index.d.ts +3 -0
- package/dist/cjs/parser/index.js +1 -0
- package/dist/{parser.d.ts → cjs/parser/lisp.d.ts} +29 -42
- package/dist/cjs/parser/lispTypes/conditionals.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/conditionals.js +135 -0
- package/dist/cjs/parser/lispTypes/control.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/control.js +204 -0
- package/dist/cjs/parser/lispTypes/declarations.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/declarations.js +99 -0
- package/dist/cjs/parser/lispTypes/index.d.ts +3 -0
- package/dist/cjs/parser/lispTypes/index.js +17 -0
- package/dist/cjs/parser/lispTypes/operators.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/operators.js +252 -0
- package/dist/cjs/parser/lispTypes/shared.d.ts +38 -0
- package/dist/cjs/parser/lispTypes/structures.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/structures.js +188 -0
- package/dist/cjs/parser/lispTypes/values.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/values.js +89 -0
- package/dist/cjs/parser/parserUtils.d.ts +34 -0
- package/dist/cjs/parser/parserUtils.js +968 -0
- package/dist/cjs/utils/CodeString.d.ts +16 -0
- package/dist/cjs/utils/CodeString.js +64 -0
- package/dist/cjs/utils/ExecContext.d.ts +34 -0
- package/dist/cjs/utils/ExecContext.js +171 -0
- package/dist/cjs/utils/Prop.d.ts +16 -0
- package/dist/cjs/utils/Prop.js +81 -0
- package/dist/cjs/utils/Scope.d.ts +47 -0
- package/dist/cjs/utils/Scope.js +127 -0
- package/dist/cjs/utils/errors.d.ts +10 -0
- package/dist/cjs/utils/errors.js +12 -0
- package/dist/cjs/utils/functionReplacements.d.ts +11 -0
- package/dist/cjs/utils/functionReplacements.js +362 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/types.d.ts +221 -0
- package/dist/cjs/utils/types.js +164 -0
- package/dist/cjs/utils/unraw.js +145 -0
- package/dist/{node → esm}/Sandbox.d.ts +15 -6
- package/dist/esm/Sandbox.js +115 -0
- package/dist/esm/Sandbox.js.map +1 -0
- package/{build → dist/esm}/SandboxExec.d.ts +8 -17
- package/dist/esm/SandboxExec.js +224 -0
- package/dist/esm/SandboxExec.js.map +1 -0
- package/dist/{eval.d.ts → esm/eval/index.d.ts} +10 -2
- package/dist/esm/eval/index.js +235 -0
- package/dist/esm/eval/index.js.map +1 -0
- package/dist/esm/executor/executorUtils.d.ts +161 -0
- package/dist/esm/executor/executorUtils.js +898 -0
- package/dist/esm/executor/executorUtils.js.map +1 -0
- package/dist/esm/executor/index.d.ts +1 -0
- package/dist/esm/executor/index.js +2 -0
- package/dist/esm/executor/ops/assignment.d.ts +1 -0
- package/dist/esm/executor/ops/assignment.js +90 -0
- package/dist/esm/executor/ops/assignment.js.map +1 -0
- package/dist/esm/executor/ops/call.d.ts +1 -0
- package/dist/esm/executor/ops/call.js +162 -0
- package/dist/esm/executor/ops/call.js.map +1 -0
- package/dist/esm/executor/ops/comparison.d.ts +1 -0
- package/dist/esm/executor/ops/comparison.js +38 -0
- package/dist/esm/executor/ops/comparison.js.map +1 -0
- package/dist/esm/executor/ops/control.d.ts +1 -0
- package/dist/esm/executor/ops/control.js +205 -0
- package/dist/esm/executor/ops/control.js.map +1 -0
- package/dist/esm/executor/ops/functions.d.ts +1 -0
- package/dist/esm/executor/ops/functions.js +57 -0
- package/dist/esm/executor/ops/functions.js.map +1 -0
- package/dist/esm/executor/ops/index.d.ts +0 -0
- package/dist/esm/executor/ops/index.js +11 -0
- package/dist/esm/executor/ops/literals.d.ts +1 -0
- package/dist/esm/executor/ops/literals.js +47 -0
- package/dist/esm/executor/ops/literals.js.map +1 -0
- package/dist/esm/executor/ops/misc.d.ts +1 -0
- package/dist/esm/executor/ops/misc.js +27 -0
- package/dist/esm/executor/ops/misc.js.map +1 -0
- package/dist/esm/executor/ops/object.d.ts +1 -0
- package/dist/esm/executor/ops/object.js +53 -0
- package/dist/esm/executor/ops/object.js.map +1 -0
- package/dist/esm/executor/ops/prop.d.ts +1 -0
- package/dist/esm/executor/ops/prop.js +72 -0
- package/dist/esm/executor/ops/prop.js.map +1 -0
- package/dist/esm/executor/ops/unary.d.ts +1 -0
- package/dist/esm/executor/ops/unary.js +50 -0
- package/dist/esm/executor/ops/unary.js.map +1 -0
- package/dist/esm/executor/ops/variables.d.ts +1 -0
- package/dist/esm/executor/ops/variables.js +18 -0
- package/dist/esm/executor/ops/variables.js.map +1 -0
- package/dist/esm/executor/opsRegistry.d.ts +33 -0
- package/dist/esm/executor/opsRegistry.js +9 -0
- package/dist/esm/executor/opsRegistry.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parser/index.d.ts +3 -0
- package/dist/esm/parser/index.js +1 -0
- package/{build/parser.d.ts → dist/esm/parser/lisp.d.ts} +29 -42
- package/dist/esm/parser/lispTypes/conditionals.d.ts +2 -0
- package/dist/esm/parser/lispTypes/conditionals.js +137 -0
- package/dist/esm/parser/lispTypes/conditionals.js.map +1 -0
- package/dist/esm/parser/lispTypes/control.d.ts +2 -0
- package/dist/esm/parser/lispTypes/control.js +206 -0
- package/dist/esm/parser/lispTypes/control.js.map +1 -0
- package/dist/esm/parser/lispTypes/declarations.d.ts +2 -0
- package/dist/esm/parser/lispTypes/declarations.js +101 -0
- package/dist/esm/parser/lispTypes/declarations.js.map +1 -0
- package/dist/esm/parser/lispTypes/index.d.ts +3 -0
- package/dist/esm/parser/lispTypes/index.js +19 -0
- package/dist/esm/parser/lispTypes/index.js.map +1 -0
- package/dist/esm/parser/lispTypes/operators.d.ts +2 -0
- package/dist/esm/parser/lispTypes/operators.js +254 -0
- package/dist/esm/parser/lispTypes/operators.js.map +1 -0
- package/dist/esm/parser/lispTypes/shared.d.ts +38 -0
- package/dist/esm/parser/lispTypes/structures.d.ts +2 -0
- package/dist/esm/parser/lispTypes/structures.js +190 -0
- package/dist/esm/parser/lispTypes/structures.js.map +1 -0
- package/dist/esm/parser/lispTypes/values.d.ts +2 -0
- package/dist/esm/parser/lispTypes/values.js +91 -0
- package/dist/esm/parser/lispTypes/values.js.map +1 -0
- package/dist/esm/parser/parserUtils.d.ts +34 -0
- package/dist/esm/parser/parserUtils.js +959 -0
- package/dist/esm/parser/parserUtils.js.map +1 -0
- package/dist/esm/utils/CodeString.d.ts +16 -0
- package/dist/esm/utils/CodeString.js +66 -0
- package/dist/esm/utils/CodeString.js.map +1 -0
- package/dist/esm/utils/ExecContext.d.ts +34 -0
- package/dist/esm/utils/ExecContext.js +168 -0
- package/dist/esm/utils/ExecContext.js.map +1 -0
- package/dist/esm/utils/Prop.d.ts +16 -0
- package/dist/esm/utils/Prop.js +80 -0
- package/dist/esm/utils/Prop.js.map +1 -0
- package/dist/esm/utils/Scope.d.ts +47 -0
- package/dist/esm/utils/Scope.js +122 -0
- package/dist/esm/utils/Scope.js.map +1 -0
- package/dist/esm/utils/errors.d.ts +10 -0
- package/dist/esm/utils/errors.js +10 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/functionReplacements.d.ts +11 -0
- package/dist/esm/utils/functionReplacements.js +361 -0
- package/dist/esm/utils/functionReplacements.js.map +1 -0
- package/dist/esm/utils/index.d.ts +7 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/types.d.ts +221 -0
- package/dist/esm/utils/types.js +160 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/utils/unraw.js +147 -0
- package/dist/esm/utils/unraw.js.map +1 -0
- package/dist/umd/Sandbox.min.js +2 -0
- package/dist/umd/Sandbox.min.js.map +1 -0
- package/dist/umd/SandboxExec.min.js +2 -0
- package/dist/umd/SandboxExec.min.js.map +1 -0
- package/package.json +70 -68
- package/build/Sandbox.js +0 -62
- package/build/SandboxExec.js +0 -214
- package/build/eval.js +0 -205
- package/build/executor.d.ts +0 -124
- package/build/executor.js +0 -1546
- package/build/parser.js +0 -1527
- package/build/unraw.js +0 -168
- package/build/utils.d.ts +0 -264
- package/build/utils.js +0 -362
- package/dist/Sandbox.d.ts +0 -25
- package/dist/Sandbox.js +0 -270
- package/dist/Sandbox.js.map +0 -1
- package/dist/Sandbox.min.js +0 -2
- package/dist/Sandbox.min.js.map +0 -1
- package/dist/SandboxExec.js +0 -218
- package/dist/SandboxExec.js.map +0 -1
- package/dist/SandboxExec.min.js +0 -2
- package/dist/SandboxExec.min.js.map +0 -1
- package/dist/executor.d.ts +0 -124
- package/dist/executor.js +0 -1550
- package/dist/executor.js.map +0 -1
- package/dist/node/Sandbox.js +0 -277
- package/dist/node/SandboxExec.d.ts +0 -66
- package/dist/node/SandboxExec.js +0 -225
- package/dist/node/eval.d.ts +0 -27
- package/dist/node/executor.d.ts +0 -124
- package/dist/node/executor.js +0 -1567
- package/dist/node/parser.d.ts +0 -154
- package/dist/node/parser.js +0 -1704
- package/dist/node/utils.d.ts +0 -264
- package/dist/node/utils.js +0 -385
- package/dist/parser.js +0 -1690
- package/dist/parser.js.map +0 -1
- package/dist/unraw.d.ts +0 -11
- package/dist/utils.d.ts +0 -264
- package/dist/utils.js +0 -365
- package/dist/utils.js.map +0 -1
- /package/{build → dist/cjs/utils}/unraw.d.ts +0 -0
- /package/dist/{node → esm/utils}/unraw.d.ts +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
//#region src/utils/types.ts
|
|
2
|
+
var AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
|
|
3
|
+
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
|
|
4
|
+
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
|
|
5
|
+
var NON_BLOCKING_THRESHOLD = 50000n;
|
|
6
|
+
var reservedWords = new Set([
|
|
7
|
+
"await",
|
|
8
|
+
"break",
|
|
9
|
+
"case",
|
|
10
|
+
"catch",
|
|
11
|
+
"class",
|
|
12
|
+
"const",
|
|
13
|
+
"continue",
|
|
14
|
+
"debugger",
|
|
15
|
+
"default",
|
|
16
|
+
"delete",
|
|
17
|
+
"do",
|
|
18
|
+
"else",
|
|
19
|
+
"enum",
|
|
20
|
+
"export",
|
|
21
|
+
"extends",
|
|
22
|
+
"false",
|
|
23
|
+
"finally",
|
|
24
|
+
"for",
|
|
25
|
+
"function",
|
|
26
|
+
"if",
|
|
27
|
+
"implements",
|
|
28
|
+
"import",
|
|
29
|
+
"in",
|
|
30
|
+
"instanceof",
|
|
31
|
+
"let",
|
|
32
|
+
"new",
|
|
33
|
+
"null",
|
|
34
|
+
"return",
|
|
35
|
+
"super",
|
|
36
|
+
"switch",
|
|
37
|
+
"this",
|
|
38
|
+
"throw",
|
|
39
|
+
"true",
|
|
40
|
+
"try",
|
|
41
|
+
"typeof",
|
|
42
|
+
"var",
|
|
43
|
+
"void",
|
|
44
|
+
"while",
|
|
45
|
+
"with"
|
|
46
|
+
]);
|
|
47
|
+
var VarType = /* @__PURE__ */ function(VarType) {
|
|
48
|
+
VarType["let"] = "let";
|
|
49
|
+
VarType["const"] = "const";
|
|
50
|
+
VarType["var"] = "var";
|
|
51
|
+
VarType["internal"] = "internal";
|
|
52
|
+
return VarType;
|
|
53
|
+
}({});
|
|
54
|
+
var LispType = /* @__PURE__ */ function(LispType) {
|
|
55
|
+
LispType[LispType["None"] = 0] = "None";
|
|
56
|
+
LispType[LispType["Prop"] = 1] = "Prop";
|
|
57
|
+
LispType[LispType["StringIndex"] = 2] = "StringIndex";
|
|
58
|
+
LispType[LispType["Let"] = 3] = "Let";
|
|
59
|
+
LispType[LispType["Const"] = 4] = "Const";
|
|
60
|
+
LispType[LispType["Call"] = 5] = "Call";
|
|
61
|
+
LispType[LispType["KeyVal"] = 6] = "KeyVal";
|
|
62
|
+
LispType[LispType["Number"] = 7] = "Number";
|
|
63
|
+
LispType[LispType["Return"] = 8] = "Return";
|
|
64
|
+
LispType[LispType["Assign"] = 9] = "Assign";
|
|
65
|
+
LispType[LispType["InlineFunction"] = 10] = "InlineFunction";
|
|
66
|
+
LispType[LispType["ArrowFunction"] = 11] = "ArrowFunction";
|
|
67
|
+
LispType[LispType["CreateArray"] = 12] = "CreateArray";
|
|
68
|
+
LispType[LispType["If"] = 13] = "If";
|
|
69
|
+
LispType[LispType["IfCase"] = 14] = "IfCase";
|
|
70
|
+
LispType[LispType["InlineIf"] = 15] = "InlineIf";
|
|
71
|
+
LispType[LispType["InlineIfCase"] = 16] = "InlineIfCase";
|
|
72
|
+
LispType[LispType["SpreadObject"] = 17] = "SpreadObject";
|
|
73
|
+
LispType[LispType["SpreadArray"] = 18] = "SpreadArray";
|
|
74
|
+
LispType[LispType["ArrayProp"] = 19] = "ArrayProp";
|
|
75
|
+
LispType[LispType["PropOptional"] = 20] = "PropOptional";
|
|
76
|
+
LispType[LispType["CallOptional"] = 21] = "CallOptional";
|
|
77
|
+
LispType[LispType["CreateObject"] = 22] = "CreateObject";
|
|
78
|
+
LispType[LispType["Group"] = 23] = "Group";
|
|
79
|
+
LispType[LispType["Not"] = 24] = "Not";
|
|
80
|
+
LispType[LispType["IncrementBefore"] = 25] = "IncrementBefore";
|
|
81
|
+
LispType[LispType["IncrementAfter"] = 26] = "IncrementAfter";
|
|
82
|
+
LispType[LispType["DecrementBefore"] = 27] = "DecrementBefore";
|
|
83
|
+
LispType[LispType["DecrementAfter"] = 28] = "DecrementAfter";
|
|
84
|
+
LispType[LispType["And"] = 29] = "And";
|
|
85
|
+
LispType[LispType["Or"] = 30] = "Or";
|
|
86
|
+
LispType[LispType["StrictNotEqual"] = 31] = "StrictNotEqual";
|
|
87
|
+
LispType[LispType["StrictEqual"] = 32] = "StrictEqual";
|
|
88
|
+
LispType[LispType["Plus"] = 33] = "Plus";
|
|
89
|
+
LispType[LispType["Var"] = 34] = "Var";
|
|
90
|
+
LispType[LispType["GlobalSymbol"] = 35] = "GlobalSymbol";
|
|
91
|
+
LispType[LispType["Literal"] = 36] = "Literal";
|
|
92
|
+
LispType[LispType["Function"] = 37] = "Function";
|
|
93
|
+
LispType[LispType["Loop"] = 38] = "Loop";
|
|
94
|
+
LispType[LispType["Try"] = 39] = "Try";
|
|
95
|
+
LispType[LispType["Switch"] = 40] = "Switch";
|
|
96
|
+
LispType[LispType["SwitchCase"] = 41] = "SwitchCase";
|
|
97
|
+
LispType[LispType["InternalBlock"] = 42] = "InternalBlock";
|
|
98
|
+
LispType[LispType["Expression"] = 43] = "Expression";
|
|
99
|
+
LispType[LispType["Await"] = 44] = "Await";
|
|
100
|
+
LispType[LispType["New"] = 45] = "New";
|
|
101
|
+
LispType[LispType["Throw"] = 46] = "Throw";
|
|
102
|
+
LispType[LispType["Minus"] = 47] = "Minus";
|
|
103
|
+
LispType[LispType["Divide"] = 48] = "Divide";
|
|
104
|
+
LispType[LispType["Power"] = 49] = "Power";
|
|
105
|
+
LispType[LispType["Multiply"] = 50] = "Multiply";
|
|
106
|
+
LispType[LispType["Modulus"] = 51] = "Modulus";
|
|
107
|
+
LispType[LispType["Equal"] = 52] = "Equal";
|
|
108
|
+
LispType[LispType["NotEqual"] = 53] = "NotEqual";
|
|
109
|
+
LispType[LispType["SmallerEqualThan"] = 54] = "SmallerEqualThan";
|
|
110
|
+
LispType[LispType["LargerEqualThan"] = 55] = "LargerEqualThan";
|
|
111
|
+
LispType[LispType["SmallerThan"] = 56] = "SmallerThan";
|
|
112
|
+
LispType[LispType["LargerThan"] = 57] = "LargerThan";
|
|
113
|
+
LispType[LispType["Negative"] = 58] = "Negative";
|
|
114
|
+
LispType[LispType["Positive"] = 59] = "Positive";
|
|
115
|
+
LispType[LispType["Typeof"] = 60] = "Typeof";
|
|
116
|
+
LispType[LispType["Delete"] = 61] = "Delete";
|
|
117
|
+
LispType[LispType["Instanceof"] = 62] = "Instanceof";
|
|
118
|
+
LispType[LispType["In"] = 63] = "In";
|
|
119
|
+
LispType[LispType["Inverse"] = 64] = "Inverse";
|
|
120
|
+
LispType[LispType["SubractEquals"] = 65] = "SubractEquals";
|
|
121
|
+
LispType[LispType["AddEquals"] = 66] = "AddEquals";
|
|
122
|
+
LispType[LispType["DivideEquals"] = 67] = "DivideEquals";
|
|
123
|
+
LispType[LispType["PowerEquals"] = 68] = "PowerEquals";
|
|
124
|
+
LispType[LispType["MultiplyEquals"] = 69] = "MultiplyEquals";
|
|
125
|
+
LispType[LispType["ModulusEquals"] = 70] = "ModulusEquals";
|
|
126
|
+
LispType[LispType["BitNegateEquals"] = 71] = "BitNegateEquals";
|
|
127
|
+
LispType[LispType["BitAndEquals"] = 72] = "BitAndEquals";
|
|
128
|
+
LispType[LispType["BitOrEquals"] = 73] = "BitOrEquals";
|
|
129
|
+
LispType[LispType["UnsignedShiftRightEquals"] = 74] = "UnsignedShiftRightEquals";
|
|
130
|
+
LispType[LispType["ShiftRightEquals"] = 75] = "ShiftRightEquals";
|
|
131
|
+
LispType[LispType["ShiftLeftEquals"] = 76] = "ShiftLeftEquals";
|
|
132
|
+
LispType[LispType["BitAnd"] = 77] = "BitAnd";
|
|
133
|
+
LispType[LispType["BitOr"] = 78] = "BitOr";
|
|
134
|
+
LispType[LispType["BitNegate"] = 79] = "BitNegate";
|
|
135
|
+
LispType[LispType["BitShiftLeft"] = 80] = "BitShiftLeft";
|
|
136
|
+
LispType[LispType["BitShiftRight"] = 81] = "BitShiftRight";
|
|
137
|
+
LispType[LispType["BitUnsignedShiftRight"] = 82] = "BitUnsignedShiftRight";
|
|
138
|
+
LispType[LispType["BigInt"] = 83] = "BigInt";
|
|
139
|
+
LispType[LispType["LiteralIndex"] = 84] = "LiteralIndex";
|
|
140
|
+
LispType[LispType["RegexIndex"] = 85] = "RegexIndex";
|
|
141
|
+
LispType[LispType["LoopAction"] = 86] = "LoopAction";
|
|
142
|
+
LispType[LispType["Void"] = 87] = "Void";
|
|
143
|
+
LispType[LispType["True"] = 88] = "True";
|
|
144
|
+
LispType[LispType["NullishCoalescing"] = 89] = "NullishCoalescing";
|
|
145
|
+
LispType[LispType["AndEquals"] = 90] = "AndEquals";
|
|
146
|
+
LispType[LispType["OrEquals"] = 91] = "OrEquals";
|
|
147
|
+
LispType[LispType["NullishCoalescingEquals"] = 92] = "NullishCoalescingEquals";
|
|
148
|
+
LispType[LispType["Block"] = 93] = "Block";
|
|
149
|
+
LispType[LispType["Labeled"] = 94] = "Labeled";
|
|
150
|
+
LispType[LispType["Internal"] = 95] = "Internal";
|
|
151
|
+
LispType[LispType["Yield"] = 96] = "Yield";
|
|
152
|
+
LispType[LispType["YieldDelegate"] = 97] = "YieldDelegate";
|
|
153
|
+
LispType[LispType["Hole"] = 98] = "Hole";
|
|
154
|
+
LispType[LispType["LispEnumSize"] = 99] = "LispEnumSize";
|
|
155
|
+
return LispType;
|
|
156
|
+
}({});
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.AsyncFunction = AsyncFunction;
|
|
159
|
+
exports.AsyncGeneratorFunction = AsyncGeneratorFunction;
|
|
160
|
+
exports.GeneratorFunction = GeneratorFunction;
|
|
161
|
+
exports.LispType = LispType;
|
|
162
|
+
exports.NON_BLOCKING_THRESHOLD = NON_BLOCKING_THRESHOLD;
|
|
163
|
+
exports.VarType = VarType;
|
|
164
|
+
exports.reservedWords = reservedWords;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
//#region src/utils/unraw.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parse a string as a base-16 number. This is more strict than `parseInt` as it
|
|
4
|
+
* will not allow any other characters, including (for example) "+", "-", and
|
|
5
|
+
* ".".
|
|
6
|
+
* @param hex A string containing a hexadecimal number.
|
|
7
|
+
* @returns The parsed integer, or `NaN` if the string is not a valid hex
|
|
8
|
+
* number.
|
|
9
|
+
*/
|
|
10
|
+
function parseHexToInt(hex) {
|
|
11
|
+
return !hex.match(/[^a-f0-9]/i) ? parseInt(hex, 16) : NaN;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Check the validity and length of a hexadecimal code and optionally enforces
|
|
15
|
+
* a specific number of hex digits.
|
|
16
|
+
* @param hex The string to validate and parse.
|
|
17
|
+
* @param errorName The name of the error message to throw a `SyntaxError` with
|
|
18
|
+
* if `hex` is invalid. This is used to index `errorMessages`.
|
|
19
|
+
* @param enforcedLength If provided, will throw an error if `hex` is not
|
|
20
|
+
* exactly this many characters.
|
|
21
|
+
* @returns The parsed hex number as a normal number.
|
|
22
|
+
* @throws {SyntaxError} If the code is not valid.
|
|
23
|
+
*/
|
|
24
|
+
function validateAndParseHex(hex, errorName, enforcedLength) {
|
|
25
|
+
const parsedHex = parseHexToInt(hex);
|
|
26
|
+
if (Number.isNaN(parsedHex) || enforcedLength !== void 0 && enforcedLength !== hex.length) throw new SyntaxError(errorName + ": " + hex);
|
|
27
|
+
return parsedHex;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse a two-digit hexadecimal character escape code.
|
|
31
|
+
* @param code The two-digit hexadecimal number that represents the character to
|
|
32
|
+
* output.
|
|
33
|
+
* @returns The single character represented by the code.
|
|
34
|
+
* @throws {SyntaxError} If the code is not valid hex or is not the right
|
|
35
|
+
* length.
|
|
36
|
+
*/
|
|
37
|
+
function parseHexadecimalCode(code) {
|
|
38
|
+
const parsedCode = validateAndParseHex(code, "Malformed Hexadecimal", 2);
|
|
39
|
+
return String.fromCharCode(parsedCode);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a four-digit Unicode character escape code.
|
|
43
|
+
* @param code The four-digit unicode number that represents the character to
|
|
44
|
+
* output.
|
|
45
|
+
* @param surrogateCode Optional four-digit unicode surrogate that represents
|
|
46
|
+
* the other half of the character to output.
|
|
47
|
+
* @returns The single character represented by the code.
|
|
48
|
+
* @throws {SyntaxError} If the codes are not valid hex or are not the right
|
|
49
|
+
* length.
|
|
50
|
+
*/
|
|
51
|
+
function parseUnicodeCode(code, surrogateCode) {
|
|
52
|
+
const parsedCode = validateAndParseHex(code, "Malformed Unicode", 4);
|
|
53
|
+
if (surrogateCode !== void 0) {
|
|
54
|
+
const parsedSurrogateCode = validateAndParseHex(surrogateCode, "Malformed Unicode", 4);
|
|
55
|
+
return String.fromCharCode(parsedCode, parsedSurrogateCode);
|
|
56
|
+
}
|
|
57
|
+
return String.fromCharCode(parsedCode);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Test if the text is surrounded by curly braces (`{}`).
|
|
61
|
+
* @param text Text to check.
|
|
62
|
+
* @returns `true` if the text is in the form `{*}`.
|
|
63
|
+
*/
|
|
64
|
+
function isCurlyBraced(text) {
|
|
65
|
+
return text.charAt(0) === "{" && text.charAt(text.length - 1) === "}";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Parse a Unicode code point character escape code.
|
|
69
|
+
* @param codePoint A unicode escape code point, including the surrounding curly
|
|
70
|
+
* braces.
|
|
71
|
+
* @returns The single character represented by the code.
|
|
72
|
+
* @throws {SyntaxError} If the code is not valid hex or does not have the
|
|
73
|
+
* surrounding curly braces.
|
|
74
|
+
*/
|
|
75
|
+
function parseUnicodeCodePointCode(codePoint) {
|
|
76
|
+
if (!isCurlyBraced(codePoint)) throw new SyntaxError("Malformed Unicode: +" + codePoint);
|
|
77
|
+
const parsedCode = validateAndParseHex(codePoint.slice(1, -1), "Malformed Unicode");
|
|
78
|
+
try {
|
|
79
|
+
return String.fromCodePoint(parsedCode);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
throw err instanceof RangeError ? /* @__PURE__ */ new SyntaxError("Code Point Limit:" + parsedCode) : err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Map of unescaped letters to their corresponding special JS escape characters.
|
|
86
|
+
* Intentionally does not include characters that map to themselves like "\'".
|
|
87
|
+
*/
|
|
88
|
+
var singleCharacterEscapes = new Map([
|
|
89
|
+
["b", "\b"],
|
|
90
|
+
["f", "\f"],
|
|
91
|
+
["n", "\n"],
|
|
92
|
+
["r", "\r"],
|
|
93
|
+
["t", " "],
|
|
94
|
+
["v", "\v"],
|
|
95
|
+
["0", "\0"]
|
|
96
|
+
]);
|
|
97
|
+
/**
|
|
98
|
+
* Parse a single character escape sequence and return the matching character.
|
|
99
|
+
* If none is matched, defaults to `code`.
|
|
100
|
+
* @param code A single character code.
|
|
101
|
+
*/
|
|
102
|
+
function parseSingleCharacterCode(code) {
|
|
103
|
+
return singleCharacterEscapes.get(code) || code;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Matches every escape sequence possible, including invalid ones.
|
|
107
|
+
*
|
|
108
|
+
* All capture groups (described below) are unique (only one will match), except
|
|
109
|
+
* for 4, which can only potentially match if 3 does.
|
|
110
|
+
*
|
|
111
|
+
* **Capture Groups:**
|
|
112
|
+
* 0. A single backslash
|
|
113
|
+
* 1. Hexadecimal code
|
|
114
|
+
* 2. Unicode code point code with surrounding curly braces
|
|
115
|
+
* 3. Unicode escape code with surrogate
|
|
116
|
+
* 4. Surrogate code
|
|
117
|
+
* 5. Unicode escape code without surrogate
|
|
118
|
+
* 6. Octal code _NOTE: includes "0"._
|
|
119
|
+
* 7. A single character (will never be \, x, u, or 0-3)
|
|
120
|
+
*/
|
|
121
|
+
var escapeMatch = /\\(?:(\\)|x([\s\S]{0,2})|u(\{[^}]*\}?)|u([\s\S]{4})\\u([^{][\s\S]{0,3})|u([\s\S]{0,4})|([0-3]?[0-7]{1,2})|([\s\S])|$)/g;
|
|
122
|
+
/**
|
|
123
|
+
* Replace raw escape character strings with their escape characters.
|
|
124
|
+
* @param raw A string where escape characters are represented as raw string
|
|
125
|
+
* values like `\'` rather than `'`.
|
|
126
|
+
* @param allowOctals If `true`, will process the now-deprecated octal escape
|
|
127
|
+
* sequences (ie, `\111`).
|
|
128
|
+
* @returns The processed string, with escape characters replaced by their
|
|
129
|
+
* respective actual Unicode characters.
|
|
130
|
+
*/
|
|
131
|
+
function unraw(raw) {
|
|
132
|
+
return raw.replace(escapeMatch, function(_, backslash, hex, codePoint, unicodeWithSurrogate, surrogate, unicode, octal, singleCharacter) {
|
|
133
|
+
if (backslash !== void 0) return "\\";
|
|
134
|
+
if (hex !== void 0) return parseHexadecimalCode(hex);
|
|
135
|
+
if (codePoint !== void 0) return parseUnicodeCodePointCode(codePoint);
|
|
136
|
+
if (unicodeWithSurrogate !== void 0) return parseUnicodeCode(unicodeWithSurrogate, surrogate);
|
|
137
|
+
if (unicode !== void 0) return parseUnicodeCode(unicode);
|
|
138
|
+
if (octal === "0") return "\0";
|
|
139
|
+
if (octal !== void 0) throw new SyntaxError("Octal Deprecation: " + octal);
|
|
140
|
+
if (singleCharacter !== void 0) return parseSingleCharacterCode(singleCharacter);
|
|
141
|
+
throw new SyntaxError("End of string");
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.default = unraw;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { IExecContext, IOptionParams, IScope } from './utils
|
|
2
|
-
import { ExecReturn } from './executor
|
|
3
|
-
import SandboxExec from './SandboxExec
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
1
|
+
import { IExecContext, IOptionParams, IScope } from './utils';
|
|
2
|
+
import { ExecReturn } from './executor';
|
|
3
|
+
import { default as SandboxExec } from './SandboxExec';
|
|
4
|
+
export { ParseError } from './parser';
|
|
5
|
+
export { LocalScope, SandboxExecutionTreeError, SandboxCapabilityError, SandboxAccessError, SandboxExecutionQuotaExceededError, SandboxError, delaySynchronousResult, } from './utils';
|
|
6
|
+
export type * from './utils';
|
|
7
|
+
export type * from './parser';
|
|
8
|
+
export type * from './executor';
|
|
9
|
+
export type * from './eval';
|
|
10
|
+
export declare class Sandbox extends SandboxExec {
|
|
6
11
|
constructor(options?: IOptionParams);
|
|
7
12
|
static audit<T>(code: string, scopes?: IScope[]): ExecReturn<T>;
|
|
8
|
-
static parse(code: string): import(
|
|
13
|
+
static parse(code: string): import('./parser').IExecutionTree;
|
|
14
|
+
get Function(): Function;
|
|
15
|
+
get AsyncFunction(): Function;
|
|
16
|
+
get eval(): Function;
|
|
9
17
|
compile<T>(code: string, optimize?: boolean): (...scopes: IScope[]) => {
|
|
10
18
|
context: IExecContext;
|
|
11
19
|
run: () => T;
|
|
@@ -23,3 +31,4 @@ export default class Sandbox extends SandboxExec {
|
|
|
23
31
|
run: () => Promise<T>;
|
|
24
32
|
};
|
|
25
33
|
}
|
|
34
|
+
export default Sandbox;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { SandboxAccessError, SandboxCapabilityError, SandboxError, SandboxExecutionQuotaExceededError, SandboxExecutionTreeError } from "./utils/errors.js";
|
|
2
|
+
import { AsyncFunction } from "./utils/types.js";
|
|
3
|
+
import { LocalScope, delaySynchronousResult, sanitizeScopes } from "./utils/Scope.js";
|
|
4
|
+
import { createExecContext } from "./utils/ExecContext.js";
|
|
5
|
+
import "./utils/index.js";
|
|
6
|
+
import parse, { ParseError } from "./parser/parserUtils.js";
|
|
7
|
+
import "./parser/index.js";
|
|
8
|
+
import { createEvalContext } from "./eval/index.js";
|
|
9
|
+
import { SandboxExec } from "./SandboxExec.js";
|
|
10
|
+
//#region src/Sandbox.ts
|
|
11
|
+
var Sandbox = class extends SandboxExec {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options, createEvalContext());
|
|
14
|
+
}
|
|
15
|
+
static audit(code, scopes = []) {
|
|
16
|
+
const globals = {};
|
|
17
|
+
for (const i of Object.getOwnPropertyNames(globalThis)) globals[i] = globalThis[i];
|
|
18
|
+
const sandbox = new SandboxExec({
|
|
19
|
+
globals,
|
|
20
|
+
audit: true
|
|
21
|
+
});
|
|
22
|
+
return sandbox.executeTree(createExecContext(sandbox, parse(code, true, false, sandbox.context.options.maxParserRecursionDepth), createEvalContext()), scopes);
|
|
23
|
+
}
|
|
24
|
+
static parse(code) {
|
|
25
|
+
return parse(code, true);
|
|
26
|
+
}
|
|
27
|
+
get Function() {
|
|
28
|
+
return createExecContext(this, {
|
|
29
|
+
tree: [],
|
|
30
|
+
constants: {
|
|
31
|
+
strings: [],
|
|
32
|
+
eager: true,
|
|
33
|
+
literals: [],
|
|
34
|
+
maxDepth: this.context.options.maxParserRecursionDepth,
|
|
35
|
+
regexes: []
|
|
36
|
+
}
|
|
37
|
+
}, this.evalContext).evals.get(Function);
|
|
38
|
+
}
|
|
39
|
+
get AsyncFunction() {
|
|
40
|
+
return createExecContext(this, {
|
|
41
|
+
tree: [],
|
|
42
|
+
constants: {
|
|
43
|
+
strings: [],
|
|
44
|
+
eager: true,
|
|
45
|
+
literals: [],
|
|
46
|
+
maxDepth: this.context.options.maxParserRecursionDepth,
|
|
47
|
+
regexes: []
|
|
48
|
+
}
|
|
49
|
+
}, this.evalContext).evals.get(AsyncFunction);
|
|
50
|
+
}
|
|
51
|
+
get eval() {
|
|
52
|
+
return createExecContext(this, {
|
|
53
|
+
tree: [],
|
|
54
|
+
constants: {
|
|
55
|
+
strings: [],
|
|
56
|
+
eager: true,
|
|
57
|
+
literals: [],
|
|
58
|
+
maxDepth: this.context.options.maxParserRecursionDepth,
|
|
59
|
+
regexes: []
|
|
60
|
+
}
|
|
61
|
+
}, this.evalContext).evals.get(eval);
|
|
62
|
+
}
|
|
63
|
+
compile(code, optimize = false) {
|
|
64
|
+
if (this.context.options.nonBlocking) throw new SandboxCapabilityError("Non-blocking mode is enabled, use Sandbox.compileAsync() instead.");
|
|
65
|
+
const parsed = parse(code, optimize, false, this.context.options.maxParserRecursionDepth);
|
|
66
|
+
const context = createExecContext(this, parsed, this.evalContext);
|
|
67
|
+
const exec = (...scopes) => {
|
|
68
|
+
sanitizeScopes(scopes, context);
|
|
69
|
+
return {
|
|
70
|
+
context,
|
|
71
|
+
run: () => this.executeTree(context, [...scopes]).result
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
return exec;
|
|
75
|
+
}
|
|
76
|
+
compileAsync(code, optimize = false) {
|
|
77
|
+
const parsed = parse(code, optimize, false, this.context.options.maxParserRecursionDepth);
|
|
78
|
+
const context = createExecContext(this, parsed, this.evalContext);
|
|
79
|
+
const exec = (...scopes) => {
|
|
80
|
+
sanitizeScopes(scopes, context);
|
|
81
|
+
return {
|
|
82
|
+
context,
|
|
83
|
+
run: () => this.executeTreeAsync(context, [...scopes]).then((ret) => ret.result)
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
return exec;
|
|
87
|
+
}
|
|
88
|
+
compileExpression(code, optimize = false) {
|
|
89
|
+
const parsed = parse(code, optimize, true, this.context.options.maxParserRecursionDepth);
|
|
90
|
+
const context = createExecContext(this, parsed, this.evalContext);
|
|
91
|
+
const exec = (...scopes) => {
|
|
92
|
+
sanitizeScopes(scopes, context);
|
|
93
|
+
return {
|
|
94
|
+
context,
|
|
95
|
+
run: () => this.executeTree(context, [...scopes]).result
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
return exec;
|
|
99
|
+
}
|
|
100
|
+
compileExpressionAsync(code, optimize = false) {
|
|
101
|
+
const parsed = parse(code, optimize, true, this.context.options.maxParserRecursionDepth);
|
|
102
|
+
const context = createExecContext(this, parsed, this.evalContext);
|
|
103
|
+
const exec = (...scopes) => {
|
|
104
|
+
return {
|
|
105
|
+
context,
|
|
106
|
+
run: () => this.executeTreeAsync(context, [...scopes]).then((ret) => ret.result)
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return exec;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { LocalScope, ParseError, Sandbox, Sandbox as default, SandboxAccessError, SandboxCapabilityError, SandboxError, SandboxExecutionQuotaExceededError, SandboxExecutionTreeError, delaySynchronousResult };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=Sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sandbox.js","names":[],"sources":["../../src/Sandbox.ts"],"sourcesContent":["import { AsyncFunction, createExecContext, SandboxCapabilityError, sanitizeScopes } from './utils';\nimport type { IExecContext, IOptionParams, IScope } from './utils';\nimport { createEvalContext } from './eval';\nimport { ExecReturn } from './executor';\nimport parse from './parser';\nimport SandboxExec from './SandboxExec';\nexport { ParseError } from './parser';\nexport {\n LocalScope,\n SandboxExecutionTreeError,\n SandboxCapabilityError,\n SandboxAccessError,\n SandboxExecutionQuotaExceededError,\n SandboxError,\n delaySynchronousResult,\n} from './utils';\n\nexport type * from './utils';\nexport type * from './parser';\nexport type * from './executor';\nexport type * from './eval';\n\nexport class Sandbox extends SandboxExec {\n constructor(options?: IOptionParams) {\n super(options, createEvalContext());\n }\n\n static audit<T>(code: string, scopes: IScope[] = []): ExecReturn<T> {\n const globals: Record<string, unknown> = {};\n for (const i of Object.getOwnPropertyNames(globalThis) as [keyof typeof globalThis]) {\n globals[i] = globalThis[i];\n }\n const sandbox = new SandboxExec({\n globals,\n audit: true,\n });\n return sandbox.executeTree(\n createExecContext(\n sandbox,\n parse(code, true, false, sandbox.context.options.maxParserRecursionDepth),\n createEvalContext(),\n ),\n scopes,\n );\n }\n\n static parse(code: string) {\n return parse(code, true);\n }\n\n get Function() {\n const context = createExecContext(\n this,\n {\n tree: [],\n constants: {\n strings: [],\n eager: true,\n literals: [],\n maxDepth: this.context.options.maxParserRecursionDepth,\n regexes: [],\n },\n },\n this.evalContext,\n );\n return context.evals.get(Function)!;\n }\n\n get AsyncFunction() {\n const context = createExecContext(\n this,\n {\n tree: [],\n constants: {\n strings: [],\n eager: true,\n literals: [],\n maxDepth: this.context.options.maxParserRecursionDepth,\n regexes: [],\n },\n },\n this.evalContext,\n );\n return context.evals.get(AsyncFunction)!;\n }\n\n get eval() {\n const context = createExecContext(\n this,\n {\n tree: [],\n constants: {\n strings: [],\n eager: true,\n literals: [],\n maxDepth: this.context.options.maxParserRecursionDepth,\n regexes: [],\n },\n },\n this.evalContext,\n );\n return context.evals.get(eval)!;\n }\n\n compile<T>(\n code: string,\n optimize = false,\n ): (...scopes: IScope[]) => { context: IExecContext; run: () => T } {\n if (this.context.options.nonBlocking)\n throw new SandboxCapabilityError(\n 'Non-blocking mode is enabled, use Sandbox.compileAsync() instead.',\n );\n const parsed = parse(code, optimize, false, this.context.options.maxParserRecursionDepth);\n const context = createExecContext(this, parsed, this.evalContext);\n const exec = (...scopes: IScope[]) => {\n sanitizeScopes(scopes, context);\n return { context, run: () => this.executeTree<T>(context, [...scopes]).result };\n };\n return exec;\n }\n\n compileAsync<T>(\n code: string,\n optimize = false,\n ): (...scopes: IScope[]) => { context: IExecContext; run: () => Promise<T> } {\n const parsed = parse(code, optimize, false, this.context.options.maxParserRecursionDepth);\n const context = createExecContext(this, parsed, this.evalContext);\n const exec = (...scopes: IScope[]) => {\n sanitizeScopes(scopes, context);\n return {\n context,\n run: () => this.executeTreeAsync<T>(context, [...scopes]).then((ret) => ret.result),\n };\n };\n return exec;\n }\n\n compileExpression<T>(\n code: string,\n optimize = false,\n ): (...scopes: IScope[]) => { context: IExecContext; run: () => T } {\n const parsed = parse(code, optimize, true, this.context.options.maxParserRecursionDepth);\n const context = createExecContext(this, parsed, this.evalContext);\n const exec = (...scopes: IScope[]) => {\n sanitizeScopes(scopes, context);\n return { context, run: () => this.executeTree<T>(context, [...scopes]).result };\n };\n return exec;\n }\n\n compileExpressionAsync<T>(\n code: string,\n optimize = false,\n ): (...scopes: IScope[]) => { context: IExecContext; run: () => Promise<T> } {\n const parsed = parse(code, optimize, true, this.context.options.maxParserRecursionDepth);\n const context = createExecContext(this, parsed, this.evalContext);\n const exec = (...scopes: IScope[]) => {\n return {\n context,\n run: () => this.executeTreeAsync<T>(context, [...scopes]).then((ret) => ret.result),\n };\n };\n return exec;\n }\n}\n\nexport default Sandbox;\n"],"mappings":"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"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { IEvalContext } from './eval
|
|
2
|
-
import { Change, ExecReturn } from './executor
|
|
3
|
-
import { IContext, IExecContext, IGlobals, IOptionParams, IScope,
|
|
4
|
-
export
|
|
5
|
-
export default class SandboxExec {
|
|
1
|
+
import { IEvalContext } from './eval';
|
|
2
|
+
import { Change, ExecReturn } from './executor';
|
|
3
|
+
import { IContext, IExecContext, IGlobals, IOptionParams, IScope, ISymbolWhitelist, SubscriptionSubject, HaltContext } from './utils';
|
|
4
|
+
export declare class SandboxExec {
|
|
6
5
|
evalContext?: IEvalContext | undefined;
|
|
7
6
|
readonly context: IContext;
|
|
8
7
|
readonly setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;
|
|
@@ -32,6 +31,7 @@ export default class SandboxExec {
|
|
|
32
31
|
}>;
|
|
33
32
|
constructor(options?: IOptionParams, evalContext?: IEvalContext | undefined);
|
|
34
33
|
static get SAFE_GLOBALS(): IGlobals;
|
|
34
|
+
static get SAFE_SYMBOLS(): ISymbolWhitelist;
|
|
35
35
|
static get SAFE_PROTOTYPES(): Map<any, Set<string>>;
|
|
36
36
|
subscribeGet(callback: (obj: SubscriptionSubject, name: string) => void, context: IExecContext): {
|
|
37
37
|
unsubscribe: () => void;
|
|
@@ -42,25 +42,16 @@ export default class SandboxExec {
|
|
|
42
42
|
subscribeSetGlobal(obj: SubscriptionSubject, name: string, callback: (modification: Change) => void): {
|
|
43
43
|
unsubscribe: () => void;
|
|
44
44
|
};
|
|
45
|
-
subscribeHalt(cb: (
|
|
46
|
-
error: Error;
|
|
47
|
-
ticks: Ticks;
|
|
48
|
-
scope: Scope;
|
|
49
|
-
context: IExecContext;
|
|
50
|
-
}) => void): {
|
|
45
|
+
subscribeHalt(cb: (context: HaltContext) => void): {
|
|
51
46
|
unsubscribe: () => void;
|
|
52
47
|
};
|
|
53
48
|
subscribeResume(cb: () => void): {
|
|
54
49
|
unsubscribe: () => void;
|
|
55
50
|
};
|
|
56
|
-
haltExecution(haltContext?:
|
|
57
|
-
error: Error;
|
|
58
|
-
ticks: Ticks;
|
|
59
|
-
scope: Scope;
|
|
60
|
-
context: IExecContext;
|
|
61
|
-
}): void;
|
|
51
|
+
haltExecution(haltContext?: HaltContext): void;
|
|
62
52
|
resumeExecution(): void;
|
|
63
53
|
getContext(fn: (...args: any[]) => any): IExecContext | undefined;
|
|
64
54
|
executeTree<T>(context: IExecContext, scopes?: IScope[]): ExecReturn<T>;
|
|
65
55
|
executeTreeAsync<T>(context: IExecContext, scopes?: IScope[]): Promise<ExecReturn<T>>;
|
|
66
56
|
}
|
|
57
|
+
export default SandboxExec;
|