@rio-cloud/cdk-v2-constructs 8.2.0-alpha.0 → 8.2.1-alpha.0
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/.jsii +2 -2
- package/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/node/assert/strict.d.ts +105 -2
- package/node_modules/@types/node/assert.d.ts +211 -92
- package/node_modules/@types/node/async_hooks.d.ts +103 -19
- package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
- package/node_modules/@types/node/buffer.d.ts +88 -516
- package/node_modules/@types/node/child_process.d.ts +167 -231
- package/node_modules/@types/node/cluster.d.ts +172 -26
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +66 -28
- package/node_modules/@types/node/constants.d.ts +14 -12
- package/node_modules/@types/node/crypto.d.ts +1458 -497
- package/node_modules/@types/node/dgram.d.ts +44 -30
- package/node_modules/@types/node/diagnostics_channel.d.ts +389 -4
- package/node_modules/@types/node/dns/promises.d.ts +120 -42
- package/node_modules/@types/node/dns.d.ts +209 -95
- package/node_modules/@types/node/domain.d.ts +14 -18
- package/node_modules/@types/node/events.d.ts +245 -113
- package/node_modules/@types/node/fs/promises.d.ts +194 -96
- package/node_modules/@types/node/fs.d.ts +695 -270
- package/node_modules/@types/node/globals.d.ts +97 -308
- package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
- package/node_modules/@types/node/http.d.ts +363 -97
- package/node_modules/@types/node/http2.d.ts +684 -231
- package/node_modules/@types/node/https.d.ts +122 -87
- package/node_modules/@types/node/index.d.ts +24 -11
- package/node_modules/@types/node/inspector.d.ts +220 -2690
- package/node_modules/@types/node/inspector.generated.d.ts +4239 -0
- package/node_modules/@types/node/module.d.ts +705 -149
- package/node_modules/@types/node/net.d.ts +178 -54
- package/node_modules/@types/node/os.d.ts +47 -17
- package/node_modules/@types/node/package.json +22 -97
- package/node_modules/@types/node/path.d.ts +12 -3
- package/node_modules/@types/node/perf_hooks.d.ts +500 -97
- package/node_modules/@types/node/process.d.ts +657 -87
- package/node_modules/@types/node/punycode.d.ts +5 -5
- package/node_modules/@types/node/querystring.d.ts +24 -13
- package/node_modules/@types/node/readline/promises.d.ts +25 -14
- package/node_modules/@types/node/readline.d.ts +102 -41
- package/node_modules/@types/node/repl.d.ts +38 -30
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +1040 -0
- package/node_modules/@types/node/stream/consumers.d.ts +33 -7
- package/node_modules/@types/node/stream/promises.d.ts +8 -1
- package/node_modules/@types/node/stream/web.d.ts +251 -28
- package/node_modules/@types/node/stream.d.ts +1060 -1055
- package/node_modules/@types/node/string_decoder.d.ts +8 -8
- package/node_modules/@types/node/test.d.ts +2133 -1166
- package/node_modules/@types/node/timers/promises.d.ts +31 -16
- package/node_modules/@types/node/timers.d.ts +159 -114
- package/node_modules/@types/node/tls.d.ts +232 -163
- package/node_modules/@types/node/trace_events.d.ts +43 -28
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
- package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
- package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
- package/node_modules/@types/node/tty.d.ts +9 -9
- package/node_modules/@types/node/url.d.ts +236 -84
- package/node_modules/@types/node/util.d.ts +562 -412
- package/node_modules/@types/node/v8.d.ts +368 -21
- package/node_modules/@types/node/vm.d.ts +443 -149
- package/node_modules/@types/node/wasi.d.ts +62 -18
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +310 -107
- package/node_modules/@types/node/zlib.d.ts +301 -73
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/agent.d.ts +13 -12
- package/node_modules/undici-types/api.d.ts +26 -26
- package/node_modules/undici-types/balanced-pool.d.ts +19 -7
- package/node_modules/undici-types/cache-interceptor.d.ts +173 -0
- package/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/undici-types/client.d.ts +26 -15
- package/node_modules/undici-types/connector.d.ts +2 -2
- package/node_modules/undici-types/cookies.d.ts +2 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +19 -12
- package/node_modules/undici-types/dispatcher.d.ts +148 -113
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici-types/errors.d.ts +79 -46
- package/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/undici-types/fetch.d.ts +41 -39
- package/node_modules/undici-types/formdata.d.ts +8 -8
- package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
- package/node_modules/undici-types/global-origin.d.ts +5 -5
- package/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/undici-types/handlers.d.ts +11 -5
- package/node_modules/undici-types/header.d.ts +157 -1
- package/node_modules/undici-types/index.d.ts +68 -43
- package/node_modules/undici-types/interceptors.d.ts +71 -3
- package/node_modules/undici-types/mock-agent.d.ts +36 -18
- package/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/undici-types/mock-client.d.ts +6 -4
- package/node_modules/undici-types/mock-errors.d.ts +3 -3
- package/node_modules/undici-types/mock-interceptor.d.ts +24 -23
- package/node_modules/undici-types/mock-pool.d.ts +6 -4
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/patch.d.ts +0 -42
- package/node_modules/undici-types/pool-stats.d.ts +8 -8
- package/node_modules/undici-types/pool.d.ts +21 -8
- package/node_modules/undici-types/proxy-agent.d.ts +5 -6
- package/node_modules/undici-types/readable.d.ts +24 -17
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/undici-types/webidl.d.ts +157 -36
- package/node_modules/undici-types/websocket.d.ts +67 -12
- package/package.json +9 -60
- package/version.json +1 -1
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4455
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -796
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1232
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4289
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -381
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1888
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -287
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -477
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -639
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1532
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -350
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1382
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2186
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -635
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -901
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/argparse/CHANGELOG.md +0 -216
- package/node_modules/undici-types/file.d.ts +0 -39
- package/node_modules/undici-types/filereader.d.ts +0 -54
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* code are reflected in the context object.
|
|
18
18
|
*
|
|
19
19
|
* ```js
|
|
20
|
-
*
|
|
20
|
+
* import vm from 'node:vm';
|
|
21
21
|
*
|
|
22
22
|
* const x = 1;
|
|
23
23
|
*
|
|
@@ -34,20 +34,21 @@
|
|
|
34
34
|
*
|
|
35
35
|
* console.log(x); // 1; y is not defined.
|
|
36
36
|
* ```
|
|
37
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
37
|
+
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/vm.js)
|
|
38
38
|
*/
|
|
39
39
|
declare module "vm" {
|
|
40
|
-
import {
|
|
40
|
+
import { NonSharedBuffer } from "node:buffer";
|
|
41
|
+
import { ImportAttributes, ImportPhase } from "node:module";
|
|
41
42
|
interface Context extends NodeJS.Dict<any> {}
|
|
42
43
|
interface BaseOptions {
|
|
43
44
|
/**
|
|
44
45
|
* Specifies the filename used in stack traces produced by this script.
|
|
45
|
-
*
|
|
46
|
+
* @default ''
|
|
46
47
|
*/
|
|
47
48
|
filename?: string | undefined;
|
|
48
49
|
/**
|
|
49
50
|
* Specifies the line number offset that is displayed in stack traces produced by this script.
|
|
50
|
-
*
|
|
51
|
+
* @default 0
|
|
51
52
|
*/
|
|
52
53
|
lineOffset?: number | undefined;
|
|
53
54
|
/**
|
|
@@ -56,25 +57,34 @@ declare module "vm" {
|
|
|
56
57
|
*/
|
|
57
58
|
columnOffset?: number | undefined;
|
|
58
59
|
}
|
|
60
|
+
type DynamicModuleLoader<T> = (
|
|
61
|
+
specifier: string,
|
|
62
|
+
referrer: T,
|
|
63
|
+
importAttributes: ImportAttributes,
|
|
64
|
+
phase: ImportPhase,
|
|
65
|
+
) => Module | Promise<Module>;
|
|
59
66
|
interface ScriptOptions extends BaseOptions {
|
|
60
67
|
/**
|
|
61
|
-
* V8's code cache data for the supplied source.
|
|
68
|
+
* Provides an optional data with V8's code cache data for the supplied source.
|
|
62
69
|
*/
|
|
63
|
-
cachedData?:
|
|
70
|
+
cachedData?: NodeJS.ArrayBufferView | undefined;
|
|
64
71
|
/** @deprecated in favor of `script.createCachedData()` */
|
|
65
72
|
produceCachedData?: boolean | undefined;
|
|
66
73
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
74
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
75
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
76
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
77
|
+
* @experimental
|
|
69
78
|
*/
|
|
70
79
|
importModuleDynamically?:
|
|
71
|
-
|
|
|
80
|
+
| DynamicModuleLoader<Script>
|
|
81
|
+
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
72
82
|
| undefined;
|
|
73
83
|
}
|
|
74
84
|
interface RunningScriptOptions extends BaseOptions {
|
|
75
85
|
/**
|
|
76
86
|
* When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
|
|
77
|
-
*
|
|
87
|
+
* @default true
|
|
78
88
|
*/
|
|
79
89
|
displayErrors?: boolean | undefined;
|
|
80
90
|
/**
|
|
@@ -86,45 +96,52 @@ declare module "vm" {
|
|
|
86
96
|
* If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
|
|
87
97
|
* 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.
|
|
88
98
|
* If execution is terminated, an `Error` will be thrown.
|
|
89
|
-
*
|
|
99
|
+
* @default false
|
|
90
100
|
*/
|
|
91
101
|
breakOnSigint?: boolean | undefined;
|
|
92
102
|
}
|
|
93
|
-
interface RunningScriptInNewContextOptions
|
|
103
|
+
interface RunningScriptInNewContextOptions
|
|
104
|
+
extends RunningScriptOptions, Pick<CreateContextOptions, "microtaskMode">
|
|
105
|
+
{
|
|
94
106
|
/**
|
|
95
107
|
* Human-readable name of the newly created context.
|
|
96
108
|
*/
|
|
97
|
-
contextName?: CreateContextOptions["name"];
|
|
109
|
+
contextName?: CreateContextOptions["name"] | undefined;
|
|
98
110
|
/**
|
|
99
111
|
* Origin corresponding to the newly created context for display purposes. The origin should be formatted like a URL,
|
|
100
112
|
* but with only the scheme, host, and port (if necessary), like the value of the `url.origin` property of a `URL` object.
|
|
101
113
|
* Most notably, this string should omit the trailing slash, as that denotes a path.
|
|
102
114
|
*/
|
|
103
|
-
contextOrigin?: CreateContextOptions["origin"];
|
|
104
|
-
contextCodeGeneration?: CreateContextOptions["codeGeneration"];
|
|
105
|
-
/**
|
|
106
|
-
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
|
107
|
-
*/
|
|
108
|
-
microtaskMode?: CreateContextOptions["microtaskMode"];
|
|
109
|
-
}
|
|
110
|
-
interface RunningCodeOptions extends RunningScriptOptions {
|
|
111
|
-
cachedData?: ScriptOptions["cachedData"];
|
|
112
|
-
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
|
|
115
|
+
contextOrigin?: CreateContextOptions["origin"] | undefined;
|
|
116
|
+
contextCodeGeneration?: CreateContextOptions["codeGeneration"] | undefined;
|
|
113
117
|
}
|
|
114
|
-
interface
|
|
115
|
-
cachedData?: ScriptOptions["cachedData"];
|
|
116
|
-
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
|
|
117
|
-
}
|
|
118
|
-
interface CompileFunctionOptions extends BaseOptions {
|
|
118
|
+
interface RunningCodeOptions extends RunningScriptOptions, Pick<ScriptOptions, "cachedData"> {
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
120
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
121
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
122
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
123
|
+
* @experimental
|
|
121
124
|
*/
|
|
122
|
-
|
|
125
|
+
importModuleDynamically?:
|
|
126
|
+
| DynamicModuleLoader<Script>
|
|
127
|
+
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
128
|
+
| undefined;
|
|
129
|
+
}
|
|
130
|
+
interface RunningCodeInNewContextOptions
|
|
131
|
+
extends RunningScriptInNewContextOptions, Pick<ScriptOptions, "cachedData">
|
|
132
|
+
{
|
|
123
133
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
134
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
135
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
136
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
137
|
+
* @experimental
|
|
126
138
|
*/
|
|
127
|
-
|
|
139
|
+
importModuleDynamically?:
|
|
140
|
+
| DynamicModuleLoader<Script>
|
|
141
|
+
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
142
|
+
| undefined;
|
|
143
|
+
}
|
|
144
|
+
interface CompileFunctionOptions extends BaseOptions, Pick<ScriptOptions, "cachedData" | "produceCachedData"> {
|
|
128
145
|
/**
|
|
129
146
|
* The sandbox/context in which the said function should be compiled in.
|
|
130
147
|
*/
|
|
@@ -133,6 +150,16 @@ declare module "vm" {
|
|
|
133
150
|
* An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
|
|
134
151
|
*/
|
|
135
152
|
contextExtensions?: Object[] | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
155
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
156
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
157
|
+
* @experimental
|
|
158
|
+
*/
|
|
159
|
+
importModuleDynamically?:
|
|
160
|
+
| DynamicModuleLoader<ReturnType<typeof compileFunction>>
|
|
161
|
+
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
162
|
+
| undefined;
|
|
136
163
|
}
|
|
137
164
|
interface CreateContextOptions {
|
|
138
165
|
/**
|
|
@@ -167,6 +194,16 @@ declare module "vm" {
|
|
|
167
194
|
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
|
168
195
|
*/
|
|
169
196
|
microtaskMode?: "afterEvaluate" | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
199
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
200
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
201
|
+
* @experimental
|
|
202
|
+
*/
|
|
203
|
+
importModuleDynamically?:
|
|
204
|
+
| DynamicModuleLoader<Context>
|
|
205
|
+
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
206
|
+
| undefined;
|
|
170
207
|
}
|
|
171
208
|
type MeasureMemoryMode = "summary" | "detailed";
|
|
172
209
|
interface MeasureMemoryOptions {
|
|
@@ -193,7 +230,7 @@ declare module "vm" {
|
|
|
193
230
|
class Script {
|
|
194
231
|
constructor(code: string, options?: ScriptOptions | string);
|
|
195
232
|
/**
|
|
196
|
-
* Runs the compiled code contained by the `vm.Script` object within the given`contextifiedObject` and returns the result. Running code does not have access
|
|
233
|
+
* Runs the compiled code contained by the `vm.Script` object within the given `contextifiedObject` and returns the result. Running code does not have access
|
|
197
234
|
* to local scope.
|
|
198
235
|
*
|
|
199
236
|
* The following example compiles code that increments a global variable, sets
|
|
@@ -201,7 +238,7 @@ declare module "vm" {
|
|
|
201
238
|
* The globals are contained in the `context` object.
|
|
202
239
|
*
|
|
203
240
|
* ```js
|
|
204
|
-
*
|
|
241
|
+
* import vm from 'node:vm';
|
|
205
242
|
*
|
|
206
243
|
* const context = {
|
|
207
244
|
* animal: 'cat',
|
|
@@ -228,9 +265,16 @@ declare module "vm" {
|
|
|
228
265
|
*/
|
|
229
266
|
runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
|
|
230
267
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
268
|
+
* This method is a shortcut to `script.runInContext(vm.createContext(options), options)`.
|
|
269
|
+
* It does several things at once:
|
|
270
|
+
*
|
|
271
|
+
* 1. Creates a new context.
|
|
272
|
+
* 2. If `contextObject` is an object, contextifies it with the new context.
|
|
273
|
+
* If `contextObject` is undefined, creates a new object and contextifies it.
|
|
274
|
+
* If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
|
|
275
|
+
* 3. Runs the compiled code contained by the `vm.Script` object within the created context. The code
|
|
276
|
+
* does not have access to the scope in which this method is called.
|
|
277
|
+
* 4. Returns the result.
|
|
234
278
|
*
|
|
235
279
|
* The following example compiles code that sets a global variable, then executes
|
|
236
280
|
* the code multiple times in different contexts. The globals are set on and
|
|
@@ -248,12 +292,22 @@ declare module "vm" {
|
|
|
248
292
|
*
|
|
249
293
|
* console.log(contexts);
|
|
250
294
|
* // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
|
|
295
|
+
*
|
|
296
|
+
* // This would throw if the context is created from a contextified object.
|
|
297
|
+
* // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary
|
|
298
|
+
* // global objects that can be frozen.
|
|
299
|
+
* const freezeScript = new vm.Script('Object.freeze(globalThis); globalThis;');
|
|
300
|
+
* const frozenContext = freezeScript.runInNewContext(vm.constants.DONT_CONTEXTIFY);
|
|
251
301
|
* ```
|
|
252
302
|
* @since v0.3.1
|
|
253
|
-
* @param contextObject
|
|
303
|
+
* @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
|
|
304
|
+
* If `undefined`, an empty contextified object will be created for backwards compatibility.
|
|
254
305
|
* @return the result of the very last statement executed in the script.
|
|
255
306
|
*/
|
|
256
|
-
runInNewContext(
|
|
307
|
+
runInNewContext(
|
|
308
|
+
contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
|
|
309
|
+
options?: RunningScriptInNewContextOptions,
|
|
310
|
+
): any;
|
|
257
311
|
/**
|
|
258
312
|
* Runs the compiled code contained by the `vm.Script` within the context of the
|
|
259
313
|
* current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
|
|
@@ -262,7 +316,7 @@ declare module "vm" {
|
|
|
262
316
|
* executes that code multiple times:
|
|
263
317
|
*
|
|
264
318
|
* ```js
|
|
265
|
-
*
|
|
319
|
+
* import vm from 'node:vm';
|
|
266
320
|
*
|
|
267
321
|
* global.globalVar = 0;
|
|
268
322
|
*
|
|
@@ -281,7 +335,7 @@ declare module "vm" {
|
|
|
281
335
|
*/
|
|
282
336
|
runInThisContext(options?: RunningScriptOptions): any;
|
|
283
337
|
/**
|
|
284
|
-
* Creates a code cache that can be used with the `Script` constructor's`cachedData` option. Returns a `Buffer`. This method may be called at any
|
|
338
|
+
* Creates a code cache that can be used with the `Script` constructor's `cachedData` option. Returns a `Buffer`. This method may be called at any
|
|
285
339
|
* time and any number of times.
|
|
286
340
|
*
|
|
287
341
|
* The code cache of the `Script` doesn't contain any JavaScript observable
|
|
@@ -314,17 +368,17 @@ declare module "vm" {
|
|
|
314
368
|
* ```
|
|
315
369
|
* @since v10.6.0
|
|
316
370
|
*/
|
|
317
|
-
createCachedData():
|
|
371
|
+
createCachedData(): NonSharedBuffer;
|
|
318
372
|
/** @deprecated in favor of `script.createCachedData()` */
|
|
319
|
-
cachedDataProduced?: boolean
|
|
373
|
+
cachedDataProduced?: boolean;
|
|
320
374
|
/**
|
|
321
375
|
* When `cachedData` is supplied to create the `vm.Script`, this value will be set
|
|
322
|
-
* to either `true` or `false` depending on acceptance of the data by V8
|
|
376
|
+
* to either `true` or `false` depending on acceptance of the data by V8.
|
|
323
377
|
* Otherwise the value is `undefined`.
|
|
324
378
|
* @since v5.7.0
|
|
325
379
|
*/
|
|
326
|
-
cachedDataRejected?: boolean
|
|
327
|
-
cachedData?:
|
|
380
|
+
cachedDataRejected?: boolean;
|
|
381
|
+
cachedData?: NonSharedBuffer;
|
|
328
382
|
/**
|
|
329
383
|
* When the script is compiled from a source that contains a source map magic
|
|
330
384
|
* comment, this property will be set to the URL of the source map.
|
|
@@ -342,14 +396,17 @@ declare module "vm" {
|
|
|
342
396
|
* ```
|
|
343
397
|
* @since v19.1.0, v18.13.0
|
|
344
398
|
*/
|
|
345
|
-
sourceMapURL
|
|
399
|
+
sourceMapURL: string | undefined;
|
|
346
400
|
}
|
|
347
401
|
/**
|
|
348
|
-
* If given
|
|
349
|
-
* that object
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* will
|
|
402
|
+
* If the given `contextObject` is an object, the `vm.createContext()` method will
|
|
403
|
+
* [prepare that object](https://nodejs.org/docs/latest-v24.x/api/vm.html#what-does-it-mean-to-contextify-an-object)
|
|
404
|
+
* and return a reference to it so that it can be used in calls to {@link runInContext} or
|
|
405
|
+
* [`script.runInContext()`](https://nodejs.org/docs/latest-v24.x/api/vm.html#scriptrunincontextcontextifiedobject-options).
|
|
406
|
+
* Inside such scripts, the global object will be wrapped by the `contextObject`, retaining all of its
|
|
407
|
+
* existing properties but also having the built-in objects and functions any standard
|
|
408
|
+
* [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global
|
|
409
|
+
* variables will remain unchanged.
|
|
353
410
|
*
|
|
354
411
|
* ```js
|
|
355
412
|
* const vm = require('node:vm');
|
|
@@ -369,7 +426,12 @@ declare module "vm" {
|
|
|
369
426
|
* ```
|
|
370
427
|
*
|
|
371
428
|
* If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
|
|
372
|
-
* empty
|
|
429
|
+
* empty contextified object will be returned.
|
|
430
|
+
*
|
|
431
|
+
* When the global object in the newly created context is contextified, it has some quirks
|
|
432
|
+
* compared to ordinary global objects. For example, it cannot be frozen. To create a context
|
|
433
|
+
* without the contextifying quirks, pass `vm.constants.DONT_CONTEXTIFY` as the `contextObject`
|
|
434
|
+
* argument. See the documentation of `vm.constants.DONT_CONTEXTIFY` for details.
|
|
373
435
|
*
|
|
374
436
|
* The `vm.createContext()` method is primarily useful for creating a single
|
|
375
437
|
* context that can be used to run multiple scripts. For instance, if emulating a
|
|
@@ -380,11 +442,17 @@ declare module "vm" {
|
|
|
380
442
|
* The provided `name` and `origin` of the context are made visible through the
|
|
381
443
|
* Inspector API.
|
|
382
444
|
* @since v0.3.1
|
|
445
|
+
* @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
|
|
446
|
+
* If `undefined`, an empty contextified object will be created for backwards compatibility.
|
|
383
447
|
* @return contextified object.
|
|
384
448
|
*/
|
|
385
|
-
function createContext(
|
|
449
|
+
function createContext(
|
|
450
|
+
contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
|
|
451
|
+
options?: CreateContextOptions,
|
|
452
|
+
): Context;
|
|
386
453
|
/**
|
|
387
|
-
* Returns `true` if the given `object` object has been
|
|
454
|
+
* Returns `true` if the given `object` object has been contextified using {@link createContext},
|
|
455
|
+
* or if it's the global object of a context created using `vm.constants.DONT_CONTEXTIFY`.
|
|
388
456
|
* @since v0.11.7
|
|
389
457
|
*/
|
|
390
458
|
function isContext(sandbox: Context): boolean;
|
|
@@ -399,7 +467,7 @@ declare module "vm" {
|
|
|
399
467
|
* The following example compiles and executes different scripts using a single `contextified` object:
|
|
400
468
|
*
|
|
401
469
|
* ```js
|
|
402
|
-
*
|
|
470
|
+
* import vm from 'node:vm';
|
|
403
471
|
*
|
|
404
472
|
* const contextObject = { globalVar: 1 };
|
|
405
473
|
* vm.createContext(contextObject);
|
|
@@ -417,13 +485,21 @@ declare module "vm" {
|
|
|
417
485
|
*/
|
|
418
486
|
function runInContext(code: string, contextifiedObject: Context, options?: RunningCodeOptions | string): any;
|
|
419
487
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* runs it within the created context, then returns the result. Running code
|
|
423
|
-
* does not have access to the local scope.
|
|
424
|
-
*
|
|
488
|
+
* This method is a shortcut to
|
|
489
|
+
* `(new vm.Script(code, options)).runInContext(vm.createContext(options), options)`.
|
|
425
490
|
* If `options` is a string, then it specifies the filename.
|
|
426
491
|
*
|
|
492
|
+
* It does several things at once:
|
|
493
|
+
*
|
|
494
|
+
* 1. Creates a new context.
|
|
495
|
+
* 2. If `contextObject` is an object, contextifies it with the new context.
|
|
496
|
+
* If `contextObject` is undefined, creates a new object and contextifies it.
|
|
497
|
+
* If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
|
|
498
|
+
* 3. Compiles the code as a`vm.Script`
|
|
499
|
+
* 4. Runs the compield code within the created context. The code does not have access to the scope in
|
|
500
|
+
* which this method is called.
|
|
501
|
+
* 5. Returns the result.
|
|
502
|
+
*
|
|
427
503
|
* The following example compiles and executes code that increments a global
|
|
428
504
|
* variable and sets a new one. These globals are contained in the `contextObject`.
|
|
429
505
|
*
|
|
@@ -438,15 +514,21 @@ declare module "vm" {
|
|
|
438
514
|
* vm.runInNewContext('count += 1; name = "kitty"', contextObject);
|
|
439
515
|
* console.log(contextObject);
|
|
440
516
|
* // Prints: { animal: 'cat', count: 3, name: 'kitty' }
|
|
517
|
+
*
|
|
518
|
+
* // This would throw if the context is created from a contextified object.
|
|
519
|
+
* // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary global objects that
|
|
520
|
+
* // can be frozen.
|
|
521
|
+
* const frozenContext = vm.runInNewContext('Object.freeze(globalThis); globalThis;', vm.constants.DONT_CONTEXTIFY);
|
|
441
522
|
* ```
|
|
442
523
|
* @since v0.3.1
|
|
443
524
|
* @param code The JavaScript code to compile and run.
|
|
444
|
-
* @param contextObject
|
|
525
|
+
* @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
|
|
526
|
+
* If `undefined`, an empty contextified object will be created for backwards compatibility.
|
|
445
527
|
* @return the result of the very last statement executed in the script.
|
|
446
528
|
*/
|
|
447
529
|
function runInNewContext(
|
|
448
530
|
code: string,
|
|
449
|
-
contextObject?: Context,
|
|
531
|
+
contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
|
|
450
532
|
options?: RunningCodeInNewContextOptions | string,
|
|
451
533
|
): any;
|
|
452
534
|
/**
|
|
@@ -460,7 +542,7 @@ declare module "vm" {
|
|
|
460
542
|
* the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
|
|
461
543
|
*
|
|
462
544
|
* ```js
|
|
463
|
-
*
|
|
545
|
+
* import vm from 'node:vm';
|
|
464
546
|
* let localVar = 'initial value';
|
|
465
547
|
*
|
|
466
548
|
* const vmResult = vm.runInThisContext('localVar = "vm";');
|
|
@@ -472,9 +554,9 @@ declare module "vm" {
|
|
|
472
554
|
* // Prints: evalResult: 'eval', localVar: 'eval'
|
|
473
555
|
* ```
|
|
474
556
|
*
|
|
475
|
-
* Because `vm.runInThisContext()` does not have access to the local scope
|
|
557
|
+
* Because `vm.runInThisContext()` does not have access to the local scope, `localVar` is unchanged. In contrast,
|
|
476
558
|
* [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
|
|
477
|
-
* local scope, so the value `localVar` is changed. In this way`vm.runInThisContext()` is much like an [indirect `eval()` call](https://es5.github.io/#x10.4.2), e.g.`(0,eval)('code')`.
|
|
559
|
+
* local scope, so the value `localVar` is changed. In this way `vm.runInThisContext()` is much like an [indirect `eval()` call](https://es5.github.io/#x10.4.2), e.g.`(0,eval)('code')`.
|
|
478
560
|
*
|
|
479
561
|
* ## Example: Running an HTTP server within a VM
|
|
480
562
|
*
|
|
@@ -482,16 +564,16 @@ declare module "vm" {
|
|
|
482
564
|
* context. The code passed to this VM context will have its own isolated scope.
|
|
483
565
|
*
|
|
484
566
|
* In order to run a simple web server using the `node:http` module the code passed
|
|
485
|
-
* to the context must either
|
|
567
|
+
* to the context must either import `node:http` on its own, or have a
|
|
486
568
|
* reference to the `node:http` module passed to it. For instance:
|
|
487
569
|
*
|
|
488
570
|
* ```js
|
|
489
571
|
* 'use strict';
|
|
490
|
-
*
|
|
572
|
+
* import vm from 'node:vm';
|
|
491
573
|
*
|
|
492
574
|
* const code = `
|
|
493
575
|
* ((require) => {
|
|
494
|
-
*
|
|
576
|
+
* const http = require('node:http');
|
|
495
577
|
*
|
|
496
578
|
* http.createServer((request, response) => {
|
|
497
579
|
* response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
@@ -524,11 +606,7 @@ declare module "vm" {
|
|
|
524
606
|
code: string,
|
|
525
607
|
params?: readonly string[],
|
|
526
608
|
options?: CompileFunctionOptions,
|
|
527
|
-
): Function &
|
|
528
|
-
cachedData?: Script["cachedData"] | undefined;
|
|
529
|
-
cachedDataProduced?: Script["cachedDataProduced"] | undefined;
|
|
530
|
-
cachedDataRejected?: Script["cachedDataRejected"] | undefined;
|
|
531
|
-
};
|
|
609
|
+
): Function & Pick<Script, "cachedData" | "cachedDataProduced" | "cachedDataRejected">;
|
|
532
610
|
/**
|
|
533
611
|
* Measure the memory known to V8 and used by all contexts known to the
|
|
534
612
|
* current V8 isolate, or the main context.
|
|
@@ -536,13 +614,13 @@ declare module "vm" {
|
|
|
536
614
|
* The format of the object that the returned Promise may resolve with is
|
|
537
615
|
* specific to the V8 engine and may change from one version of V8 to the next.
|
|
538
616
|
*
|
|
539
|
-
* The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
|
|
617
|
+
* The returned result is different from the statistics returned by `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
|
|
540
618
|
* memory reachable by each V8 specific contexts in the current instance of
|
|
541
619
|
* the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
|
|
542
620
|
* the memory occupied by each heap space in the current V8 instance.
|
|
543
621
|
*
|
|
544
622
|
* ```js
|
|
545
|
-
*
|
|
623
|
+
* import vm from 'node:vm';
|
|
546
624
|
* // Measure the memory used by the main context.
|
|
547
625
|
* vm.measureMemory({ mode: 'summary' })
|
|
548
626
|
* // This is the same as vm.measureMemory()
|
|
@@ -585,15 +663,12 @@ declare module "vm" {
|
|
|
585
663
|
* @experimental
|
|
586
664
|
*/
|
|
587
665
|
function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
|
|
588
|
-
interface ModuleEvaluateOptions {
|
|
589
|
-
timeout?: RunningScriptOptions["timeout"] | undefined;
|
|
590
|
-
breakOnSigint?: RunningScriptOptions["breakOnSigint"] | undefined;
|
|
591
|
-
}
|
|
666
|
+
interface ModuleEvaluateOptions extends Pick<RunningScriptOptions, "breakOnSigint" | "timeout"> {}
|
|
592
667
|
type ModuleLinker = (
|
|
593
668
|
specifier: string,
|
|
594
669
|
referencingModule: Module,
|
|
595
670
|
extra: {
|
|
596
|
-
|
|
671
|
+
attributes: ImportAttributes;
|
|
597
672
|
},
|
|
598
673
|
) => Module | Promise<Module>;
|
|
599
674
|
type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
|
|
@@ -602,14 +677,12 @@ declare module "vm" {
|
|
|
602
677
|
* flag enabled.
|
|
603
678
|
*
|
|
604
679
|
* The `vm.Module` class provides a low-level interface for using
|
|
605
|
-
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
606
|
-
* s as defined in the ECMAScript
|
|
680
|
+
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
681
|
+
* class that closely mirrors [Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)s as defined in the ECMAScript
|
|
607
682
|
* specification.
|
|
608
683
|
*
|
|
609
684
|
* Unlike `vm.Script` however, every `vm.Module` object is bound to a context from
|
|
610
|
-
* its creation.
|
|
611
|
-
* in contrast with the synchronous nature of `vm.Script` objects. The use of
|
|
612
|
-
* 'async' functions can help with manipulating `vm.Module` objects.
|
|
685
|
+
* its creation.
|
|
613
686
|
*
|
|
614
687
|
* Using a `vm.Module` object requires three distinct steps: creation/parsing,
|
|
615
688
|
* linking, and evaluation. These three steps are illustrated in the following
|
|
@@ -637,7 +710,7 @@ declare module "vm" {
|
|
|
637
710
|
* // Here, we attempt to obtain the default export from the module "foo", and
|
|
638
711
|
* // put it into local binding "secret".
|
|
639
712
|
*
|
|
640
|
-
* const
|
|
713
|
+
* const rootModule = new vm.SourceTextModule(`
|
|
641
714
|
* import s from 'foo';
|
|
642
715
|
* s;
|
|
643
716
|
* print(s);
|
|
@@ -647,39 +720,48 @@ declare module "vm" {
|
|
|
647
720
|
* //
|
|
648
721
|
* // "Link" the imported dependencies of this Module to it.
|
|
649
722
|
* //
|
|
650
|
-
* //
|
|
651
|
-
* //
|
|
652
|
-
* // the imported module. The callback is expected to return a Module that
|
|
653
|
-
* // corresponds to the provided specifier, with certain requirements documented
|
|
654
|
-
* // in `module.link()`.
|
|
655
|
-
* //
|
|
656
|
-
* // If linking has not started for the returned Module, the same linker
|
|
657
|
-
* // callback will be called on the returned Module.
|
|
723
|
+
* // Obtain the requested dependencies of a SourceTextModule by
|
|
724
|
+
* // `sourceTextModule.moduleRequests` and resolve them.
|
|
658
725
|
* //
|
|
659
726
|
* // Even top-level Modules without dependencies must be explicitly linked. The
|
|
660
|
-
* //
|
|
727
|
+
* // array passed to `sourceTextModule.linkRequests(modules)` can be
|
|
728
|
+
* // empty, however.
|
|
661
729
|
* //
|
|
662
|
-
* //
|
|
663
|
-
* //
|
|
664
|
-
* //
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
730
|
+
* // Note: This is a contrived example in that the resolveAndLinkDependencies
|
|
731
|
+
* // creates a new "foo" module every time it is called. In a full-fledged
|
|
732
|
+
* // module system, a cache would probably be used to avoid duplicated modules.
|
|
733
|
+
*
|
|
734
|
+
* const moduleMap = new Map([
|
|
735
|
+
* ['root', rootModule],
|
|
736
|
+
* ]);
|
|
737
|
+
*
|
|
738
|
+
* function resolveAndLinkDependencies(module) {
|
|
739
|
+
* const requestedModules = module.moduleRequests.map((request) => {
|
|
740
|
+
* // In a full-fledged module system, the resolveAndLinkDependencies would
|
|
741
|
+
* // resolve the module with the module cache key `[specifier, attributes]`.
|
|
742
|
+
* // In this example, we just use the specifier as the key.
|
|
743
|
+
* const specifier = request.specifier;
|
|
744
|
+
*
|
|
745
|
+
* let requestedModule = moduleMap.get(specifier);
|
|
746
|
+
* if (requestedModule === undefined) {
|
|
747
|
+
* requestedModule = new vm.SourceTextModule(`
|
|
748
|
+
* // The "secret" variable refers to the global variable we added to
|
|
749
|
+
* // "contextifiedObject" when creating the context.
|
|
750
|
+
* export default secret;
|
|
751
|
+
* `, { context: module.context });
|
|
752
|
+
* moduleMap.set(specifier, requestedModule);
|
|
753
|
+
* // Resolve the dependencies of the new module as well.
|
|
754
|
+
* resolveAndLinkDependencies(requestedModule);
|
|
755
|
+
* }
|
|
756
|
+
*
|
|
757
|
+
* return requestedModule;
|
|
758
|
+
* });
|
|
759
|
+
*
|
|
760
|
+
* module.linkRequests(requestedModules);
|
|
681
761
|
* }
|
|
682
|
-
*
|
|
762
|
+
*
|
|
763
|
+
* resolveAndLinkDependencies(rootModule);
|
|
764
|
+
* rootModule.instantiate();
|
|
683
765
|
*
|
|
684
766
|
* // Step 3
|
|
685
767
|
* //
|
|
@@ -687,20 +769,12 @@ declare module "vm" {
|
|
|
687
769
|
* // resolve after the module has finished evaluating.
|
|
688
770
|
*
|
|
689
771
|
* // Prints 42.
|
|
690
|
-
* await
|
|
772
|
+
* await rootModule.evaluate();
|
|
691
773
|
* ```
|
|
692
774
|
* @since v13.0.0, v12.16.0
|
|
693
775
|
* @experimental
|
|
694
776
|
*/
|
|
695
777
|
class Module {
|
|
696
|
-
/**
|
|
697
|
-
* The specifiers of all dependencies of this module. The returned array is frozen
|
|
698
|
-
* to disallow any changes to it.
|
|
699
|
-
*
|
|
700
|
-
* Corresponds to the `[[RequestedModules]]` field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in
|
|
701
|
-
* the ECMAScript specification.
|
|
702
|
-
*/
|
|
703
|
-
dependencySpecifiers: readonly string[];
|
|
704
778
|
/**
|
|
705
779
|
* If the `module.status` is `'errored'`, this property contains the exception
|
|
706
780
|
* thrown by the module during evaluation. If the status is anything else,
|
|
@@ -740,24 +814,39 @@ declare module "vm" {
|
|
|
740
814
|
* * `'errored'`: The module has been evaluated, but an exception was thrown.
|
|
741
815
|
*
|
|
742
816
|
* Other than `'errored'`, this status string corresponds to the specification's [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records)'s `[[Status]]` field. `'errored'`
|
|
743
|
-
* corresponds to`'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
|
|
817
|
+
* corresponds to `'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
|
|
744
818
|
* value that is not `undefined`.
|
|
745
819
|
*/
|
|
746
820
|
status: ModuleStatus;
|
|
747
821
|
/**
|
|
748
|
-
* Evaluate the module.
|
|
822
|
+
* Evaluate the module and its depenendencies. Corresponds to the [Evaluate() concrete method](https://tc39.es/ecma262/#sec-moduleevaluation)
|
|
823
|
+
* field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records)s in the ECMAScript specification.
|
|
749
824
|
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
* case it will either do nothing if the initial evaluation ended in success
|
|
753
|
-
* (`module.status` is `'evaluated'`) or it will re-throw the exception that the
|
|
754
|
-
* initial evaluation resulted in (`module.status` is `'errored'`).
|
|
825
|
+
* If the module is a `vm.SourceTextModule`, `evaluate()` must be called after the module has been instantiated;
|
|
826
|
+
* otherwise `evaluate()` will return a rejected promise.
|
|
755
827
|
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
828
|
+
* For a `vm.SourceTextModule`, the promise returned by `evaluate()` may be fulfilled either synchronously or asynchronously:
|
|
829
|
+
* 1. If the `vm.SourceTextModule` has no top-level `await` in itself or any of its dependencies, the promise will be
|
|
830
|
+
* fulfilled synchronously after the module and all its dependencies have been evaluated.
|
|
831
|
+
* 1. If the evaluation succeeds, the promise will be _synchronously_ resolved to `undefined`.
|
|
832
|
+
* 2. If the evaluation results in an exception, the promise will be _synchronously_ rejected with the exception that causes the evaluation to fail, which is the same as `module.error`.
|
|
833
|
+
* 2. If the `vm.SourceTextModule` has top-level `await` in itself or any of its dependencies, the promise will be fulfilled asynchronously after the module and all its dependencies have been evaluated.
|
|
834
|
+
* 1. If the evaluation succeeds, the promise will be _asynchronously_ resolved to `undefined`.
|
|
835
|
+
* 2. If the evaluation results in an exception, the promise will be _asynchronously_ rejected with the exception that causes the evaluation to fail.
|
|
758
836
|
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
837
|
+
* If the module is a `vm.SyntheticModule`, `evaluate()` always returns a promise that fulfills synchronously,
|
|
838
|
+
* see the specification of [Evaluate() of a Synthetic Module Record](https://tc39.es/ecma262/#sec-smr-Evaluate):
|
|
839
|
+
* 1. If the `evaluateCallback` passed to its constructor throws an exception synchronously, `evaluate()` returns a promise that will be synchronously rejected with that exception.
|
|
840
|
+
* 2. If the `evaluateCallback` does not throw an exception, `evaluate()` returns a promise that will be synchronously resolved to `undefined`.
|
|
841
|
+
*
|
|
842
|
+
* The `evaluateCallback` of a `vm.SyntheticModule` is executed synchronously within the `evaluate()` call, and its return value is discarded. This means if `evaluateCallback` is an asynchronous function, the promise
|
|
843
|
+
* returned by `evaluate()` will not reflect its asynchronous behavior, and any rejections from an asynchronous `evaluateCallback` will be lost.
|
|
844
|
+
*
|
|
845
|
+
* evaluate() could also be called again after the module has already been evaluated, in which case:
|
|
846
|
+
* 1. If the initial evaluation ended in success (`module.status` is `'evaluated'`), it will do nothing and return a promise that resolves to `undefined`.
|
|
847
|
+
* 2. If the initial evaluation resulted in an exception (`module.status` is `'errored'`), it will re-reject the exception that the initial evaluation resulted in.
|
|
848
|
+
*
|
|
849
|
+
* This method cannot be called while the module is being evaluated (`module.status` is `'evaluating'`).
|
|
761
850
|
* @return Fulfills with `undefined` upon success.
|
|
762
851
|
*/
|
|
763
852
|
evaluate(options?: ModuleEvaluateOptions): Promise<void>;
|
|
@@ -765,6 +854,10 @@ declare module "vm" {
|
|
|
765
854
|
* Link module dependencies. This method must be called before evaluation, and
|
|
766
855
|
* can only be called once per module.
|
|
767
856
|
*
|
|
857
|
+
* Use `sourceTextModule.linkRequests(modules)` and
|
|
858
|
+
* `sourceTextModule.instantiate()` to link modules either synchronously or
|
|
859
|
+
* asynchronously.
|
|
860
|
+
*
|
|
768
861
|
* The function is expected to return a `Module` object or a `Promise` that
|
|
769
862
|
* eventually resolves to a `Module` object. The returned `Module` must satisfy the
|
|
770
863
|
* following two invariants:
|
|
@@ -773,7 +866,7 @@ declare module "vm" {
|
|
|
773
866
|
* * Its `status` must not be `'errored'`.
|
|
774
867
|
*
|
|
775
868
|
* If the returned `Module`'s `status` is `'unlinked'`, this method will be
|
|
776
|
-
* recursively called on the returned `Module` with the same provided `linker`function.
|
|
869
|
+
* recursively called on the returned `Module` with the same provided `linker` function.
|
|
777
870
|
*
|
|
778
871
|
* `link()` returns a `Promise` that will either get resolved when all linking
|
|
779
872
|
* instances resolve to a valid `Module`, or rejected if the linker function either
|
|
@@ -795,21 +888,43 @@ declare module "vm" {
|
|
|
795
888
|
*/
|
|
796
889
|
link(linker: ModuleLinker): Promise<void>;
|
|
797
890
|
}
|
|
798
|
-
interface SourceTextModuleOptions {
|
|
891
|
+
interface SourceTextModuleOptions extends Pick<ScriptOptions, "cachedData" | "columnOffset" | "lineOffset"> {
|
|
799
892
|
/**
|
|
800
893
|
* String used in stack traces.
|
|
801
894
|
* @default 'vm:module(i)' where i is a context-specific ascending index.
|
|
802
895
|
*/
|
|
803
896
|
identifier?: string | undefined;
|
|
804
|
-
cachedData?: ScriptOptions["cachedData"] | undefined;
|
|
805
897
|
context?: Context | undefined;
|
|
806
|
-
lineOffset?: BaseOptions["lineOffset"] | undefined;
|
|
807
|
-
columnOffset?: BaseOptions["columnOffset"] | undefined;
|
|
808
898
|
/**
|
|
809
899
|
* Called during evaluation of this module to initialize the `import.meta`.
|
|
810
900
|
*/
|
|
811
901
|
initializeImportMeta?: ((meta: ImportMeta, module: SourceTextModule) => void) | undefined;
|
|
812
|
-
|
|
902
|
+
/**
|
|
903
|
+
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
904
|
+
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
905
|
+
* [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
906
|
+
* @experimental
|
|
907
|
+
*/
|
|
908
|
+
importModuleDynamically?: DynamicModuleLoader<SourceTextModule> | undefined;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* A `ModuleRequest` represents the request to import a module with given import attributes and phase.
|
|
912
|
+
* @since 24.4.0
|
|
913
|
+
*/
|
|
914
|
+
interface ModuleRequest {
|
|
915
|
+
/**
|
|
916
|
+
* The specifier of the requested module.
|
|
917
|
+
*/
|
|
918
|
+
specifier: string;
|
|
919
|
+
/**
|
|
920
|
+
* The `"with"` value passed to the `WithClause` in a `ImportDeclaration`, or an empty object if no value was
|
|
921
|
+
* provided.
|
|
922
|
+
*/
|
|
923
|
+
attributes: ImportAttributes;
|
|
924
|
+
/**
|
|
925
|
+
* The phase of the requested module (`"source"` or `"evaluation"`).
|
|
926
|
+
*/
|
|
927
|
+
phase: ImportPhase;
|
|
813
928
|
}
|
|
814
929
|
/**
|
|
815
930
|
* This feature is only available with the `--experimental-vm-modules` command
|
|
@@ -823,9 +938,163 @@ declare module "vm" {
|
|
|
823
938
|
class SourceTextModule extends Module {
|
|
824
939
|
/**
|
|
825
940
|
* Creates a new `SourceTextModule` instance.
|
|
941
|
+
*
|
|
942
|
+
* Properties assigned to the `import.meta` object that are objects may
|
|
943
|
+
* allow the module to access information outside the specified `context`. Use
|
|
944
|
+
* `vm.runInContext()` to create objects in a specific context.
|
|
945
|
+
*
|
|
946
|
+
* ```js
|
|
947
|
+
* import vm from 'node:vm';
|
|
948
|
+
*
|
|
949
|
+
* const contextifiedObject = vm.createContext({ secret: 42 });
|
|
950
|
+
*
|
|
951
|
+
* const module = new vm.SourceTextModule(
|
|
952
|
+
* 'Object.getPrototypeOf(import.meta.prop).secret = secret;',
|
|
953
|
+
* {
|
|
954
|
+
* initializeImportMeta(meta) {
|
|
955
|
+
* // Note: this object is created in the top context. As such,
|
|
956
|
+
* // Object.getPrototypeOf(import.meta.prop) points to the
|
|
957
|
+
* // Object.prototype in the top context rather than that in
|
|
958
|
+
* // the contextified object.
|
|
959
|
+
* meta.prop = {};
|
|
960
|
+
* },
|
|
961
|
+
* });
|
|
962
|
+
* // The module has an empty `moduleRequests` array.
|
|
963
|
+
* module.linkRequests([]);
|
|
964
|
+
* module.instantiate();
|
|
965
|
+
* await module.evaluate();
|
|
966
|
+
*
|
|
967
|
+
* // Now, Object.prototype.secret will be equal to 42.
|
|
968
|
+
* //
|
|
969
|
+
* // To fix this problem, replace
|
|
970
|
+
* // meta.prop = {};
|
|
971
|
+
* // above with
|
|
972
|
+
* // meta.prop = vm.runInContext('{}', contextifiedObject);
|
|
973
|
+
* ```
|
|
826
974
|
* @param code JavaScript Module code to parse
|
|
827
975
|
*/
|
|
828
976
|
constructor(code: string, options?: SourceTextModuleOptions);
|
|
977
|
+
/**
|
|
978
|
+
* @deprecated Use `sourceTextModule.moduleRequests` instead.
|
|
979
|
+
*/
|
|
980
|
+
readonly dependencySpecifiers: readonly string[];
|
|
981
|
+
/**
|
|
982
|
+
* Iterates over the dependency graph and returns `true` if any module in its
|
|
983
|
+
* dependencies or this module itself contains top-level `await` expressions,
|
|
984
|
+
* otherwise returns `false`.
|
|
985
|
+
*
|
|
986
|
+
* The search may be slow if the graph is big enough.
|
|
987
|
+
*
|
|
988
|
+
* This requires the module to be instantiated first. If the module is not
|
|
989
|
+
* instantiated yet, an error will be thrown.
|
|
990
|
+
* @since v24.9.0
|
|
991
|
+
*/
|
|
992
|
+
hasAsyncGraph(): boolean;
|
|
993
|
+
/**
|
|
994
|
+
* Returns whether the module itself contains any top-level `await` expressions.
|
|
995
|
+
*
|
|
996
|
+
* This corresponds to the field `[[HasTLA]]` in [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) in the
|
|
997
|
+
* ECMAScript specification.
|
|
998
|
+
* @since v24.9.0
|
|
999
|
+
*/
|
|
1000
|
+
hasTopLevelAwait(): boolean;
|
|
1001
|
+
/**
|
|
1002
|
+
* Instantiate the module with the linked requested modules.
|
|
1003
|
+
*
|
|
1004
|
+
* This resolves the imported bindings of the module, including re-exported
|
|
1005
|
+
* binding names. When there are any bindings that cannot be resolved,
|
|
1006
|
+
* an error would be thrown synchronously.
|
|
1007
|
+
*
|
|
1008
|
+
* If the requested modules include cyclic dependencies, the
|
|
1009
|
+
* `sourceTextModule.linkRequests(modules)` method must be called on all
|
|
1010
|
+
* modules in the cycle before calling this method.
|
|
1011
|
+
* @since v24.8.0
|
|
1012
|
+
*/
|
|
1013
|
+
instantiate(): void;
|
|
1014
|
+
/**
|
|
1015
|
+
* Link module dependencies. This method must be called before evaluation, and
|
|
1016
|
+
* can only be called once per module.
|
|
1017
|
+
*
|
|
1018
|
+
* The order of the module instances in the `modules` array should correspond to the order of
|
|
1019
|
+
* `sourceTextModule.moduleRequests` being resolved. If two module requests have the same
|
|
1020
|
+
* specifier and import attributes, they must be resolved with the same module instance or an
|
|
1021
|
+
* `ERR_MODULE_LINK_MISMATCH` would be thrown. For example, when linking requests for this
|
|
1022
|
+
* module:
|
|
1023
|
+
*
|
|
1024
|
+
* ```js
|
|
1025
|
+
* import foo from 'foo';
|
|
1026
|
+
* import source Foo from 'foo';
|
|
1027
|
+
* ```
|
|
1028
|
+
*
|
|
1029
|
+
* The `modules` array must contain two references to the same instance, because the two
|
|
1030
|
+
* module requests are identical but in two phases.
|
|
1031
|
+
*
|
|
1032
|
+
* If the module has no dependencies, the `modules` array can be empty.
|
|
1033
|
+
*
|
|
1034
|
+
* Users can use `sourceTextModule.moduleRequests` to implement the host-defined
|
|
1035
|
+
* [HostLoadImportedModule](https://tc39.es/ecma262/#sec-HostLoadImportedModule) abstract operation in the ECMAScript specification,
|
|
1036
|
+
* and using `sourceTextModule.linkRequests()` to invoke specification defined
|
|
1037
|
+
* [FinishLoadingImportedModule](https://tc39.es/ecma262/#sec-FinishLoadingImportedModule), on the module with all dependencies in a batch.
|
|
1038
|
+
*
|
|
1039
|
+
* It's up to the creator of the `SourceTextModule` to determine if the resolution
|
|
1040
|
+
* of the dependencies is synchronous or asynchronous.
|
|
1041
|
+
*
|
|
1042
|
+
* After each module in the `modules` array is linked, call
|
|
1043
|
+
* `sourceTextModule.instantiate()`.
|
|
1044
|
+
* @since v24.8.0
|
|
1045
|
+
* @param modules Array of `vm.Module` objects that this module depends on.
|
|
1046
|
+
* The order of the modules in the array is the order of
|
|
1047
|
+
* `sourceTextModule.moduleRequests`.
|
|
1048
|
+
*/
|
|
1049
|
+
linkRequests(modules: readonly Module[]): void;
|
|
1050
|
+
/**
|
|
1051
|
+
* The requested import dependencies of this module. The returned array is frozen
|
|
1052
|
+
* to disallow any changes to it.
|
|
1053
|
+
*
|
|
1054
|
+
* For example, given a source text:
|
|
1055
|
+
*
|
|
1056
|
+
* ```js
|
|
1057
|
+
* import foo from 'foo';
|
|
1058
|
+
* import fooAlias from 'foo';
|
|
1059
|
+
* import bar from './bar.js';
|
|
1060
|
+
* import withAttrs from '../with-attrs.ts' with { arbitraryAttr: 'attr-val' };
|
|
1061
|
+
* import source Module from 'wasm-mod.wasm';
|
|
1062
|
+
* ```
|
|
1063
|
+
*
|
|
1064
|
+
* The value of the `sourceTextModule.moduleRequests` will be:
|
|
1065
|
+
*
|
|
1066
|
+
* ```js
|
|
1067
|
+
* [
|
|
1068
|
+
* {
|
|
1069
|
+
* specifier: 'foo',
|
|
1070
|
+
* attributes: {},
|
|
1071
|
+
* phase: 'evaluation',
|
|
1072
|
+
* },
|
|
1073
|
+
* {
|
|
1074
|
+
* specifier: 'foo',
|
|
1075
|
+
* attributes: {},
|
|
1076
|
+
* phase: 'evaluation',
|
|
1077
|
+
* },
|
|
1078
|
+
* {
|
|
1079
|
+
* specifier: './bar.js',
|
|
1080
|
+
* attributes: {},
|
|
1081
|
+
* phase: 'evaluation',
|
|
1082
|
+
* },
|
|
1083
|
+
* {
|
|
1084
|
+
* specifier: '../with-attrs.ts',
|
|
1085
|
+
* attributes: { arbitraryAttr: 'attr-val' },
|
|
1086
|
+
* phase: 'evaluation',
|
|
1087
|
+
* },
|
|
1088
|
+
* {
|
|
1089
|
+
* specifier: 'wasm-mod.wasm',
|
|
1090
|
+
* attributes: {},
|
|
1091
|
+
* phase: 'source',
|
|
1092
|
+
* },
|
|
1093
|
+
* ];
|
|
1094
|
+
* ```
|
|
1095
|
+
* @since v24.4.0
|
|
1096
|
+
*/
|
|
1097
|
+
readonly moduleRequests: readonly ModuleRequest[];
|
|
829
1098
|
}
|
|
830
1099
|
interface SyntheticModuleOptions {
|
|
831
1100
|
/**
|
|
@@ -848,7 +1117,7 @@ declare module "vm" {
|
|
|
848
1117
|
* module graphs.
|
|
849
1118
|
*
|
|
850
1119
|
* ```js
|
|
851
|
-
*
|
|
1120
|
+
* import vm from 'node:vm';
|
|
852
1121
|
*
|
|
853
1122
|
* const source = '{ "a": 1 }';
|
|
854
1123
|
* const module = new vm.SyntheticModule(['default'], function() {
|
|
@@ -873,9 +1142,7 @@ declare module "vm" {
|
|
|
873
1142
|
options?: SyntheticModuleOptions,
|
|
874
1143
|
);
|
|
875
1144
|
/**
|
|
876
|
-
* This method
|
|
877
|
-
* it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error
|
|
878
|
-
* will be thrown.
|
|
1145
|
+
* This method sets the module export binding slots with the given value.
|
|
879
1146
|
*
|
|
880
1147
|
* ```js
|
|
881
1148
|
* import vm from 'node:vm';
|
|
@@ -884,7 +1151,6 @@ declare module "vm" {
|
|
|
884
1151
|
* m.setExport('x', 1);
|
|
885
1152
|
* });
|
|
886
1153
|
*
|
|
887
|
-
* await m.link(() => {});
|
|
888
1154
|
* await m.evaluate();
|
|
889
1155
|
*
|
|
890
1156
|
* assert.strictEqual(m.namespace.x, 1);
|
|
@@ -895,6 +1161,34 @@ declare module "vm" {
|
|
|
895
1161
|
*/
|
|
896
1162
|
setExport(name: string, value: any): void;
|
|
897
1163
|
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Returns an object containing commonly used constants for VM operations.
|
|
1166
|
+
* @since v21.7.0, v20.12.0
|
|
1167
|
+
*/
|
|
1168
|
+
namespace constants {
|
|
1169
|
+
/**
|
|
1170
|
+
* A constant that can be used as the `importModuleDynamically` option to `vm.Script`
|
|
1171
|
+
* and `vm.compileFunction()` so that Node.js uses the default ESM loader from the main
|
|
1172
|
+
* context to load the requested module.
|
|
1173
|
+
*
|
|
1174
|
+
* For detailed information, see [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
|
|
1175
|
+
* @since v21.7.0, v20.12.0
|
|
1176
|
+
*/
|
|
1177
|
+
const USE_MAIN_CONTEXT_DEFAULT_LOADER: number;
|
|
1178
|
+
/**
|
|
1179
|
+
* This constant, when used as the `contextObject` argument in vm APIs, instructs Node.js to create
|
|
1180
|
+
* a context without wrapping its global object with another object in a Node.js-specific manner.
|
|
1181
|
+
* As a result, the `globalThis` value inside the new context would behave more closely to an ordinary
|
|
1182
|
+
* one.
|
|
1183
|
+
*
|
|
1184
|
+
* When `vm.constants.DONT_CONTEXTIFY` is used as the `contextObject` argument to {@link createContext},
|
|
1185
|
+
* the returned object is a proxy-like object to the global object in the newly created context with
|
|
1186
|
+
* fewer Node.js-specific quirks. It is reference equal to the `globalThis` value in the new context,
|
|
1187
|
+
* can be modified from outside the context, and can be used to access built-ins in the new context directly.
|
|
1188
|
+
* @since v22.8.0
|
|
1189
|
+
*/
|
|
1190
|
+
const DONT_CONTEXTIFY: number;
|
|
1191
|
+
}
|
|
898
1192
|
}
|
|
899
1193
|
declare module "node:vm" {
|
|
900
1194
|
export * from "vm";
|