@@ -58,6 +58,12 @@ const {
5858} = internalBinding ( 'heap_utils' ) ;
5959const { HeapSnapshotStream } = require ( 'internal/heap_utils' ) ;
6060
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+ */
6167function writeHeapSnapshot ( filename ) {
6268 if ( filename !== undefined ) {
6369 filename = getValidatedPath ( filename ) ;
@@ -66,6 +72,11 @@ function writeHeapSnapshot(filename) {
6672 return triggerHeapSnapshot ( filename ) ;
6773}
6874
75+ /**
76+ * Generates a snapshot of the current V8 heap
77+ * and returns a Readable Stream.
78+ * @returns {import('./stream.js').Readable }
79+ */
6980function getHeapSnapshot ( ) {
7081 const handle = createHeapSnapshotStream ( ) ;
7182 assert ( handle ) ;
@@ -111,11 +122,32 @@ const {
111122
112123const kNumberOfHeapSpaces = kHeapSpaces . length ;
113124
125+ /**
126+ * Sets V8 command-line flags.
127+ * @param {string } flags
128+ * @returns {void }
129+ */
114130function setFlagsFromString ( flags ) {
115131 validateString ( flags , 'flags' ) ;
116132 _setFlagsFromString ( flags ) ;
117133}
118134
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+ */
119151function getHeapStatistics ( ) {
120152 const buffer = binding . heapStatisticsBuffer ;
121153
@@ -136,6 +168,16 @@ function getHeapStatistics() {
136168 } ;
137169}
138170
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+ */
139181function getHeapSpaceStatistics ( ) {
140182 const heapSpaceStatistics = new Array ( kNumberOfHeapSpaces ) ;
141183 const buffer = binding . heapSpaceStatisticsBuffer ;
@@ -154,6 +196,14 @@ function getHeapSpaceStatistics() {
154196 return heapSpaceStatistics ;
155197}
156198
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+ */
157207function getHeapCodeStatistics ( ) {
158208 const buffer = binding . heapCodeStatisticsBuffer ;
159209
@@ -170,6 +220,11 @@ function getHeapCodeStatistics() {
170220/* JS methods for the base objects */
171221Serializer . prototype . _getDataCloneError = Error ;
172222
223+ /**
224+ * Reads raw bytes from the deserializer's internal buffer.
225+ * @param {number } length
226+ * @returns {Buffer }
227+ */
173228Deserializer . prototype . readRawBytes = function readRawBytes ( length ) {
174229 const offset = this . _readRawBytes ( length ) ;
175230 // `this.buffer` can be a Buffer or a plain Uint8Array, so just calling
@@ -210,6 +265,12 @@ class DefaultSerializer extends Serializer {
210265 this . _setTreatArrayBufferViewsAsHostObjects ( true ) ;
211266 }
212267
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+ */
213274 _writeHostObject ( abView ) {
214275 let i = 0 ;
215276 if ( abView . constructor === Buffer ) {
@@ -232,6 +293,11 @@ class DefaultSerializer extends Serializer {
232293}
233294
234295class 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+ */
235301 _readHostObject ( ) {
236302 const typeIndex = this . readUint32 ( ) ;
237303 const ctor = arrayBufferViewTypes [ typeIndex ] ;
@@ -254,13 +320,25 @@ class DefaultDeserializer extends Deserializer {
254320 }
255321}
256322
323+ /**
324+ * Uses a `DefaultSerializer` to serialize `value`
325+ * into a buffer.
326+ * @param {any } value
327+ * @returns {Buffer }
328+ */
257329function serialize ( value ) {
258330 const ser = new DefaultSerializer ( ) ;
259331 ser . writeHeader ( ) ;
260332 ser . writeValue ( value ) ;
261333 return ser . releaseBuffer ( ) ;
262334}
263335
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+ */
264342function deserialize ( buffer ) {
265343 const der = new DefaultDeserializer ( buffer ) ;
266344 der . readHeader ( ) ;
0 commit comments