UNPKG

6.83 kBTypeScriptView Raw
1declare module 'node:v8' {
2 export * from 'v8';
3}
4
5declare module 'v8' {
6 import { Readable } from 'node:stream';
7
8 interface HeapSpaceInfo {
9 space_name: string;
10 space_size: number;
11 space_used_size: number;
12 space_available_size: number;
13 physical_space_size: number;
14 }
15
16 // ** Signifies if the --zap_code_space option is enabled or not. 1 == enabled, 0 == disabled. */
17 type DoesZapCodeSpaceFlag = 0 | 1;
18
19 interface HeapInfo {
20 total_heap_size: number;
21 total_heap_size_executable: number;
22 total_physical_size: number;
23 total_available_size: number;
24 used_heap_size: number;
25 heap_size_limit: number;
26 malloced_memory: number;
27 peak_malloced_memory: number;
28 does_zap_garbage: DoesZapCodeSpaceFlag;
29 number_of_native_contexts: number;
30 number_of_detached_contexts: number;
31 }
32
33 interface HeapCodeStatistics {
34 code_and_metadata_size: number;
35 bytecode_and_metadata_size: number;
36 external_script_source_size: number;
37 }
38
39 /**
40 * Returns an integer representing a "version tag" derived from the V8 version, command line flags and detected CPU features.
41 * This is useful for determining whether a vm.Script cachedData buffer is compatible with this instance of V8.
42 */
43 function cachedDataVersionTag(): number;
44
45 function getHeapStatistics(): HeapInfo;
46 function getHeapSpaceStatistics(): HeapSpaceInfo[];
47 function setFlagsFromString(flags: string): void;
48 /**
49 * Generates a snapshot of the current V8 heap and returns a Readable
50 * Stream that may be used to read the JSON serialized representation.
51 * This conversation was marked as resolved by joyeecheung
52 * This JSON stream format is intended to be used with tools such as
53 * Chrome DevTools. The JSON schema is undocumented and specific to the
54 * V8 engine, and may change from one version of V8 to the next.
55 */
56 function getHeapSnapshot(): Readable;
57
58 /**
59 *
60 * @param fileName The file path where the V8 heap snapshot is to be
61 * saved. If not specified, a file name with the pattern
62 * `'Heap-${yyyymmdd}-${hhmmss}-${pid}-${thread_id}.heapsnapshot'` will be
63 * generated, where `{pid}` will be the PID of the Node.js process,
64 * `{thread_id}` will be `0` when `writeHeapSnapshot()` is called from
65 * the main Node.js thread or the id of a worker thread.
66 */
67 function writeHeapSnapshot(fileName?: string): string;
68
69 function getHeapCodeStatistics(): HeapCodeStatistics;
70
71 class Serializer {
72 /**
73 * Writes out a header, which includes the serialization format version.
74 */
75 writeHeader(): void;
76
77 /**
78 * Serializes a JavaScript value and adds the serialized representation to the internal buffer.
79 * This throws an error if value cannot be serialized.
80 */
81 writeValue(val: any): boolean;
82
83 /**
84 * Returns the stored internal buffer.
85 * This serializer should not be used once the buffer is released.
86 * Calling this method results in undefined behavior if a previous write has failed.
87 */
88 releaseBuffer(): Buffer;
89
90 /**
91 * Marks an ArrayBuffer as having its contents transferred out of band.\
92 * Pass the corresponding ArrayBuffer in the deserializing context to deserializer.transferArrayBuffer().
93 */
94 transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
95
96 /**
97 * Write a raw 32-bit unsigned integer.
98 */
99 writeUint32(value: number): void;
100
101 /**
102 * Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
103 */
104 writeUint64(hi: number, lo: number): void;
105
106 /**
107 * Write a JS number value.
108 */
109 writeDouble(value: number): void;
110
111 /**
112 * Write raw bytes into the serializer’s internal buffer.
113 * The deserializer will require a way to compute the length of the buffer.
114 */
115 writeRawBytes(buffer: NodeJS.TypedArray): void;
116 }
117
118 /**
119 * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
120 * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
121 */
122 class DefaultSerializer extends Serializer {
123 }
124
125 class Deserializer {
126 constructor(data: NodeJS.TypedArray);
127 /**
128 * Reads and validates a header (including the format version).
129 * May, for example, reject an invalid or unsupported wire format.
130 * In that case, an Error is thrown.
131 */
132 readHeader(): boolean;
133
134 /**
135 * Deserializes a JavaScript value from the buffer and returns it.
136 */
137 readValue(): any;
138
139 /**
140 * Marks an ArrayBuffer as having its contents transferred out of band.
141 * Pass the corresponding `ArrayBuffer` in the serializing context to serializer.transferArrayBuffer()
142 * (or return the id from serializer._getSharedArrayBufferId() in the case of SharedArrayBuffers).
143 */
144 transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
145
146 /**
147 * Reads the underlying wire format version.
148 * Likely mostly to be useful to legacy code reading old wire format versions.
149 * May not be called before .readHeader().
150 */
151 getWireFormatVersion(): number;
152
153 /**
154 * Read a raw 32-bit unsigned integer and return it.
155 */
156 readUint32(): number;
157
158 /**
159 * Read a raw 64-bit unsigned integer and return it as an array [hi, lo] with two 32-bit unsigned integer entries.
160 */
161 readUint64(): [number, number];
162
163 /**
164 * Read a JS number value.
165 */
166 readDouble(): number;
167
168 /**
169 * Read raw bytes from the deserializer’s internal buffer.
170 * The length parameter must correspond to the length of the buffer that was passed to serializer.writeRawBytes().
171 */
172 readRawBytes(length: number): Buffer;
173 }
174
175 /**
176 * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
177 * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
178 */
179 class DefaultDeserializer extends Deserializer {
180 }
181
182 /**
183 * Uses a `DefaultSerializer` to serialize value into a buffer.
184 */
185 function serialize(value: any): Buffer;
186
187 /**
188 * Uses a `DefaultDeserializer` with default options to read a JS value from a buffer.
189 */
190 function deserialize(data: NodeJS.TypedArray): any;
191}