@@ -58,6 +58,12 @@ const {
58
58
} = internalBinding ( 'heap_utils' ) ;
59
59
const { HeapSnapshotStream } = require ( 'internal/heap_utils' ) ;
60
60
61
+ /**
62
+ * Generates a snapshot of the current V8 heap
63
+ * and writes it to a JSON file.
64
+ * @param {string } [filename]
65
+ * @returns {string }
66
+ */
61
67
function writeHeapSnapshot ( filename ) {
62
68
if ( filename !== undefined ) {
63
69
filename = getValidatedPath ( filename ) ;
@@ -66,6 +72,11 @@ function writeHeapSnapshot(filename) {
66
72
return triggerHeapSnapshot ( filename ) ;
67
73
}
68
74
75
+ /**
76
+ * Generates a snapshot of the current V8 heap
77
+ * and returns a Readable Stream.
78
+ * @returns {import('./stream.js').Readable }
79
+ */
69
80
function getHeapSnapshot ( ) {
70
81
const handle = createHeapSnapshotStream ( ) ;
71
82
assert ( handle ) ;
@@ -110,11 +121,32 @@ const {
110
121
111
122
const kNumberOfHeapSpaces = kHeapSpaces . length ;
112
123
124
+ /**
125
+ * Sets V8 command-line flags.
126
+ * @param {string } flags
127
+ * @returns {void }
128
+ */
113
129
function setFlagsFromString ( flags ) {
114
130
validateString ( flags , 'flags' ) ;
115
131
_setFlagsFromString ( flags ) ;
116
132
}
117
133
134
+ /**
135
+ * Gets the current V8 heap statistics.
136
+ * @returns {{
137
+ * total_heap_size: number;
138
+ * total_heap_size_executable: number;
139
+ * total_physical_size: number;
140
+ * total_available_size: number;
141
+ * used_heap_size: number;
142
+ * heap_size_limit: number;
143
+ * malloced_memory: number;
144
+ * peak_malloced_memory: number;
145
+ * does_zap_garbage: number;
146
+ * number_of_native_contexts: number;
147
+ * number_of_detached_contexts: number;
148
+ * }}
149
+ */
118
150
function getHeapStatistics ( ) {
119
151
const buffer = heapStatisticsBuffer ;
120
152
@@ -135,6 +167,16 @@ function getHeapStatistics() {
135
167
} ;
136
168
}
137
169
170
+ /**
171
+ * Gets the current V8 heap space statistics.
172
+ * @returns {{
173
+ * space_name: string;
174
+ * space_size: number;
175
+ * space_used_size: number;
176
+ * space_available_size: number;
177
+ * physical_space_size: number;
178
+ * }[] }
179
+ */
138
180
function getHeapSpaceStatistics ( ) {
139
181
const heapSpaceStatistics = new Array ( kNumberOfHeapSpaces ) ;
140
182
const buffer = heapSpaceStatisticsBuffer ;
@@ -153,6 +195,14 @@ function getHeapSpaceStatistics() {
153
195
return heapSpaceStatistics ;
154
196
}
155
197
198
+ /**
199
+ * Gets the current V8 heap code statistics.
200
+ * @returns {{
201
+ * code_and_metadata_size: number;
202
+ * bytecode_and_metadata_size: number;
203
+ * external_script_source_size: number;
204
+ * }}
205
+ */
156
206
function getHeapCodeStatistics ( ) {
157
207
const buffer = heapCodeStatisticsBuffer ;
158
208
@@ -169,6 +219,11 @@ function getHeapCodeStatistics() {
169
219
/* JS methods for the base objects */
170
220
Serializer . prototype . _getDataCloneError = Error ;
171
221
222
+ /**
223
+ * Reads raw bytes from the deserializer's internal buffer.
224
+ * @param {number } length
225
+ * @returns {Buffer }
226
+ */
172
227
Deserializer . prototype . readRawBytes = function readRawBytes ( length ) {
173
228
const offset = this . _readRawBytes ( length ) ;
174
229
// `this.buffer` can be a Buffer or a plain Uint8Array, so just calling
@@ -209,6 +264,12 @@ class DefaultSerializer extends Serializer {
209
264
this . _setTreatArrayBufferViewsAsHostObjects ( true ) ;
210
265
}
211
266
267
+ /**
268
+ * Used to write some kind of host object, i.e. an
269
+ * object that is created by native C++ bindings.
270
+ * @param {Object } abView
271
+ * @returns {void }
272
+ */
212
273
_writeHostObject ( abView ) {
213
274
let i = 0 ;
214
275
if ( abView . constructor === Buffer ) {
@@ -231,6 +292,11 @@ class DefaultSerializer extends Serializer {
231
292
}
232
293
233
294
class DefaultDeserializer extends Deserializer {
295
+ /**
296
+ * Used to read some kind of host object, i.e. an
297
+ * object that is created by native C++ bindings.
298
+ * @returns {any }
299
+ */
234
300
_readHostObject ( ) {
235
301
const typeIndex = this . readUint32 ( ) ;
236
302
const ctor = arrayBufferViewTypes [ typeIndex ] ;
@@ -253,13 +319,25 @@ class DefaultDeserializer extends Deserializer {
253
319
}
254
320
}
255
321
322
+ /**
323
+ * Uses a `DefaultSerializer` to serialize `value`
324
+ * into a buffer.
325
+ * @param {any } value
326
+ * @returns {Buffer }
327
+ */
256
328
function serialize ( value ) {
257
329
const ser = new DefaultSerializer ( ) ;
258
330
ser . writeHeader ( ) ;
259
331
ser . writeValue ( value ) ;
260
332
return ser . releaseBuffer ( ) ;
261
333
}
262
334
335
+ /**
336
+ * Uses a `DefaultDeserializer` with default options
337
+ * to read a JavaScript value from a buffer.
338
+ * @param {Buffer | TypedArray | DataView } buffer
339
+ * @returns {any }
340
+ */
263
341
function deserialize ( buffer ) {
264
342
const der = new DefaultDeserializer ( buffer ) ;
265
343
der . readHeader ( ) ;
0 commit comments