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