UNPKG

@mariozechner/jailjs

Version:

Lightweight JavaScript interpreter for isolated execution. For plugins, user scripts, and browser extensions. Not for adversarial code - use SandboxJS or isolated-vm for that.

69 lines 1.69 kB
import type * as t from "@babel/types"; /** * Complete ES5 JavaScript interpreter with sandboxing support */ export interface InterpreterOptions { maxOps?: number; /** * Optional parser function for eval() support. * If not provided, eval() will throw an error. * Signature: (code: string) => Program AST node */ parse?: (code: string) => t.Program; } export declare class Interpreter { private globalScope; private opCount; private maxOps; private parse?; constructor(globalEnv?: Record<string, any>, options?: InterpreterOptions); /** * Evaluate a pre-parsed AST */ evaluate(ast: t.Program): any; /** * Hoist function and var declarations to the top of their scope */ private hoistDeclarations; /** * Create a new scope */ private createScope; /** * Get variable from scope chain */ private getVar; /** * Set variable in scope chain */ private setVar; /** * Declare variable with var semantics (function-scoped hoisting) */ private declareVar; /** * Declare let/const variable (block-scoped) */ private declareLet; /** * Check operation count to prevent infinite loops */ private checkOps; /** * Main evaluation function - handles all AST node types */ private evalNode; /** * Apply compound assignment operators */ private applyAssignmentOperator; /** * Create an interpreted function */ private createFunction; /** * Call an interpreted function */ private callFunction; } //# sourceMappingURL=interpreter.d.ts.map