Projekt

Obecné

Profil

Stáhnout (5.6 KB) Statistiky
| Větev: | Revize:
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;
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
        /**
30
         * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
31
         * Default: `true`.
32
         */
33
        displayErrors?: boolean;
34
        /**
35
         * Specifies the number of milliseconds to execute code before terminating execution.
36
         * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
37
         */
38
        timeout?: number;
39
        /**
40
         * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
41
         * 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.
42
         * If execution is terminated, an `Error` will be thrown.
43
         * Default: `false`.
44
         */
45
        breakOnSigint?: boolean;
46
    }
47
    interface CompileFunctionOptions extends BaseOptions {
48
        /**
49
         * Provides an optional data with V8's code cache data for the supplied source.
50
         */
51
        cachedData?: Buffer;
52
        /**
53
         * Specifies whether to produce new cache data.
54
         * Default: `false`,
55
         */
56
        produceCachedData?: boolean;
57
        /**
58
         * The sandbox/context in which the said function should be compiled in.
59
         */
60
        parsingContext?: Context;
61

    
62
        /**
63
         * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
64
         */
65
        contextExtensions?: Object[];
66
    }
67

    
68
    interface CreateContextOptions {
69
        /**
70
         * Human-readable name of the newly created context.
71
         * @default 'VM Context i' Where i is an ascending numerical index of the created context.
72
         */
73
        name?: string;
74
        /**
75
         * Corresponds to the newly created context for display purposes.
76
         * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
77
         * like the value of the `url.origin` property of a URL object.
78
         * Most notably, this string should omit the trailing slash, as that denotes a path.
79
         * @default ''
80
         */
81
        origin?: string;
82
        codeGeneration?: {
83
            /**
84
             * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
85
             * will throw an EvalError.
86
             * @default true
87
             */
88
            strings?: boolean;
89
            /**
90
             * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
91
             * @default true
92
             */
93
            wasm?: boolean;
94
        };
95
    }
96

    
97
    type MeasureMemoryMode = 'summary' | 'detailed';
98

    
99
    interface MeasureMemoryOptions {
100
        /**
101
         * @default 'summary'
102
         */
103
        mode?: MeasureMemoryMode;
104
        context?: Context;
105
    }
106

    
107
    interface MemoryMeasurement {
108
        total: {
109
            jsMemoryEstimate: number;
110
            jsMemoryRange: [number, number];
111
        };
112
    }
113

    
114
    class Script {
115
        constructor(code: string, options?: ScriptOptions);
116
        runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any;
117
        runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any;
118
        runInThisContext(options?: RunningScriptOptions): any;
119
        createCachedData(): Buffer;
120
    }
121
    function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
122
    function isContext(sandbox: Context): boolean;
123
    function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions | string): any;
124
    function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions | string): any;
125
    function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
126
    function compileFunction(code: string, params?: string[], options?: CompileFunctionOptions): Function;
127

    
128
    /**
129
     * Measure the memory known to V8 and used by the current execution context or a specified context.
130
     *
131
     * The format of the object that the returned Promise may resolve with is
132
     * specific to the V8 engine and may change from one version of V8 to the next.
133
     *
134
     * The returned result is different from the statistics returned by
135
     * `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measures
136
     * the memory reachable by V8 from a specific context, while
137
     * `v8.getHeapSpaceStatistics()` measures the memory used by an instance
138
     * of V8 engine, which can switch among multiple contexts that reference
139
     * objects in the heap of one engine.
140
     *
141
     * @experimental
142
     */
143
    function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
144
}
(43-43/45)