@nyariv/sandboxjs 0.8.23 → 0.8.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +22 -0
  3. package/.prettierrc +4 -0
  4. package/.vscode/settings.json +4 -0
  5. package/README.md +1 -1
  6. package/build/Sandbox.d.ts +11 -79
  7. package/build/Sandbox.js +21 -216
  8. package/build/SandboxExec.d.ts +25 -0
  9. package/build/SandboxExec.js +169 -0
  10. package/build/eval.d.ts +18 -0
  11. package/build/eval.js +43 -0
  12. package/build/executor.d.ts +29 -90
  13. package/build/executor.js +249 -328
  14. package/build/parser.d.ts +8 -239
  15. package/build/parser.js +345 -444
  16. package/build/unraw.js +13 -16
  17. package/build/utils.d.ts +242 -0
  18. package/build/utils.js +276 -0
  19. package/dist/Sandbox.d.ts +11 -79
  20. package/dist/Sandbox.js +106 -1
  21. package/dist/Sandbox.js.map +1 -1
  22. package/dist/Sandbox.min.js +2 -0
  23. package/dist/Sandbox.min.js.map +1 -0
  24. package/dist/SandboxExec.d.ts +25 -0
  25. package/dist/SandboxExec.js +173 -0
  26. package/dist/SandboxExec.js.map +1 -0
  27. package/dist/SandboxExec.min.js +2 -0
  28. package/dist/SandboxExec.min.js.map +1 -0
  29. package/dist/eval.d.ts +18 -0
  30. package/dist/executor.d.ts +29 -90
  31. package/dist/executor.js +1270 -0
  32. package/dist/executor.js.map +1 -0
  33. package/dist/node/Sandbox.d.ts +11 -79
  34. package/dist/node/Sandbox.js +36 -3150
  35. package/dist/node/SandboxExec.d.ts +25 -0
  36. package/dist/node/SandboxExec.js +176 -0
  37. package/dist/node/eval.d.ts +18 -0
  38. package/dist/node/executor.d.ts +29 -90
  39. package/dist/node/executor.js +1289 -0
  40. package/dist/node/parser.d.ts +8 -239
  41. package/dist/node/parser.js +1527 -0
  42. package/dist/node/utils.d.ts +242 -0
  43. package/dist/node/utils.js +290 -0
  44. package/dist/parser.d.ts +8 -239
  45. package/dist/parser.js +1513 -0
  46. package/dist/parser.js.map +1 -0
  47. package/dist/utils.d.ts +242 -0
  48. package/dist/utils.js +279 -0
  49. package/dist/utils.js.map +1 -0
  50. package/jest.config.js +200 -0
  51. package/package.json +16 -5
  52. package/tsconfig.jest.json +16 -0
  53. package/.github/workflows/npm-publish.yml +0 -34
  54. package/rollup.config.mjs +0 -33
