UNPKG

2.48 kBTypeScriptView Raw
1declare module "vm" {
2 interface Context {
3 [key: string]: any;
4 }
5 interface BaseOptions {
6 /**
7 * Specifies the filename used in stack traces produced by this script.
8 * Default: `''`.
9 */
10 filename?: string;
11 /**
12 * Specifies the line number offset that is displayed in stack traces produced by this script.
13 * Default: `0`.
14 */
15 lineOffset?: number;
16 /**
17 * Specifies the column number offset that is displayed in stack traces produced by this script.
18 * Default: `0`
19 */
20 columnOffset?: number;
21 }
22 interface ScriptOptions extends BaseOptions {
23 displayErrors?: boolean;
24 timeout?: number;
25 cachedData?: Buffer;
26 produceCachedData?: boolean;
27 }
28 interface RunningScriptOptions extends BaseOptions {
29 displayErrors?: boolean;
30 timeout?: number;
31 }
32 interface CompileFunctionOptions extends BaseOptions {
33 /**
34 * Provides an optional data with V8's code cache data for the supplied source.
35 */
36 cachedData?: Buffer;
37 /**
38 * Specifies whether to produce new cache data.
39 * Default: `false`,
40 */
41 produceCachedData?: boolean;
42 /**
43 * The sandbox/context in which the said function should be compiled in.
44 */
45 parsingContext?: Context;
46
47 /**
48 * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
49 */
50 contextExtensions?: Object[];
51 }
52 class Script {
53 constructor(code: string, options?: ScriptOptions);
54 runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any;
55 runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any;
56 runInThisContext(options?: RunningScriptOptions): any;
57 }
58 function createContext(sandbox?: Context): Context;
59 function isContext(sandbox: Context): boolean;
60 function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions | string): any;
61 function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions | string): any;
62 function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
63 function compileFunction(code: string, params: string[], options: CompileFunctionOptions): Function;
64}