@types/node 18.19.22 → 18.19.23

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 (56) hide show
  1. node v18.19/README.md +1 -1
  2. node v18.19/package.json +3 -10
  3. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  4. node v18.19/ts4.8/assert.d.ts +0 -985
  5. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  6. node v18.19/ts4.8/buffer.d.ts +0 -2353
  7. node v18.19/ts4.8/child_process.d.ts +0 -1544
  8. node v18.19/ts4.8/cluster.d.ts +0 -432
  9. node v18.19/ts4.8/console.d.ts +0 -412
  10. node v18.19/ts4.8/constants.d.ts +0 -19
  11. node v18.19/ts4.8/crypto.d.ts +0 -4457
  12. node v18.19/ts4.8/dgram.d.ts +0 -596
  13. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  14. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  15. node v18.19/ts4.8/dns.d.ts +0 -809
  16. node v18.19/ts4.8/dom-events.d.ts +0 -122
  17. node v18.19/ts4.8/domain.d.ts +0 -170
  18. node v18.19/ts4.8/events.d.ts +0 -819
  19. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  20. node v18.19/ts4.8/fs.d.ts +0 -4231
  21. node v18.19/ts4.8/globals.d.ts +0 -377
  22. node v18.19/ts4.8/globals.global.d.ts +0 -1
  23. node v18.19/ts4.8/http.d.ts +0 -1803
  24. node v18.19/ts4.8/http2.d.ts +0 -2386
  25. node v18.19/ts4.8/https.d.ts +0 -544
  26. node v18.19/ts4.8/index.d.ts +0 -88
  27. node v18.19/ts4.8/inspector.d.ts +0 -2739
  28. node v18.19/ts4.8/module.d.ts +0 -298
  29. node v18.19/ts4.8/net.d.ts +0 -918
  30. node v18.19/ts4.8/os.d.ts +0 -473
  31. node v18.19/ts4.8/path.d.ts +0 -191
  32. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  33. node v18.19/ts4.8/process.d.ts +0 -1548
  34. node v18.19/ts4.8/punycode.d.ts +0 -117
  35. node v18.19/ts4.8/querystring.d.ts +0 -141
  36. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  37. node v18.19/ts4.8/readline.d.ts +0 -666
  38. node v18.19/ts4.8/repl.d.ts +0 -430
  39. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  40. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  41. node v18.19/ts4.8/stream/web.d.ts +0 -352
  42. node v18.19/ts4.8/stream.d.ts +0 -1731
  43. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  44. node v18.19/ts4.8/test.d.ts +0 -1113
  45. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  46. node v18.19/ts4.8/timers.d.ts +0 -126
  47. node v18.19/ts4.8/tls.d.ts +0 -1203
  48. node v18.19/ts4.8/trace_events.d.ts +0 -171
  49. node v18.19/ts4.8/tty.d.ts +0 -206
  50. node v18.19/ts4.8/url.d.ts +0 -954
  51. node v18.19/ts4.8/util.d.ts +0 -2075
  52. node v18.19/ts4.8/v8.d.ts +0 -753
  53. node v18.19/ts4.8/vm.d.ts +0 -667
  54. node v18.19/ts4.8/wasi.d.ts +0 -158
  55. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  56. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,667 +0,0 @@