package/dist/utils.js ADDED
@@ -0,0 +1,279 @@
1
+ const SandboxGlobal = function SandboxGlobal(globals) {
2
+ if (globals === globalThis)
3
+ return globalThis;
4
+ for (const i in globals) {
5
+ this[i] = globals[i];
6
+ }
7
+ };
8
+ class ExecContext {
9
+ constructor(ctx, constants, tree, getSubscriptions, setSubscriptions, changeSubscriptions, setSubscriptionsGlobal, changeSubscriptionsGlobal, evals, registerSandboxFunction, allowJit, evalContext) {
10
+ this.ctx = ctx;
11
+ this.constants = constants;
12
+ this.tree = tree;
13
+ this.getSubscriptions = getSubscriptions;
14
+ this.setSubscriptions = setSubscriptions;
15
+ this.changeSubscriptions = changeSubscriptions;
16
+ this.setSubscriptionsGlobal = setSubscriptionsGlobal;
17
+ this.changeSubscriptionsGlobal = changeSubscriptionsGlobal;
18
+ this.evals = evals;
19
+ this.registerSandboxFunction = registerSandboxFunction;
20
+ this.allowJit = allowJit;
21
+ this.evalContext = evalContext;
22
+ }
23
+ }
24
+ function createContext(sandbox, options) {
25
+ const sandboxGlobal = new SandboxGlobal(options.globals);
26
+ const context = {
27
+ sandbox: sandbox,
28
+ globalsWhitelist: new Set(Object.values(options.globals)),
29
+ prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),
30
+ options,
31
+ globalScope: new Scope(null, options.globals, sandboxGlobal),
32
+ sandboxGlobal,
33
+ };
34
+ context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()), new Set());
35
+ return context;
36
+ }
37
+ function createExecContext(sandbox, executionTree, evalContext) {
38
+ const evals = new Map();
39
+ const execContext = new ExecContext(sandbox.context, executionTree.constants, executionTree.tree, new Set(), new WeakMap(), new WeakMap(), sandbox.setSubscriptions, sandbox.changeSubscriptions, evals, (fn) => sandbox.sandboxFunctions.set(fn, execContext), !!evalContext, evalContext);
40
+ if (evalContext) {
41
+ const func = evalContext.sandboxFunction(execContext);
42
+ evals.set(Function, func);
43
+ evals.set(eval, evalContext.sandboxedEval(func));
44
+ evals.set(setTimeout, evalContext.sandboxedSetTimeout(func));
45
+ evals.set(setInterval, evalContext.sandboxedSetInterval(func));
46
+ }
47
+ return execContext;
48
+ }
49
+ class CodeString {
50
+ constructor(str) {
51
+ this.ref = { str: '' };
52
+ if (str instanceof CodeString) {
53
+ this.ref = str.ref;
54
+ this.start = str.start;
55
+ this.end = str.end;
56
+ }
57
+ else {
58
+ this.ref.str = str;
59
+ this.start = 0;
60
+ this.end = str.length;
61
+ }
62
+ }
63
+ substring(start, end) {
64
+ if (!this.length)
65
+ return this;
66
+ start = this.start + start;
67
+ if (start < 0) {
68
+ start = 0;
69
+ }
70
+ if (start > this.end) {
71
+ start = this.end;
72
+ }
73
+ end = end === undefined ? this.end : this.start + end;
74
+ if (end < 0) {
75
+ end = 0;
76
+ }
77
+ if (end > this.end) {
78
+ end = this.end;
79
+ }
80
+ const code = new CodeString(this);
81
+ code.start = start;
82
+ code.end = end;
83
+ return code;
84
+ }
85
+ get length() {
86
+ const len = this.end - this.start;
87
+ return len < 0 ? 0 : len;
88
+ }
89
+ char(i) {
90
+ if (this.start === this.end)
91
+ return undefined;
92
+ return this.ref.str[this.start + i];
93
+ }
94
+ toString() {
95
+ return this.ref.str.substring(this.start, this.end);
96
+ }
97
+ trimStart() {
98
+ const found = /^\s+/.exec(this.toString());
99
+ const code = new CodeString(this);
100
+ if (found) {
101
+ code.start += found[0].length;
102
+ }
103
+ return code;
104
+ }
105
+ slice(start, end) {
106
+ if (start < 0) {
107
+ start = this.end - this.start + start;
108
+ }
109
+ if (start < 0) {
110
+ start = 0;
111
+ }
112
+ if (end === undefined) {
113
+ end = this.end - this.start;
114
+ }
115
+ if (end < 0) {
116
+ end = this.end - this.start + end;
117
+ }
118
+ if (end < 0) {
119
+ end = 0;
120
+ }
121
+ return this.substring(start, end);
122
+ }
123
+ trim() {
124
+ const code = this.trimStart();
125
+ const found = /\s+$/.exec(code.toString());
126
+ if (found) {
127
+ code.end -= found[0].length;
128
+ }
129
+ return code;
130
+ }
131
+ valueOf() {
132
+ return this.toString();
133
+ }
134
+ }
135
+ function keysOnly(obj) {
136
+ const ret = Object.assign({}, obj);
137
+ for (const key in ret) {
138
+ ret[key] = true;
139
+ }
140
+ return ret;
141
+ }
142
+ const reservedWords = new Set([
143
+ 'instanceof',
144
+ 'typeof',
145
+ 'return',
146
+ 'throw',
147
+ 'try',
148
+ 'catch',
149
+ 'if',
150
+ 'finally',
151
+ 'else',
152
+ 'in',
153
+ 'of',
154
+ 'var',
155
+ 'let',
156
+ 'const',
157
+ 'for',
158
+ 'delete',
159
+ 'false',
160
+ 'true',
161
+ 'while',
162
+ 'do',
163
+ 'break',
164
+ 'continue',
165
+ 'new',
166
+ 'function',
167
+ 'async',
168
+ 'await',
169
+ 'switch',
170
+ 'case',
171
+ ]);
172
+ class Scope {
173
+ constructor(parent, vars = {}, functionThis) {
174
+ this.const = {};
175
+ this.let = {};
176
+ this.var = {};
177
+ const isFuncScope = functionThis !== undefined || parent === null;
178
+ this.parent = parent;
179
+ this.allVars = vars;
180
+ this.let = isFuncScope ? this.let : keysOnly(vars);
181
+ this.var = isFuncScope ? keysOnly(vars) : this.var;
182
+ this.globals = parent === null ? keysOnly(vars) : {};
183
+ this.functionThis = functionThis;
184
+ }
185
+ get(key, functionScope = false) {
186
+ const functionThis = this.functionThis;
187
+ if (key === 'this' && functionThis !== undefined) {
188
+ return new Prop({ this: functionThis }, key, true, false, true);
189
+ }
190
+ if (reservedWords.has(key))
191
+ throw new SyntaxError("Unexepected token '" + key + "'");
192
+ if (this.parent === null || !functionScope || functionThis !== undefined) {
193
+ if (this.globals.hasOwnProperty(key)) {
194
+ return new Prop(functionThis, key, false, true, true);
195
+ }
196
+ if (key in this.allVars && (!(key in {}) || this.allVars.hasOwnProperty(key))) {
197
+ return new Prop(this.allVars, key, this.const.hasOwnProperty(key), this.globals.hasOwnProperty(key), true);
198
+ }
199
+ if (this.parent === null) {
200
+ return new Prop(undefined, key);
201
+ }
202
+ }
203
+ return this.parent.get(key, functionScope);
204
+ }
205
+ set(key, val) {
206
+ if (key === 'this')
207
+ throw new SyntaxError('"this" cannot be assigned');
208
+ if (reservedWords.has(key))
209
+ throw new SyntaxError("Unexepected token '" + key + "'");
210
+ const prop = this.get(key);
211
+ if (prop.context === undefined) {
212
+ throw new ReferenceError(`Variable '${key}' was not declared.`);
213
+ }
214
+ if (prop.isConst) {
215
+ throw new TypeError(`Cannot assign to const variable '${key}'`);
216
+ }
217
+ if (prop.isGlobal) {
218
+ throw new SandboxError(`Cannot override global variable '${key}'`);
219
+ }
220
+ if (!(prop.context instanceof Object))
221
+ throw new SandboxError('Scope is not an object');
222
+ prop.context[prop.prop] = val;
223
+ return prop;
224
+ }
225
+ declare(key, type, value = undefined, isGlobal = false) {
226
+ if (key === 'this')
227
+ throw new SyntaxError('"this" cannot be declared');
228
+ if (reservedWords.has(key))
229
+ throw new SyntaxError("Unexepected token '" + key + "'");
230
+ if (type === 'var' && this.functionThis === undefined && this.parent !== null) {
231
+ return this.parent.declare(key, type, value, isGlobal);
232
+ }
233
+ else if ((this[type].hasOwnProperty(key) && type !== 'const' && !this.globals.hasOwnProperty(key)) ||
234
+ !(key in this.allVars)) {
235
+ if (isGlobal) {
236
+ this.globals[key] = true;
237
+ }
238
+ this[type][key] = true;
239
+ this.allVars[key] = value;
240
+ }
241
+ else {
242
+ throw new SandboxError(`Identifier '${key}' has already been declared`);
243
+ }
244
+ return new Prop(this.allVars, key, this.const.hasOwnProperty(key), isGlobal);
245
+ }
246
+ }
247
+ class FunctionScope {
248
+ }
249
+ class LocalScope {
250
+ }
251
+ class SandboxError extends Error {
252
+ }
253
+ function isLisp(item) {
254
+ return (Array.isArray(item) &&
255
+ typeof item[0] === 'number' &&
256
+ item[0] !== 0 /* LispType.None */ &&
257
+ item[0] !== 88 /* LispType.True */);
258
+ }
259
+ class Prop {
260
+ constructor(context, prop, isConst = false, isGlobal = false, isVariable = false) {
261
+ this.context = context;
262
+ this.prop = prop;
263
+ this.isConst = isConst;
264
+ this.isGlobal = isGlobal;
265
+ this.isVariable = isVariable;
266
+ }
267
+ get(context) {
268
+ const ctx = this.context;
269
+ if (ctx === undefined)
270
+ throw new ReferenceError(`${this.prop} is not defined`);
271
+ if (ctx === null)
272
+ throw new TypeError(`Cannot read properties of null, (reading '${this.prop}')`);
273
+ context.getSubscriptions.forEach((cb) => cb(ctx, this.prop));
274
+ return ctx[this.prop];
275
+ }
276
+ }
277
+
278
+ export { CodeString, ExecContext, FunctionScope, LocalScope, Prop, SandboxError, SandboxGlobal, Scope, createContext, createExecContext, isLisp };
279
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import { IEvalContext } from './eval';\nimport { Change, Unknown } from './executor';\nimport { IConstants, IExecutionTree, Lisp, LispItem } from './parser';\nimport SandboxExec from './SandboxExec';\n\nexport type replacementCallback = (obj: any, isStaticAccess: boolean) => any;\n\nexport interface IOptionParams {\n audit?: boolean;\n forbidFunctionCalls?: boolean;\n forbidFunctionCreation?: boolean;\n prototypeReplacements?: Map<new () => any, replacementCallback>;\n prototypeWhitelist?: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IOptions {\n audit: boolean;\n forbidFunctionCalls: boolean;\n forbidFunctionCreation: boolean;\n prototypeReplacements: Map<new () => any, replacementCallback>;\n prototypeWhitelist: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IContext {\n sandbox: SandboxExec;\n globalScope: Scope;\n sandboxGlobal: ISandboxGlobal;\n globalsWhitelist: Set<any>;\n prototypeWhitelist: Map<any, Set<string>>;\n options: IOptions;\n auditReport?: IAuditReport;\n}\n\nexport interface IAuditReport {\n globalsAccess: Set<unknown>;\n prototypeAccess: { [name: string]: Set<string> };\n}\n\nexport interface Ticks {\n ticks: bigint;\n}\n\nexport type SubscriptionSubject = object;\n\nexport interface IExecContext extends IExecutionTree {\n ctx: IContext;\n getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>;\n setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptionsGlobal: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n registerSandboxFunction: (fn: (...args: any[]) => any) => void;\n evals: Map<any, any>;\n allowJit: boolean;\n evalContext?: IEvalContext;\n}\n\nexport interface ISandboxGlobal {\n [key: string]: unknown;\n}\ninterface SandboxGlobalConstructor {\n new (globals: IGlobals): ISandboxGlobal;\n}\n\nexport const SandboxGlobal = function SandboxGlobal(this: ISandboxGlobal, globals: IGlobals) {\n if (globals === (globalThis as any)) return globalThis;\n for (const i in globals) {\n this[i] = globals[i];\n }\n} as any as SandboxGlobalConstructor;\n\nexport type IGlobals = ISandboxGlobal;\n\nexport class ExecContext implements IExecContext {\n constructor(\n public ctx: IContext,\n public constants: IConstants,\n public tree: Lisp[],\n public getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>,\n public setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>,\n public setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Set<(modification: Change) => void>\n >,\n public evals: Map<any, any>,\n public registerSandboxFunction: (fn: (...args: any[]) => any) => void,\n public allowJit: boolean,\n public evalContext?: IEvalContext\n ) {}\n}\n\nexport function createContext(sandbox: SandboxExec, options: IOptions): IContext {\n const sandboxGlobal = new SandboxGlobal(options.globals);\n const context = {\n sandbox: sandbox,\n globalsWhitelist: new Set(Object.values(options.globals)),\n prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),\n options,\n globalScope: new Scope(null, options.globals, sandboxGlobal),\n sandboxGlobal,\n };\n context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()) as Object, new Set());\n return context;\n}\n\nexport function createExecContext(\n sandbox: {\n setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n sandboxFunctions: WeakMap<(...args: any[]) => any, IExecContext>;\n context: IContext;\n },\n executionTree: IExecutionTree,\n evalContext?: IEvalContext\n): IExecContext {\n const evals = new Map();\n const execContext: IExecContext = new ExecContext(\n sandbox.context,\n executionTree.constants,\n executionTree.tree,\n new Set<(obj: SubscriptionSubject, name: string) => void>(),\n new WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>(),\n new WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>(),\n sandbox.setSubscriptions,\n sandbox.changeSubscriptions,\n evals,\n (fn) => sandbox.sandboxFunctions.set(fn, execContext),\n !!evalContext,\n evalContext\n );\n if (evalContext) {\n const func = evalContext.sandboxFunction(execContext);\n evals.set(Function, func);\n evals.set(eval, evalContext.sandboxedEval(func));\n evals.set(setTimeout, evalContext.sandboxedSetTimeout(func));\n evals.set(setInterval, evalContext.sandboxedSetInterval(func));\n }\n return execContext;\n}\n\nexport class CodeString {\n start: number;\n end: number;\n ref: { str: string };\n constructor(str: string | CodeString) {\n this.ref = { str: '' };\n if (str instanceof CodeString) {\n this.ref = str.ref;\n this.start = str.start;\n this.end = str.end;\n } else {\n this.ref.str = str;\n this.start = 0;\n this.end = str.length;\n }\n }\n\n substring(start: number, end?: number): CodeString {\n if (!this.length) return this;\n start = this.start + start;\n if (start < 0) {\n start = 0;\n }\n if (start > this.end) {\n start = this.end;\n }\n end = end === undefined ? this.end : this.start + end;\n if (end < 0) {\n end = 0;\n }\n if (end > this.end) {\n end = this.end;\n }\n const code = new CodeString(this);\n code.start = start;\n code.end = end;\n return code;\n }\n\n get length() {\n const len = this.end - this.start;\n return len < 0 ? 0 : len;\n }\n\n char(i: number) {\n if (this.start === this.end) return undefined;\n return this.ref.str[this.start + i];\n }\n\n toString() {\n return this.ref.str.substring(this.start, this.end);\n }\n\n trimStart() {\n const found = /^\\s+/.exec(this.toString());\n const code = new CodeString(this);\n if (found) {\n code.start += found[0].length;\n }\n return code;\n }\n\n slice(start: number, end?: number) {\n if (start < 0) {\n start = this.end - this.start + start;\n }\n if (start < 0) {\n start = 0;\n }\n if (end === undefined) {\n end = this.end - this.start;\n }\n\n if (end < 0) {\n end = this.end - this.start + end;\n }\n if (end < 0) {\n end = 0;\n }\n return this.substring(start, end);\n }\n\n trim() {\n const code = this.trimStart();\n const found = /\\s+$/.exec(code.toString());\n if (found) {\n code.end -= found[0].length;\n }\n return code;\n }\n\n valueOf() {\n return this.toString();\n }\n}\n\nfunction keysOnly(obj: unknown): Record<string, true> {\n const ret: Record<string, true> = Object.assign({}, obj);\n for (const key in ret) {\n ret[key] = true;\n }\n return ret;\n}\n\nconst reservedWords = new Set([\n 'instanceof',\n 'typeof',\n 'return',\n 'throw',\n 'try',\n 'catch',\n 'if',\n 'finally',\n 'else',\n 'in',\n 'of',\n 'var',\n 'let',\n 'const',\n 'for',\n 'delete',\n 'false',\n 'true',\n 'while',\n 'do',\n 'break',\n 'continue',\n 'new',\n 'function',\n 'async',\n 'await',\n 'switch',\n 'case',\n]);\n\nexport const enum VarType {\n let = 'let',\n const = 'const',\n var = 'var',\n}\n\nexport class Scope {\n parent: Scope | null;\n const: { [key: string]: true } = {};\n let: { [key: string]: true } = {};\n var: { [key: string]: true } = {};\n globals: { [key: string]: true };\n allVars: { [key: string]: unknown } & Object;\n functionThis?: Unknown;\n constructor(parent: Scope | null, vars = {}, functionThis?: Unknown) {\n const isFuncScope = functionThis !== undefined || parent === null;\n this.parent = parent;\n this.allVars = vars;\n this.let = isFuncScope ? this.let : keysOnly(vars);\n this.var = isFuncScope ? keysOnly(vars) : this.var;\n this.globals = parent === null ? keysOnly(vars) : {};\n this.functionThis = functionThis;\n }\n\n get(key: string, functionScope = false): Prop {\n const functionThis = this.functionThis;\n if (key === 'this' && functionThis !== undefined) {\n return new Prop({ this: functionThis }, key, true, false, true);\n }\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (this.parent === null || !functionScope || functionThis !== undefined) {\n if (this.globals.hasOwnProperty(key)) {\n return new Prop(functionThis, key, false, true, true);\n }\n if (key in this.allVars && (!(key in {}) || this.allVars.hasOwnProperty(key))) {\n return new Prop(\n this.allVars,\n key,\n this.const.hasOwnProperty(key),\n this.globals.hasOwnProperty(key),\n true\n );\n }\n if (this.parent === null) {\n return new Prop(undefined, key);\n }\n }\n return this.parent.get(key, functionScope);\n }\n\n set(key: string, val: unknown) {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be assigned');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n const prop = this.get(key);\n if (prop.context === undefined) {\n throw new ReferenceError(`Variable '${key}' was not declared.`);\n }\n if (prop.isConst) {\n throw new TypeError(`Cannot assign to const variable '${key}'`);\n }\n if (prop.isGlobal) {\n throw new SandboxError(`Cannot override global variable '${key}'`);\n }\n if (!(prop.context instanceof Object)) throw new SandboxError('Scope is not an object');\n prop.context[prop.prop] = val;\n return prop;\n }\n\n declare(key: string, type: VarType, value: unknown = undefined, isGlobal = false): Prop {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be declared');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (type === 'var' && this.functionThis === undefined && this.parent !== null) {\n return this.parent.declare(key, type, value, isGlobal);\n } else if (\n (this[type].hasOwnProperty(key) && type !== 'const' && !this.globals.hasOwnProperty(key)) ||\n !(key in this.allVars)\n ) {\n if (isGlobal) {\n this.globals[key] = true;\n }\n this[type][key] = true;\n this.allVars[key] = value;\n } else {\n throw new SandboxError(`Identifier '${key}' has already been declared`);\n }\n return new Prop(this.allVars, key, this.const.hasOwnProperty(key), isGlobal);\n }\n}\n\nexport interface IScope {\n [key: string]: any;\n}\n\nexport class FunctionScope implements IScope {}\n\nexport class LocalScope implements IScope {}\n\nexport class SandboxError extends Error {}\n\nexport function isLisp<Type extends Lisp = Lisp>(item: LispItem | LispItem): item is Type {\n return (\n Array.isArray(item) &&\n typeof item[0] === 'number' &&\n item[0] !== LispType.None &&\n item[0] !== LispType.True\n );\n}\n\nexport const enum LispType {\n None,\n Prop,\n StringIndex,\n Let,\n Const,\n Call,\n KeyVal,\n Number,\n Return,\n Assign,\n InlineFunction,\n ArrowFunction,\n CreateArray,\n If,\n IfCase,\n InlineIf,\n InlineIfCase,\n SpreadObject,\n SpreadArray,\n ArrayProp,\n PropOptional,\n CallOptional,\n CreateObject,\n Group,\n Not,\n IncrementBefore,\n IncrementAfter,\n DecrementBefore,\n DecrementAfter,\n And,\n Or,\n StrictNotEqual,\n StrictEqual,\n Plus,\n Var,\n GlobalSymbol,\n Literal,\n Function,\n Loop,\n Try,\n Switch,\n SwitchCase,\n Block,\n Expression,\n Await,\n New,\n Throw,\n Minus,\n Divide,\n Power,\n Multiply,\n Modulus,\n Equal,\n NotEqual,\n SmallerEqualThan,\n LargerEqualThan,\n SmallerThan,\n LargerThan,\n Negative,\n Positive,\n Typeof,\n Delete,\n Instanceof,\n In,\n Inverse,\n SubractEquals,\n AddEquals,\n DivideEquals,\n PowerEquals,\n MultiplyEquals,\n ModulusEquals,\n BitNegateEquals,\n BitAndEquals,\n BitOrEquals,\n UnsignedShiftRightEquals,\n ShiftRightEquals,\n ShiftLeftEquals,\n BitAnd,\n BitOr,\n BitNegate,\n BitShiftLeft,\n BitShiftRight,\n BitUnsignedShiftRight,\n BigInt,\n LiteralIndex,\n RegexIndex,\n LoopAction,\n Void,\n True,\n\n LispEnumSize,\n}\n\nexport class Prop {\n constructor(\n public context: Unknown,\n public prop: string,\n public isConst = false,\n public isGlobal = false,\n public isVariable = false\n ) {}\n\n get<T = unknown>(context: IExecContext): T {\n const ctx = this.context;\n if (ctx === undefined) throw new ReferenceError(`${this.prop} is not defined`);\n if (ctx === null)\n throw new TypeError(`Cannot read properties of null, (reading '${this.prop}')`);\n context.getSubscriptions.forEach((cb) => cb(ctx, this.prop));\n return (ctx as any)[this.prop] as T;\n }\n}\n"],"names":[],"mappings":"AAmFa,MAAA,aAAa,GAAG,SAAS,aAAa,CAAuB,OAAiB,EAAA;IACzF,IAAI,OAAO,KAAM,UAAkB;AAAE,QAAA,OAAO,UAAU,CAAC;AACvD,IAAA,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;KACtB;AACH,EAAqC;MAIxB,WAAW,CAAA;IACtB,WACS,CAAA,GAAa,EACb,SAAqB,EACrB,IAAY,EACZ,gBAAuE,EACvE,gBAGN,EACM,mBAAsF,EACtF,sBAGN,EACM,yBAGN,EACM,KAAoB,EACpB,uBAA8D,EAC9D,QAAiB,EACjB,WAA0B,EAAA;QApB1B,IAAG,CAAA,GAAA,GAAH,GAAG,CAAU;QACb,IAAS,CAAA,SAAA,GAAT,SAAS,CAAY;QACrB,IAAI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AA,GAAG,CAAc,OAAqB,EAAA;AACpC,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,cAAc,CAAC,CAAA,EAAG,IAAI,CAAC,IAAI,CAAiB,eAAA,CAAA,CAAC,CAAC;QAC/E,IAAI,GAAG,KAAK,IAAI;YACd,MAAM,IAAI,SAAS,CAAC,CAAA,0CAAA,EAA6C,IAAI,CAAC,IAAI,CAAI,EAAA,CAAA,CAAC,CAAC;AAClF,QAAA,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,QAAA,OAAQ,GAAW,CAAC,IAAI,CAAC,IAAI,CAAM,CAAC;KACrC;AACF;;;;"}
package/jest.config.js ADDED
@@ -0,0 +1,200 @@
1
+ /**
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ /** @type {import('jest').Config} */
7
+ export default {
8
+ // All imported modules in your tests should be mocked automatically
9
+ // automock: false,
10
+
11
+ // Stop running tests after `n` failures
12
+ // bail: 0,
13
+
14
+ // The directory where Jest should store its cached dependency information
15
+ // cacheDirectory: "C:\\Users\\user\\AppData\\Local\\Temp\\jest",
16
+
17
+ // Automatically clear mock calls, instances, contexts and results before every test
18
+ // clearMocks: false,
19
+
20
+ // Indicates whether the coverage information should be collected while executing the test
21
+ collectCoverage: true,
22
+
23
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
24
+ // collectCoverageFrom: undefined,
25
+
26
+ // The directory where Jest should output its coverage files
27
+ coverageDirectory: "coverage",
28
+
29
+ // An array of regexp pattern strings used to skip coverage collection
30
+ // coveragePathIgnorePatterns: [
31
+ // "\\\\node_modules\\\\"
32
+ // ],
33
+
34
+ // Indicates which provider should be used to instrument code for coverage
35
+ coverageProvider: "v8",
36
+
37
+ // A list of reporter names that Jest uses when writing coverage reports
38
+ // coverageReporters: [
39
+ // "json",
40
+ // "text",
41
+ // "lcov",
42
+ // "clover"
43
+ // ],
44
+
45
+ // An object that configures minimum threshold enforcement for coverage results
46
+ // coverageThreshold: undefined,
47
+
48
+ // A path to a custom dependency extractor
49
+ // dependencyExtractor: undefined,
50
+
51
+ // Make calling deprecated APIs throw helpful error messages
52
+ // errorOnDeprecated: false,
53
+
54
+ // The default configuration for fake timers
55
+ // fakeTimers: {
56
+ // "enableGlobally": false
57
+ // },
58
+
59
+ // Force coverage collection from ignored files using an array of glob patterns
60
+ // forceCoverageMatch: [],
61
+
62
+ // A path to a module which exports an async function that is triggered once before all test suites
63
+ // globalSetup: undefined,
64
+
65
+ // A path to a module which exports an async function that is triggered once after all test suites
66
+ // globalTeardown: undefined,
67
+
68
+ // A set of global variables that need to be available in all test environments
69
+ // globals: {},
70
+
71
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
72
+ // maxWorkers: "50%",
73
+
74
+ // An array of directory names to be searched recursively up from the requiring module's location
75
+ // moduleDirectories: [
76
+ // "node_modules"
77
+ // ],
78
+
79
+ // An array of file extensions your modules use
80
+ moduleFileExtensions: [
81
+ "js",
82
+ "mjs",
83
+ "cjs",
84
+ "jsx",
85
+ "ts",
86
+ "tsx",
87
+ "json",
88
+ "node"
89
+ ],
90
+
91
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
92
+ moduleNameMapper: {
93
+ '^(\\.{1,2}/.*)\\.js$': '$1', // fixes path issues
94
+ },
95
+
96
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
97
+ // modulePathIgnorePatterns: [],
98
+
99
+ // Activates notifications for test results
100
+ // notify: false,
101
+
102
+ // An enum that specifies notification mode. Requires { notify: true }
103
+ // notifyMode: "failure-change",
104
+
105
+ // A preset that is used as a base for Jest's configuration
106
+ preset: 'ts-jest/presets/default-esm',
107
+
108
+ // Run tests from one or more projects
109
+ // projects: undefined,
110
+
111
+ // Use this configuration option to add custom reporters to Jest
112
+ // reporters: undefined,
113
+
114
+ // Automatically reset mock state before every test
115
+ // resetMocks: false,
116
+
117
+ // Reset the module registry before running each individual test
118
+ // resetModules: false,
119
+
120
+ // A path to a custom resolver
121
+ // resolver: undefined,
122
+
123
+ // Automatically restore mock state and implementation before every test
124
+ // restoreMocks: false,
125
+
126
+ // The root directory that Jest should scan for tests and modules within
127
+ // rootDir: undefined,
128
+
129
+ // A list of paths to directories that Jest should use to search for files in
130
+ // roots: [
131
+ // "<rootDir>"
132
+ // ],
133
+
134
+ // Allows you to use a custom runner instead of Jest's default test runner
135
+ // runner: "jest-runner",
136
+
137
+ // The paths to modules that run some code to configure or set up the testing environment before each test
138
+ // setupFiles: [],
139
+
140
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
141
+ // setupFilesAfterEnv: [],
142
+
143
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
144
+ // slowTestThreshold: 5,
145
+
146
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
147
+ // snapshotSerializers: [],
148
+
149
+ // The test environment that will be used for testing
150
+ testEnvironment: 'node',
151
+
152
+ // Options that will be passed to the testEnvironment
153
+ // testEnvironmentOptions: {},
154
+
155
+ // Adds a location field to test results
156
+ // testLocationInResults: false,
157
+
158
+ // The glob patterns Jest uses to detect test files
159
+ // testMatch: [
160
+ // "**/__tests__/**/*.[jt]s?(x)",
161
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
162
+ // ],
163
+
164
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
165
+ // testPathIgnorePatterns: [
166
+ // "\\\\node_modules\\\\"
167
+ // ],
168
+
169
+ // The regexp pattern or array of patterns that Jest uses to detect test files
170
+ // testRegex: [],
171
+
172
+ // This option allows the use of a custom results processor
173
+ // testResultsProcessor: undefined,
174
+
175
+ // This option allows use of a custom test runner
176
+ // testRunner: "jest-circus/runner",
177
+
178
+ // A map from regular expressions to paths to transformers
179
+ transform: {
180
+ '^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: 'tsconfig.jest.json' }],
181
+ },
182
+
183
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
184
+ // transformIgnorePatterns: [
185
+ // "\\\\node_modules\\\\",
186
+ // "\\.pnp\\.[^\\\\]+$"
187
+ // ],
188
+
189
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
190
+ // unmockedModulePathPatterns: undefined,
191
+
192
+ // Indicates whether each individual test should be reported during the run
193
+ // verbose: undefined,
194
+
195
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
196
+ // watchPathIgnorePatterns: [],
197
+
198
+ // Whether to use watchman for file crawling
199
+ // watchman: true,
200
+ };
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@nyariv/sandboxjs",
3
- "version": "0.8.23",
3
+ "version": "0.8.25",
4
4
  "description": "Javascript sandboxing library.",
