mcpbrowser 0.2.0 → 0.2.2

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.
Files changed (134) hide show
  1. package/.mcpregistry_github_token +1 -0
  2. package/.mcpregistry_registry_token +1 -0
  3. package/README.md +68 -35
  4. package/extension/.vscodeignore +6 -0
  5. package/extension/LICENSE +21 -0
  6. package/extension/README.md +61 -0
  7. package/extension/icon.png +0 -0
  8. package/extension/icon.svg +35 -0
  9. package/extension/mcpbrowser-0.1.1.vsix +0 -0
  10. package/extension/mcpbrowser-0.1.2.vsix +0 -0
  11. package/extension/mcpbrowser-0.1.3.vsix +0 -0
  12. package/extension/mcpbrowser-0.1.4.vsix +0 -0
  13. package/extension/mcpbrowser-config-0.1.0.vsix +0 -0
  14. package/extension/node_modules/.package-lock.json +32 -0
  15. package/extension/node_modules/@types/node/LICENSE +21 -0
  16. package/extension/node_modules/@types/node/README.md +15 -0
  17. package/extension/node_modules/@types/node/assert/strict.d.ts +8 -0
  18. package/extension/node_modules/@types/node/assert.d.ts +1062 -0
  19. package/extension/node_modules/@types/node/async_hooks.d.ts +605 -0
  20. package/extension/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  21. package/extension/node_modules/@types/node/buffer.d.ts +1936 -0
  22. package/extension/node_modules/@types/node/child_process.d.ts +1475 -0
  23. package/extension/node_modules/@types/node/cluster.d.ts +577 -0
  24. package/extension/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  25. package/extension/node_modules/@types/node/compatibility/index.d.ts +9 -0
  26. package/extension/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  27. package/extension/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  28. package/extension/node_modules/@types/node/console.d.ts +452 -0
  29. package/extension/node_modules/@types/node/constants.d.ts +21 -0
  30. package/extension/node_modules/@types/node/crypto.d.ts +4590 -0
  31. package/extension/node_modules/@types/node/dgram.d.ts +597 -0
  32. package/extension/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  33. package/extension/node_modules/@types/node/dns/promises.d.ts +479 -0
  34. package/extension/node_modules/@types/node/dns.d.ts +871 -0
  35. package/extension/node_modules/@types/node/domain.d.ts +170 -0
  36. package/extension/node_modules/@types/node/events.d.ts +977 -0
  37. package/extension/node_modules/@types/node/fs/promises.d.ts +1270 -0
  38. package/extension/node_modules/@types/node/fs.d.ts +4375 -0
  39. package/extension/node_modules/@types/node/globals.d.ts +172 -0
  40. package/extension/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  41. package/extension/node_modules/@types/node/http.d.ts +2049 -0
  42. package/extension/node_modules/@types/node/http2.d.ts +2631 -0
  43. package/extension/node_modules/@types/node/https.d.ts +578 -0
  44. package/extension/node_modules/@types/node/index.d.ts +93 -0
  45. package/extension/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  46. package/extension/node_modules/@types/node/module.d.ts +539 -0
  47. package/extension/node_modules/@types/node/net.d.ts +1012 -0
  48. package/extension/node_modules/@types/node/os.d.ts +506 -0
  49. package/extension/node_modules/@types/node/package.json +140 -0
  50. package/extension/node_modules/@types/node/path.d.ts +200 -0
  51. package/extension/node_modules/@types/node/perf_hooks.d.ts +961 -0
  52. package/extension/node_modules/@types/node/process.d.ts +1957 -0
  53. package/extension/node_modules/@types/node/punycode.d.ts +117 -0
  54. package/extension/node_modules/@types/node/querystring.d.ts +152 -0
  55. package/extension/node_modules/@types/node/readline/promises.d.ts +162 -0
  56. package/extension/node_modules/@types/node/readline.d.ts +589 -0
  57. package/extension/node_modules/@types/node/repl.d.ts +430 -0
  58. package/extension/node_modules/@types/node/sea.d.ts +153 -0
  59. package/extension/node_modules/@types/node/stream/consumers.d.ts +38 -0
  60. package/extension/node_modules/@types/node/stream/promises.d.ts +90 -0
  61. package/extension/node_modules/@types/node/stream/web.d.ts +533 -0
  62. package/extension/node_modules/@types/node/stream.d.ts +1675 -0
  63. package/extension/node_modules/@types/node/string_decoder.d.ts +67 -0
  64. package/extension/node_modules/@types/node/test.d.ts +1787 -0
  65. package/extension/node_modules/@types/node/timers/promises.d.ts +108 -0
  66. package/extension/node_modules/@types/node/timers.d.ts +286 -0
  67. package/extension/node_modules/@types/node/tls.d.ts +1255 -0
  68. package/extension/node_modules/@types/node/trace_events.d.ts +197 -0
  69. package/extension/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  70. package/extension/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  71. package/extension/node_modules/@types/node/ts5.6/index.d.ts +93 -0
  72. package/extension/node_modules/@types/node/tty.d.ts +208 -0
  73. package/extension/node_modules/@types/node/url.d.ts +964 -0
  74. package/extension/node_modules/@types/node/util.d.ts +2331 -0
  75. package/extension/node_modules/@types/node/v8.d.ts +809 -0
  76. package/extension/node_modules/@types/node/vm.d.ts +1001 -0
  77. package/extension/node_modules/@types/node/wasi.d.ts +181 -0
  78. package/extension/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  79. package/extension/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  80. package/extension/node_modules/@types/node/web-globals/events.d.ts +97 -0
  81. package/extension/node_modules/@types/node/web-globals/fetch.d.ts +46 -0
  82. package/extension/node_modules/@types/node/worker_threads.d.ts +715 -0
  83. package/extension/node_modules/@types/node/zlib.d.ts +540 -0
  84. package/extension/node_modules/@types/vscode/LICENSE +21 -0
  85. package/extension/node_modules/@types/vscode/README.md +15 -0
  86. package/extension/node_modules/@types/vscode/index.d.ts +21153 -0
  87. package/extension/node_modules/@types/vscode/package.json +26 -0
  88. package/extension/node_modules/undici-types/LICENSE +21 -0
  89. package/extension/node_modules/undici-types/README.md +6 -0
  90. package/extension/node_modules/undici-types/agent.d.ts +31 -0
  91. package/extension/node_modules/undici-types/api.d.ts +43 -0
  92. package/extension/node_modules/undici-types/balanced-pool.d.ts +29 -0
  93. package/extension/node_modules/undici-types/cache.d.ts +36 -0
  94. package/extension/node_modules/undici-types/client.d.ts +108 -0
  95. package/extension/node_modules/undici-types/connector.d.ts +34 -0
  96. package/extension/node_modules/undici-types/content-type.d.ts +21 -0
  97. package/extension/node_modules/undici-types/cookies.d.ts +28 -0
  98. package/extension/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  99. package/extension/node_modules/undici-types/dispatcher.d.ts +256 -0
  100. package/extension/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  101. package/extension/node_modules/undici-types/errors.d.ts +149 -0
  102. package/extension/node_modules/undici-types/eventsource.d.ts +61 -0
  103. package/extension/node_modules/undici-types/fetch.d.ts +209 -0
  104. package/extension/node_modules/undici-types/file.d.ts +39 -0
  105. package/extension/node_modules/undici-types/filereader.d.ts +54 -0
  106. package/extension/node_modules/undici-types/formdata.d.ts +108 -0
  107. package/extension/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  108. package/extension/node_modules/undici-types/global-origin.d.ts +7 -0
  109. package/extension/node_modules/undici-types/handlers.d.ts +15 -0
  110. package/extension/node_modules/undici-types/header.d.ts +4 -0
  111. package/extension/node_modules/undici-types/index.d.ts +71 -0
  112. package/extension/node_modules/undici-types/interceptors.d.ts +17 -0
  113. package/extension/node_modules/undici-types/mock-agent.d.ts +50 -0
  114. package/extension/node_modules/undici-types/mock-client.d.ts +25 -0
  115. package/extension/node_modules/undici-types/mock-errors.d.ts +12 -0
  116. package/extension/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  117. package/extension/node_modules/undici-types/mock-pool.d.ts +25 -0
  118. package/extension/node_modules/undici-types/package.json +55 -0
  119. package/extension/node_modules/undici-types/patch.d.ts +33 -0
  120. package/extension/node_modules/undici-types/pool-stats.d.ts +19 -0
  121. package/extension/node_modules/undici-types/pool.d.ts +39 -0
  122. package/extension/node_modules/undici-types/proxy-agent.d.ts +28 -0
  123. package/extension/node_modules/undici-types/readable.d.ts +65 -0
  124. package/extension/node_modules/undici-types/retry-agent.d.ts +8 -0
  125. package/extension/node_modules/undici-types/retry-handler.d.ts +116 -0
  126. package/extension/node_modules/undici-types/util.d.ts +18 -0
  127. package/extension/node_modules/undici-types/webidl.d.ts +228 -0
  128. package/extension/node_modules/undici-types/websocket.d.ts +150 -0
  129. package/extension/package-lock.json +44 -0
  130. package/extension/package.json +55 -0
  131. package/extension/src/extension.js +257 -0
  132. package/package.json +2 -1
  133. package/server.json +20 -0
  134. package/src/mcp-browser.js +1 -1
