UNPKG

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