5
5
  "main": "dist/node/Sandbox.js",
6
6
  "module": "./build/Sandbox.js",
7
- "browser": "./dist/Sandbox.js",
7
+ "browser": "./dist/Sandbox.min.js",
8
8
  "scripts": {
9
- "test": "mocha test/test.js",
10
- "build": "tsc --project tsconfig.json --outDir build --declaration && rollup -c"
9
+ "test": "jest",
10
+ "build": "tsc --project tsconfig.json --outDir build --declaration && rollup -c",
11
+ "lint": "eslint --ignore-path .eslintignore --ext .js,.ts .",
12
+ "lint:fix": "eslint --ignore-path .eslintignore --ext .js,.ts --fix .",
13
+ "format": "prettier --ignore-path .eslintignore --write \"**/*.+(js|ts|json)\""
11
14
  },
12
15
  "repository": {
13
16
  "type": "git",
@@ -23,12 +26,20 @@
23
26
  "@rollup/plugin-node-resolve": "^15.0.1",
24
27
  "@rollup/plugin-terser": "^0.4.0",
25
28
  "@rollup/plugin-typescript": "^11.0.0",
29
+ "@types/jest": "^29.5.14",
30
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
31
+ "@typescript-eslint/parser": "^5.57.0",
26
32
  "chai": "^4.3.7",
33
+ "eslint": "^8.37.0",
34
+ "eslint-config-prettier": "^8.8.0",
35
+ "jest": "^29.7.0",
27
36
  "mocha": "^10.2.0",
28
37
  "node-fetch": "^2",
38
+ "prettier": "^2.8.7",
29
39
  "rollup": "^3.20.2",
30
40
  "rollup-plugin-filesize": "^10.0",
41
+ "ts-jest": "^29.3.2",
31
42
  "tslib": "^2.5.0",
32
- "typescript": "^5.0"
43
+ "typescript": "^5.8.3"
33
44
  }