@@ -0,0 +1,1001 @@
1
+ /**
2
+ * The `node:vm` module enables compiling and running code within V8 Virtual
3
+ * Machine contexts.
4
+ *
5
+ * **The `node:vm` module is not a security**
6
+ * **mechanism. Do not use it to run untrusted code.**
7
+ *
8
+ * JavaScript code can be compiled and run immediately or
9
+ * compiled, saved, and run later.
10
+ *
11
+ * A common use case is to run the code in a different V8 Context. This means
12
+ * invoked code has a different global object than the invoking code.
13
+ *
14
+ * One can provide the context by `contextifying` an
15
+ * object. The invoked code treats any property in the context like a
16
+ * global variable. Any changes to global variables caused by the invoked
17
+ * code are reflected in the context object.
18
+ *
19
+ * ```js
20
+ * import vm from 'node:vm';
21
+ *
22
+ * const x = 1;
23
+ *
24
+ * const context = { x: 2 };
25
+ * vm.createContext(context); // Contextify the object.
26
+ *
27
+ * const code = 'x += 40; var y = 17;';
28
+ * // `x` and `y` are global variables in the context.
29
+ * // Initially, x has the value 2 because that is the value of context.x.
30
+ * vm.runInContext(code, context);
31
+ *
32
+ * console.log(context.x); // 42
33
+ * console.log(context.y); // 17
34
+ *
35
+ * console.log(x); // 1; y is not defined.
36
+ * ```
37
+ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/vm.js)
38
+ */
39
+ declare module "vm" {
40
+ import { NonSharedBuffer } from "node:buffer";
41
+ import { ImportAttributes } from "node:module";
42
+ interface Context extends NodeJS.Dict<any> {}
43
+ interface BaseOptions {
44
+ /**
45
+ * Specifies the filename used in stack traces produced by this script.
46
+ * @default ''
47
+ */
48
+ filename?: string | undefined;
49
+ /**
50
+ * Specifies the line number offset that is displayed in stack traces produced by this script.
51
+ * @default 0
52
+ */
53
+ lineOffset?: number | undefined;
54
+ /**
55
+ * Specifies the column number offset that is displayed in stack traces produced by this script.
56
+ * @default 0
57
+ */
58
+ columnOffset?: number | undefined;
59
+ }
60
+ type DynamicModuleLoader<T> = (
61
+ specifier: string,
62
+ referrer: T,
63
+ importAttributes: ImportAttributes,
64
+ ) => Module | Promise<Module>;
65
+ interface ScriptOptions extends BaseOptions {
66
+ /**
67
+ * Provides an optional data with V8's code cache data for the supplied source.
68
+ */
69
+ cachedData?: NodeJS.ArrayBufferView | undefined;
70
+ /** @deprecated in favor of `script.createCachedData()` */
71
+ produceCachedData?: boolean | undefined;
72
+ /**
73
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
74
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
75
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v20.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
76
+ */
77
+ importModuleDynamically?:
78
+ | DynamicModuleLoader<Script>
79
+ | typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
80
+ | undefined;
81
+ }
82
+ interface RunningScriptOptions extends BaseOptions {
83
+ /**
84
+ * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
85
+ * @default true
86
+ */
87
+ displayErrors?: boolean | undefined;
88
+ /**
89
+ * Specifies the number of milliseconds to execute code before terminating execution.
90
+ * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
91
+ */
92
+ timeout?: number | undefined;
93
+ /**
94
+ * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
95
+ * 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.
96
+ * If execution is terminated, an `Error` will be thrown.
97
+ * @default false
98
+ */
99
+ breakOnSigint?: boolean | undefined;
100
+ }
101
+ interface RunningScriptInNewContextOptions
102
+ extends RunningScriptOptions, Pick<CreateContextOptions, "microtaskMode">
103
+ {
104
+ /**
105
+ * Human-readable name of the newly created context.
106
+ */
107
+ contextName?: CreateContextOptions["name"] | undefined;
108
+ /**
109
+ * Origin corresponding to the newly created context for display purposes. The origin should be formatted like a URL,
110
+ * but with only the scheme, host, and port (if necessary), like the value of the `url.origin` property of a `URL` object.
111
+ * Most notably, this string should omit the trailing slash, as that denotes a path.
112
+ */
113
+ contextOrigin?: CreateContextOptions["origin"] | undefined;
114
+ contextCodeGeneration?: CreateContextOptions["codeGeneration"] | undefined;
115
+ }
116
+ interface RunningCodeOptions extends RunningScriptOptions, Pick<ScriptOptions, "cachedData"> {
117
+ /**
118
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
119
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
120
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
121
+ */
122
+ importModuleDynamically?:
123
+ | DynamicModuleLoader<Script>
124
+ | typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
125
+ | undefined;
126
+ }
127
+ interface RunningCodeInNewContextOptions
128
+ extends RunningScriptInNewContextOptions, Pick<ScriptOptions, "cachedData">
129
+ {
130
+ /**
131
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
132
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
133
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
134
+ */
135
+ importModuleDynamically?:
136
+ | DynamicModuleLoader<Script>
137
+ | typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
138
+ | undefined;
139
+ }
140
+ interface CompileFunctionOptions extends BaseOptions, Pick<ScriptOptions, "cachedData" | "produceCachedData"> {
141
+ /**
142
+ * The sandbox/context in which the said function should be compiled in.
143
+ */
144
+ parsingContext?: Context | undefined;
145
+ /**
146
+ * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
147
+ */
148
+ contextExtensions?: Object[] | undefined;
149
+ /**
150
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
151
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
152
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
153
+ */
154
+ importModuleDynamically?:
155
+ | DynamicModuleLoader<ReturnType<typeof compileFunction>>
156
+ | typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
157
+ | undefined;
158
+ }
159
+ interface CreateContextOptions {
160
+ /**
161
+ * Human-readable name of the newly created context.
162
+ * @default 'VM Context i' Where i is an ascending numerical index of the created context.
163
+ */
164
+ name?: string | undefined;
165
+ /**
166
+ * Corresponds to the newly created context for display purposes.
167
+ * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
168
+ * like the value of the `url.origin` property of a URL object.
169
+ * Most notably, this string should omit the trailing slash, as that denotes a path.
170
+ * @default ''
171
+ */
172
+ origin?: string | undefined;
173
+ codeGeneration?:
174
+ | {
175
+ /**
176
+ * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
177
+ * will throw an EvalError.
178
+ * @default true
179
+ */
180
+ strings?: boolean | undefined;
181
+ /**
182
+ * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
183
+ * @default true
184
+ */
185
+ wasm?: boolean | undefined;
186
+ }
187
+ | undefined;
188
+ /**
189
+ * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
190
+ */
191
+ microtaskMode?: "afterEvaluate" | undefined;
192
+ /**
193
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
194
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
195
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
196
+ */
197
+ importModuleDynamically?:
198
+ | DynamicModuleLoader<Context>
199
+ | typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
200
+ | undefined;
201
+ }
202
+ type MeasureMemoryMode = "summary" | "detailed";
203
+ interface MeasureMemoryOptions {
204
+ /**
205
+ * @default 'summary'
206
+ */
207
+ mode?: MeasureMemoryMode | undefined;
208
+ /**
209
+ * @default 'default'
210
+ */
211
+ execution?: "default" | "eager" | undefined;
212
+ }
213
+ interface MemoryMeasurement {
214
+ total: {
215
+ jsMemoryEstimate: number;
216
+ jsMemoryRange: [number, number];
217
+ };
218
+ }
219
+ /**
220
+ * Instances of the `vm.Script` class contain precompiled scripts that can be
221
+ * executed in specific contexts.
222
+ * @since v0.3.1
223
+ */
224
+ class Script {
225
+ constructor(code: string, options?: ScriptOptions | string);
226
+ /**
227
+ * Runs the compiled code contained by the `vm.Script` object within the given `contextifiedObject` and returns the result. Running code does not have access
228
+ * to local scope.
229
+ *
230
+ * The following example compiles code that increments a global variable, sets
231
+ * the value of another global variable, then execute the code multiple times.
232
+ * The globals are contained in the `context` object.
233
+ *
234
+ * ```js
235
+ * import vm from 'node:vm';
236
+ *
237
+ * const context = {
238
+ * animal: 'cat',
239
+ * count: 2,
240
+ * };
241
+ *
242
+ * const script = new vm.Script('count += 1; name = "kitty";');
243
+ *
244
+ * vm.createContext(context);
245
+ * for (let i = 0; i < 10; ++i) {
246
+ * script.runInContext(context);
247
+ * }
248
+ *
249
+ * console.log(context);
250
+ * // Prints: { animal: 'cat', count: 12, name: 'kitty' }
251
+ * ```
252
+ *
253
+ * Using the `timeout` or `breakOnSigint` options will result in new event loops
254
+ * and corresponding threads being started, which have a non-zero performance
255
+ * overhead.
256
+ * @since v0.3.1
257
+ * @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
258
+ * @return the result of the very last statement executed in the script.
259
+ */
260
+ runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
261
+ /**
262
+ * This method is a shortcut to `script.runInContext(vm.createContext(options), options)`.
263
+ * It does several things at once:
264
+ *
265
+ * 1. Creates a new context.
266
+ * 2. If `contextObject` is an object, contextifies it with the new context.
267
+ * If `contextObject` is undefined, creates a new object and contextifies it.
268
+ * If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
269
+ * 3. Runs the compiled code contained by the `vm.Script` object within the created context. The code
270
+ * does not have access to the scope in which this method is called.
271
+ * 4. Returns the result.
272
+ *
273
+ * The following example compiles code that sets a global variable, then executes
274
+ * the code multiple times in different contexts. The globals are set on and
275
+ * contained within each individual `context`.
276
+ *
277
+ * ```js
278
+ * const vm = require('node:vm');
279
+ *
280
+ * const script = new vm.Script('globalVar = "set"');
281
+ *
282
+ * const contexts = [{}, {}, {}];
283
+ * contexts.forEach((context) => {
284
+ * script.runInNewContext(context);
285
+ * });
286
+ *
287
+ * console.log(contexts);
288
+ * // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
289
+ *
290
+ * // This would throw if the context is created from a contextified object.
291
+ * // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary
292
+ * // global objects that can be frozen.
293
+ * const freezeScript = new vm.Script('Object.freeze(globalThis); globalThis;');
294
+ * const frozenContext = freezeScript.runInNewContext(vm.constants.DONT_CONTEXTIFY);
295
+ * ```
296
+ * @since v0.3.1
297
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
298
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
299
+ * @return the result of the very last statement executed in the script.
300
+ */
301
+ runInNewContext(
302
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
303
+ options?: RunningScriptInNewContextOptions,
304
+ ): any;
305
+ /**
306
+ * Runs the compiled code contained by the `vm.Script` within the context of the
307
+ * current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
308
+ *
309
+ * The following example compiles code that increments a `global` variable then
310
+ * executes that code multiple times:
311
+ *
312
+ * ```js
313
+ * import vm from 'node:vm';
314
+ *
315
+ * global.globalVar = 0;
316
+ *
317
+ * const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
318
+ *
319
+ * for (let i = 0; i < 1000; ++i) {
320
+ * script.runInThisContext();
321
+ * }
322
+ *
323
+ * console.log(globalVar);
324
+ *
325
+ * // 1000
326
+ * ```
327
+ * @since v0.3.1
328
+ * @return the result of the very last statement executed in the script.
329
+ */
330
+ runInThisContext(options?: RunningScriptOptions): any;
331
+ /**
332
+ * 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
333
+ * time and any number of times.
334
+ *
335
+ * The code cache of the `Script` doesn't contain any JavaScript observable
336
+ * states. The code cache is safe to be saved along side the script source and
337
+ * used to construct new `Script` instances multiple times.
338
+ *
339
+ * Functions in the `Script` source can be marked as lazily compiled and they are
340
+ * not compiled at construction of the `Script`. These functions are going to be
341
+ * compiled when they are invoked the first time. The code cache serializes the
342
+ * metadata that V8 currently knows about the `Script` that it can use to speed up
343
+ * future compilations.
344
+ *
345
+ * ```js
346
+ * const script = new vm.Script(`
347
+ * function add(a, b) {
348
+ * return a + b;
349
+ * }
350
+ *
351
+ * const x = add(1, 2);
352
+ * `);
353
+ *
354
+ * const cacheWithoutAdd = script.createCachedData();
355
+ * // In `cacheWithoutAdd` the function `add()` is marked for full compilation
356
+ * // upon invocation.
357
+ *
358
+ * script.runInThisContext();
359
+ *
360
+ * const cacheWithAdd = script.createCachedData();
361
+ * // `cacheWithAdd` contains fully compiled function `add()`.
362
+ * ```
363
+ * @since v10.6.0
364
+ */
365
+ createCachedData(): NonSharedBuffer;
366
+ /** @deprecated in favor of `script.createCachedData()` */
367
+ cachedDataProduced?: boolean;
368
+ /**
369
+ * When `cachedData` is supplied to create the `vm.Script`, this value will be set
370
+ * to either `true` or `false` depending on acceptance of the data by V8.
371
+ * Otherwise the value is `undefined`.
372
+ * @since v5.7.0
373
+ */
374
+ cachedDataRejected?: boolean;
375
+ cachedData?: NonSharedBuffer;
376
+ /**
377
+ * When the script is compiled from a source that contains a source map magic
378
+ * comment, this property will be set to the URL of the source map.
379
+ *
380
+ * ```js
381
+ * import vm from 'node:vm';
382
+ *
383
+ * const script = new vm.Script(`
384
+ * function myFunc() {}
385
+ * //# sourceMappingURL=sourcemap.json
386
+ * `);
387
+ *
388
+ * console.log(script.sourceMapURL);
389
+ * // Prints: sourcemap.json
390
+ * ```
391
+ * @since v19.1.0, v18.13.0
392
+ */
393
+ sourceMapURL: string | undefined;
394
+ }
395
+ /**
396
+ * If the given `contextObject` is an object, the `vm.createContext()` method will
397
+ * [prepare that object](https://nodejs.org/docs/latest-v20.x/api/vm.html#what-does-it-mean-to-contextify-an-object)
398
+ * and return a reference to it so that it can be used in calls to {@link runInContext} or
399
+ * [`script.runInContext()`](https://nodejs.org/docs/latest-v20.x/api/vm.html#scriptrunincontextcontextifiedobject-options).
400
+ * Inside such scripts, the global object will be wrapped by the `contextObject`, retaining all of its
401
+ * existing properties but also having the built-in objects and functions any standard
402
+ * [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global
403
+ * variables will remain unchanged.
404
+ *
405
+ * ```js
406
+ * const vm = require('node:vm');
407
+ *
408
+ * global.globalVar = 3;
409
+ *
410
+ * const context = { globalVar: 1 };
411
+ * vm.createContext(context);
412
+ *
413
+ * vm.runInContext('globalVar *= 2;', context);
414
+ *
415
+ * console.log(context);
416
+ * // Prints: { globalVar: 2 }
417
+ *
418
+ * console.log(global.globalVar);
419
+ * // Prints: 3
420
+ * ```
421
+ *
422
+ * If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
423
+ * empty contextified object will be returned.
424
+ *
425
+ * When the global object in the newly created context is contextified, it has some quirks
426
+ * compared to ordinary global objects. For example, it cannot be frozen. To create a context
427
+ * without the contextifying quirks, pass `vm.constants.DONT_CONTEXTIFY` as the `contextObject`
428
+ * argument. See the documentation of `vm.constants.DONT_CONTEXTIFY` for details.
429
+ *
430
+ * The `vm.createContext()` method is primarily useful for creating a single
431
+ * context that can be used to run multiple scripts. For instance, if emulating a
432
+ * web browser, the method can be used to create a single context representing a
433
+ * window's global object, then run all `<script>` tags together within that
434
+ * context.
435
+ *
436
+ * The provided `name` and `origin` of the context are made visible through the
437
+ * Inspector API.
438
+ * @since v0.3.1
439
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
440
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
441
+ * @return contextified object.
442
+ */
443
+ function createContext(
444
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
445
+ options?: CreateContextOptions,
446
+ ): Context;
447
+ /**
448
+ * Returns `true` if the given `object` object has been contextified using {@link createContext},
449
+ * or if it's the global object of a context created using `vm.constants.DONT_CONTEXTIFY`.
450
+ * @since v0.11.7
451
+ */
452
+ function isContext(sandbox: Context): boolean;
453
+ /**
454
+ * The `vm.runInContext()` method compiles `code`, runs it within the context of
455
+ * the `contextifiedObject`, then returns the result. Running code does not have
456
+ * access to the local scope. The `contextifiedObject` object _must_ have been
457
+ * previously `contextified` using the {@link createContext} method.
458
+ *
459
+ * If `options` is a string, then it specifies the filename.
460
+ *
461
+ * The following example compiles and executes different scripts using a single `contextified` object:
462
+ *
463
+ * ```js
464
+ * import vm from 'node:vm';
465
+ *
466
+ * const contextObject = { globalVar: 1 };
467
+ * vm.createContext(contextObject);
468
+ *
469
+ * for (let i = 0; i < 10; ++i) {
470
+ * vm.runInContext('globalVar *= 2;', contextObject);
471
+ * }
472
+ * console.log(contextObject);
473
+ * // Prints: { globalVar: 1024 }
474
+ * ```
475
+ * @since v0.3.1
476
+ * @param code The JavaScript code to compile and run.
477
+ * @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
478
+ * @return the result of the very last statement executed in the script.
479
+ */
480
+ function runInContext(code: string, contextifiedObject: Context, options?: RunningCodeOptions | string): any;
481
+ /**
482
+ * This method is a shortcut to
483
+ * `(new vm.Script(code, options)).runInContext(vm.createContext(options), options)`.
484
+ * If `options` is a string, then it specifies the filename.
485
+ *
486
+ * It does several things at once:
487
+ *
488
+ * 1. Creates a new context.
489
+ * 2. If `contextObject` is an object, contextifies it with the new context.
490
+ * If `contextObject` is undefined, creates a new object and contextifies it.
491
+ * If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
492
+ * 3. Compiles the code as a`vm.Script`
493
+ * 4. Runs the compield code within the created context. The code does not have access to the scope in
494
+ * which this method is called.
495
+ * 5. Returns the result.
496
+ *
497
+ * The following example compiles and executes code that increments a global
498
+ * variable and sets a new one. These globals are contained in the `contextObject`.
499
+ *
500
+ * ```js
501
+ * const vm = require('node:vm');
502
+ *
503
+ * const contextObject = {
504
+ * animal: 'cat',
505
+ * count: 2,
506
+ * };
507
+ *
508
+ * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
509
+ * console.log(contextObject);
510
+ * // Prints: { animal: 'cat', count: 3, name: 'kitty' }
511
+ *
512
+ * // This would throw if the context is created from a contextified object.
513
+ * // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary global objects that
514
+ * // can be frozen.
515
+ * const frozenContext = vm.runInNewContext('Object.freeze(globalThis); globalThis;', vm.constants.DONT_CONTEXTIFY);
516
+ * ```
517
+ * @since v0.3.1
518
+ * @param code The JavaScript code to compile and run.
519
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
520
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
521
+ * @return the result of the very last statement executed in the script.
522
+ */
523
+ function runInNewContext(
524
+ code: string,
525
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
526
+ options?: RunningCodeInNewContextOptions | string,
527
+ ): any;
528
+ /**
529
+ * `vm.runInThisContext()` compiles `code`, runs it within the context of the
530
+ * current `global` and returns the result. Running code does not have access to
531
+ * local scope, but does have access to the current `global` object.
532
+ *
533
+ * If `options` is a string, then it specifies the filename.
534
+ *
535
+ * The following example illustrates using both `vm.runInThisContext()` and
536
+ * the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
537
+ *
538
+ * ```js
539
+ * import vm from 'node:vm';
540
+ * let localVar = 'initial value';
541
+ *
542
+ * const vmResult = vm.runInThisContext('localVar = "vm";');
543
+ * console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
544
+ * // Prints: vmResult: 'vm', localVar: 'initial value'
545
+ *
546
+ * const evalResult = eval('localVar = "eval";');
547
+ * console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
548
+ * // Prints: evalResult: 'eval', localVar: 'eval'
549
+ * ```
550
+ *
551
+ * Because `vm.runInThisContext()` does not have access to the local scope, `localVar` is unchanged. In contrast,
552
+ * [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
553
+ * 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')`.
554
+ *
555
+ * ## Example: Running an HTTP server within a VM
556
+ *
557
+ * When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
558
+ * context. The code passed to this VM context will have its own isolated scope.
559
+ *
560
+ * In order to run a simple web server using the `node:http` module the code passed
561
+ * to the context must either call `require('node:http')` on its own, or have a
562
+ * reference to the `node:http` module passed to it. For instance:
563
+ *
564
+ * ```js
565
+ * 'use strict';
566
+ * import vm from 'node:vm';
567
+ *
568
+ * const code = `
569
+ * ((require) => {
570
+ * const http = require('node:http');
571
+ * http.createServer((request, response) => {
572
+ * response.writeHead(200, { 'Content-Type': 'text/plain' });
573
+ * response.end('Hello World\\n');
574
+ * }).listen(8124);
575
+ *
576
+ * console.log('Server running at http://127.0.0.1:8124/');
577
+ * })`;
578
+ *
579
+ * vm.runInThisContext(code)(require);
580
+ * ```
581
+ *
582
+ * The `require()` in the above case shares the state with the context it is
583
+ * passed from. This may introduce risks when untrusted code is executed, e.g.
584
+ * altering objects in the context in unwanted ways.
585
+ * @since v0.3.1
586
+ * @param code The JavaScript code to compile and run.
587
+ * @return the result of the very last statement executed in the script.
588
+ */
589
+ function runInThisContext(code: string, options?: RunningCodeOptions | string): any;
590
+ /**
591
+ * Compiles the given code into the provided context (if no context is
592
+ * supplied, the current context is used), and returns it wrapped inside a
593
+ * function with the given `params`.
594
+ * @since v10.10.0
595
+ * @param code The body of the function to compile.
596
+ * @param params An array of strings containing all parameters for the function.
597
+ */
598
+ function compileFunction(
599
+ code: string,
600
+ params?: readonly string[],
601
+ options?: CompileFunctionOptions,
602
+ ): Function & Pick<Script, "cachedData" | "cachedDataProduced" | "cachedDataRejected">;
603
+ /**
604
+ * Measure the memory known to V8 and used by all contexts known to the
605
+ * current V8 isolate, or the main context.
606
+ *
607
+ * The format of the object that the returned Promise may resolve with is
608
+ * specific to the V8 engine and may change from one version of V8 to the next.
609
+ *
610
+ * The returned result is different from the statistics returned by `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
611
+ * memory reachable by each V8 specific contexts in the current instance of
612
+ * the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
613
+ * the memory occupied by each heap space in the current V8 instance.
614
+ *
615
+ * ```js
616
+ * import vm from 'node:vm';
617
+ * // Measure the memory used by the main context.
618
+ * vm.measureMemory({ mode: 'summary' })
619
+ * // This is the same as vm.measureMemory()
620
+ * .then((result) => {
621
+ * // The current format is:
622
+ * // {
623
+ * // total: {
624
+ * // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
625
+ * // }
626
+ * // }
627
+ * console.log(result);
628
+ * });
629
+ *
630
+ * const context = vm.createContext({ a: 1 });
631
+ * vm.measureMemory({ mode: 'detailed', execution: 'eager' })
632
+ * .then((result) => {
633
+ * // Reference the context here so that it won't be GC'ed
634
+ * // until the measurement is complete.
635
+ * console.log(context.a);
636
+ * // {
637
+ * // total: {
638
+ * // jsMemoryEstimate: 2574732,
639
+ * // jsMemoryRange: [ 2574732, 2904372 ]
640
+ * // },
641
+ * // current: {
642
+ * // jsMemoryEstimate: 2438996,
643
+ * // jsMemoryRange: [ 2438996, 2768636 ]
644
+ * // },
645
+ * // other: [
646
+ * // {
647
+ * // jsMemoryEstimate: 135736,
648
+ * // jsMemoryRange: [ 135736, 465376 ]
649
+ * // }
650
+ * // ]
651
+ * // }
652
+ * console.log(result);
653
+ * });
654
+ * ```
655
+ * @since v13.10.0
656
+ * @experimental
657
+ */
658
+ function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
659
+ interface ModuleEvaluateOptions extends Pick<RunningScriptOptions, "breakOnSigint" | "timeout"> {}
660
+ type ModuleLinker = (
661
+ specifier: string,
662
+ referencingModule: Module,
663
+ extra: {
664
+ /** @deprecated Use `attributes` instead */
665
+ assert: ImportAttributes;
666
+ attributes: ImportAttributes;
667
+ },
668
+ ) => Module | Promise<Module>;
669
+ type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
670
+ /**
671
+ * This feature is only available with the `--experimental-vm-modules` command
672
+ * flag enabled.
673
+ *
674
+ * The `vm.Module` class provides a low-level interface for using
675
+ * ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script` class that closely mirrors [Module Record](https://262.ecma-international.org/14.0/#sec-abstract-module-records) s as
676
+ * defined in the ECMAScript
677
+ * specification.
678
+ *
679
+ * Unlike `vm.Script` however, every `vm.Module` object is bound to a context from
680
+ * its creation. Operations on `vm.Module` objects are intrinsically asynchronous,
681
+ * in contrast with the synchronous nature of `vm.Script` objects. The use of
682
+ * 'async' functions can help with manipulating `vm.Module` objects.
683
+ *
684
+ * Using a `vm.Module` object requires three distinct steps: creation/parsing,
685
+ * linking, and evaluation. These three steps are illustrated in the following
686
+ * example.
687
+ *
688
+ * This implementation lies at a lower level than the `ECMAScript Module
689
+ * loader`. There is also no way to interact with the Loader yet, though
690
+ * support is planned.
691
+ *
692
+ * ```js
693
+ * import vm from 'node:vm';
694
+ *
695
+ * const contextifiedObject = vm.createContext({
696
+ * secret: 42,
697
+ * print: console.log,
698
+ * });
699
+ *
700
+ * // Step 1
701
+ * //
702
+ * // Create a Module by constructing a new `vm.SourceTextModule` object. This
703
+ * // parses the provided source text, throwing a `SyntaxError` if anything goes
704
+ * // wrong. By default, a Module is created in the top context. But here, we
705
+ * // specify `contextifiedObject` as the context this Module belongs to.
706
+ * //
707
+ * // Here, we attempt to obtain the default export from the module "foo", and
708
+ * // put it into local binding "secret".
709
+ *
710
+ * const bar = new vm.SourceTextModule(`
711
+ * import s from 'foo';
712
+ * s;
713
+ * print(s);
714
+ * `, { context: contextifiedObject });
715
+ *
716
+ * // Step 2
717
+ * //
718
+ * // "Link" the imported dependencies of this Module to it.
719
+ * //
720
+ * // The provided linking callback (the "linker") accepts two arguments: the
721
+ * // parent module (`bar` in this case) and the string that is the specifier of
722
+ * // the imported module. The callback is expected to return a Module that
723
+ * // corresponds to the provided specifier, with certain requirements documented
724
+ * // in `module.link()`.
725
+ * //
726
+ * // If linking has not started for the returned Module, the same linker
727
+ * // callback will be called on the returned Module.
728
+ * //
729
+ * // Even top-level Modules without dependencies must be explicitly linked. The
730
+ * // callback provided would never be called, however.
731
+ * //
732
+ * // The link() method returns a Promise that will be resolved when all the
733
+ * // Promises returned by the linker resolve.
734
+ * //
735
+ * // Note: This is a contrived example in that the linker function creates a new
736
+ * // "foo" module every time it is called. In a full-fledged module system, a
737
+ * // cache would probably be used to avoid duplicated modules.
738
+ *
739
+ * async function linker(specifier, referencingModule) {
740
+ * if (specifier === 'foo') {
741
+ * return new vm.SourceTextModule(`
742
+ * // The "secret" variable refers to the global variable we added to
743
+ * // "contextifiedObject" when creating the context.
744
+ * export default secret;
745
+ * `, { context: referencingModule.context });
746
+ *
747
+ * // Using `contextifiedObject` instead of `referencingModule.context`
748
+ * // here would work as well.
749
+ * }
750
+ * throw new Error(`Unable to resolve dependency: ${specifier}`);
751
+ * }
752
+ * await bar.link(linker);
753
+ *
754
+ * // Step 3
755
+ * //
756
+ * // Evaluate the Module. The evaluate() method returns a promise which will
757
+ * // resolve after the module has finished evaluating.
758
+ *
759
+ * // Prints 42.
760
+ * await bar.evaluate();
761
+ * ```
762
+ * @since v13.0.0, v12.16.0
763
+ * @experimental
764
+ */
765
+ class Module {
766
+ /**
767
+ * The specifiers of all dependencies of this module. The returned array is frozen
768
+ * to disallow any changes to it.
769
+ *
770
+ * Corresponds to the `[[RequestedModules]]` field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in
771
+ * the ECMAScript specification.
772
+ */
773
+ dependencySpecifiers: readonly string[];
774
+ /**
775
+ * If the `module.status` is `'errored'`, this property contains the exception
776
+ * thrown by the module during evaluation. If the status is anything else,
777
+ * accessing this property will result in a thrown exception.
778
+ *
779
+ * The value `undefined` cannot be used for cases where there is not a thrown
780
+ * exception due to possible ambiguity with `throw undefined;`.
781
+ *
782
+ * Corresponds to the `[[EvaluationError]]` field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s
783
+ * in the ECMAScript specification.
784
+ */
785
+ error: any;
786
+ /**
787
+ * The identifier of the current module, as set in the constructor.
788
+ */
789
+ identifier: string;
790
+ context: Context;
791
+ /**
792
+ * The namespace object of the module. This is only available after linking
793
+ * (`module.link()`) has completed.
794
+ *
795
+ * Corresponds to the [GetModuleNamespace](https://tc39.es/ecma262/#sec-getmodulenamespace) abstract operation in the ECMAScript
796
+ * specification.
797
+ */
798
+ namespace: Object;
799
+ /**
800
+ * The current status of the module. Will be one of:
801
+ *
802
+ * * `'unlinked'`: `module.link()` has not yet been called.
803
+ * * `'linking'`: `module.link()` has been called, but not all Promises returned
804
+ * by the linker function have been resolved yet.
805
+ * * `'linked'`: The module has been linked successfully, and all of its
806
+ * dependencies are linked, but `module.evaluate()` has not yet been called.
807
+ * * `'evaluating'`: The module is being evaluated through a `module.evaluate()` on
808
+ * itself or a parent module.
809
+ * * `'evaluated'`: The module has been successfully evaluated.
810
+ * * `'errored'`: The module has been evaluated, but an exception was thrown.
811
+ *
812
+ * 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'`
813
+ * corresponds to `'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
814
+ * value that is not `undefined`.
815
+ */
816
+ status: ModuleStatus;
817
+ /**
818
+ * Evaluate the module.
819
+ *
820
+ * This must be called after the module has been linked; otherwise it will reject.
821
+ * It could be called also when the module has already been evaluated, in which
822
+ * case it will either do nothing if the initial evaluation ended in success
823
+ * (`module.status` is `'evaluated'`) or it will re-throw the exception that the
824
+ * initial evaluation resulted in (`module.status` is `'errored'`).
825
+ *
826
+ * This method cannot be called while the module is being evaluated
827
+ * (`module.status` is `'evaluating'`).
828
+ *
829
+ * Corresponds to the [Evaluate() concrete method](https://tc39.es/ecma262/#sec-moduleevaluation) field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in the
830
+ * ECMAScript specification.
831
+ * @return Fulfills with `undefined` upon success.
832
+ */
833
+ evaluate(options?: ModuleEvaluateOptions): Promise<void>;
834
+ /**
835
+ * Link module dependencies. This method must be called before evaluation, and
836
+ * can only be called once per module.
837
+ *
838
+ * The function is expected to return a `Module` object or a `Promise` that
839
+ * eventually resolves to a `Module` object. The returned `Module` must satisfy the
840
+ * following two invariants:
841
+ *
842
+ * * It must belong to the same context as the parent `Module`.
843
+ * * Its `status` must not be `'errored'`.
844
+ *
845
+ * If the returned `Module`'s `status` is `'unlinked'`, this method will be
846
+ * recursively called on the returned `Module` with the same provided `linker` function.
847
+ *
848
+ * `link()` returns a `Promise` that will either get resolved when all linking
849
+ * instances resolve to a valid `Module`, or rejected if the linker function either
850
+ * throws an exception or returns an invalid `Module`.
851
+ *
852
+ * The linker function roughly corresponds to the implementation-defined [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) abstract operation in the
853
+ * ECMAScript
854
+ * specification, with a few key differences:
855
+ *
856
+ * * The linker function is allowed to be asynchronous while [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) is synchronous.
857
+ *
858
+ * The actual [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) implementation used during module
859
+ * linking is one that returns the modules linked during linking. Since at
860
+ * that point all modules would have been fully linked already, the [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) implementation is fully synchronous per
861
+ * specification.
862
+ *
863
+ * Corresponds to the [Link() concrete method](https://tc39.es/ecma262/#sec-moduledeclarationlinking) field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in
864
+ * the ECMAScript specification.
865
+ */
866
+ link(linker: ModuleLinker): Promise<void>;
867
+ }
868
+ interface SourceTextModuleOptions extends Pick<ScriptOptions, "cachedData" | "columnOffset" | "lineOffset"> {
869
+ /**
870
+ * String used in stack traces.
871
+ * @default 'vm:module(i)' where i is a context-specific ascending index.
872
+ */
873
+ identifier?: string | undefined;
874
+ context?: Context | undefined;
875
+ /**
876
+ * Called during evaluation of this module to initialize the `import.meta`.
877
+ */
878
+ initializeImportMeta?: ((meta: ImportMeta, module: SourceTextModule) => void) | undefined;
879
+ /**
880
+ * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
881
+ * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
882
+ * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
883
+ */
884
+ importModuleDynamically?: DynamicModuleLoader<SourceTextModule> | undefined;
885
+ }
886
+ /**
887
+ * This feature is only available with the `--experimental-vm-modules` command
888
+ * flag enabled.
889
+ *
890
+ * The `vm.SourceTextModule` class provides the [Source Text Module Record](https://tc39.es/ecma262/#sec-source-text-module-records) as
891
+ * defined in the ECMAScript specification.
892
+ * @since v9.6.0
893
+ * @experimental
894
+ */
895
+ class SourceTextModule extends Module {
896
+ /**
897
+ * Creates a new `SourceTextModule` instance.
898
+ * @param code JavaScript Module code to parse
899
+ */
900
+ constructor(code: string, options?: SourceTextModuleOptions);
901
+ }
902
+ interface SyntheticModuleOptions {
903
+ /**
904
+ * String used in stack traces.
905
+ * @default 'vm:module(i)' where i is a context-specific ascending index.
906
+ */
907
+ identifier?: string | undefined;
908
+ /**
909
+ * The contextified object as returned by the `vm.createContext()` method, to compile and evaluate this module in.
910
+ */
911
+ context?: Context | undefined;
912
+ }
913
+ /**
914
+ * This feature is only available with the `--experimental-vm-modules` command
915
+ * flag enabled.
916
+ *
917
+ * The `vm.SyntheticModule` class provides the [Synthetic Module Record](https://heycam.github.io/webidl/#synthetic-module-records) as
918
+ * defined in the WebIDL specification. The purpose of synthetic modules is to
919
+ * provide a generic interface for exposing non-JavaScript sources to ECMAScript
920
+ * module graphs.
921
+ *
922
+ * ```js
923
+ * import vm from 'node:vm';
924
+ *
925
+ * const source = '{ "a": 1 }';
926
+ * const module = new vm.SyntheticModule(['default'], function() {
927
+ * const obj = JSON.parse(source);
928
+ * this.setExport('default', obj);
929
+ * });
930
+ *
931
+ * // Use `module` in linking...
932
+ * ```
933
+ * @since v13.0.0, v12.16.0
934
+ * @experimental
935
+ */
936
+ class SyntheticModule extends Module {
937
+ /**
938
+ * Creates a new `SyntheticModule` instance.
939
+ * @param exportNames Array of names that will be exported from the module.
940
+ * @param evaluateCallback Called when the module is evaluated.
941
+ */
942
+ constructor(
943
+ exportNames: string[],
944
+ evaluateCallback: (this: SyntheticModule) => void,
945
+ options?: SyntheticModuleOptions,
946
+ );
947
+ /**
948
+ * This method is used after the module is linked to set the values of exports. If
949
+ * it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error
950
+ * will be thrown.
951
+ *
952
+ * ```js
953
+ * import vm from 'node:vm';
954
+ *
955
+ * const m = new vm.SyntheticModule(['x'], () => {
956
+ * m.setExport('x', 1);
957
+ * });
958
+ *
959
+ * await m.link(() => {});
960
+ * await m.evaluate();
961
+ *
962
+ * assert.strictEqual(m.namespace.x, 1);
963
+ * ```
964
+ * @since v13.0.0, v12.16.0
965
+ * @param name Name of the export to set.
966
+ * @param value The value to set the export to.
967
+ */
968
+ setExport(name: string, value: any): void;
969
+ }
970
+ /**
971
+ * Returns an object containing commonly used constants for VM operations.
972
+ * @since v20.12.0
973
+ */
974
+ namespace constants {
975
+ /**
976
+ * A constant that can be used as the `importModuleDynamically` option to `vm.Script`
977
+ * and `vm.compileFunction()` so that Node.js uses the default ESM loader from the main
978
+ * context to load the requested module.
979
+ *
980
+ * For detailed information, see [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v20.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
981
+ * @since v20.12.0
982
+ */
983
+ const USE_MAIN_CONTEXT_DEFAULT_LOADER: number;
984
+ /**
985
+ * This constant, when used as the `contextObject` argument in vm APIs, instructs Node.js to create
986
+ * a context without wrapping its global object with another object in a Node.js-specific manner.
987
+ * As a result, the `globalThis` value inside the new context would behave more closely to an ordinary
988
+ * one.
989
+ *
990
+ * When `vm.constants.DONT_CONTEXTIFY` is used as the `contextObject` argument to {@link createContext},
991
+ * the returned object is a proxy-like object to the global object in the newly created context with
992
+ * fewer Node.js-specific quirks. It is reference equal to the `globalThis` value in the new context,
993
+ * can be modified from outside the context, and can be used to access built-ins in the new context directly.
994
+ * @since v20.18.0
995
+ */
996
+ const DONT_CONTEXTIFY: number;
997
+ }
998
+ }
999
+ declare module "node:vm" {
1000
+ export * from "vm";
1001
+ }