@cuxt/sandboxjs 0.1.1 → 0.1.4
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 +17 -16
- 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 -1554
- 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 -1558
- 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 -1575
- 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,47 @@
|
|
|
1
|
+
import { VarType, IExecContext, IScope } from './types';
|
|
2
|
+
import { Prop } from './Prop';
|
|
3
|
+
export type Unknown = undefined | null | Record<string | number, unknown>;
|
|
4
|
+
export declare class Scope {
|
|
5
|
+
parent: Scope | null;
|
|
6
|
+
const: {
|
|
7
|
+
[key: string]: true;
|
|
8
|
+
};
|
|
9
|
+
let: {
|
|
10
|
+
[key: string]: true;
|
|
11
|
+
};
|
|
12
|
+
var: {
|
|
13
|
+
[key: string]: true;
|
|
14
|
+
};
|
|
15
|
+
internal: {
|
|
16
|
+
[key: string]: true;
|
|
17
|
+
};
|
|
18
|
+
globals: {
|
|
19
|
+
[key: string]: true;
|
|
20
|
+
};
|
|
21
|
+
allVars: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
} & object;
|
|
24
|
+
internalVars: {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
functionThis?: Unknown;
|
|
28
|
+
constructor(parent: Scope | null, vars?: {}, functionThis?: Unknown);
|
|
29
|
+
get(key: string, internal: boolean): Prop;
|
|
30
|
+
set(key: string, val: unknown, internal: boolean): Prop<unknown>;
|
|
31
|
+
getWhereValScope(key: string, isThis: boolean, internal: boolean): Scope | null;
|
|
32
|
+
getWhereVarScope(key: string, localScope: boolean, internal: boolean): Scope;
|
|
33
|
+
declare(key: string, type: VarType, value: unknown, isGlobal: boolean, internal: boolean): Prop;
|
|
34
|
+
}
|
|
35
|
+
export declare class FunctionScope implements IScope {
|
|
36
|
+
}
|
|
37
|
+
export declare class LocalScope implements IScope {
|
|
38
|
+
}
|
|
39
|
+
export declare const optional: {};
|
|
40
|
+
export declare class DelayedSynchronousResult {
|
|
41
|
+
readonly result: unknown;
|
|
42
|
+
constructor(cb: () => unknown);
|
|
43
|
+
}
|
|
44
|
+
export declare function delaySynchronousResult(cb: () => Promise<unknown>): DelayedSynchronousResult;
|
|
45
|
+
export declare function sanitizeProp(value: unknown, context: IExecContext, cache?: WeakSet<object>): unknown;
|
|
46
|
+
export declare function sanitizeScope(scope: IScope, context: IExecContext, cache?: WeakSet<object>): void;
|
|
47
|
+
export declare function sanitizeScopes(scopes: IScope[], context: IExecContext, cache?: WeakSet<object>): void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { SandboxError } from "./errors.js";
|
|
2
|
+
import { VarType, reservedWords } from "./types.js";
|
|
3
|
+
import { Prop, hasOwnProperty, resolveSandboxProp } from "./Prop.js";
|
|
4
|
+
//#region src/utils/Scope.ts
|
|
5
|
+
function keysOnly(obj) {
|
|
6
|
+
const ret = Object.assign({}, obj);
|
|
7
|
+
for (const key in ret) ret[key] = true;
|
|
8
|
+
return ret;
|
|
9
|
+
}
|
|
10
|
+
var Scope = class {
|
|
11
|
+
constructor(parent, vars = {}, functionThis) {
|
|
12
|
+
this.const = {};
|
|
13
|
+
this.let = {};
|
|
14
|
+
this.var = {};
|
|
15
|
+
this.internal = {};
|
|
16
|
+
this.internalVars = {};
|
|
17
|
+
const isFuncScope = functionThis !== void 0 || parent === null;
|
|
18
|
+
this.parent = parent;
|
|
19
|
+
this.allVars = vars;
|
|
20
|
+
this.let = isFuncScope ? this.let : keysOnly(vars);
|
|
21
|
+
this.var = isFuncScope ? keysOnly(vars) : this.var;
|
|
22
|
+
this.globals = parent === null ? keysOnly(vars) : {};
|
|
23
|
+
this.functionThis = functionThis;
|
|
24
|
+
}
|
|
25
|
+
get(key, internal) {
|
|
26
|
+
const isThis = key === "this";
|
|
27
|
+
const scope = this.getWhereValScope(key, isThis, internal);
|
|
28
|
+
if (scope && isThis) return new Prop({ this: scope.functionThis }, key, false, false, true);
|
|
29
|
+
if (!scope) return new Prop(void 0, key);
|
|
30
|
+
if (internal && scope.internalVars[key]) return new Prop(scope.internalVars, key, false, false, true, true);
|
|
31
|
+
return new Prop(scope.allVars, key, hasOwnProperty(scope.const, key), hasOwnProperty(scope.globals, key), true);
|
|
32
|
+
}
|
|
33
|
+
set(key, val, internal) {
|
|
34
|
+
if (key === "this") throw new SyntaxError("\"this\" cannot be assigned");
|
|
35
|
+
if (reservedWords.has(key)) throw new SyntaxError("Unexepected token '" + key + "'");
|
|
36
|
+
const prop = this.get(key, internal);
|
|
37
|
+
if (prop.context === void 0) throw new ReferenceError(`Variable '${key}' was not declared.`);
|
|
38
|
+
if (prop.context === null) throw new TypeError(`Cannot set properties of null, (setting '${key}')`);
|
|
39
|
+
if (prop.isConst) throw new TypeError(`Assignment to constant variable`);
|
|
40
|
+
if (prop.isGlobal) throw new SandboxError(`Cannot override global variable '${key}'`);
|
|
41
|
+
prop.context[prop.prop] = val;
|
|
42
|
+
return prop;
|
|
43
|
+
}
|
|
44
|
+
getWhereValScope(key, isThis, internal) {
|
|
45
|
+
let scope = this;
|
|
46
|
+
if (isThis) {
|
|
47
|
+
do {
|
|
48
|
+
if (scope.functionThis !== void 0) return scope;
|
|
49
|
+
scope = scope.parent;
|
|
50
|
+
} while (scope !== null);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
do {
|
|
54
|
+
if (internal && key in scope.internalVars && !(key in {} && !hasOwnProperty(scope.internalVars, key))) return scope;
|
|
55
|
+
if (key in scope.allVars && !(key in {} && !hasOwnProperty(scope.allVars, key))) return scope;
|
|
56
|
+
scope = scope.parent;
|
|
57
|
+
} while (scope !== null);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
getWhereVarScope(key, localScope, internal) {
|
|
61
|
+
let scope = this;
|
|
62
|
+
do {
|
|
63
|
+
if (internal && key in scope.internalVars && !(key in {} && !hasOwnProperty(scope.internalVars, key))) return scope;
|
|
64
|
+
if (key in scope.allVars && !(key in {} && !hasOwnProperty(scope.allVars, key))) return scope;
|
|
65
|
+
if (scope.parent === null || localScope || scope.functionThis !== void 0) return scope;
|
|
66
|
+
scope = scope.parent;
|
|
67
|
+
} while (scope !== null);
|
|
68
|
+
return scope;
|
|
69
|
+
}
|
|
70
|
+
declare(key, type, value, isGlobal, internal) {
|
|
71
|
+
if (key === "this") throw new SyntaxError("\"this\" cannot be declared");
|
|
72
|
+
if (reservedWords.has(key)) throw new SyntaxError("Unexepected token '" + key + "'");
|
|
73
|
+
const existingScope = this.getWhereVarScope(key, type !== VarType.var, internal);
|
|
74
|
+
if (type === VarType.var) {
|
|
75
|
+
if (existingScope.var[key]) {
|
|
76
|
+
existingScope.allVars[key] = value;
|
|
77
|
+
if (!isGlobal) delete existingScope.globals[key];
|
|
78
|
+
else existingScope.globals[key] = true;
|
|
79
|
+
return new Prop(existingScope.allVars, key, false, existingScope.globals[key], true);
|
|
80
|
+
} else if (key in existingScope.allVars) throw new SyntaxError(`Identifier '${key}' has already been declared`);
|
|
81
|
+
}
|
|
82
|
+
if (key in existingScope.allVars || key in existingScope.internalVars) throw new SyntaxError(`Identifier '${key}' has already been declared`);
|
|
83
|
+
if (isGlobal) existingScope.globals[key] = true;
|
|
84
|
+
existingScope[type][key] = true;
|
|
85
|
+
if (type === VarType.internal) existingScope.internalVars[key] = value;
|
|
86
|
+
else existingScope.allVars[key] = value;
|
|
87
|
+
return new Prop(type === VarType.internal ? this.internalVars : this.allVars, key, type === VarType.const, isGlobal, true, type === VarType.internal);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var LocalScope = class {};
|
|
91
|
+
var optional = {};
|
|
92
|
+
var DelayedSynchronousResult = class {
|
|
93
|
+
constructor(cb) {
|
|
94
|
+
this.result = cb();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function delaySynchronousResult(cb) {
|
|
98
|
+
return new DelayedSynchronousResult(cb);
|
|
99
|
+
}
|
|
100
|
+
function sanitizeProp(value, context, cache = /* @__PURE__ */ new WeakSet()) {
|
|
101
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return value;
|
|
102
|
+
value = resolveSandboxProp(value, context) || value;
|
|
103
|
+
if (value instanceof Prop) value = value.get(context);
|
|
104
|
+
if (value === optional) return;
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function sanitizeScope(scope, context, cache = /* @__PURE__ */ new WeakSet()) {
|
|
108
|
+
if (cache.has(scope)) return;
|
|
109
|
+
cache.add(scope);
|
|
110
|
+
for (const key in scope) {
|
|
111
|
+
const val = scope[key];
|
|
112
|
+
if (val !== null && typeof val === "object") sanitizeScope(val, context, cache);
|
|
113
|
+
scope[key] = sanitizeProp(val, context);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function sanitizeScopes(scopes, context, cache = /* @__PURE__ */ new WeakSet()) {
|
|
117
|
+
for (const scope of scopes) sanitizeScope(scope, context, cache);
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { DelayedSynchronousResult, LocalScope, Scope, delaySynchronousResult, optional, sanitizeProp, sanitizeScope, sanitizeScopes };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=Scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scope.js","names":[],"sources":["../../../src/utils/Scope.ts"],"sourcesContent":["import { reservedWords, VarType } from './types';\nimport { Prop, resolveSandboxProp, hasOwnProperty } from './Prop';\nimport { SandboxError } from './errors';\nimport type { IExecContext, IScope } from './types';\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\nexport type Unknown = undefined | null | Record<string | number, unknown>;\n\nexport class Scope {\n parent: Scope | null;\n const: { [key: string]: true } = {};\n let: { [key: string]: true } = {};\n var: { [key: string]: true } = {};\n internal: { [key: string]: true } = {};\n globals: { [key: string]: true };\n allVars: { [key: string]: unknown } & object;\n internalVars: { [key: string]: unknown } = {};\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, internal: boolean): Prop {\n const isThis = key === 'this';\n const scope = this.getWhereValScope(key, isThis, internal);\n if (scope && isThis) {\n return new Prop({ this: scope.functionThis }, key, false, false, true);\n }\n if (!scope) {\n return new Prop(undefined, key);\n }\n if (internal && scope.internalVars[key]) {\n return new Prop(scope.internalVars, key, false, false, true, true);\n }\n return new Prop(\n scope.allVars,\n key,\n hasOwnProperty(scope.const, key),\n hasOwnProperty(scope.globals, key),\n true,\n );\n }\n\n set(key: string, val: unknown, internal: boolean) {\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, internal);\n if (prop.context === undefined) {\n throw new ReferenceError(`Variable '${key}' was not declared.`);\n }\n if (prop.context === null) {\n throw new TypeError(`Cannot set properties of null, (setting '${key}')`);\n }\n if (prop.isConst) {\n throw new TypeError(`Assignment to constant variable`);\n }\n if (prop.isGlobal) {\n throw new SandboxError(`Cannot override global variable '${key}'`);\n }\n (prop.context as any)[prop.prop] = val;\n return prop;\n }\n\n getWhereValScope(key: string, isThis: boolean, internal: boolean): Scope | null {\n let scope: Scope = this;\n if (isThis) {\n do {\n if (scope.functionThis !== undefined) return scope;\n scope = scope.parent!;\n } while (scope !== null);\n return null;\n }\n do {\n if (\n internal &&\n key in scope.internalVars &&\n !(key in {} && !hasOwnProperty(scope.internalVars, key))\n ) {\n return scope;\n }\n if (key in scope.allVars && !(key in {} && !hasOwnProperty(scope.allVars, key))) {\n return scope;\n }\n scope = scope.parent!;\n } while (scope !== null);\n return null;\n }\n\n getWhereVarScope(key: string, localScope: boolean, internal: boolean): Scope {\n let scope: Scope = this;\n do {\n if (\n internal &&\n key in scope.internalVars &&\n !(key in {} && !hasOwnProperty(scope.internalVars, key))\n ) {\n return scope;\n }\n if (key in scope.allVars && !(key in {} && !hasOwnProperty(scope.allVars, key))) {\n return scope;\n }\n if (scope.parent === null || localScope || scope.functionThis !== undefined) {\n return scope;\n }\n scope = scope.parent!;\n } while (scope !== null);\n return scope;\n }\n\n declare(key: string, type: VarType, value: unknown, isGlobal: boolean, internal: boolean): Prop {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be declared');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n const existingScope = this.getWhereVarScope(key, type !== VarType.var, internal);\n if (type === VarType.var) {\n if (existingScope.var[key]) {\n existingScope.allVars[key] = value;\n if (!isGlobal) {\n delete existingScope.globals[key];\n } else {\n existingScope.globals[key] = true;\n }\n return new Prop(existingScope.allVars, key, false, existingScope.globals[key], true);\n } else if (key in existingScope.allVars) {\n throw new SyntaxError(`Identifier '${key}' has already been declared`);\n }\n }\n if (key in existingScope.allVars || key in existingScope.internalVars) {\n throw new SyntaxError(`Identifier '${key}' has already been declared`);\n }\n\n if (isGlobal) {\n existingScope.globals[key] = true;\n }\n existingScope[type][key] = true;\n if (type === VarType.internal) {\n existingScope.internalVars[key] = value;\n } else {\n existingScope.allVars[key] = value;\n }\n\n return new Prop(\n type === VarType.internal ? this.internalVars : this.allVars,\n key,\n type === VarType.const,\n isGlobal,\n true,\n type === VarType.internal,\n );\n }\n}\n\nexport class FunctionScope implements IScope {}\n\nexport class LocalScope implements IScope {}\n\nexport const optional = {};\n\nexport class DelayedSynchronousResult {\n readonly result: unknown;\n constructor(cb: () => unknown) {\n this.result = cb();\n }\n}\n\nexport function delaySynchronousResult(cb: () => Promise<unknown>) {\n return new DelayedSynchronousResult(cb);\n}\n\nexport function sanitizeProp(\n value: unknown,\n context: IExecContext,\n cache = new WeakSet<object>(),\n): unknown {\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return value;\n\n value = resolveSandboxProp(value, context) || value;\n\n if (value instanceof Prop) {\n value = value.get(context);\n }\n\n if (value === optional) {\n return undefined;\n }\n\n return value;\n}\n\nexport function sanitizeScope(scope: IScope, context: IExecContext, cache = new WeakSet<object>()) {\n if (cache.has(scope)) return;\n cache.add(scope);\n for (const key in scope) {\n const val = scope[key];\n if (val !== null && typeof val === 'object') {\n sanitizeScope(val, context, cache);\n }\n scope[key] = sanitizeProp(val, context);\n }\n}\n\nexport function sanitizeScopes(\n scopes: IScope[],\n context: IExecContext,\n cache = new WeakSet<object>(),\n) {\n for (const scope of scopes) {\n sanitizeScope(scope, context, cache);\n }\n}\n"],"mappings":";;;;AAKA,SAAS,SAAS,KAAoC;CACpD,MAAM,MAA4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O,OAAO;EACvB,MAAM,MAAM,MAAM;AAClB,MAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,eAAc,KAAK,SAAS,MAAM;AAEpC,QAAM,OAAO,aAAa,KAAK,QAAQ;;;AAI3C,SAAgB,eACd,QACA,SACA,wBAAQ,IAAI,SAAiB,EAC7B;AACA,MAAK,MAAM,SAAS,OAClB,eAAc,OAAO,SAAS,MAAM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SandboxError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class SandboxExecutionQuotaExceededError extends SandboxError {
|
|
4
|
+
}
|
|
5
|
+
export declare class SandboxExecutionTreeError extends SandboxError {
|
|
6
|
+
}
|
|
7
|
+
export declare class SandboxCapabilityError extends SandboxError {
|
|
8
|
+
}
|
|
9
|
+
export declare class SandboxAccessError extends SandboxError {
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/utils/errors.ts
|
|
2
|
+
var SandboxError = class extends Error {};
|
|
3
|
+
var SandboxExecutionQuotaExceededError = class extends SandboxError {};
|
|
4
|
+
var SandboxExecutionTreeError = class extends SandboxError {};
|
|
5
|
+
var SandboxCapabilityError = class extends SandboxError {};
|
|
6
|
+
var SandboxAccessError = class extends SandboxError {};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SandboxAccessError, SandboxCapabilityError, SandboxError, SandboxExecutionQuotaExceededError, SandboxExecutionTreeError };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../../src/utils/errors.ts"],"sourcesContent":["import { IExecContext, IScope } from './types';\n\nexport class SandboxError extends Error {}\n\nexport class SandboxExecutionQuotaExceededError extends SandboxError {}\n\nexport class SandboxExecutionTreeError extends SandboxError {}\n\nexport class SandboxCapabilityError extends SandboxError {}\n\nexport class SandboxAccessError extends SandboxError {}\n"],"mappings":";AAEA,IAAa,eAAb,cAAkC,MAAM;AAExC,IAAa,qCAAb,cAAwD,aAAa;AAErE,IAAa,4BAAb,cAA+C,aAAa;AAE5D,IAAa,yBAAb,cAA4C,aAAa;AAEzD,IAAa,qBAAb,cAAwC,aAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IExecContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if adding `expectTicks` would exceed the tick limit, and throws SandboxExecutionQuotaExceededError
|
|
4
|
+
* (which bypasses user try/catch) if so. Otherwise increments the tick counter.
|
|
5
|
+
*/
|
|
6
|
+
export declare function checkTicksAndThrow(ctx: IExecContext, expectTicks: bigint): void;
|
|
7
|
+
export declare const typedArrayProtos: Set<any>;
|
|
8
|
+
type Factory = (ctx: IExecContext) => Function;
|
|
9
|
+
export declare const DEFAULT_FUNCTION_REPLACEMENTS: Map<Function, Factory>;
|
|
10
|
+
export declare const THIS_DEPENDENT_FUNCTION_REPLACEMENTS: Set<Function>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { SandboxExecutionQuotaExceededError } from "./errors.js";
|
|
2
|
+
//#region src/utils/functionReplacements.ts
|
|
3
|
+
/**
|
|
4
|
+
* Checks if adding `expectTicks` would exceed the tick limit, and throws SandboxExecutionQuotaExceededError
|
|
5
|
+
* (which bypasses user try/catch) if so. Otherwise increments the tick counter.
|
|
6
|
+
*/
|
|
7
|
+
function checkTicksAndThrow(ctx, expectTicks) {
|
|
8
|
+
const { ticks } = ctx.ctx;
|
|
9
|
+
if (ticks.tickLimit !== void 0 && ticks.tickLimit <= ticks.ticks + expectTicks) throw new SandboxExecutionQuotaExceededError("Execution quota exceeded");
|
|
10
|
+
ticks.ticks += expectTicks;
|
|
11
|
+
}
|
|
12
|
+
var typedArrayProtos = new Set([
|
|
13
|
+
Int8Array,
|
|
14
|
+
Uint8Array,
|
|
15
|
+
Uint8ClampedArray,
|
|
16
|
+
Int16Array,
|
|
17
|
+
Uint16Array,
|
|
18
|
+
Int32Array,
|
|
19
|
+
Uint32Array,
|
|
20
|
+
Float32Array,
|
|
21
|
+
Float64Array
|
|
22
|
+
].map((T) => Object.getPrototypeOf(T.prototype)));
|
|
23
|
+
function isTypedArray(obj) {
|
|
24
|
+
return ArrayBuffer.isView(obj) && !(obj instanceof DataView) && typedArrayProtos.has(Object.getPrototypeOf(Object.getPrototypeOf(obj)));
|
|
25
|
+
}
|
|
26
|
+
function makeReplacement(original, getTicks) {
|
|
27
|
+
return (ctx) => function(...args) {
|
|
28
|
+
checkTicksAndThrow(ctx, getTicks(this, args));
|
|
29
|
+
return original.apply(this, args);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var arr = [];
|
|
33
|
+
var arrProto = Array.prototype;
|
|
34
|
+
function arrayTicks(complexity, original) {
|
|
35
|
+
return (thisArg, args) => {
|
|
36
|
+
if (!Array.isArray(thisArg)) return 0n;
|
|
37
|
+
const n = BigInt(thisArg.length);
|
|
38
|
+
switch (complexity) {
|
|
39
|
+
case "one": return 1n;
|
|
40
|
+
case "n": return n;
|
|
41
|
+
case "nlogn": return thisArg.length <= 1 ? 1n : n * BigInt(Math.round(Math.log2(thisArg.length)));
|
|
42
|
+
case "arrs": {
|
|
43
|
+
let ticks = 0n;
|
|
44
|
+
const maxDepth = original === arr.flat ? typeof args[0] === "number" ? args[0] : 1 : 1;
|
|
45
|
+
const recurse = (a, depth = 0) => {
|
|
46
|
+
ticks += BigInt(a.length);
|
|
47
|
+
if (depth >= maxDepth) return;
|
|
48
|
+
for (const item of a) if (Array.isArray(item)) recurse(item, depth + 1);
|
|
49
|
+
};
|
|
50
|
+
recurse(thisArg);
|
|
51
|
+
return ticks;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var arrayReplacementDefs = [
|
|
57
|
+
[arr.push, "one"],
|
|
58
|
+
[arr.pop, "one"],
|
|
59
|
+
[arrProto.at, "one"],
|
|
60
|
+
[arr.fill, "n"],
|
|
61
|
+
[arr.includes, "n"],
|
|
62
|
+
[arr.indexOf, "n"],
|
|
63
|
+
[arr.lastIndexOf, "n"],
|
|
64
|
+
[arr.find, "n"],
|
|
65
|
+
[arr.findIndex, "n"],
|
|
66
|
+
[arrProto.findLast, "n"],
|
|
67
|
+
[arrProto.findLastIndex, "n"],
|
|
68
|
+
[arr.forEach, "n"],
|
|
69
|
+
[arr.map, "n"],
|
|
70
|
+
[arr.filter, "n"],
|
|
71
|
+
[arr.reduce, "n"],
|
|
72
|
+
[arr.reduceRight, "n"],
|
|
73
|
+
[arr.every, "n"],
|
|
74
|
+
[arr.some, "n"],
|
|
75
|
+
[arr.join, "n"],
|
|
76
|
+
[arr.reverse, "n"],
|
|
77
|
+
[arr.shift, "n"],
|
|
78
|
+
[arr.unshift, "n"],
|
|
79
|
+
[arr.splice, "n"],
|
|
80
|
+
[arr.slice, "n"],
|
|
81
|
+
[arr.copyWithin, "n"],
|
|
82
|
+
[arr.entries, "n"],
|
|
83
|
+
[arr.keys, "n"],
|
|
84
|
+
[arr.values, "n"],
|
|
85
|
+
[arrProto.toReversed, "n"],
|
|
86
|
+
[arrProto.toSpliced, "n"],
|
|
87
|
+
[arrProto.with, "n"],
|
|
88
|
+
[arr.toString, "n"],
|
|
89
|
+
[arr.toLocaleString, "n"],
|
|
90
|
+
[arr.sort, "nlogn"],
|
|
91
|
+
[arrProto.toSorted, "nlogn"],
|
|
92
|
+
[arr.flat, "arrs"],
|
|
93
|
+
[arr.flatMap, "arrs"],
|
|
94
|
+
[arr.concat, "arrs"]
|
|
95
|
+
];
|
|
96
|
+
var str = "";
|
|
97
|
+
var strProto = String.prototype;
|
|
98
|
+
function stringTicks(complexity) {
|
|
99
|
+
return (thisArg) => {
|
|
100
|
+
if (typeof thisArg !== "string") return 0n;
|
|
101
|
+
return complexity === "one" ? 1n : BigInt(thisArg.length);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
var stringReplacementDefs = [
|
|
105
|
+
[str.charAt, "one"],
|
|
106
|
+
[str.charCodeAt, "one"],
|
|
107
|
+
[str.codePointAt, "one"],
|
|
108
|
+
[strProto.at, "one"],
|
|
109
|
+
[str.indexOf, "n"],
|
|
110
|
+
[str.lastIndexOf, "n"],
|
|
111
|
+
[str.includes, "n"],
|
|
112
|
+
[str.startsWith, "n"],
|
|
113
|
+
[str.endsWith, "n"],
|
|
114
|
+
[str.slice, "n"],
|
|
115
|
+
[str.substring, "n"],
|
|
116
|
+
[str.padStart, "n"],
|
|
117
|
+
[str.padEnd, "n"],
|
|
118
|
+
[str.repeat, "n"],
|
|
119
|
+
[str.split, "n"],
|
|
120
|
+
[str.replace, "n"],
|
|
121
|
+
[strProto.replaceAll, "n"],
|
|
122
|
+
[str.match, "n"],
|
|
123
|
+
[str.matchAll, "n"],
|
|
124
|
+
[str.search, "n"],
|
|
125
|
+
[str.trim, "n"],
|
|
126
|
+
[str.trimStart, "n"],
|
|
127
|
+
[str.trimEnd, "n"],
|
|
128
|
+
[str.toLowerCase, "n"],
|
|
129
|
+
[str.toUpperCase, "n"],
|
|
130
|
+
[str.toLocaleLowerCase, "n"],
|
|
131
|
+
[str.toLocaleUpperCase, "n"],
|
|
132
|
+
[str.normalize, "n"],
|
|
133
|
+
[str.concat, "n"],
|
|
134
|
+
[str.toString, "n"],
|
|
135
|
+
[str.valueOf, "n"]
|
|
136
|
+
];
|
|
137
|
+
var _map = /* @__PURE__ */ new Map();
|
|
138
|
+
var mapReplacementDefs = [
|
|
139
|
+
[_map.get, "one"],
|
|
140
|
+
[_map.set, "one"],
|
|
141
|
+
[_map.has, "one"],
|
|
142
|
+
[_map.delete, "one"],
|
|
143
|
+
[_map.keys, "n"],
|
|
144
|
+
[_map.values, "n"],
|
|
145
|
+
[_map.entries, "n"],
|
|
146
|
+
[_map.forEach, "n"],
|
|
147
|
+
[_map.clear, "n"]
|
|
148
|
+
];
|
|
149
|
+
function mapTicks(complexity) {
|
|
150
|
+
return (thisArg) => {
|
|
151
|
+
if (!(thisArg instanceof Map)) return 0n;
|
|
152
|
+
return complexity === "one" ? 1n : BigInt(thisArg.size);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
var _set = /* @__PURE__ */ new Set();
|
|
156
|
+
var setReplacementDefs = [
|
|
157
|
+
[_set.add, "one"],
|
|
158
|
+
[_set.has, "one"],
|
|
159
|
+
[_set.delete, "one"],
|
|
160
|
+
[_set.values, "n"],
|
|
161
|
+
[_set.keys, "n"],
|
|
162
|
+
[_set.entries, "n"],
|
|
163
|
+
[_set.forEach, "n"],
|
|
164
|
+
[_set.clear, "n"]
|
|
165
|
+
];
|
|
166
|
+
function setTicks(complexity) {
|
|
167
|
+
return (thisArg) => {
|
|
168
|
+
if (!(thisArg instanceof Set)) return 0n;
|
|
169
|
+
return complexity === "one" ? 1n : BigInt(thisArg.size);
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
var typedArrayReplacementDefs = [];
|
|
173
|
+
for (const proto of typedArrayProtos) {
|
|
174
|
+
if (proto.at) typedArrayReplacementDefs.push([proto.at, "one"]);
|
|
175
|
+
if (proto.set) typedArrayReplacementDefs.push([proto.set, "one"]);
|
|
176
|
+
for (const m of [
|
|
177
|
+
"fill",
|
|
178
|
+
"find",
|
|
179
|
+
"findIndex",
|
|
180
|
+
"findLast",
|
|
181
|
+
"findLastIndex",
|
|
182
|
+
"includes",
|
|
183
|
+
"indexOf",
|
|
184
|
+
"lastIndexOf",
|
|
185
|
+
"forEach",
|
|
186
|
+
"map",
|
|
187
|
+
"filter",
|
|
188
|
+
"reduce",
|
|
189
|
+
"reduceRight",
|
|
190
|
+
"every",
|
|
191
|
+
"some",
|
|
192
|
+
"join",
|
|
193
|
+
"reverse",
|
|
194
|
+
"slice",
|
|
195
|
+
"subarray",
|
|
196
|
+
"copyWithin",
|
|
197
|
+
"entries",
|
|
198
|
+
"keys",
|
|
199
|
+
"values",
|
|
200
|
+
"toReversed",
|
|
201
|
+
"with",
|
|
202
|
+
"toString",
|
|
203
|
+
"toLocaleString"
|
|
204
|
+
]) if (proto[m]) typedArrayReplacementDefs.push([proto[m], "n"]);
|
|
205
|
+
if (proto.sort) typedArrayReplacementDefs.push([proto.sort, "nlogn"]);
|
|
206
|
+
if (proto.toSorted) typedArrayReplacementDefs.push([proto.toSorted, "nlogn"]);
|
|
207
|
+
}
|
|
208
|
+
function typedArrayTicks(complexity) {
|
|
209
|
+
return (thisArg) => {
|
|
210
|
+
if (!isTypedArray(thisArg)) return 0n;
|
|
211
|
+
const n = BigInt(thisArg.length);
|
|
212
|
+
switch (complexity) {
|
|
213
|
+
case "one": return 1n;
|
|
214
|
+
case "n": return n;
|
|
215
|
+
case "nlogn": return thisArg.length <= 1 ? 1n : n * BigInt(Math.round(Math.log2(thisArg.length)));
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
var mathReplacementDefs = [
|
|
220
|
+
[Math.max],
|
|
221
|
+
[Math.min],
|
|
222
|
+
[Math.hypot]
|
|
223
|
+
];
|
|
224
|
+
var _re = /x/;
|
|
225
|
+
var regexpReplacementDefs = [
|
|
226
|
+
_re.exec,
|
|
227
|
+
_re.test,
|
|
228
|
+
_re[Symbol.match],
|
|
229
|
+
_re[Symbol.matchAll],
|
|
230
|
+
_re[Symbol.replace],
|
|
231
|
+
_re[Symbol.search],
|
|
232
|
+
_re[Symbol.split]
|
|
233
|
+
];
|
|
234
|
+
var promiseReplacementDefs = [
|
|
235
|
+
Promise.all,
|
|
236
|
+
Promise.allSettled,
|
|
237
|
+
Promise.race,
|
|
238
|
+
...typeof Promise.any === "function" ? [Promise.any] : []
|
|
239
|
+
];
|
|
240
|
+
var objectReplacementDefs = [
|
|
241
|
+
[Object.prototype.hasOwnProperty, "one"],
|
|
242
|
+
[Object.prototype.propertyIsEnumerable, "one"],
|
|
243
|
+
[Object.prototype.isPrototypeOf, "one"],
|
|
244
|
+
[Object.create, "one"],
|
|
245
|
+
[Object.getPrototypeOf, "one"],
|
|
246
|
+
[Object.setPrototypeOf, "one"],
|
|
247
|
+
[Object.is, "one"],
|
|
248
|
+
[Object.defineProperty, "one"],
|
|
249
|
+
[Object.getOwnPropertyDescriptor, "one"],
|
|
250
|
+
[Object.isExtensible, "one"],
|
|
251
|
+
[Object.preventExtensions, "one"],
|
|
252
|
+
[Object.keys, "n"],
|
|
253
|
+
[Object.values, "n"],
|
|
254
|
+
[Object.entries, "n"],
|
|
255
|
+
[Object.assign, "n"],
|
|
256
|
+
[Object.fromEntries, "n"],
|
|
257
|
+
[Object.getOwnPropertyNames, "n"],
|
|
258
|
+
[Object.getOwnPropertySymbols, "n"],
|
|
259
|
+
[Object.getOwnPropertyDescriptors, "n"],
|
|
260
|
+
[Object.freeze, "n"],
|
|
261
|
+
[Object.seal, "n"],
|
|
262
|
+
[Object.isFrozen, "n"],
|
|
263
|
+
[Object.isSealed, "n"]
|
|
264
|
+
];
|
|
265
|
+
function objectTicks(complexity, isStatic) {
|
|
266
|
+
return (thisArg, args) => {
|
|
267
|
+
if (complexity === "one") return 1n;
|
|
268
|
+
const target = isStatic ? args[0] : thisArg;
|
|
269
|
+
if (target !== null && typeof target === "object") return BigInt(Object.keys(target).length);
|
|
270
|
+
return 1n;
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
var staticObjectMethods = new Set([
|
|
274
|
+
Object.keys,
|
|
275
|
+
Object.values,
|
|
276
|
+
Object.entries,
|
|
277
|
+
Object.assign,
|
|
278
|
+
Object.fromEntries,
|
|
279
|
+
Object.getOwnPropertyNames,
|
|
280
|
+
Object.getOwnPropertySymbols,
|
|
281
|
+
Object.getOwnPropertyDescriptors,
|
|
282
|
+
Object.freeze,
|
|
283
|
+
Object.seal,
|
|
284
|
+
Object.isFrozen,
|
|
285
|
+
Object.isSealed
|
|
286
|
+
]);
|
|
287
|
+
var DEFAULT_FUNCTION_REPLACEMENTS = /* @__PURE__ */ new Map();
|
|
288
|
+
var THIS_DEPENDENT_FUNCTION_REPLACEMENTS = /* @__PURE__ */ new Set();
|
|
289
|
+
for (const [original, complexity] of arrayReplacementDefs) {
|
|
290
|
+
if (!original) continue;
|
|
291
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, arrayTicks(complexity, original)));
|
|
292
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
293
|
+
}
|
|
294
|
+
for (const [original, complexity] of stringReplacementDefs) {
|
|
295
|
+
if (!original) continue;
|
|
296
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, stringTicks(complexity)));
|
|
297
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
298
|
+
}
|
|
299
|
+
for (const [original, complexity] of mapReplacementDefs) {
|
|
300
|
+
if (!original) continue;
|
|
301
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, mapTicks(complexity)));
|
|
302
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
303
|
+
}
|
|
304
|
+
for (const [original, complexity] of setReplacementDefs) {
|
|
305
|
+
if (!original) continue;
|
|
306
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, setTicks(complexity)));
|
|
307
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
308
|
+
}
|
|
309
|
+
for (const [original, complexity] of typedArrayReplacementDefs) {
|
|
310
|
+
if (!original) continue;
|
|
311
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, typedArrayTicks(complexity)));
|
|
312
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
313
|
+
}
|
|
314
|
+
for (const [original] of mathReplacementDefs) {
|
|
315
|
+
if (!original) continue;
|
|
316
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, (_thisArg, args) => BigInt(args.length)));
|
|
317
|
+
}
|
|
318
|
+
for (const original of [JSON.parse, JSON.stringify]) DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, (_thisArg, args) => {
|
|
319
|
+
const target = args[0];
|
|
320
|
+
if (typeof target === "string") return BigInt(target.length);
|
|
321
|
+
if (target !== null && typeof target === "object") return BigInt(Object.keys(target).length);
|
|
322
|
+
return 1n;
|
|
323
|
+
}));
|
|
324
|
+
for (const original of regexpReplacementDefs) {
|
|
325
|
+
if (!original) continue;
|
|
326
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, (_thisArg, args) => {
|
|
327
|
+
const input = args[0];
|
|
328
|
+
return typeof input === "string" ? BigInt(input.length) : 1n;
|
|
329
|
+
}));
|
|
330
|
+
THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
331
|
+
}
|
|
332
|
+
for (const original of promiseReplacementDefs) {
|
|
333
|
+
if (!original) continue;
|
|
334
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, (_thisArg, args) => {
|
|
335
|
+
const iterable = args[0];
|
|
336
|
+
return Array.isArray(iterable) ? BigInt(iterable.length) : 0n;
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
for (const [original, complexity] of objectReplacementDefs) {
|
|
340
|
+
if (!original) continue;
|
|
341
|
+
const isStatic = staticObjectMethods.has(original);
|
|
342
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, objectTicks(complexity, isStatic)));
|
|
343
|
+
if (!isStatic) THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);
|
|
344
|
+
}
|
|
345
|
+
if (Array.from) DEFAULT_FUNCTION_REPLACEMENTS.set(Array.from, makeReplacement(Array.from, (_thisArg, args) => {
|
|
346
|
+
const source = args[0];
|
|
347
|
+
if (source != null && typeof source.length === "number") return BigInt(source.length);
|
|
348
|
+
return 0n;
|
|
349
|
+
}));
|
|
350
|
+
if (typeof Array.fromAsync === "function") {
|
|
351
|
+
const fromAsync = Array.fromAsync;
|
|
352
|
+
DEFAULT_FUNCTION_REPLACEMENTS.set(fromAsync, makeReplacement(fromAsync, (_thisArg, args) => {
|
|
353
|
+
const source = args[0];
|
|
354
|
+
if (source != null && typeof source.length === "number") return BigInt(source.length);
|
|
355
|
+
return 0n;
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
export { DEFAULT_FUNCTION_REPLACEMENTS, THIS_DEPENDENT_FUNCTION_REPLACEMENTS, checkTicksAndThrow, typedArrayProtos };
|
|
360
|
+
|
|
361
|
+
//# sourceMappingURL=functionReplacements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functionReplacements.js","names":[],"sources":["../../../src/utils/functionReplacements.ts"],"sourcesContent":["import type { IContext, IExecContext } from './types';\nimport { SandboxExecutionQuotaExceededError } from './errors';\n\n/**\n * Checks if adding `expectTicks` would exceed the tick limit, and throws SandboxExecutionQuotaExceededError\n * (which bypasses user try/catch) if so. Otherwise increments the tick counter.\n */\nexport function checkTicksAndThrow(ctx: IExecContext, expectTicks: bigint): void {\n const { ticks } = ctx.ctx;\n if (ticks.tickLimit !== undefined && ticks.tickLimit <= ticks.ticks + expectTicks) {\n throw new SandboxExecutionQuotaExceededError('Execution quota exceeded');\n }\n ticks.ticks += expectTicks;\n}\n\n// ---------------------------------------------------------------------------\n// TypedArray shared prototype detection (mirrors call.ts)\n// ---------------------------------------------------------------------------\n\nconst _typedArrayCtors = [\n Int8Array,\n Uint8Array,\n Uint8ClampedArray,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array,\n];\nexport const typedArrayProtos = new Set(\n _typedArrayCtors.map((T) => Object.getPrototypeOf(T.prototype) as any),\n);\n\nfunction isTypedArray(obj: unknown): obj is { length: number } {\n return (\n ArrayBuffer.isView(obj) &&\n !(obj instanceof DataView) &&\n typedArrayProtos.has(Object.getPrototypeOf(Object.getPrototypeOf(obj)))\n );\n}\n\n// ---------------------------------------------------------------------------\n// Helpers to build replacements\n// ---------------------------------------------------------------------------\n\ntype Factory = (ctx: IExecContext) => Function;\n\nfunction makeReplacement(\n original: Function,\n getTicks: (thisArg: unknown, args: unknown[]) => bigint,\n): Factory {\n return (ctx: IExecContext) =>\n function (this: unknown, ...args: unknown[]) {\n checkTicksAndThrow(ctx, getTicks(this, args));\n return (original as any).apply(this, args);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Array replacements\n// ---------------------------------------------------------------------------\n\nconst arr: any[] = [];\nconst arrProto = Array.prototype as any;\n\nfunction arrayTicks(\n complexity: 'one' | 'n' | 'nlogn' | 'arrs',\n original: Function,\n): (thisArg: unknown, args: unknown[]) => bigint {\n return (thisArg, args) => {\n if (!Array.isArray(thisArg)) return 0n;\n const n = BigInt(thisArg.length);\n switch (complexity) {\n case 'one':\n return 1n;\n case 'n':\n return n;\n case 'nlogn':\n return thisArg.length <= 1 ? 1n : n * BigInt(Math.round(Math.log2(thisArg.length)));\n case 'arrs': {\n let ticks = 0n;\n const maxDepth = original === arr.flat ? (typeof args[0] === 'number' ? args[0] : 1) : 1;\n const recurse = (a: unknown[], depth = 0) => {\n ticks += BigInt(a.length);\n if (depth >= maxDepth) return;\n for (const item of a) {\n if (Array.isArray(item)) recurse(item, depth + 1);\n }\n };\n recurse(thisArg);\n return ticks;\n }\n }\n };\n}\n\nconst arrayReplacementDefs: [Function, 'one' | 'n' | 'nlogn' | 'arrs'][] = [\n // O(1)\n [arr.push, 'one'],\n [arr.pop, 'one'],\n [arrProto.at, 'one'],\n // O(n)\n [arr.fill, 'n'],\n [arr.includes, 'n'],\n [arr.indexOf, 'n'],\n [arr.lastIndexOf, 'n'],\n [arr.find, 'n'],\n [arr.findIndex, 'n'],\n [arrProto.findLast, 'n'],\n [arrProto.findLastIndex, 'n'],\n [arr.forEach, 'n'],\n [arr.map, 'n'],\n [arr.filter, 'n'],\n [arr.reduce, 'n'],\n [arr.reduceRight, 'n'],\n [arr.every, 'n'],\n [arr.some, 'n'],\n [arr.join, 'n'],\n [arr.reverse, 'n'],\n [arr.shift, 'n'],\n [arr.unshift, 'n'],\n [arr.splice, 'n'],\n [arr.slice, 'n'],\n [arr.copyWithin, 'n'],\n [arr.entries, 'n'],\n [arr.keys, 'n'],\n [arr.values, 'n'],\n [arrProto.toReversed, 'n'],\n [arrProto.toSpliced, 'n'],\n [arrProto.with, 'n'],\n [arr.toString, 'n'],\n [arr.toLocaleString, 'n'],\n // O(n log n)\n [arr.sort, 'nlogn'],\n [arrProto.toSorted, 'nlogn'],\n // O(n) across arrays\n [arr.flat, 'arrs'],\n [arr.flatMap, 'arrs'],\n [arr.concat, 'arrs'],\n];\n\n// ---------------------------------------------------------------------------\n// String replacements\n// ---------------------------------------------------------------------------\n\nconst str = '';\nconst strProto = String.prototype as any;\n\nfunction stringTicks(complexity: 'one' | 'n'): (thisArg: unknown, _args: unknown[]) => bigint {\n return (thisArg) => {\n if (typeof thisArg !== 'string') return 0n;\n return complexity === 'one' ? 1n : BigInt(thisArg.length);\n };\n}\n\nconst stringReplacementDefs: [Function, 'one' | 'n'][] = [\n // O(1)\n [str.charAt, 'one'],\n [str.charCodeAt, 'one'],\n [str.codePointAt, 'one'],\n [strProto.at, 'one'],\n // O(n)\n [str.indexOf, 'n'],\n [str.lastIndexOf, 'n'],\n [str.includes, 'n'],\n [str.startsWith, 'n'],\n [str.endsWith, 'n'],\n [str.slice, 'n'],\n [str.substring, 'n'],\n [str.padStart, 'n'],\n [str.padEnd, 'n'],\n [str.repeat, 'n'],\n [str.split, 'n'],\n [str.replace, 'n'],\n [strProto.replaceAll, 'n'],\n [str.match, 'n'],\n [str.matchAll, 'n'],\n [str.search, 'n'],\n [str.trim, 'n'],\n [str.trimStart, 'n'],\n [str.trimEnd, 'n'],\n [str.toLowerCase, 'n'],\n [str.toUpperCase, 'n'],\n [str.toLocaleLowerCase, 'n'],\n [str.toLocaleUpperCase, 'n'],\n [str.normalize, 'n'],\n [str.concat, 'n'],\n [str.toString, 'n'],\n [str.valueOf, 'n'],\n];\n\n// ---------------------------------------------------------------------------\n// Map replacements\n// ---------------------------------------------------------------------------\n\nconst _map = new Map<never, never>();\n\nconst mapReplacementDefs: [Function, 'one' | 'n'][] = [\n [_map.get, 'one'],\n [_map.set, 'one'],\n [_map.has, 'one'],\n [_map.delete, 'one'],\n [_map.keys, 'n'],\n [_map.values, 'n'],\n [_map.entries, 'n'],\n [_map.forEach, 'n'],\n [_map.clear, 'n'],\n];\n\nfunction mapTicks(complexity: 'one' | 'n'): (thisArg: unknown, _args: unknown[]) => bigint {\n return (thisArg) => {\n if (!(thisArg instanceof Map)) return 0n;\n return complexity === 'one' ? 1n : BigInt(thisArg.size);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Set replacements\n// ---------------------------------------------------------------------------\n\nconst _set = new Set<never>();\n\nconst setReplacementDefs: [Function, 'one' | 'n'][] = [\n [_set.add, 'one'],\n [_set.has, 'one'],\n [_set.delete, 'one'],\n [_set.values, 'n'],\n [_set.keys, 'n'],\n [_set.entries, 'n'],\n [_set.forEach, 'n'],\n [_set.clear, 'n'],\n];\n\nfunction setTicks(complexity: 'one' | 'n'): (thisArg: unknown, _args: unknown[]) => bigint {\n return (thisArg) => {\n if (!(thisArg instanceof Set)) return 0n;\n return complexity === 'one' ? 1n : BigInt(thisArg.size);\n };\n}\n\n// ---------------------------------------------------------------------------\n// TypedArray replacements\n// ---------------------------------------------------------------------------\n\nconst typedArrayReplacementDefs: [Function, 'one' | 'n' | 'nlogn'][] = [];\nfor (const proto of typedArrayProtos) {\n if (proto.at) typedArrayReplacementDefs.push([proto.at, 'one']);\n if (proto.set) typedArrayReplacementDefs.push([proto.set, 'one']);\n const nMethods = [\n 'fill',\n 'find',\n 'findIndex',\n 'findLast',\n 'findLastIndex',\n 'includes',\n 'indexOf',\n 'lastIndexOf',\n 'forEach',\n 'map',\n 'filter',\n 'reduce',\n 'reduceRight',\n 'every',\n 'some',\n 'join',\n 'reverse',\n 'slice',\n 'subarray',\n 'copyWithin',\n 'entries',\n 'keys',\n 'values',\n 'toReversed',\n 'with',\n 'toString',\n 'toLocaleString',\n ] as const;\n for (const m of nMethods) {\n if (proto[m]) typedArrayReplacementDefs.push([proto[m], 'n']);\n }\n if (proto.sort) typedArrayReplacementDefs.push([proto.sort, 'nlogn']);\n if (proto.toSorted) typedArrayReplacementDefs.push([proto.toSorted, 'nlogn']);\n}\n\nfunction typedArrayTicks(\n complexity: 'one' | 'n' | 'nlogn',\n): (thisArg: unknown, _args: unknown[]) => bigint {\n return (thisArg) => {\n if (!isTypedArray(thisArg)) return 0n;\n const n = BigInt(thisArg.length);\n switch (complexity) {\n case 'one':\n return 1n;\n case 'n':\n return n;\n case 'nlogn':\n return (thisArg as any).length <= 1\n ? 1n\n : n * BigInt(Math.round(Math.log2((thisArg as any).length)));\n }\n };\n}\n\n// ---------------------------------------------------------------------------\n// Math replacements\n// ---------------------------------------------------------------------------\n\nconst mathReplacementDefs: [Function][] = [[Math.max], [Math.min], [Math.hypot]];\n\n// ---------------------------------------------------------------------------\n// JSON replacements\n// ---------------------------------------------------------------------------\n\n// (JSON.stringify with subscription traversal is handled separately in LispType.Call)\n\n// ---------------------------------------------------------------------------\n// RegExp replacements\n// ---------------------------------------------------------------------------\n\nconst _re = /x/;\n\nconst regexpReplacementDefs: Function[] = [\n _re.exec,\n _re.test,\n (_re as any)[Symbol.match],\n (_re as any)[Symbol.matchAll],\n (_re as any)[Symbol.replace],\n (_re as any)[Symbol.search],\n (_re as any)[Symbol.split],\n];\n\n// ---------------------------------------------------------------------------\n// Promise replacements\n// ---------------------------------------------------------------------------\n\nconst promiseReplacementDefs: Function[] = [\n Promise.all,\n Promise.allSettled,\n Promise.race,\n ...(typeof (Promise as any).any === 'function' ? [(Promise as any).any] : []),\n];\n\n// ---------------------------------------------------------------------------\n// Object replacements\n// ---------------------------------------------------------------------------\n\nconst objectReplacementDefs: [Function, 'one' | 'n'][] = [\n [Object.prototype.hasOwnProperty, 'one'],\n [Object.prototype.propertyIsEnumerable, 'one'],\n [Object.prototype.isPrototypeOf, 'one'],\n [Object.create, 'one'],\n [Object.getPrototypeOf, 'one'],\n [Object.setPrototypeOf, 'one'],\n [Object.is, 'one'],\n [Object.defineProperty, 'one'],\n [Object.getOwnPropertyDescriptor, 'one'],\n [Object.isExtensible, 'one'],\n [Object.preventExtensions, 'one'],\n [Object.keys, 'n'],\n [Object.values, 'n'],\n [Object.entries, 'n'],\n [Object.assign, 'n'],\n [Object.fromEntries, 'n'],\n [Object.getOwnPropertyNames, 'n'],\n [Object.getOwnPropertySymbols, 'n'],\n [Object.getOwnPropertyDescriptors, 'n'],\n [Object.freeze, 'n'],\n [Object.seal, 'n'],\n [Object.isFrozen, 'n'],\n [Object.isSealed, 'n'],\n];\n\nfunction objectTicks(\n complexity: 'one' | 'n',\n isStatic: boolean,\n): (thisArg: unknown, args: unknown[]) => bigint {\n return (thisArg, args) => {\n if (complexity === 'one') return 1n;\n const target = isStatic ? args[0] : thisArg;\n if (target !== null && typeof target === 'object')\n return BigInt(Object.keys(target as object).length);\n return 1n;\n };\n}\n\n// Static Object methods whose tick count is based on args[0] key count\nconst staticObjectMethods = new Set<Function>([\n Object.keys,\n Object.values,\n Object.entries,\n Object.assign,\n Object.fromEntries,\n Object.getOwnPropertyNames,\n Object.getOwnPropertySymbols,\n Object.getOwnPropertyDescriptors,\n Object.freeze,\n Object.seal,\n Object.isFrozen,\n Object.isSealed,\n]);\n\n// ---------------------------------------------------------------------------\n// Array.from / Array.fromAsync\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Build the default replacements map\n// ---------------------------------------------------------------------------\n\nexport const DEFAULT_FUNCTION_REPLACEMENTS = new Map<Function, Factory>();\nexport const THIS_DEPENDENT_FUNCTION_REPLACEMENTS = new Set<Function>();\n\n// Array\nfor (const [original, complexity] of arrayReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, arrayTicks(complexity, original)),\n );\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// String\nfor (const [original, complexity] of stringReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, stringTicks(complexity)));\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// Map\nfor (const [original, complexity] of mapReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, mapTicks(complexity)));\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// Set\nfor (const [original, complexity] of setReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(original, makeReplacement(original, setTicks(complexity)));\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// TypedArray\nfor (const [original, complexity] of typedArrayReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, typedArrayTicks(complexity)),\n );\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// Math — O(n) on arg count\nfor (const [original] of mathReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, (_thisArg, args) => BigInt(args.length)),\n );\n}\n\n// JSON — O(n) on string/object size\nfor (const original of [JSON.parse, JSON.stringify]) {\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, (_thisArg, args) => {\n const target = args[0];\n if (typeof target === 'string') return BigInt(target.length);\n if (target !== null && typeof target === 'object')\n return BigInt(Object.keys(target as object).length);\n return 1n;\n }),\n );\n}\n\n// RegExp — O(n) on input string length\nfor (const original of regexpReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, (_thisArg, args) => {\n const input = args[0];\n return typeof input === 'string' ? BigInt(input.length) : 1n;\n }),\n );\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n}\n\n// Promise.all/allSettled/race/any — O(n) on iterable length\nfor (const original of promiseReplacementDefs) {\n if (!original) continue;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, (_thisArg, args) => {\n const iterable = args[0];\n return Array.isArray(iterable) ? BigInt(iterable.length) : 0n;\n }),\n );\n}\n\n// Object static & instance methods\nfor (const [original, complexity] of objectReplacementDefs) {\n if (!original) continue;\n const isStatic = staticObjectMethods.has(original);\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n original,\n makeReplacement(original, objectTicks(complexity, isStatic)),\n );\n if (!isStatic) {\n THIS_DEPENDENT_FUNCTION_REPLACEMENTS.add(original);\n }\n}\n\n// Array.from — O(n) on source length\nif (Array.from) {\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n Array.from,\n makeReplacement(Array.from, (_thisArg, args) => {\n const source = args[0];\n if (source != null && typeof (source as any).length === 'number')\n return BigInt((source as any).length);\n return 0n;\n }),\n );\n}\n\n// Array.fromAsync — O(n) on source length (if available)\nif (typeof (Array as any).fromAsync === 'function') {\n const fromAsync = (Array as any).fromAsync as Function;\n DEFAULT_FUNCTION_REPLACEMENTS.set(\n fromAsync,\n makeReplacement(fromAsync, (_thisArg, args) => {\n const source = args[0];\n if (source != null && typeof (source as any).length === 'number')\n return BigInt((source as any).length);\n return 0n;\n }),\n );\n}\n"],"mappings":";;;;;;AAOA,SAAgB,mBAAmB,KAAmB,aAA2B;CAC/E,MAAM,EAAE,UAAU,IAAI;AACtB,KAAI,MAAM,cAAc,KAAA,KAAa,MAAM,aAAa,MAAM,QAAQ,YACpE,OAAM,IAAI,mCAAmC,2BAA2B;AAE1E,OAAM,SAAS;;AAkBjB,IAAa,mBAAmB,IAAI,IAXX;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAEkB,KAAK,MAAM,OAAO,eAAe,EAAE,UAAU,CAAQ,CACvE;AAED,SAAS,aAAa,KAAyC;AAC7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