@types/node 16.18.78 → 16.18.80
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.
- node v16.18/README.md +1 -1
- node v16.18/package.json +2 -2
- node v16.18/ts4.8/crypto.d.ts +5 -2
- node v16.18/ts4.8/diagnostics_channel.d.ts +1 -1
- node v16.18/ts4.8/dns/promises.d.ts +1 -0
- node v16.18/ts4.8/dns.d.ts +1 -0
- node v16.18/ts4.8/events.d.ts +49 -0
- node v16.18/ts4.8/http.d.ts +3 -2
- node v16.18/ts4.8/index.d.ts +1 -1
- node v16.18/ts4.8/os.d.ts +0 -1
- node v16.18/ts4.8/perf_hooks.d.ts +1 -1
- node v16.18/ts4.8/stream.d.ts +38 -2
- node v16.18/ts4.8/v8.d.ts +181 -27
- node v16.18/v8.d.ts +181 -27
node v16.18/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v16.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Thu, 08 Feb 2024 20:35:44 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
|
|
14
14
|
# Credits
|
node v16.18/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "16.18.
|
|
3
|
+
"version": "16.18.80",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -222,6 +222,6 @@
|
|
|
222
222
|
},
|
|
223
223
|
"scripts": {},
|
|
224
224
|
"dependencies": {},
|
|
225
|
-
"typesPublisherContentHash": "
|
|
225
|
+
"typesPublisherContentHash": "0747ef1ff42367a2c659aab5fc827387e23d727f290cd39647ba32a7618902a6",
|
|
226
226
|
"typeScriptVersion": "4.6"
|
|
227
227
|
}
|
node v16.18/ts4.8/crypto.d.ts
CHANGED
|
@@ -1205,11 +1205,13 @@ declare module "crypto" {
|
|
|
1205
1205
|
format?: KeyFormat | undefined;
|
|
1206
1206
|
type?: "pkcs1" | "pkcs8" | "sec1" | undefined;
|
|
1207
1207
|
passphrase?: string | Buffer | undefined;
|
|
1208
|
+
encoding?: string | undefined;
|
|
1208
1209
|
}
|
|
1209
1210
|
interface PublicKeyInput {
|
|
1210
1211
|
key: string | Buffer;
|
|
1211
1212
|
format?: KeyFormat | undefined;
|
|
1212
1213
|
type?: "pkcs1" | "spki" | undefined;
|
|
1214
|
+
encoding?: string | undefined;
|
|
1213
1215
|
}
|
|
1214
1216
|
/**
|
|
1215
1217
|
* Asynchronously generates a new random secret key of the given `length`. The`type` will determine which validations will be performed on the `length`.
|
|
@@ -3490,12 +3492,13 @@ declare module "crypto" {
|
|
|
3490
3492
|
*/
|
|
3491
3493
|
disableEntropyCache?: boolean | undefined;
|
|
3492
3494
|
}
|
|
3495
|
+
type UUID = `${string}-${string}-${string}-${string}-${string}`;
|
|
3493
3496
|
/**
|
|
3494
3497
|
* Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
|
|
3495
3498
|
* cryptographic pseudorandom number generator.
|
|
3496
3499
|
* @since v15.6.0
|
|
3497
3500
|
*/
|
|
3498
|
-
function randomUUID(options?: RandomUUIDOptions):
|
|
3501
|
+
function randomUUID(options?: RandomUUIDOptions): UUID;
|
|
3499
3502
|
interface X509CheckOptions {
|
|
3500
3503
|
/**
|
|
3501
3504
|
* @default 'always'
|
|
@@ -3978,7 +3981,7 @@ declare module "crypto" {
|
|
|
3978
3981
|
* The UUID is generated using a cryptographic pseudorandom number generator.
|
|
3979
3982
|
* @since v16.7.0
|
|
3980
3983
|
*/
|
|
3981
|
-
randomUUID():
|
|
3984
|
+
randomUUID(): UUID;
|
|
3982
3985
|
CryptoKey: CryptoKeyConstructor;
|
|
3983
3986
|
}
|
|
3984
3987
|
// This constructor throws ILLEGAL_CONSTRUCTOR so it should not be newable.
|
|
@@ -57,6 +57,7 @@ declare module "diagnostics_channel" {
|
|
|
57
57
|
* @return The named channel object
|
|
58
58
|
*/
|
|
59
59
|
function channel(name: string | symbol): Channel;
|
|
60
|
+
type ChannelListener = (message: unknown, name: string | symbol) => void;
|
|
60
61
|
/**
|
|
61
62
|
* Register a message handler to subscribe to this channel. This message handler will be run synchronously
|
|
62
63
|
* whenever a message is published to the channel. Any errors thrown in the message handler will
|
|
@@ -96,7 +97,6 @@ declare module "diagnostics_channel" {
|
|
|
96
97
|
* @returns `true` if the handler was found, `false` otherwise
|
|
97
98
|
*/
|
|
98
99
|
function unsubscribe(name: string | symbol, onMessage: ChannelListener): boolean;
|
|
99
|
-
type ChannelListener = (message: unknown, name: string | symbol) => void;
|
|
100
100
|
/**
|
|
101
101
|
* The class `Channel` represents an individual named channel within the data
|
|
102
102
|
* pipeline. It is use to track subscribers and to publish messages when there
|
|
@@ -353,6 +353,7 @@ declare module "dns/promises" {
|
|
|
353
353
|
resolve4: typeof resolve4;
|
|
354
354
|
resolve6: typeof resolve6;
|
|
355
355
|
resolveAny: typeof resolveAny;
|
|
356
|
+
resolveCaa: typeof resolveCaa;
|
|
356
357
|
resolveCname: typeof resolveCname;
|
|
357
358
|
resolveMx: typeof resolveMx;
|
|
358
359
|
resolveNaptr: typeof resolveNaptr;
|
node v16.18/ts4.8/dns.d.ts
CHANGED
|
@@ -761,6 +761,7 @@ declare module "dns" {
|
|
|
761
761
|
resolve4: typeof resolve4;
|
|
762
762
|
resolve6: typeof resolve6;
|
|
763
763
|
resolveAny: typeof resolveAny;
|
|
764
|
+
resolveCaa: typeof resolveCaa;
|
|
764
765
|
resolveCname: typeof resolveCname;
|
|
765
766
|
resolveMx: typeof resolveMx;
|
|
766
767
|
resolveNaptr: typeof resolveNaptr;
|
node v16.18/ts4.8/events.d.ts
CHANGED
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
* @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/events.js)
|
|
36
36
|
*/
|
|
37
37
|
declare module "events" {
|
|
38
|
+
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
|
|
39
|
+
|
|
38
40
|
interface EventEmitterOptions {
|
|
39
41
|
/**
|
|
40
42
|
* Enables automatic capturing of promise rejection.
|
|
@@ -72,6 +74,9 @@ declare module "events" {
|
|
|
72
74
|
*/
|
|
73
75
|
class EventEmitter {
|
|
74
76
|
constructor(options?: EventEmitterOptions);
|
|
77
|
+
|
|
78
|
+
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string, ...args: any[]): void;
|
|
79
|
+
|
|
75
80
|
/**
|
|
76
81
|
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
|
77
82
|
* event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
|
|
@@ -314,10 +319,54 @@ declare module "events" {
|
|
|
314
319
|
*/
|
|
315
320
|
signal?: AbortSignal | undefined;
|
|
316
321
|
}
|
|
322
|
+
|
|
323
|
+
export interface EventEmitterReferencingAsyncResource extends AsyncResource {
|
|
324
|
+
readonly eventEmitter: EventEmitterAsyncResource;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
|
|
328
|
+
/**
|
|
329
|
+
* The type of async event, this is required when instantiating `EventEmitterAsyncResource`
|
|
330
|
+
* directly rather than as a child class.
|
|
331
|
+
* @default new.target.name if instantiated as a child class.
|
|
332
|
+
*/
|
|
333
|
+
name?: string;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
|
|
338
|
+
* manual async tracking. Specifically, all events emitted by instances of
|
|
339
|
+
* `EventEmitterAsyncResource` will run within its async context.
|
|
340
|
+
*
|
|
341
|
+
* The EventEmitterAsyncResource class has the same methods and takes the
|
|
342
|
+
* same options as EventEmitter and AsyncResource themselves.
|
|
343
|
+
* @throws if `options.name` is not provided when instantiated directly.
|
|
344
|
+
* @since v17.4.0, v16.14.0
|
|
345
|
+
*/
|
|
346
|
+
export class EventEmitterAsyncResource extends EventEmitter {
|
|
347
|
+
/**
|
|
348
|
+
* @param options Only optional in child class.
|
|
349
|
+
*/
|
|
350
|
+
constructor(options?: EventEmitterAsyncResourceOptions);
|
|
351
|
+
/**
|
|
352
|
+
* Call all destroy hooks. This should only ever be called once. An
|
|
353
|
+
* error will be thrown if it is called more than once. This must be
|
|
354
|
+
* manually called. If the resource is left to be collected by the GC then
|
|
355
|
+
* the destroy hooks will never be called.
|
|
356
|
+
*/
|
|
357
|
+
emitDestroy(): void;
|
|
358
|
+
/** The unique asyncId assigned to the resource. */
|
|
359
|
+
readonly asyncId: number;
|
|
360
|
+
/** The same triggerAsyncId that is passed to the AsyncResource constructor. */
|
|
361
|
+
readonly triggerAsyncId: number;
|
|
362
|
+
/** The underlying AsyncResource */
|
|
363
|
+
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
|
364
|
+
}
|
|
317
365
|
}
|
|
318
366
|
global {
|
|
319
367
|
namespace NodeJS {
|
|
320
368
|
interface EventEmitter {
|
|
369
|
+
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string, ...args: any[]): void;
|
|
321
370
|
/**
|
|
322
371
|
* Alias for `emitter.on(eventName, listener)`.
|
|
323
372
|
* @since v0.1.26
|
node v16.18/ts4.8/http.d.ts
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
declare module "http" {
|
|
43
43
|
import * as stream from "node:stream";
|
|
44
44
|
import { URL } from "node:url";
|
|
45
|
+
import { EventEmitter } from "node:events";
|
|
45
46
|
import { LookupFunction, Server as NetServer, Socket, TcpSocketConnectOpts } from "node:net";
|
|
46
47
|
// incoming headers will never contain number
|
|
47
48
|
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
|
@@ -1216,9 +1217,9 @@ declare module "http" {
|
|
|
1216
1217
|
* ```
|
|
1217
1218
|
* @since v0.3.4
|
|
1218
1219
|
*/
|
|
1219
|
-
class Agent {
|
|
1220
|
+
class Agent extends EventEmitter {
|
|
1220
1221
|
/**
|
|
1221
|
-
* By default set to 256
|
|
1222
|
+
* By default set to 256. For agents with `keepAlive` enabled, this
|
|
1222
1223
|
* sets the maximum number of sockets that will be left open in the free
|
|
1223
1224
|
* state.
|
|
1224
1225
|
* @since v0.11.7
|
node v16.18/ts4.8/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
// NOTE: These definitions support NodeJS and TypeScript 4.
|
|
25
|
+
// NOTE: These definitions support NodeJS and TypeScript 4.9+.
|
|
26
26
|
|
|
27
27
|
// Reference required types from the default lib:
|
|
28
28
|
/// <reference lib="es2020" />
|
node v16.18/ts4.8/os.d.ts
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
declare module "perf_hooks" {
|
|
32
32
|
import { AsyncResource } from "node:async_hooks";
|
|
33
|
-
type EntryType = "node" | "mark" | "measure" | "gc" | "function" | "http2" | "http";
|
|
33
|
+
type EntryType = "node" | "mark" | "measure" | "gc" | "function" | "http2" | "http" | "dns";
|
|
34
34
|
interface NodeGCPerformanceDetail {
|
|
35
35
|
/**
|
|
36
36
|
* When `performanceEntry.entryType` is equal to 'gc', `the performance.kind` property identifies
|
node v16.18/ts4.8/stream.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
declare module "stream" {
|
|
20
20
|
import { Abortable, EventEmitter } from "node:events";
|
|
21
|
-
import { Blob } from "node:buffer";
|
|
21
|
+
import { Blob as NodeBlob } from "node:buffer";
|
|
22
22
|
import * as streamPromises from "node:stream/promises";
|
|
23
23
|
import * as streamConsumers from "node:stream/consumers";
|
|
24
24
|
class internal extends EventEmitter {
|
|
@@ -45,6 +45,12 @@ declare module "stream" {
|
|
|
45
45
|
encoding?: BufferEncoding | undefined;
|
|
46
46
|
read?(this: Readable, size: number): void;
|
|
47
47
|
}
|
|
48
|
+
interface ArrayOptions {
|
|
49
|
+
/** the maximum concurrent invocations of `fn` to call on the stream at once. **Default: 1**. */
|
|
50
|
+
concurrency?: number;
|
|
51
|
+
/** allows destroying the stream if the signal is aborted. */
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}
|
|
48
54
|
/**
|
|
49
55
|
* @since v0.9.4
|
|
50
56
|
*/
|
|
@@ -397,6 +403,36 @@ declare module "stream" {
|
|
|
397
403
|
*/
|
|
398
404
|
wrap(stream: NodeJS.ReadableStream): this;
|
|
399
405
|
push(chunk: any, encoding?: BufferEncoding): boolean;
|
|
406
|
+
/**
|
|
407
|
+
* The iterator created by this method gives users the option to cancel the destruction
|
|
408
|
+
* of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
|
|
409
|
+
* or if the iterator should destroy the stream if the stream emitted an error during iteration.
|
|
410
|
+
* @since v16.3.0
|
|
411
|
+
* @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
|
|
412
|
+
* or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
|
|
413
|
+
* **Default: `true`**.
|
|
414
|
+
*/
|
|
415
|
+
iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
|
|
416
|
+
/**
|
|
417
|
+
* This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
|
|
418
|
+
* If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
|
|
419
|
+
* @since v17.4.0, v16.14.0
|
|
420
|
+
* @param fn a function to map over every chunk in the stream. Async or not.
|
|
421
|
+
* @returns a stream mapped with the function *fn*.
|
|
422
|
+
*/
|
|
423
|
+
map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
|
|
424
|
+
/**
|
|
425
|
+
* This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
|
|
426
|
+
* and if it returns a truthy value, the chunk will be passed to the result stream.
|
|
427
|
+
* If the *fn* function returns a promise - that promise will be `await`ed.
|
|
428
|
+
* @since v17.4.0, v16.14.0
|
|
429
|
+
* @param fn a function to filter chunks from the stream. Async or not.
|
|
430
|
+
* @returns a stream filtered with the predicate *fn*.
|
|
431
|
+
*/
|
|
432
|
+
filter(
|
|
433
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
434
|
+
options?: ArrayOptions,
|
|
435
|
+
): Readable;
|
|
400
436
|
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
401
437
|
/**
|
|
402
438
|
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
|
|
@@ -848,7 +884,7 @@ declare module "stream" {
|
|
|
848
884
|
static from(
|
|
849
885
|
src:
|
|
850
886
|
| Stream
|
|
851
|
-
|
|
|
887
|
+
| NodeBlob
|
|
852
888
|
| ArrayBuffer
|
|
853
889
|
| string
|
|
854
890
|
| Iterable<any>
|
node v16.18/ts4.8/v8.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
|
|
2
|
+
* The `node:v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
|
|
3
3
|
*
|
|
4
4
|
* ```js
|
|
5
|
-
* const v8 = require('v8');
|
|
5
|
+
* const v8 = require('node:v8');
|
|
6
6
|
* ```
|
|
7
|
-
* @see [source](https://github.com/nodejs/node/blob/v16.
|
|
7
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/v8.js)
|
|
8
8
|
*/
|
|
9
9
|
declare module "v8" {
|
|
10
10
|
import { Readable } from "node:stream";
|
|
@@ -29,6 +29,9 @@ declare module "v8" {
|
|
|
29
29
|
does_zap_garbage: DoesZapCodeSpaceFlag;
|
|
30
30
|
number_of_native_contexts: number;
|
|
31
31
|
number_of_detached_contexts: number;
|
|
32
|
+
total_global_handles_size: number;
|
|
33
|
+
used_global_handles_size: number;
|
|
34
|
+
external_memory: number;
|
|
32
35
|
}
|
|
33
36
|
interface HeapCodeStatistics {
|
|
34
37
|
code_and_metadata_size: number;
|
|
@@ -68,6 +71,15 @@ declare module "v8" {
|
|
|
68
71
|
* of contexts that were detached and not yet garbage collected. This number
|
|
69
72
|
* being non-zero indicates a potential memory leak.
|
|
70
73
|
*
|
|
74
|
+
* `total_global_handles_size` The value of total\_global\_handles\_size is the
|
|
75
|
+
* total memory size of V8 global handles.
|
|
76
|
+
*
|
|
77
|
+
* `used_global_handles_size` The value of used\_global\_handles\_size is the
|
|
78
|
+
* used memory size of V8 global handles.
|
|
79
|
+
*
|
|
80
|
+
* `external_memory` The value of external\_memory is the memory size of array
|
|
81
|
+
* buffers and external strings.
|
|
82
|
+
*
|
|
71
83
|
* ```js
|
|
72
84
|
* {
|
|
73
85
|
* total_heap_size: 7326976,
|
|
@@ -80,7 +92,10 @@ declare module "v8" {
|
|
|
80
92
|
* peak_malloced_memory: 1127496,
|
|
81
93
|
* does_zap_garbage: 0,
|
|
82
94
|
* number_of_native_contexts: 1,
|
|
83
|
-
* number_of_detached_contexts: 0
|
|
95
|
+
* number_of_detached_contexts: 0,
|
|
96
|
+
* total_global_handles_size: 8192,
|
|
97
|
+
* used_global_handles_size: 3296,
|
|
98
|
+
* external_memory: 318824
|
|
84
99
|
* }
|
|
85
100
|
* ```
|
|
86
101
|
* @since v1.0.0
|
|
@@ -90,7 +105,7 @@ declare module "v8" {
|
|
|
90
105
|
* Returns statistics about the V8 heap spaces, i.e. the segments which make up
|
|
91
106
|
* the V8 heap. Neither the ordering of heap spaces, nor the availability of a
|
|
92
107
|
* heap space can be guaranteed as the statistics are provided via the
|
|
93
|
-
* V8[`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
|
|
108
|
+
* V8 [`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
|
|
94
109
|
* next.
|
|
95
110
|
*
|
|
96
111
|
* The value returned is an array of objects containing the following properties:
|
|
@@ -149,7 +164,7 @@ declare module "v8" {
|
|
|
149
164
|
*
|
|
150
165
|
* ```js
|
|
151
166
|
* // Print GC events to stdout for one minute.
|
|
152
|
-
* const v8 = require('v8');
|
|
167
|
+
* const v8 = require('node:v8');
|
|
153
168
|
* v8.setFlagsFromString('--trace_gc');
|
|
154
169
|
* setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
|
|
155
170
|
* ```
|
|
@@ -163,9 +178,16 @@ declare module "v8" {
|
|
|
163
178
|
* Chrome DevTools. The JSON schema is undocumented and specific to the
|
|
164
179
|
* V8 engine. Therefore, the schema may change from one version of V8 to the next.
|
|
165
180
|
*
|
|
181
|
+
* Creating a heap snapshot requires memory about twice the size of the heap at
|
|
182
|
+
* the time the snapshot is created. This results in the risk of OOM killers
|
|
183
|
+
* terminating the process.
|
|
184
|
+
*
|
|
185
|
+
* Generating a snapshot is a synchronous operation which blocks the event loop
|
|
186
|
+
* for a duration depending on the heap size.
|
|
187
|
+
*
|
|
166
188
|
* ```js
|
|
167
189
|
* // Print heap snapshot to the console
|
|
168
|
-
* const v8 = require('v8');
|
|
190
|
+
* const v8 = require('node:v8');
|
|
169
191
|
* const stream = v8.getHeapSnapshot();
|
|
170
192
|
* stream.pipe(process.stdout);
|
|
171
193
|
* ```
|
|
@@ -182,13 +204,20 @@ declare module "v8" {
|
|
|
182
204
|
* A heap snapshot is specific to a single V8 isolate. When using `worker threads`, a heap snapshot generated from the main thread will
|
|
183
205
|
* not contain any information about the workers, and vice versa.
|
|
184
206
|
*
|
|
207
|
+
* Creating a heap snapshot requires memory about twice the size of the heap at
|
|
208
|
+
* the time the snapshot is created. This results in the risk of OOM killers
|
|
209
|
+
* terminating the process.
|
|
210
|
+
*
|
|
211
|
+
* Generating a snapshot is a synchronous operation which blocks the event loop
|
|
212
|
+
* for a duration depending on the heap size.
|
|
213
|
+
*
|
|
185
214
|
* ```js
|
|
186
|
-
* const { writeHeapSnapshot } = require('v8');
|
|
215
|
+
* const { writeHeapSnapshot } = require('node:v8');
|
|
187
216
|
* const {
|
|
188
217
|
* Worker,
|
|
189
218
|
* isMainThread,
|
|
190
|
-
* parentPort
|
|
191
|
-
* } = require('worker_threads');
|
|
219
|
+
* parentPort,
|
|
220
|
+
* } = require('node:worker_threads');
|
|
192
221
|
*
|
|
193
222
|
* if (isMainThread) {
|
|
194
223
|
* const worker = new Worker(__filename);
|
|
@@ -219,13 +248,16 @@ declare module "v8" {
|
|
|
219
248
|
*/
|
|
220
249
|
function writeHeapSnapshot(filename?: string): string;
|
|
221
250
|
/**
|
|
222
|
-
*
|
|
251
|
+
* Get statistics about code and its metadata in the heap, see
|
|
252
|
+
* V8 [`GetHeapCodeAndMetadataStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#a6079122af17612ef54ef3348ce170866) API. Returns an object with the
|
|
253
|
+
* following properties:
|
|
223
254
|
*
|
|
224
255
|
* ```js
|
|
225
256
|
* {
|
|
226
257
|
* code_and_metadata_size: 212208,
|
|
227
258
|
* bytecode_and_metadata_size: 161368,
|
|
228
|
-
* external_script_source_size: 1410794
|
|
259
|
+
* external_script_source_size: 1410794,
|
|
260
|
+
* cpu_profiler_metadata_size: 0,
|
|
229
261
|
* }
|
|
230
262
|
* ```
|
|
231
263
|
* @since v12.8.0
|
|
@@ -275,7 +307,7 @@ declare module "v8" {
|
|
|
275
307
|
*/
|
|
276
308
|
writeDouble(value: number): void;
|
|
277
309
|
/**
|
|
278
|
-
* Write raw bytes into the serializer
|
|
310
|
+
* Write raw bytes into the serializer's internal buffer. The deserializer
|
|
279
311
|
* will require a way to compute the length of the buffer.
|
|
280
312
|
* For use inside of a custom `serializer._writeHostObject()`.
|
|
281
313
|
*/
|
|
@@ -331,7 +363,7 @@ declare module "v8" {
|
|
|
331
363
|
*/
|
|
332
364
|
readDouble(): number;
|
|
333
365
|
/**
|
|
334
|
-
* Read raw bytes from the deserializer
|
|
366
|
+
* Read raw bytes from the deserializer's internal buffer. The `length` parameter
|
|
335
367
|
* must correspond to the length of the buffer that was passed to `serializer.writeRawBytes()`.
|
|
336
368
|
* For use inside of a custom `deserializer._readHostObject()`.
|
|
337
369
|
*/
|
|
@@ -344,6 +376,10 @@ declare module "v8" {
|
|
|
344
376
|
class DefaultDeserializer extends Deserializer {}
|
|
345
377
|
/**
|
|
346
378
|
* Uses a `DefaultSerializer` to serialize `value` into a buffer.
|
|
379
|
+
*
|
|
380
|
+
* `ERR_BUFFER_TOO_LARGE` will be thrown when trying to
|
|
381
|
+
* serialize a huge object which requires buffer
|
|
382
|
+
* larger than `buffer.constants.MAX_LENGTH`.
|
|
347
383
|
* @since v8.0.0
|
|
348
384
|
*/
|
|
349
385
|
function serialize(value: any): Buffer;
|
|
@@ -362,20 +398,27 @@ declare module "v8" {
|
|
|
362
398
|
*
|
|
363
399
|
* When the process is about to exit, one last coverage will still be written to
|
|
364
400
|
* disk unless {@link stopCoverage} is invoked before the process exits.
|
|
365
|
-
* @since v15.1.0, v12.22.0
|
|
401
|
+
* @since v15.1.0, v14.18.0, v12.22.0
|
|
366
402
|
*/
|
|
367
403
|
function takeCoverage(): void;
|
|
368
404
|
/**
|
|
369
405
|
* The `v8.stopCoverage()` method allows the user to stop the coverage collection
|
|
370
406
|
* started by `NODE_V8_COVERAGE`, so that V8 can release the execution count
|
|
371
407
|
* records and optimize code. This can be used in conjunction with {@link takeCoverage} if the user wants to collect the coverage on demand.
|
|
372
|
-
* @since v15.1.0, v12.22.0
|
|
408
|
+
* @since v15.1.0, v14.18.0, v12.22.0
|
|
373
409
|
*/
|
|
374
410
|
function stopCoverage(): void;
|
|
411
|
+
/**
|
|
412
|
+
* The API is a no-op if `--heapsnapshot-near-heap-limit` is already set from the command line or the API is called more than once.
|
|
413
|
+
* `limit` must be a positive integer. See [`--heapsnapshot-near-heap-limit`](https://nodejs.org/docs/latest-v16.x/api/cli.html#--heapsnapshot-near-heap-limitmax_count) for more information.
|
|
414
|
+
* @experimental
|
|
415
|
+
* @since v16.18.0
|
|
416
|
+
*/
|
|
417
|
+
function setHeapSnapshotNearHeapLimit(limit: number): void;
|
|
375
418
|
/**
|
|
376
419
|
* Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This will
|
|
377
420
|
* happen if a promise is created without ever getting a continuation.
|
|
378
|
-
* @since
|
|
421
|
+
* @since v16.14.0
|
|
379
422
|
* @param promise The promise being created.
|
|
380
423
|
* @param parent The promise continued from, if applicable.
|
|
381
424
|
*/
|
|
@@ -387,14 +430,14 @@ declare module "v8" {
|
|
|
387
430
|
*
|
|
388
431
|
* The before callback will be called 0 to N times. The before callback will typically be called 0 times if no continuation was ever made for the promise.
|
|
389
432
|
* The before callback may be called many times in the case where many continuations have been made from the same promise.
|
|
390
|
-
* @since
|
|
433
|
+
* @since v16.14.0
|
|
391
434
|
*/
|
|
392
435
|
interface Before {
|
|
393
436
|
(promise: Promise<unknown>): void;
|
|
394
437
|
}
|
|
395
438
|
/**
|
|
396
439
|
* Called immediately after a promise continuation executes. This may be after a `then()`, `catch()`, or `finally()` handler or before an await after another await.
|
|
397
|
-
* @since
|
|
440
|
+
* @since v16.14.0
|
|
398
441
|
*/
|
|
399
442
|
interface After {
|
|
400
443
|
(promise: Promise<unknown>): void;
|
|
@@ -402,7 +445,7 @@ declare module "v8" {
|
|
|
402
445
|
/**
|
|
403
446
|
* Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of {@link Promise.resolve()} or
|
|
404
447
|
* {@link Promise.reject()}.
|
|
405
|
-
* @since
|
|
448
|
+
* @since v16.14.0
|
|
406
449
|
*/
|
|
407
450
|
interface Settled {
|
|
408
451
|
(promise: Promise<unknown>): void;
|
|
@@ -413,7 +456,7 @@ declare module "v8" {
|
|
|
413
456
|
*
|
|
414
457
|
* Because promises are asynchronous resources whose lifecycle is tracked via the promise hooks mechanism, the `init()`, `before()`, `after()`, and
|
|
415
458
|
* `settled()` callbacks must not be async functions as they create more promises which would produce an infinite loop.
|
|
416
|
-
* @since
|
|
459
|
+
* @since v16.14.0
|
|
417
460
|
*/
|
|
418
461
|
interface HookCallbacks {
|
|
419
462
|
init?: Init;
|
|
@@ -424,28 +467,28 @@ declare module "v8" {
|
|
|
424
467
|
interface PromiseHooks {
|
|
425
468
|
/**
|
|
426
469
|
* The `init` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
427
|
-
* @since
|
|
470
|
+
* @since v16.14.0
|
|
428
471
|
* @param init The {@link Init | `init` callback} to call when a promise is created.
|
|
429
472
|
* @return Call to stop the hook.
|
|
430
473
|
*/
|
|
431
474
|
onInit: (init: Init) => Function;
|
|
432
475
|
/**
|
|
433
476
|
* The `settled` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
434
|
-
* @since
|
|
477
|
+
* @since v16.14.0
|
|
435
478
|
* @param settled The {@link Settled | `settled` callback} to call when a promise is created.
|
|
436
479
|
* @return Call to stop the hook.
|
|
437
480
|
*/
|
|
438
481
|
onSettled: (settled: Settled) => Function;
|
|
439
482
|
/**
|
|
440
483
|
* The `before` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
441
|
-
* @since
|
|
484
|
+
* @since v16.14.0
|
|
442
485
|
* @param before The {@link Before | `before` callback} to call before a promise continuation executes.
|
|
443
486
|
* @return Call to stop the hook.
|
|
444
487
|
*/
|
|
445
488
|
onBefore: (before: Before) => Function;
|
|
446
489
|
/**
|
|
447
490
|
* The `after` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
448
|
-
* @since
|
|
491
|
+
* @since v16.14.0
|
|
449
492
|
* @param after The {@link After | `after` callback} to call after a promise continuation executes.
|
|
450
493
|
* @return Call to stop the hook.
|
|
451
494
|
*/
|
|
@@ -455,7 +498,7 @@ declare module "v8" {
|
|
|
455
498
|
* The callbacks `init()`/`before()`/`after()`/`settled()` are called for the respective events during a promise's lifetime.
|
|
456
499
|
* All callbacks are optional. For example, if only promise creation needs to be tracked, then only the init callback needs to be passed.
|
|
457
500
|
* The hook callbacks must be plain functions. Providing async functions will throw as it would produce an infinite microtask loop.
|
|
458
|
-
* @since
|
|
501
|
+
* @since v16.14.0
|
|
459
502
|
* @param callbacks The {@link HookCallbacks | Hook Callbacks} to register
|
|
460
503
|
* @return Used for disabling hooks
|
|
461
504
|
*/
|
|
@@ -463,9 +506,120 @@ declare module "v8" {
|
|
|
463
506
|
}
|
|
464
507
|
/**
|
|
465
508
|
* The `promiseHooks` interface can be used to track promise lifecycle events.
|
|
466
|
-
* @since
|
|
509
|
+
* @since v16.14.0
|
|
467
510
|
*/
|
|
468
511
|
const promiseHooks: PromiseHooks;
|
|
512
|
+
type StartupSnapshotCallbackFn = (args: any) => any;
|
|
513
|
+
interface StartupSnapshot {
|
|
514
|
+
/**
|
|
515
|
+
* Add a callback that will be called when the Node.js instance is about to get serialized into a snapshot and exit.
|
|
516
|
+
* This can be used to release resources that should not or cannot be serialized or to convert user data into a form more suitable for serialization.
|
|
517
|
+
* @since v16.17.0
|
|
518
|
+
*/
|
|
519
|
+
addSerializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
520
|
+
/**
|
|
521
|
+
* Add a callback that will be called when the Node.js instance is deserialized from a snapshot.
|
|
522
|
+
* The `callback` and the `data` (if provided) will be serialized into the snapshot, they can be used to re-initialize the state of the application or
|
|
523
|
+
* to re-acquire resources that the application needs when the application is restarted from the snapshot.
|
|
524
|
+
* @since v16.17.0
|
|
525
|
+
*/
|
|
526
|
+
addDeserializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
527
|
+
/**
|
|
528
|
+
* This sets the entry point of the Node.js application when it is deserialized from a snapshot. This can be called only once in the snapshot building script.
|
|
529
|
+
* If called, the deserialized application no longer needs an additional entry point script to start up and will simply invoke the callback along with the deserialized
|
|
530
|
+
* data (if provided), otherwise an entry point script still needs to be provided to the deserialized application.
|
|
531
|
+
* @since v16.17.0
|
|
532
|
+
*/
|
|
533
|
+
setDeserializeMainFunction(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
534
|
+
/**
|
|
535
|
+
* Returns true if the Node.js instance is run to build a snapshot.
|
|
536
|
+
* @since v16.17.0
|
|
537
|
+
*/
|
|
538
|
+
isBuildingSnapshot(): boolean;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* The `v8.startupSnapshot` interface can be used to add serialization and deserialization hooks for custom startup snapshots.
|
|
542
|
+
*
|
|
543
|
+
* ```bash
|
|
544
|
+
* $ node --snapshot-blob snapshot.blob --build-snapshot entry.js
|
|
545
|
+
* # This launches a process with the snapshot
|
|
546
|
+
* $ node --snapshot-blob snapshot.blob
|
|
547
|
+
* ```
|
|
548
|
+
*
|
|
549
|
+
* In the example above, `entry.js` can use methods from the `v8.startupSnapshot` interface to specify how to save information for custom objects
|
|
550
|
+
* in the snapshot during serialization
|
|
551
|
+
* and how the information can be used to synchronize these objects during deserialization of the snapshot.
|
|
552
|
+
* For example, if the `entry.js` contains the following script:
|
|
553
|
+
*
|
|
554
|
+
* ```js
|
|
555
|
+
* 'use strict';
|
|
556
|
+
*
|
|
557
|
+
* const fs = require('node:fs');
|
|
558
|
+
* const zlib = require('node:zlib');
|
|
559
|
+
* const path = require('node:path');
|
|
560
|
+
* const assert = require('node:assert');
|
|
561
|
+
*
|
|
562
|
+
* const v8 = require('node:v8');
|
|
563
|
+
*
|
|
564
|
+
* class BookShelf {
|
|
565
|
+
* storage = new Map();
|
|
566
|
+
*
|
|
567
|
+
* // Reading a series of files from directory and store them into storage.
|
|
568
|
+
* constructor(directory, books) {
|
|
569
|
+
* for (const book of books) {
|
|
570
|
+
* this.storage.set(book, fs.readFileSync(path.join(directory, book)));
|
|
571
|
+
* }
|
|
572
|
+
* }
|
|
573
|
+
*
|
|
574
|
+
* static compressAll(shelf) {
|
|
575
|
+
* for (const [ book, content ] of shelf.storage) {
|
|
576
|
+
* shelf.storage.set(book, zlib.gzipSync(content));
|
|
577
|
+
* }
|
|
578
|
+
* }
|
|
579
|
+
*
|
|
580
|
+
* static decompressAll(shelf) {
|
|
581
|
+
* for (const [ book, content ] of shelf.storage) {
|
|
582
|
+
* shelf.storage.set(book, zlib.gunzipSync(content));
|
|
583
|
+
* }
|
|
584
|
+
* }
|
|
585
|
+
* }
|
|
586
|
+
*
|
|
587
|
+
* // __dirname here is where the snapshot script is placed
|
|
588
|
+
* // during snapshot building time.
|
|
589
|
+
* const shelf = new BookShelf(__dirname, [
|
|
590
|
+
* 'book1.en_US.txt',
|
|
591
|
+
* 'book1.es_ES.txt',
|
|
592
|
+
* 'book2.zh_CN.txt',
|
|
593
|
+
* ]);
|
|
594
|
+
*
|
|
595
|
+
* assert(v8.startupSnapshot.isBuildingSnapshot());
|
|
596
|
+
* // On snapshot serialization, compress the books to reduce size.
|
|
597
|
+
* v8.startupSnapshot.addSerializeCallback(BookShelf.compressAll, shelf);
|
|
598
|
+
* // On snapshot deserialization, decompress the books.
|
|
599
|
+
* v8.startupSnapshot.addDeserializeCallback(BookShelf.decompressAll, shelf);
|
|
600
|
+
* v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
|
|
601
|
+
* // process.env and process.argv are refreshed during snapshot
|
|
602
|
+
* // deserialization.
|
|
603
|
+
* const lang = process.env.BOOK_LANG || 'en_US';
|
|
604
|
+
* const book = process.argv[1];
|
|
605
|
+
* const name = `${book}.${lang}.txt`;
|
|
606
|
+
* console.log(shelf.storage.get(name));
|
|
607
|
+
* }, shelf);
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* The resulted binary will get print the data deserialized from the snapshot during start up, using the refreshed `process.env` and `process.argv` of the launched process:
|
|
611
|
+
*
|
|
612
|
+
* ```bash
|
|
613
|
+
* $ BOOK_LANG=es_ES node --snapshot-blob snapshot.blob book1
|
|
614
|
+
* # Prints content of book1.es_ES.txt deserialized from the snapshot.
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* Currently the application deserialized from a user-land snapshot cannot be snapshotted again, so these APIs are only available to applications that are not deserialized from a user-land snapshot.
|
|
618
|
+
*
|
|
619
|
+
* @experimental
|
|
620
|
+
* @since v16.17.0
|
|
621
|
+
*/
|
|
622
|
+
const startupSnapshot: StartupSnapshot;
|
|
469
623
|
}
|
|
470
624
|
declare module "node:v8" {
|
|
471
625
|
export * from "v8";
|
node v16.18/v8.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
|
|
2
|
+
* The `node:v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
|
|
3
3
|
*
|
|
4
4
|
* ```js
|
|
5
|
-
* const v8 = require('v8');
|
|
5
|
+
* const v8 = require('node:v8');
|
|
6
6
|
* ```
|
|
7
|
-
* @see [source](https://github.com/nodejs/node/blob/v16.
|
|
7
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/v8.js)
|
|
8
8
|
*/
|
|
9
9
|
declare module "v8" {
|
|
10
10
|
import { Readable } from "node:stream";
|
|
@@ -29,6 +29,9 @@ declare module "v8" {
|
|
|
29
29
|
does_zap_garbage: DoesZapCodeSpaceFlag;
|
|
30
30
|
number_of_native_contexts: number;
|
|
31
31
|
number_of_detached_contexts: number;
|
|
32
|
+
total_global_handles_size: number;
|
|
33
|
+
used_global_handles_size: number;
|
|
34
|
+
external_memory: number;
|
|
32
35
|
}
|
|
33
36
|
interface HeapCodeStatistics {
|
|
34
37
|
code_and_metadata_size: number;
|
|
@@ -68,6 +71,15 @@ declare module "v8" {
|
|
|
68
71
|
* of contexts that were detached and not yet garbage collected. This number
|
|
69
72
|
* being non-zero indicates a potential memory leak.
|
|
70
73
|
*
|
|
74
|
+
* `total_global_handles_size` The value of total\_global\_handles\_size is the
|
|
75
|
+
* total memory size of V8 global handles.
|
|
76
|
+
*
|
|
77
|
+
* `used_global_handles_size` The value of used\_global\_handles\_size is the
|
|
78
|
+
* used memory size of V8 global handles.
|
|
79
|
+
*
|
|
80
|
+
* `external_memory` The value of external\_memory is the memory size of array
|
|
81
|
+
* buffers and external strings.
|
|
82
|
+
*
|
|
71
83
|
* ```js
|
|
72
84
|
* {
|
|
73
85
|
* total_heap_size: 7326976,
|
|
@@ -80,7 +92,10 @@ declare module "v8" {
|
|
|
80
92
|
* peak_malloced_memory: 1127496,
|
|
81
93
|
* does_zap_garbage: 0,
|
|
82
94
|
* number_of_native_contexts: 1,
|
|
83
|
-
* number_of_detached_contexts: 0
|
|
95
|
+
* number_of_detached_contexts: 0,
|
|
96
|
+
* total_global_handles_size: 8192,
|
|
97
|
+
* used_global_handles_size: 3296,
|
|
98
|
+
* external_memory: 318824
|
|
84
99
|
* }
|
|
85
100
|
* ```
|
|
86
101
|
* @since v1.0.0
|
|
@@ -90,7 +105,7 @@ declare module "v8" {
|
|
|
90
105
|
* Returns statistics about the V8 heap spaces, i.e. the segments which make up
|
|
91
106
|
* the V8 heap. Neither the ordering of heap spaces, nor the availability of a
|
|
92
107
|
* heap space can be guaranteed as the statistics are provided via the
|
|
93
|
-
* V8[`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
|
|
108
|
+
* V8 [`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
|
|
94
109
|
* next.
|
|
95
110
|
*
|
|
96
111
|
* The value returned is an array of objects containing the following properties:
|
|
@@ -149,7 +164,7 @@ declare module "v8" {
|
|
|
149
164
|
*
|
|
150
165
|
* ```js
|
|
151
166
|
* // Print GC events to stdout for one minute.
|
|
152
|
-
* const v8 = require('v8');
|
|
167
|
+
* const v8 = require('node:v8');
|
|
153
168
|
* v8.setFlagsFromString('--trace_gc');
|
|
154
169
|
* setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
|
|
155
170
|
* ```
|
|
@@ -163,9 +178,16 @@ declare module "v8" {
|
|
|
163
178
|
* Chrome DevTools. The JSON schema is undocumented and specific to the
|
|
164
179
|
* V8 engine. Therefore, the schema may change from one version of V8 to the next.
|
|
165
180
|
*
|
|
181
|
+
* Creating a heap snapshot requires memory about twice the size of the heap at
|
|
182
|
+
* the time the snapshot is created. This results in the risk of OOM killers
|
|
183
|
+
* terminating the process.
|
|
184
|
+
*
|
|
185
|
+
* Generating a snapshot is a synchronous operation which blocks the event loop
|
|
186
|
+
* for a duration depending on the heap size.
|
|
187
|
+
*
|
|
166
188
|
* ```js
|
|
167
189
|
* // Print heap snapshot to the console
|
|
168
|
-
* const v8 = require('v8');
|
|
190
|
+
* const v8 = require('node:v8');
|
|
169
191
|
* const stream = v8.getHeapSnapshot();
|
|
170
192
|
* stream.pipe(process.stdout);
|
|
171
193
|
* ```
|
|
@@ -182,13 +204,20 @@ declare module "v8" {
|
|
|
182
204
|
* A heap snapshot is specific to a single V8 isolate. When using `worker threads`, a heap snapshot generated from the main thread will
|
|
183
205
|
* not contain any information about the workers, and vice versa.
|
|
184
206
|
*
|
|
207
|
+
* Creating a heap snapshot requires memory about twice the size of the heap at
|
|
208
|
+
* the time the snapshot is created. This results in the risk of OOM killers
|
|
209
|
+
* terminating the process.
|
|
210
|
+
*
|
|
211
|
+
* Generating a snapshot is a synchronous operation which blocks the event loop
|
|
212
|
+
* for a duration depending on the heap size.
|
|
213
|
+
*
|
|
185
214
|
* ```js
|
|
186
|
-
* const { writeHeapSnapshot } = require('v8');
|
|
215
|
+
* const { writeHeapSnapshot } = require('node:v8');
|
|
187
216
|
* const {
|
|
188
217
|
* Worker,
|
|
189
218
|
* isMainThread,
|
|
190
|
-
* parentPort
|
|
191
|
-
* } = require('worker_threads');
|
|
219
|
+
* parentPort,
|
|
220
|
+
* } = require('node:worker_threads');
|
|
192
221
|
*
|
|
193
222
|
* if (isMainThread) {
|
|
194
223
|
* const worker = new Worker(__filename);
|
|
@@ -219,13 +248,16 @@ declare module "v8" {
|
|
|
219
248
|
*/
|
|
220
249
|
function writeHeapSnapshot(filename?: string): string;
|
|
221
250
|
/**
|
|
222
|
-
*
|
|
251
|
+
* Get statistics about code and its metadata in the heap, see
|
|
252
|
+
* V8 [`GetHeapCodeAndMetadataStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#a6079122af17612ef54ef3348ce170866) API. Returns an object with the
|
|
253
|
+
* following properties:
|
|
223
254
|
*
|
|
224
255
|
* ```js
|
|
225
256
|
* {
|
|
226
257
|
* code_and_metadata_size: 212208,
|
|
227
258
|
* bytecode_and_metadata_size: 161368,
|
|
228
|
-
* external_script_source_size: 1410794
|
|
259
|
+
* external_script_source_size: 1410794,
|
|
260
|
+
* cpu_profiler_metadata_size: 0,
|
|
229
261
|
* }
|
|
230
262
|
* ```
|
|
231
263
|
* @since v12.8.0
|
|
@@ -275,7 +307,7 @@ declare module "v8" {
|
|
|
275
307
|
*/
|
|
276
308
|
writeDouble(value: number): void;
|
|
277
309
|
/**
|
|
278
|
-
* Write raw bytes into the serializer
|
|
310
|
+
* Write raw bytes into the serializer's internal buffer. The deserializer
|
|
279
311
|
* will require a way to compute the length of the buffer.
|
|
280
312
|
* For use inside of a custom `serializer._writeHostObject()`.
|
|
281
313
|
*/
|
|
@@ -331,7 +363,7 @@ declare module "v8" {
|
|
|
331
363
|
*/
|
|
332
364
|
readDouble(): number;
|
|
333
365
|
/**
|
|
334
|
-
* Read raw bytes from the deserializer
|
|
366
|
+
* Read raw bytes from the deserializer's internal buffer. The `length` parameter
|
|
335
367
|
* must correspond to the length of the buffer that was passed to `serializer.writeRawBytes()`.
|
|
336
368
|
* For use inside of a custom `deserializer._readHostObject()`.
|
|
337
369
|
*/
|
|
@@ -344,6 +376,10 @@ declare module "v8" {
|
|
|
344
376
|
class DefaultDeserializer extends Deserializer {}
|
|
345
377
|
/**
|
|
346
378
|
* Uses a `DefaultSerializer` to serialize `value` into a buffer.
|
|
379
|
+
*
|
|
380
|
+
* `ERR_BUFFER_TOO_LARGE` will be thrown when trying to
|
|
381
|
+
* serialize a huge object which requires buffer
|
|
382
|
+
* larger than `buffer.constants.MAX_LENGTH`.
|
|
347
383
|
* @since v8.0.0
|
|
348
384
|
*/
|
|
349
385
|
function serialize(value: any): Buffer;
|
|
@@ -362,20 +398,27 @@ declare module "v8" {
|
|
|
362
398
|
*
|
|
363
399
|
* When the process is about to exit, one last coverage will still be written to
|
|
364
400
|
* disk unless {@link stopCoverage} is invoked before the process exits.
|
|
365
|
-
* @since v15.1.0, v12.22.0
|
|
401
|
+
* @since v15.1.0, v14.18.0, v12.22.0
|
|
366
402
|
*/
|
|
367
403
|
function takeCoverage(): void;
|
|
368
404
|
/**
|
|
369
405
|
* The `v8.stopCoverage()` method allows the user to stop the coverage collection
|
|
370
406
|
* started by `NODE_V8_COVERAGE`, so that V8 can release the execution count
|
|
371
407
|
* records and optimize code. This can be used in conjunction with {@link takeCoverage} if the user wants to collect the coverage on demand.
|
|
372
|
-
* @since v15.1.0, v12.22.0
|
|
408
|
+
* @since v15.1.0, v14.18.0, v12.22.0
|
|
373
409
|
*/
|
|
374
410
|
function stopCoverage(): void;
|
|
411
|
+
/**
|
|
412
|
+
* The API is a no-op if `--heapsnapshot-near-heap-limit` is already set from the command line or the API is called more than once.
|
|
413
|
+
* `limit` must be a positive integer. See [`--heapsnapshot-near-heap-limit`](https://nodejs.org/docs/latest-v16.x/api/cli.html#--heapsnapshot-near-heap-limitmax_count) for more information.
|
|
414
|
+
* @experimental
|
|
415
|
+
* @since v16.18.0
|
|
416
|
+
*/
|
|
417
|
+
function setHeapSnapshotNearHeapLimit(limit: number): void;
|
|
375
418
|
/**
|
|
376
419
|
* Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This will
|
|
377
420
|
* happen if a promise is created without ever getting a continuation.
|
|
378
|
-
* @since
|
|
421
|
+
* @since v16.14.0
|
|
379
422
|
* @param promise The promise being created.
|
|
380
423
|
* @param parent The promise continued from, if applicable.
|
|
381
424
|
*/
|
|
@@ -387,14 +430,14 @@ declare module "v8" {
|
|
|
387
430
|
*
|
|
388
431
|
* The before callback will be called 0 to N times. The before callback will typically be called 0 times if no continuation was ever made for the promise.
|
|
389
432
|
* The before callback may be called many times in the case where many continuations have been made from the same promise.
|
|
390
|
-
* @since
|
|
433
|
+
* @since v16.14.0
|
|
391
434
|
*/
|
|
392
435
|
interface Before {
|
|
393
436
|
(promise: Promise<unknown>): void;
|
|
394
437
|
}
|
|
395
438
|
/**
|
|
396
439
|
* Called immediately after a promise continuation executes. This may be after a `then()`, `catch()`, or `finally()` handler or before an await after another await.
|
|
397
|
-
* @since
|
|
440
|
+
* @since v16.14.0
|
|
398
441
|
*/
|
|
399
442
|
interface After {
|
|
400
443
|
(promise: Promise<unknown>): void;
|
|
@@ -402,7 +445,7 @@ declare module "v8" {
|
|
|
402
445
|
/**
|
|
403
446
|
* Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of {@link Promise.resolve()} or
|
|
404
447
|
* {@link Promise.reject()}.
|
|
405
|
-
* @since
|
|
448
|
+
* @since v16.14.0
|
|
406
449
|
*/
|
|
407
450
|
interface Settled {
|
|
408
451
|
(promise: Promise<unknown>): void;
|
|
@@ -413,7 +456,7 @@ declare module "v8" {
|
|
|
413
456
|
*
|
|
414
457
|
* Because promises are asynchronous resources whose lifecycle is tracked via the promise hooks mechanism, the `init()`, `before()`, `after()`, and
|
|
415
458
|
* `settled()` callbacks must not be async functions as they create more promises which would produce an infinite loop.
|
|
416
|
-
* @since
|
|
459
|
+
* @since v16.14.0
|
|
417
460
|
*/
|
|
418
461
|
interface HookCallbacks {
|
|
419
462
|
init?: Init;
|
|
@@ -424,28 +467,28 @@ declare module "v8" {
|
|
|
424
467
|
interface PromiseHooks {
|
|
425
468
|
/**
|
|
426
469
|
* The `init` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
427
|
-
* @since
|
|
470
|
+
* @since v16.14.0
|
|
428
471
|
* @param init The {@link Init | `init` callback} to call when a promise is created.
|
|
429
472
|
* @return Call to stop the hook.
|
|
430
473
|
*/
|
|
431
474
|
onInit: (init: Init) => Function;
|
|
432
475
|
/**
|
|
433
476
|
* The `settled` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
434
|
-
* @since
|
|
477
|
+
* @since v16.14.0
|
|
435
478
|
* @param settled The {@link Settled | `settled` callback} to call when a promise is created.
|
|
436
479
|
* @return Call to stop the hook.
|
|
437
480
|
*/
|
|
438
481
|
onSettled: (settled: Settled) => Function;
|
|
439
482
|
/**
|
|
440
483
|
* The `before` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
441
|
-
* @since
|
|
484
|
+
* @since v16.14.0
|
|
442
485
|
* @param before The {@link Before | `before` callback} to call before a promise continuation executes.
|
|
443
486
|
* @return Call to stop the hook.
|
|
444
487
|
*/
|
|
445
488
|
onBefore: (before: Before) => Function;
|
|
446
489
|
/**
|
|
447
490
|
* The `after` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
|
|
448
|
-
* @since
|
|
491
|
+
* @since v16.14.0
|
|
449
492
|
* @param after The {@link After | `after` callback} to call after a promise continuation executes.
|
|
450
493
|
* @return Call to stop the hook.
|
|
451
494
|
*/
|
|
@@ -455,7 +498,7 @@ declare module "v8" {
|
|
|
455
498
|
* The callbacks `init()`/`before()`/`after()`/`settled()` are called for the respective events during a promise's lifetime.
|
|
456
499
|
* All callbacks are optional. For example, if only promise creation needs to be tracked, then only the init callback needs to be passed.
|
|
457
500
|
* The hook callbacks must be plain functions. Providing async functions will throw as it would produce an infinite microtask loop.
|
|
458
|
-
* @since
|
|
501
|
+
* @since v16.14.0
|
|
459
502
|
* @param callbacks The {@link HookCallbacks | Hook Callbacks} to register
|
|
460
503
|
* @return Used for disabling hooks
|
|
461
504
|
*/
|
|
@@ -463,9 +506,120 @@ declare module "v8" {
|
|
|
463
506
|
}
|
|
464
507
|
/**
|
|
465
508
|
* The `promiseHooks` interface can be used to track promise lifecycle events.
|
|
466
|
-
* @since
|
|
509
|
+
* @since v16.14.0
|
|
467
510
|
*/
|
|
468
511
|
const promiseHooks: PromiseHooks;
|
|
512
|
+
type StartupSnapshotCallbackFn = (args: any) => any;
|
|
513
|
+
interface StartupSnapshot {
|
|
514
|
+
/**
|
|
515
|
+
* Add a callback that will be called when the Node.js instance is about to get serialized into a snapshot and exit.
|
|
516
|
+
* This can be used to release resources that should not or cannot be serialized or to convert user data into a form more suitable for serialization.
|
|
517
|
+
* @since v16.17.0
|
|
518
|
+
*/
|
|
519
|
+
addSerializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
520
|
+
/**
|
|
521
|
+
* Add a callback that will be called when the Node.js instance is deserialized from a snapshot.
|
|
522
|
+
* The `callback` and the `data` (if provided) will be serialized into the snapshot, they can be used to re-initialize the state of the application or
|
|
523
|
+
* to re-acquire resources that the application needs when the application is restarted from the snapshot.
|
|
524
|
+
* @since v16.17.0
|
|
525
|
+
*/
|
|
526
|
+
addDeserializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
527
|
+
/**
|
|
528
|
+
* This sets the entry point of the Node.js application when it is deserialized from a snapshot. This can be called only once in the snapshot building script.
|
|
529
|
+
* If called, the deserialized application no longer needs an additional entry point script to start up and will simply invoke the callback along with the deserialized
|
|
530
|
+
* data (if provided), otherwise an entry point script still needs to be provided to the deserialized application.
|
|
531
|
+
* @since v16.17.0
|
|
532
|
+
*/
|
|
533
|
+
setDeserializeMainFunction(callback: StartupSnapshotCallbackFn, data?: any): void;
|
|
534
|
+
/**
|
|
535
|
+
* Returns true if the Node.js instance is run to build a snapshot.
|
|
536
|
+
* @since v16.17.0
|
|
537
|
+
*/
|
|
538
|
+
isBuildingSnapshot(): boolean;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* The `v8.startupSnapshot` interface can be used to add serialization and deserialization hooks for custom startup snapshots.
|
|
542
|
+
*
|
|
543
|
+
* ```bash
|
|
544
|
+
* $ node --snapshot-blob snapshot.blob --build-snapshot entry.js
|
|
545
|
+
* # This launches a process with the snapshot
|
|
546
|
+
* $ node --snapshot-blob snapshot.blob
|
|
547
|
+
* ```
|
|
548
|
+
*
|
|
549
|
+
* In the example above, `entry.js` can use methods from the `v8.startupSnapshot` interface to specify how to save information for custom objects
|
|
550
|
+
* in the snapshot during serialization
|
|
551
|
+
* and how the information can be used to synchronize these objects during deserialization of the snapshot.
|
|
552
|
+
* For example, if the `entry.js` contains the following script:
|
|
553
|
+
*
|
|
554
|
+
* ```js
|
|
555
|
+
* 'use strict';
|
|
556
|
+
*
|
|
557
|
+
* const fs = require('node:fs');
|
|
558
|
+
* const zlib = require('node:zlib');
|
|
559
|
+
* const path = require('node:path');
|
|
560
|
+
* const assert = require('node:assert');
|
|
561
|
+
*
|
|
562
|
+
* const v8 = require('node:v8');
|
|
563
|
+
*
|
|
564
|
+
* class BookShelf {
|
|
565
|
+
* storage = new Map();
|
|
566
|
+
*
|
|
567
|
+
* // Reading a series of files from directory and store them into storage.
|
|
568
|
+
* constructor(directory, books) {
|
|
569
|
+
* for (const book of books) {
|
|
570
|
+
* this.storage.set(book, fs.readFileSync(path.join(directory, book)));
|
|
571
|
+
* }
|
|
572
|
+
* }
|
|
573
|
+
*
|
|
574
|
+
* static compressAll(shelf) {
|
|
575
|
+
* for (const [ book, content ] of shelf.storage) {
|
|
576
|
+
* shelf.storage.set(book, zlib.gzipSync(content));
|
|
577
|
+
* }
|
|
578
|
+
* }
|
|
579
|
+
*
|
|
580
|
+
* static decompressAll(shelf) {
|
|
581
|
+
* for (const [ book, content ] of shelf.storage) {
|
|
582
|
+
* shelf.storage.set(book, zlib.gunzipSync(content));
|
|
583
|
+
* }
|
|
584
|
+
* }
|
|
585
|
+
* }
|
|
586
|
+
*
|
|
587
|
+
* // __dirname here is where the snapshot script is placed
|
|
588
|
+
* // during snapshot building time.
|
|
589
|
+
* const shelf = new BookShelf(__dirname, [
|
|
590
|
+
* 'book1.en_US.txt',
|
|
591
|
+
* 'book1.es_ES.txt',
|
|
592
|
+
* 'book2.zh_CN.txt',
|
|
593
|
+
* ]);
|
|
594
|
+
*
|
|
595
|
+
* assert(v8.startupSnapshot.isBuildingSnapshot());
|
|
596
|
+
* // On snapshot serialization, compress the books to reduce size.
|
|
597
|
+
* v8.startupSnapshot.addSerializeCallback(BookShelf.compressAll, shelf);
|
|
598
|
+
* // On snapshot deserialization, decompress the books.
|
|
599
|
+
* v8.startupSnapshot.addDeserializeCallback(BookShelf.decompressAll, shelf);
|
|
600
|
+
* v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
|
|
601
|
+
* // process.env and process.argv are refreshed during snapshot
|
|
602
|
+
* // deserialization.
|
|
603
|
+
* const lang = process.env.BOOK_LANG || 'en_US';
|
|
604
|
+
* const book = process.argv[1];
|
|
605
|
+
* const name = `${book}.${lang}.txt`;
|
|
606
|
+
* console.log(shelf.storage.get(name));
|
|
607
|
+
* }, shelf);
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* The resulted binary will get print the data deserialized from the snapshot during start up, using the refreshed `process.env` and `process.argv` of the launched process:
|
|
611
|
+
*
|
|
612
|
+
* ```bash
|
|
613
|
+
* $ BOOK_LANG=es_ES node --snapshot-blob snapshot.blob book1
|
|
614
|
+
* # Prints content of book1.es_ES.txt deserialized from the snapshot.
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* Currently the application deserialized from a user-land snapshot cannot be snapshotted again, so these APIs are only available to applications that are not deserialized from a user-land snapshot.
|
|
618
|
+
*
|
|
619
|
+
* @experimental
|
|
620
|
+
* @since v16.17.0
|
|
621
|
+
*/
|
|
622
|
+
const startupSnapshot: StartupSnapshot;
|
|
469
623
|
}
|
|
470
624
|
declare module "node:v8" {
|
|
471
625
|
export * from "v8";
|