34
45
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ES2020",
4
+ "target": "ES2020",
5
+ "rootDir": "src/",
6
+ "baseUrl": ".",
7
+ "strict": true,
8
+ "moduleResolution": "node",
9
+ "resolveJsonModule": true,
10
+ "esModuleInterop": true,
11
+ "noImplicitAny": false
12
+ },
13
+ "files": ["src/SandboxExec.ts"],
14
+ "include": ["src/**/*"],
15
+ "exclude": []
16
+ }
@@ -1,34 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v2
15
- - uses: actions/setup-node@v1
16
- with:
17
- node-version: 18
18
- - run: npm ci
19
- - run: npm test
20
-
21
- publish-npm:
22
- needs: build
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v2
26
- - uses: actions/setup-node@v1
27
- with:
28
- node-version: 18
29
- registry-url: https://registry.npmjs.org/
30
- - run: npm ci
31
- - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
34
-
package/rollup.config.mjs DELETED
@@ -1,33 +0,0 @@
1
- import filesize from 'rollup-plugin-filesize';
2
- import resolve from '@rollup/plugin-node-resolve';
3
- import typescript from '@rollup/plugin-typescript';
4
- import terser from "@rollup/plugin-terser";
5
-
6
- const extensions = ['.js', '.ts']
7
-
8
- export default [
9
- {
10
- input: ['src/Sandbox.ts'],
11
- output: [{dir: "dist/node", exports: 'named', format: "cjs"}],
12
- plugins: [
13
- typescript({
14
- "declaration": true,
15
- "declarationDir": "./dist/node"
16
- }),
17
- resolve({ extensions })
18
- ]
19
- },
20
- {
21
- input: ['src/Sandbox.ts'],
22
- output: [{dir: "dist", sourcemap: true, exports: 'named', format: "esm"}],
23
- plugins: [
24
- typescript({
25
- "declaration": true,
26
- "declarationDir": "./dist"
27
- }),
28
- resolve({ extensions }),
29
- terser({keep_fnames: /SandboxFunction/}),
30
- filesize()
31
- ]
32
- },
33
- ]