1
- /**
2
- * The `vm` module enables compiling and running code within V8 Virtual
3
- * Machine contexts.
4
- *
5
- * **The `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
- * const vm = require('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/v18.0.0/lib/vm.js)
38
- */
39
- declare module "vm" {
40
- import { ImportAttributes } from "node:module";
41
- interface Context extends NodeJS.Dict<any> {}
42
- interface BaseOptions {
43
- /**
44
- * Specifies the filename used in stack traces produced by this script.
45
- * Default: `''`.
46
- */
47
- filename?: string | undefined;
48
- /**
49
- * Specifies the line number offset that is displayed in stack traces produced by this script.
50
- * Default: `0`.
51
- */
52
- lineOffset?: number | undefined;
53
- /**
54
- * Specifies the column number offset that is displayed in stack traces produced by this script.
55
- * @default 0
56
- */
57
- columnOffset?: number | undefined;
58
- }
59
- interface ScriptOptions extends BaseOptions {
60
- /**
61
- * V8's code cache data for the supplied source.
62
- */
63
- cachedData?: Buffer | NodeJS.ArrayBufferView | undefined;
64
- /** @deprecated in favor of `script.createCachedData()` */
65
- produceCachedData?: boolean | undefined;
66
- /**
67
- * Called during evaluation of this module when `import()` is called.
68
- * If this option is not specified, calls to `import()` will reject with `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`.
69
- */
70
- importModuleDynamically?:
71
- | ((specifier: string, script: Script, importAttributes: ImportAttributes) => Module)
72
- | undefined;
73
- }
74
- interface RunningScriptOptions extends BaseOptions {
75
- /**
76
- * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
77
- * Default: `true`.
78
- */
79
- displayErrors?: boolean | undefined;
80
- /**
81
- * Specifies the number of milliseconds to execute code before terminating execution.
82
- * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
83
- */
84
- timeout?: number | undefined;
85
- /**
86
- * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
87
- * 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
- * If execution is terminated, an `Error` will be thrown.
89
- * Default: `false`.
90
- */
91
- breakOnSigint?: boolean | undefined;
92
- }
93
- interface RunningScriptInNewContextOptions extends RunningScriptOptions {
94
- /**
95
- * Human-readable name of the newly created context.
96
- */
97
- contextName?: CreateContextOptions["name"];
98
- /**
99
- * Origin corresponding to the newly created context for display purposes. The origin should be formatted like a URL,
100
- * but with only the scheme, host, and port (if necessary), like the value of the `url.origin` property of a `URL` object.
101
- * Most notably, this string should omit the trailing slash, as that denotes a path.
102
- */
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"];
113
- }
114
- interface RunningCodeInNewContextOptions extends RunningScriptInNewContextOptions {
115
- cachedData?: ScriptOptions["cachedData"];
116
- importModuleDynamically?: ScriptOptions["importModuleDynamically"];
117
- }
118
- interface CompileFunctionOptions extends BaseOptions {
119
- /**
120
- * Provides an optional data with V8's code cache data for the supplied source.
121
- */
122
- cachedData?: Buffer | undefined;
123
- /**
124
- * Specifies whether to produce new cache data.
125
- * Default: `false`,
126
- */
127
- produceCachedData?: boolean | undefined;
128
- /**
129
- * The sandbox/context in which the said function should be compiled in.
130
- */
131
- parsingContext?: Context | undefined;
132
- /**
133
- * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
134
- */
135
- contextExtensions?: Object[] | undefined;
136
- }
137
- interface CreateContextOptions {
138
- /**
139
- * Human-readable name of the newly created context.
140
- * @default 'VM Context i' Where i is an ascending numerical index of the created context.
141
- */
142
- name?: string | undefined;
143
- /**
144
- * Corresponds to the newly created context for display purposes.
145
- * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
146
- * like the value of the `url.origin` property of a URL object.
147
- * Most notably, this string should omit the trailing slash, as that denotes a path.
148
- * @default ''
149
- */
150
- origin?: string | undefined;
151
- codeGeneration?:
152
- | {
153
- /**
154
- * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
155
- * will throw an EvalError.
156
- * @default true
157
- */
158
- strings?: boolean | undefined;
159
- /**
160
- * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
161
- * @default true
162
- */
163
- wasm?: boolean | undefined;
164
- }
165
- | undefined;
166
- /**
167
- * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
168
- */
169
- microtaskMode?: "afterEvaluate" | undefined;
170
- }
171
- type MeasureMemoryMode = "summary" | "detailed";
172
- interface MeasureMemoryOptions {
173
- /**
174
- * @default 'summary'
175
- */
176
- mode?: MeasureMemoryMode | undefined;
177
- /**
178
- * @default 'default'
179
- */
180
- execution?: "default" | "eager" | undefined;
181
- }
182
- interface MemoryMeasurement {
183
- total: {
184
- jsMemoryEstimate: number;
185
- jsMemoryRange: [number, number];
186
- };
187
- }
188
- /**
189
- * Instances of the `vm.Script` class contain precompiled scripts that can be
190
- * executed in specific contexts.
191
- * @since v0.3.1
192
- */
193
- class Script {
194
- constructor(code: string, options?: ScriptOptions | string);
195
- /**
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
197
- * to local scope.
198
- *
199
- * The following example compiles code that increments a global variable, sets
200
- * the value of another global variable, then execute the code multiple times.
201
- * The globals are contained in the `context` object.
202
- *
203
- * ```js
204
- * const vm = require('vm');
205
- *
206
- * const context = {
207
- * animal: 'cat',
208
- * count: 2
209
- * };
210
- *
211
- * const script = new vm.Script('count += 1; name = "kitty";');
212
- *
213
- * vm.createContext(context);
214
- * for (let i = 0; i < 10; ++i) {
215
- * script.runInContext(context);
216
- * }
217
- *
218
- * console.log(context);
219
- * // Prints: { animal: 'cat', count: 12, name: 'kitty' }
220
- * ```
221
- *
222
- * Using the `timeout` or `breakOnSigint` options will result in new event loops
223
- * and corresponding threads being started, which have a non-zero performance
224
- * overhead.
225
- * @since v0.3.1
226
- * @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
227
- * @return the result of the very last statement executed in the script.
228
- */
229
- runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
230
- /**
231
- * First contextifies the given `contextObject`, runs the compiled code contained
232
- * by the `vm.Script` object within the created context, and returns the result.
233
- * Running code does not have access to local scope.
234
- *
235
- * The following example compiles code that sets a global variable, then executes
236
- * the code multiple times in different contexts. The globals are set on and
237
- * contained within each individual `context`.
238
- *
239
- * ```js
240
- * const vm = require('vm');
241
- *
242
- * const script = new vm.Script('globalVar = "set"');
243
- *
244
- * const contexts = [{}, {}, {}];
245
- * contexts.forEach((context) => {
246
- * script.runInNewContext(context);
247
- * });
248
- *
249
- * console.log(contexts);
250
- * // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
251
- * ```
252
- * @since v0.3.1
253
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
254
- * @return the result of the very last statement executed in the script.
255
- */
256
- runInNewContext(contextObject?: Context, options?: RunningScriptInNewContextOptions): any;
257
- /**
258
- * Runs the compiled code contained by the `vm.Script` within the context of the
259
- * current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
260
- *
261
- * The following example compiles code that increments a `global` variable then
262
- * executes that code multiple times:
263
- *
264
- * ```js
265
- * const vm = require('vm');
266
- *
267
- * global.globalVar = 0;
268
- *
269
- * const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
270
- *
271
- * for (let i = 0; i < 1000; ++i) {
272
- * script.runInThisContext();
273
- * }
274
- *
275
- * console.log(globalVar);
276
- *
277
- * // 1000
278
- * ```
279
- * @since v0.3.1
280
- * @return the result of the very last statement executed in the script.
281
- */
282
- runInThisContext(options?: RunningScriptOptions): any;
283
- /**
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
285
- * time and any number of times.
286
- *
287
- * ```js
288
- * const script = new vm.Script(`
289
- * function add(a, b) {
290
- * return a + b;
291
- * }
292
- *
293
- * const x = add(1, 2);
294
- * `);
295
- *
296
- * const cacheWithoutX = script.createCachedData();
297
- *
298
- * script.runInThisContext();
299
- *
300
- * const cacheWithX = script.createCachedData();
301
- * ```
302
- * @since v10.6.0
303
- */
304
- createCachedData(): Buffer;
305
- /** @deprecated in favor of `script.createCachedData()` */
306
- cachedDataProduced?: boolean | undefined;
307
- cachedDataRejected?: boolean | undefined;
308
- cachedData?: Buffer | undefined;
309
- /**
310
- * When the script is compiled from a source that contains a source map magic comment, this property will be set to the URL of the source map.
311
- */
312
- sourceMapURL?: string | undefined;
313
- }
314
- /**
315
- * If given a `contextObject`, the `vm.createContext()` method will `prepare
316
- * that object` so that it can be used in calls to {@link runInContext} or `script.runInContext()`. Inside such scripts,
317
- * the `contextObject` will be the global object, retaining all of its existing
318
- * properties but also having the built-in objects and functions any standard [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global variables
319
- * will remain unchanged.
320
- *
321
- * ```js
322
- * const vm = require('vm');
323
- *
324
- * global.globalVar = 3;
325
- *
326
- * const context = { globalVar: 1 };
327
- * vm.createContext(context);
328
- *
329
- * vm.runInContext('globalVar *= 2;', context);
330
- *
331
- * console.log(context);
332
- * // Prints: { globalVar: 2 }
333
- *
334
- * console.log(global.globalVar);
335
- * // Prints: 3
336
- * ```
337
- *
338
- * If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
339
- * empty `contextified` object will be returned.
340
- *
341
- * The `vm.createContext()` method is primarily useful for creating a single
342
- * context that can be used to run multiple scripts. For instance, if emulating a
343
- * web browser, the method can be used to create a single context representing a
344
- * window's global object, then run all `<script>` tags together within that
345
- * context.
346
- *
347
- * The provided `name` and `origin` of the context are made visible through the
348
- * Inspector API.
349
- * @since v0.3.1
350
- * @return contextified object.
351
- */
352
- function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
353
- /**
354
- * Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
355
- * @since v0.11.7
356
- */
357
- function isContext(sandbox: Context): boolean;
358
- /**
359
- * The `vm.runInContext()` method compiles `code`, runs it within the context of
360
- * the `contextifiedObject`, then returns the result. Running code does not have
361
- * access to the local scope. The `contextifiedObject` object _must_ have been
362
- * previously `contextified` using the {@link createContext} method.
363
- *
364
- * If `options` is a string, then it specifies the filename.
365
- *
366
- * The following example compiles and executes different scripts using a single `contextified` object:
367
- *
368
- * ```js
369
- * const vm = require('vm');
370
- *
371
- * const contextObject = { globalVar: 1 };
372
- * vm.createContext(contextObject);
373
- *
374
- * for (let i = 0; i < 10; ++i) {
375
- * vm.runInContext('globalVar *= 2;', contextObject);
376
- * }
377
- * console.log(contextObject);
378
- * // Prints: { globalVar: 1024 }
379
- * ```
380
- * @since v0.3.1
381
- * @param code The JavaScript code to compile and run.
382
- * @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
383
- * @return the result of the very last statement executed in the script.
384
- */
385
- function runInContext(code: string, contextifiedObject: Context, options?: RunningCodeOptions | string): any;
386
- /**
387
- * The `vm.runInNewContext()` first contextifies the given `contextObject` (or
388
- * creates a new `contextObject` if passed as `undefined`), compiles the `code`,
389
- * runs it within the created context, then returns the result. Running code
390
- * does not have access to the local scope.
391
- *
392
- * If `options` is a string, then it specifies the filename.
393
- *
394
- * The following example compiles and executes code that increments a global
395
- * variable and sets a new one. These globals are contained in the `contextObject`.
396
- *
397
- * ```js
398
- * const vm = require('vm');
399
- *
400
- * const contextObject = {
401
- * animal: 'cat',
402
- * count: 2
403
- * };
404
- *
405
- * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
406
- * console.log(contextObject);
407
- * // Prints: { animal: 'cat', count: 3, name: 'kitty' }
408
- * ```
409
- * @since v0.3.1
410
- * @param code The JavaScript code to compile and run.
411
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
412
- * @return the result of the very last statement executed in the script.
413
- */
414
- function runInNewContext(
415
- code: string,
416
- contextObject?: Context,
417
- options?: RunningCodeInNewContextOptions | string,
418
- ): any;
419
- /**
420
- * `vm.runInThisContext()` compiles `code`, runs it within the context of the
421
- * current `global` and returns the result. Running code does not have access to
422
- * local scope, but does have access to the current `global` object.
423
- *
424
- * If `options` is a string, then it specifies the filename.
425
- *
426
- * The following example illustrates using both `vm.runInThisContext()` and
427
- * the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
428
- *
429
- * ```js
430
- * const vm = require('vm');
431
- * let localVar = 'initial value';
432
- *
433
- * const vmResult = vm.runInThisContext('localVar = "vm";');
434
- * console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
435
- * // Prints: vmResult: 'vm', localVar: 'initial value'
436
- *
437
- * const evalResult = eval('localVar = "eval";');
438
- * console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
439
- * // Prints: evalResult: 'eval', localVar: 'eval'
440
- * ```
441
- *
442
- * Because `vm.runInThisContext()` does not have access to the local scope,`localVar` is unchanged. In contrast,
443
- * [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
444
- * 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')`.
445
- *
446
- * ## Example: Running an HTTP server within a VM
447
- *
448
- * When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
449
- * context. The code passed to this VM context will have its own isolated scope.
450
- *
451
- * In order to run a simple web server using the `http` module the code passed to
452
- * the context must either call `require('http')` on its own, or have a reference
453
- * to the `http` module passed to it. For instance:
454
- *
455
- * ```js
456
- * 'use strict';
457
- * const vm = require('vm');
458
- *
459
- * const code = `
460
- * ((require) => {
461
- * const http = require('http');
462
- *
463
- * http.createServer((request, response) => {
464
- * response.writeHead(200, { 'Content-Type': 'text/plain' });
465
- * response.end('Hello World\\n');
466
- * }).listen(8124);
467
- *
468
- * console.log('Server running at http://127.0.0.1:8124/');
469
- * })`;
470
- *
471
- * vm.runInThisContext(code)(require);
472
- * ```
473
- *
474
- * The `require()` in the above case shares the state with the context it is
475
- * passed from. This may introduce risks when untrusted code is executed, e.g.
476
- * altering objects in the context in unwanted ways.
477
- * @since v0.3.1
478
- * @param code The JavaScript code to compile and run.
479
- * @return the result of the very last statement executed in the script.
480
- */
481
- function runInThisContext(code: string, options?: RunningCodeOptions | string): any;
482
- /**
483
- * Compiles the given code into the provided context (if no context is
484
- * supplied, the current context is used), and returns it wrapped inside a
485
- * function with the given `params`.
486
- * @since v10.10.0
487
- * @param code The body of the function to compile.
488
- * @param params An array of strings containing all parameters for the function.
489
- */
490
- function compileFunction(
491
- code: string,
492
- params?: readonly string[],
493
- options?: CompileFunctionOptions,
494
- ): Function & {
495
- cachedData?: Script["cachedData"] | undefined;
496
- cachedDataProduced?: Script["cachedDataProduced"] | undefined;
497
- cachedDataRejected?: Script["cachedDataRejected"] | undefined;
498
- };
499
- /**
500
- * Measure the memory known to V8 and used by all contexts known to the
501
- * current V8 isolate, or the main context.
502
- *
503
- * The format of the object that the returned Promise may resolve with is
504
- * specific to the V8 engine and may change from one version of V8 to the next.
505
- *
506
- * The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
507
- * memory reachable by each V8 specific contexts in the current instance of
508
- * the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
509
- * the memory occupied by each heap space in the current V8 instance.
510
- *
511
- * ```js
512
- * const vm = require('vm');
513
- * // Measure the memory used by the main context.
514
- * vm.measureMemory({ mode: 'summary' })
515
- * // This is the same as vm.measureMemory()
516
- * .then((result) => {
517
- * // The current format is:
518
- * // {
519
- * // total: {
520
- * // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
521
- * // }
522
- * // }
523
- * console.log(result);
524
- * });
525
- *
526
- * const context = vm.createContext({ a: 1 });
527
- * vm.measureMemory({ mode: 'detailed', execution: 'eager' })
528
- * .then((result) => {
529
- * // Reference the context here so that it won't be GC'ed
530
- * // until the measurement is complete.
531
- * console.log(context.a);
532
- * // {
533
- * // total: {
534
- * // jsMemoryEstimate: 2574732,
535
- * // jsMemoryRange: [ 2574732, 2904372 ]
536
- * // },
537
- * // current: {
538
- * // jsMemoryEstimate: 2438996,
539
- * // jsMemoryRange: [ 2438996, 2768636 ]
540
- * // },
541
- * // other: [
542
- * // {
543
- * // jsMemoryEstimate: 135736,
544
- * // jsMemoryRange: [ 135736, 465376 ]
545
- * // }
546
- * // ]
547
- * // }
548
- * console.log(result);
549
- * });
550
- * ```
551
- * @since v13.10.0
552
- * @experimental
553
- */
554
- function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
555
-
556
- interface ModuleEvaluateOptions {
557
- timeout?: RunningScriptOptions["timeout"] | undefined;
558
- breakOnSigint?: RunningScriptOptions["breakOnSigint"] | undefined;
559
- }
560
- type ModuleLinker = (
561
- specifier: string,
562
- referencingModule: Module,
563
- extra: {
564
- /** @deprecated Use `attributes` instead */
565
- assert: ImportAttributes;
566
- attributes: ImportAttributes;
567
- },
568
- ) => Module | Promise<Module>;
569
- type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
570
- class Module {
571
- /**
572
- * The specifiers of all dependencies of this module.
573
- */
574
- dependencySpecifiers: readonly string[];
575
- /**
576
- * If the `module.status` is `'errored'`, this property contains the exception thrown by the module during evaluation.
577
- * If the status is anything else, accessing this property will result in a thrown exception.
578
- */
579
- error: any;
580
- /**
581
- * The identifier of the current module, as set in the constructor.
582
- */
583
- identifier: string;
584
- context: Context;
585
- /**
586
- * The namespace object of the module. This is only available after linking (`module.link()`) has completed.
587
- */
588
- namespace: Object;
589
- /**
590
- * The current status of the module.
591
- */
592
- status: ModuleStatus;
593
- /**
594
- * Evaluate the module.
595
- *
596
- * This must be called after the module has been linked; otherwise it will reject
597
- * It could be called also when the module has already been evaluated, in which case it will either do nothing
598
- * if the initial evaluation ended in success (`module.status` is `'evaluated'`) or it will re-throw the exception
599
- * that the initial evaluation resulted in (`module.status` is `'errored'`).
600
- *
601
- * This method cannot be called while the module is being evaluated (`module.status` is `'evaluating'`).
602
- */
603
- evaluate(options?: ModuleEvaluateOptions): Promise<void>;
604
- /**
605
- * Link module dependencies. This method must be called before evaluation, and can only be called once per module.
606
- */
607
- link(linker: ModuleLinker): Promise<void>;
608
- }
609
-
610
- interface SourceTextModuleOptions {
611
- /**
612
- * String used in stack traces.
613
- * @default 'vm:module(i)' where i is a context-specific ascending index.
614
- */
615
- identifier?: string | undefined;
616
- cachedData?: ScriptOptions["cachedData"] | undefined;
617
- context?: Context | undefined;
618
- lineOffset?: BaseOptions["lineOffset"] | undefined;
619
- columnOffset?: BaseOptions["columnOffset"] | undefined;
620
- /**
621
- * Called during evaluation of this module to initialize the `import.meta`.
622
- */
623
- initializeImportMeta?: ((meta: ImportMeta, module: SourceTextModule) => void) | undefined;
624
- importModuleDynamically?: ScriptOptions["importModuleDynamically"] | undefined;
625
- }
626
- class SourceTextModule extends Module {
627
- /**
628
- * Creates a new `SourceTextModule` instance.
629
- * @param code JavaScript Module code to parse
630
- */
631
- constructor(code: string, options?: SourceTextModuleOptions);
632
- }
633
-
634
- interface SyntheticModuleOptions {
635
- /**
636
- * String used in stack traces.
637
- * @default 'vm:module(i)' where i is a context-specific ascending index.
638
- */
639
- identifier?: string | undefined;
640
- /**
641
- * The contextified object as returned by the `vm.createContext()` method, to compile and evaluate this module in.
642
- */
643
- context?: Context | undefined;
644
- }
645
- class SyntheticModule extends Module {
646
- /**
647
- * Creates a new `SyntheticModule` instance.
648
- * @param exportNames Array of names that will be exported from the module.
649
- * @param evaluateCallback Called when the module is evaluated.
650
- */
651
- constructor(
652
- exportNames: string[],
653
- evaluateCallback: (this: SyntheticModule) => void,
654
- options?: SyntheticModuleOptions,
655
- );
656
- /**
657
- * This method is used after the module is linked to set the values of exports.
658
- * If it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error will be thrown.
659
- * @param name
660
- * @param value
661
- */
662
- setExport(name: string, value: any): void;
663
- }
664
- }
665
- declare module "node:vm" {
666
- export * from "vm";
667
- }