[6a3a178] | 1 | declare 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 | undefined;
|
---|
| 11 | /**
|
---|
| 12 | * Specifies the line number offset that is displayed in stack traces produced by this script.
|
---|
| 13 | * Default: `0`.
|
---|
| 14 | */
|
---|
| 15 | lineOffset?: number | undefined;
|
---|
| 16 | /**
|
---|
| 17 | * Specifies the column number offset that is displayed in stack traces produced by this script.
|
---|
| 18 | * @default 0
|
---|
| 19 | */
|
---|
| 20 | columnOffset?: number | undefined;
|
---|
| 21 | }
|
---|
| 22 | interface ScriptOptions extends BaseOptions {
|
---|
| 23 | displayErrors?: boolean | undefined;
|
---|
| 24 | timeout?: number | undefined;
|
---|
| 25 | cachedData?: Buffer | undefined;
|
---|
| 26 | /** @deprecated in favor of `script.createCachedData()` */
|
---|
| 27 | produceCachedData?: boolean | undefined;
|
---|
| 28 | }
|
---|
| 29 | interface RunningScriptOptions extends BaseOptions {
|
---|
| 30 | /**
|
---|
| 31 | * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
|
---|
| 32 | * Default: `true`.
|
---|
| 33 | */
|
---|
| 34 | displayErrors?: boolean | undefined;
|
---|
| 35 | /**
|
---|
| 36 | * Specifies the number of milliseconds to execute code before terminating execution.
|
---|
| 37 | * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
|
---|
| 38 | */
|
---|
| 39 | timeout?: number | undefined;
|
---|
| 40 | /**
|
---|
| 41 | * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
|
---|
| 42 | * Existing handlers for the event that have been attached via `process.on('SIGINT')` will be disabled during script execution, but will continue to work after that.
|
---|
| 43 | * If execution is terminated, an `Error` will be thrown.
|
---|
| 44 | * Default: `false`.
|
---|
| 45 | */
|
---|
| 46 | breakOnSigint?: boolean | undefined;
|
---|
| 47 | }
|
---|
| 48 | interface CompileFunctionOptions extends BaseOptions {
|
---|
| 49 | /**
|
---|
| 50 | * Provides an optional data with V8's code cache data for the supplied source.
|
---|
| 51 | */
|
---|
| 52 | cachedData?: Buffer | undefined;
|
---|
| 53 | /**
|
---|
| 54 | * Specifies whether to produce new cache data.
|
---|
| 55 | * Default: `false`,
|
---|
| 56 | */
|
---|
| 57 | produceCachedData?: boolean | undefined;
|
---|
| 58 | /**
|
---|
| 59 | * The sandbox/context in which the said function should be compiled in.
|
---|
| 60 | */
|
---|
| 61 | parsingContext?: Context | undefined;
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
|
---|
| 65 | */
|
---|
| 66 | contextExtensions?: Object[] | undefined;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | interface CreateContextOptions {
|
---|
| 70 | /**
|
---|
| 71 | * Human-readable name of the newly created context.
|
---|
| 72 | * @default 'VM Context i' Where i is an ascending numerical index of the created context.
|
---|
| 73 | */
|
---|
| 74 | name?: string | undefined;
|
---|
| 75 | /**
|
---|
| 76 | * Corresponds to the newly created context for display purposes.
|
---|
| 77 | * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
|
---|
| 78 | * like the value of the `url.origin` property of a URL object.
|
---|
| 79 | * Most notably, this string should omit the trailing slash, as that denotes a path.
|
---|
| 80 | * @default ''
|
---|
| 81 | */
|
---|
| 82 | origin?: string | undefined;
|
---|
| 83 | codeGeneration?: {
|
---|
| 84 | /**
|
---|
| 85 | * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
|
---|
| 86 | * will throw an EvalError.
|
---|
| 87 | * @default true
|
---|
| 88 | */
|
---|
| 89 | strings?: boolean | undefined;
|
---|
| 90 | /**
|
---|
| 91 | * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
|
---|
| 92 | * @default true
|
---|
| 93 | */
|
---|
| 94 | wasm?: boolean | undefined;
|
---|
| 95 | } | undefined;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | class Script {
|
---|
| 99 | constructor(code: string, options?: ScriptOptions);
|
---|
| 100 | runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any;
|
---|
| 101 | runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any;
|
---|
| 102 | runInThisContext(options?: RunningScriptOptions): any;
|
---|
| 103 | createCachedData(): Buffer;
|
---|
| 104 | cachedDataRejected?: boolean | undefined;
|
---|
| 105 | }
|
---|
| 106 | function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
|
---|
| 107 | function isContext(sandbox: Context): boolean;
|
---|
| 108 | function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions | string): any;
|
---|
| 109 | function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions | string): any;
|
---|
| 110 | function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
|
---|
| 111 | function compileFunction(code: string, params?: ReadonlyArray<string>, options?: CompileFunctionOptions): Function;
|
---|
| 112 | }
|
---|