[6a3a178] | 1 | declare 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 | /**
|
---|
| 68 | * @experimental
|
---|
| 69 | */
|
---|
| 70 | class Serializer {
|
---|
| 71 | /**
|
---|
| 72 | * Writes out a header, which includes the serialization format version.
|
---|
| 73 | */
|
---|
| 74 | writeHeader(): void;
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * Serializes a JavaScript value and adds the serialized representation to the internal buffer.
|
---|
| 78 | * This throws an error if value cannot be serialized.
|
---|
| 79 | */
|
---|
| 80 | writeValue(val: any): boolean;
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Returns the stored internal buffer.
|
---|
| 84 | * This serializer should not be used once the buffer is released.
|
---|
| 85 | * Calling this method results in undefined behavior if a previous write has failed.
|
---|
| 86 | */
|
---|
| 87 | releaseBuffer(): Buffer;
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * Marks an ArrayBuffer as having its contents transferred out of band.\
|
---|
| 91 | * Pass the corresponding ArrayBuffer in the deserializing context to deserializer.transferArrayBuffer().
|
---|
| 92 | */
|
---|
| 93 | transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * Write a raw 32-bit unsigned integer.
|
---|
| 97 | */
|
---|
| 98 | writeUint32(value: number): void;
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
|
---|
| 102 | */
|
---|
| 103 | writeUint64(hi: number, lo: number): void;
|
---|
| 104 |
|
---|
| 105 | /**
|
---|
| 106 | * Write a JS number value.
|
---|
| 107 | */
|
---|
| 108 | writeDouble(value: number): void;
|
---|
| 109 |
|
---|
| 110 | /**
|
---|
| 111 | * Write raw bytes into the serializer’s internal buffer.
|
---|
| 112 | * The deserializer will require a way to compute the length of the buffer.
|
---|
| 113 | */
|
---|
| 114 | writeRawBytes(buffer: NodeJS.TypedArray): void;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /**
|
---|
| 118 | * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
|
---|
| 119 | * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
|
---|
| 120 | * @experimental
|
---|
| 121 | */
|
---|
| 122 | class DefaultSerializer extends Serializer {
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * @experimental
|
---|
| 127 | */
|
---|
| 128 | class Deserializer {
|
---|
| 129 | constructor(data: NodeJS.TypedArray);
|
---|
| 130 | /**
|
---|
| 131 | * Reads and validates a header (including the format version).
|
---|
| 132 | * May, for example, reject an invalid or unsupported wire format.
|
---|
| 133 | * In that case, an Error is thrown.
|
---|
| 134 | */
|
---|
| 135 | readHeader(): boolean;
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * Deserializes a JavaScript value from the buffer and returns it.
|
---|
| 139 | */
|
---|
| 140 | readValue(): any;
|
---|
| 141 |
|
---|
| 142 | /**
|
---|
| 143 | * Marks an ArrayBuffer as having its contents transferred out of band.
|
---|
| 144 | * Pass the corresponding `ArrayBuffer` in the serializing context to serializer.transferArrayBuffer()
|
---|
| 145 | * (or return the id from serializer._getSharedArrayBufferId() in the case of SharedArrayBuffers).
|
---|
| 146 | */
|
---|
| 147 | transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
|
---|
| 148 |
|
---|
| 149 | /**
|
---|
| 150 | * Reads the underlying wire format version.
|
---|
| 151 | * Likely mostly to be useful to legacy code reading old wire format versions.
|
---|
| 152 | * May not be called before .readHeader().
|
---|
| 153 | */
|
---|
| 154 | getWireFormatVersion(): number;
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * Read a raw 32-bit unsigned integer and return it.
|
---|
| 158 | */
|
---|
| 159 | readUint32(): number;
|
---|
| 160 |
|
---|
| 161 | /**
|
---|
| 162 | * Read a raw 64-bit unsigned integer and return it as an array [hi, lo] with two 32-bit unsigned integer entries.
|
---|
| 163 | */
|
---|
| 164 | readUint64(): [number, number];
|
---|
| 165 |
|
---|
| 166 | /**
|
---|
| 167 | * Read a JS number value.
|
---|
| 168 | */
|
---|
| 169 | readDouble(): number;
|
---|
| 170 |
|
---|
| 171 | /**
|
---|
| 172 | * Read raw bytes from the deserializer’s internal buffer.
|
---|
| 173 | * The length parameter must correspond to the length of the buffer that was passed to serializer.writeRawBytes().
|
---|
| 174 | */
|
---|
| 175 | readRawBytes(length: number): Buffer;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /**
|
---|
| 179 | * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
|
---|
| 180 | * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
|
---|
| 181 | * @experimental
|
---|
| 182 | */
|
---|
| 183 | class DefaultDeserializer extends Deserializer {
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | /**
|
---|
| 187 | * Uses a `DefaultSerializer` to serialize value into a buffer.
|
---|
| 188 | * @experimental
|
---|
| 189 | */
|
---|
| 190 | function serialize(value: any): Buffer;
|
---|
| 191 |
|
---|
| 192 | /**
|
---|
| 193 | * Uses a `DefaultDeserializer` with default options to read a JS value from a buffer.
|
---|
| 194 | * @experimental
|
---|
| 195 | */
|
---|
| 196 | function deserialize(data: NodeJS.TypedArray): any;
|
---|
| 197 | }
|
---|