• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3<head>
4  <meta charset="utf-8">
5  <meta name="viewport" content="width=device-width">
6  <meta name="nodejs.org:node-version" content="v14.21.2">
7  <title>V8 | Node.js v14.21.2 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/v8.html">
12</head>
13<body class="alt apidoc" id="api-section-v8">
14  <div id="content" class="clearfix">
15    <div id="column2" class="interior">
16      <div id="intro" class="interior">
17        <a href="/" title="Go back to the home page">
18          Node.js
19        </a>
20      </div>
21      <ul>
22<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
23<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
24</ul>
25<hr class="line">
26<ul>
27<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
28<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
29<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
30<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
31<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
32<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
33<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
34<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
35<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
36<li><a href="console.html" class="nav-console">Console</a></li>
37<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
38<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
39<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
40<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
41<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
42<li><a href="dns.html" class="nav-dns">DNS</a></li>
43<li><a href="domain.html" class="nav-domain">Domain</a></li>
44<li><a href="errors.html" class="nav-errors">Errors</a></li>
45<li><a href="events.html" class="nav-events">Events</a></li>
46<li><a href="fs.html" class="nav-fs">File system</a></li>
47<li><a href="globals.html" class="nav-globals">Globals</a></li>
48<li><a href="http.html" class="nav-http">HTTP</a></li>
49<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
50<li><a href="https.html" class="nav-https">HTTPS</a></li>
51<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
52<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
53<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
54<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
55<li><a href="module.html" class="nav-module">Modules: <code>module</code> API</a></li>
56<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
57<li><a href="net.html" class="nav-net">Net</a></li>
58<li><a href="os.html" class="nav-os">OS</a></li>
59<li><a href="path.html" class="nav-path">Path</a></li>
60<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
61<li><a href="policy.html" class="nav-policy">Policies</a></li>
62<li><a href="process.html" class="nav-process">Process</a></li>
63<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
64<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
65<li><a href="readline.html" class="nav-readline">Readline</a></li>
66<li><a href="repl.html" class="nav-repl">REPL</a></li>
67<li><a href="report.html" class="nav-report">Report</a></li>
68<li><a href="stream.html" class="nav-stream">Stream</a></li>
69<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
70<li><a href="timers.html" class="nav-timers">Timers</a></li>
71<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
72<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
73<li><a href="tty.html" class="nav-tty">TTY</a></li>
74<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
75<li><a href="url.html" class="nav-url">URL</a></li>
76<li><a href="util.html" class="nav-util">Utilities</a></li>
77<li><a href="v8.html" class="nav-v8 active">V8</a></li>
78<li><a href="vm.html" class="nav-vm">VM</a></li>
79<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
80<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
81<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
82</ul>
83<hr class="line">
84<ul>
85<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
86</ul>
87    </div>
88
89    <div id="column1" data-id="v8" class="interior">
90      <header>
91        <div class="header-container">
92          <h1>Node.js v14.21.2 documentation</h1>
93          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
94            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
95              <path fill="none" d="M0 0h24v24H0z" />
96              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
97              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
98            </svg>
99            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
100              <path d="M0 0h24v24H0z" fill="none" />
101              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
102            </svg>
103          </button>
104        </div>
105        <div id="gtoc">
106          <ul>
107            <li>
108              <a href="index.html">Index</a>
109            </li>
110            <li>
111              <a href="all.html">View on single page</a>
112            </li>
113            <li>
114              <a href="v8.json">View as JSON</a>
115            </li>
116
117    <li class="version-picker">
118      <a href="#">View another version <span>&#x25bc;</span></a>
119      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v19.x/api/v8.html">19.x</a></li>
120<li><a href="https://nodejs.org/docs/latest-v18.x/api/v8.html">18.x <b>LTS</b></a></li>
121<li><a href="https://nodejs.org/docs/latest-v17.x/api/v8.html">17.x</a></li>
122<li><a href="https://nodejs.org/docs/latest-v16.x/api/v8.html">16.x <b>LTS</b></a></li>
123<li><a href="https://nodejs.org/docs/latest-v15.x/api/v8.html">15.x</a></li>
124<li><a href="https://nodejs.org/docs/latest-v14.x/api/v8.html">14.x <b>LTS</b></a></li>
125<li><a href="https://nodejs.org/docs/latest-v13.x/api/v8.html">13.x</a></li>
126<li><a href="https://nodejs.org/docs/latest-v12.x/api/v8.html">12.x</a></li>
127<li><a href="https://nodejs.org/docs/latest-v11.x/api/v8.html">11.x</a></li>
128<li><a href="https://nodejs.org/docs/latest-v10.x/api/v8.html">10.x</a></li>
129<li><a href="https://nodejs.org/docs/latest-v9.x/api/v8.html">9.x</a></li>
130<li><a href="https://nodejs.org/docs/latest-v8.x/api/v8.html">8.x</a></li>
131<li><a href="https://nodejs.org/docs/latest-v7.x/api/v8.html">7.x</a></li>
132<li><a href="https://nodejs.org/docs/latest-v6.x/api/v8.html">6.x</a></li>
133<li><a href="https://nodejs.org/docs/latest-v5.x/api/v8.html">5.x</a></li>
134<li><a href="https://nodejs.org/docs/latest-v4.x/api/v8.html">4.x</a></li></ol>
135    </li>
136
137            <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/v8.md">Edit on GitHub</a></li>
138          </ul>
139        </div>
140        <hr>
141      </header>
142
143      <details id="toc" open><summary>Table of contents</summary><ul>
144<li><a href="#v8_v8">V8</a>
145<ul>
146<li><a href="#v8_v8_cacheddataversiontag"><code>v8.cachedDataVersionTag()</code></a></li>
147<li><a href="#v8_v8_getheapcodestatistics"><code>v8.getHeapCodeStatistics()</code></a></li>
148<li><a href="#v8_v8_getheapsnapshot"><code>v8.getHeapSnapshot()</code></a></li>
149<li><a href="#v8_v8_getheapspacestatistics"><code>v8.getHeapSpaceStatistics()</code></a></li>
150<li><a href="#v8_v8_getheapstatistics"><code>v8.getHeapStatistics()</code></a></li>
151<li><a href="#v8_v8_setflagsfromstring_flags"><code>v8.setFlagsFromString(flags)</code></a></li>
152<li><a href="#v8_v8_stopcoverage"><code>v8.stopCoverage()</code></a></li>
153<li><a href="#v8_v8_takecoverage"><code>v8.takeCoverage()</code></a></li>
154<li><a href="#v8_v8_writeheapsnapshot_filename"><code>v8.writeHeapSnapshot([filename])</code></a></li>
155<li><a href="#v8_serialization_api">Serialization API</a>
156<ul>
157<li><a href="#v8_v8_serialize_value"><code>v8.serialize(value)</code></a></li>
158<li><a href="#v8_v8_deserialize_buffer"><code>v8.deserialize(buffer)</code></a></li>
159<li><a href="#v8_class_v8_serializer">Class: <code>v8.Serializer</code></a>
160<ul>
161<li><a href="#v8_new_serializer"><code>new Serializer()</code></a></li>
162<li><a href="#v8_serializer_writeheader"><code>serializer.writeHeader()</code></a></li>
163<li><a href="#v8_serializer_writevalue_value"><code>serializer.writeValue(value)</code></a></li>
164<li><a href="#v8_serializer_releasebuffer"><code>serializer.releaseBuffer()</code></a></li>
165<li><a href="#v8_serializer_transferarraybuffer_id_arraybuffer"><code>serializer.transferArrayBuffer(id, arrayBuffer)</code></a></li>
166<li><a href="#v8_serializer_writeuint32_value"><code>serializer.writeUint32(value)</code></a></li>
167<li><a href="#v8_serializer_writeuint64_hi_lo"><code>serializer.writeUint64(hi, lo)</code></a></li>
168<li><a href="#v8_serializer_writedouble_value"><code>serializer.writeDouble(value)</code></a></li>
169<li><a href="#v8_serializer_writerawbytes_buffer"><code>serializer.writeRawBytes(buffer)</code></a></li>
170<li><a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject(object)</code></a></li>
171<li><a href="#v8_serializer_getdatacloneerror_message"><code>serializer._getDataCloneError(message)</code></a></li>
172<li><a href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer"><code>serializer._getSharedArrayBufferId(sharedArrayBuffer)</code></a></li>
173<li><a href="#v8_serializer_settreatarraybufferviewsashostobjects_flag"><code>serializer._setTreatArrayBufferViewsAsHostObjects(flag)</code></a></li>
174</ul>
175</li>
176<li><a href="#v8_class_v8_deserializer">Class: <code>v8.Deserializer</code></a>
177<ul>
178<li><a href="#v8_new_deserializer_buffer"><code>new Deserializer(buffer)</code></a></li>
179<li><a href="#v8_deserializer_readheader"><code>deserializer.readHeader()</code></a></li>
180<li><a href="#v8_deserializer_readvalue"><code>deserializer.readValue()</code></a></li>
181<li><a href="#v8_deserializer_transferarraybuffer_id_arraybuffer"><code>deserializer.transferArrayBuffer(id, arrayBuffer)</code></a></li>
182<li><a href="#v8_deserializer_getwireformatversion"><code>deserializer.getWireFormatVersion()</code></a></li>
183<li><a href="#v8_deserializer_readuint32"><code>deserializer.readUint32()</code></a></li>
184<li><a href="#v8_deserializer_readuint64"><code>deserializer.readUint64()</code></a></li>
185<li><a href="#v8_deserializer_readdouble"><code>deserializer.readDouble()</code></a></li>
186<li><a href="#v8_deserializer_readrawbytes_length"><code>deserializer.readRawBytes(length)</code></a></li>
187<li><a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a></li>
188</ul>
189</li>
190<li><a href="#v8_class_v8_defaultserializer">Class: <code>v8.DefaultSerializer</code></a></li>
191<li><a href="#v8_class_v8_defaultdeserializer">Class: <code>v8.DefaultDeserializer</code></a></li>
192</ul>
193</li>
194</ul>
195</li>
196</ul></details>
197
198      <div id="apicontent">
199        <h2>V8<span><a class="mark" href="#v8_v8" id="v8_v8">#</a></span></h2>
200
201<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.21.2/lib/v8.js">lib/v8.js</a></p>
202<p>The <code>v8</code> module exposes APIs that are specific to the version of <a href="https://developers.google.com/v8/">V8</a>
203built into the Node.js binary. It can be accessed using:</p>
204<pre><code class="language-js"><span class="hljs-keyword">const</span> v8 = <span class="hljs-built_in">require</span>(<span class="hljs-string">'v8'</span>);</code></pre>
205<section><h3><code>v8.cachedDataVersionTag()</code><span><a class="mark" href="#v8_v8_cacheddataversiontag" id="v8_v8_cacheddataversiontag">#</a></span></h3>
206<div class="api_metadata">
207<span>Added in: v8.0.0</span>
208</div>
209<ul>
210<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
211</ul>
212<p>Returns an integer representing a version tag derived from the V8 version,
213command-line flags, and detected CPU features. This is useful for determining
214whether a <a href="vm.html#vm_new_vm_script_code_options"><code>vm.Script</code></a> <code>cachedData</code> buffer is compatible with this instance
215of V8.</p>
216<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(v8.<span class="hljs-title function_">cachedDataVersionTag</span>()); <span class="hljs-comment">// 3947234607</span>
217<span class="hljs-comment">// The value returned by v8.cachedDataVersionTag() is derived from the V8</span>
218<span class="hljs-comment">// version, command-line flags, and detected CPU features. Test that the value</span>
219<span class="hljs-comment">// does indeed update when flags are toggled.</span>
220v8.<span class="hljs-title function_">setFlagsFromString</span>(<span class="hljs-string">'--allow_natives_syntax'</span>);
221<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(v8.<span class="hljs-title function_">cachedDataVersionTag</span>()); <span class="hljs-comment">// 183726201</span></code></pre>
222</section><section><h3><code>v8.getHeapCodeStatistics()</code><span><a class="mark" href="#v8_v8_getheapcodestatistics" id="v8_v8_getheapcodestatistics">#</a></span></h3>
223<div class="api_metadata">
224<span>Added in: v12.8.0</span>
225</div>
226<ul>
227<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
228</ul>
229<p>Returns an object with the following properties:</p>
230<ul>
231<li><code>code_and_metadata_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
232<li><code>bytecode_and_metadata_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
233<li><code>external_script_source_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
234</ul>
235<!-- eslint-skip -->
236<pre><code class="language-js">{
237  <span class="hljs-attr">code_and_metadata_size</span>: <span class="hljs-number">212208</span>,
238  <span class="hljs-attr">bytecode_and_metadata_size</span>: <span class="hljs-number">161368</span>,
239  <span class="hljs-attr">external_script_source_size</span>: <span class="hljs-number">1410794</span>
240}</code></pre>
241</section><section><h3><code>v8.getHeapSnapshot()</code><span><a class="mark" href="#v8_v8_getheapsnapshot" id="v8_v8_getheapsnapshot">#</a></span></h3>
242<div class="api_metadata">
243<span>Added in: v11.13.0</span>
244</div>
245<ul>
246<li>Returns: <a href="stream.html#stream_class_stream_readable" class="type">&#x3C;stream.Readable></a> A Readable Stream containing the V8 heap snapshot</li>
247</ul>
248<p>Generates a snapshot of the current V8 heap and returns a Readable
249Stream that may be used to read the JSON serialized representation.
250This JSON stream format is intended to be used with tools such as
251Chrome DevTools. The JSON schema is undocumented and specific to the
252V8 engine. Therefore, the schema may change from one version of V8 to the next.</p>
253<pre><code class="language-js"><span class="hljs-comment">// Print heap snapshot to the console</span>
254<span class="hljs-keyword">const</span> v8 = <span class="hljs-built_in">require</span>(<span class="hljs-string">'v8'</span>);
255<span class="hljs-keyword">const</span> stream = v8.<span class="hljs-title function_">getHeapSnapshot</span>();
256stream.<span class="hljs-title function_">pipe</span>(process.<span class="hljs-property">stdout</span>);</code></pre>
257</section><section><h3><code>v8.getHeapSpaceStatistics()</code><span><a class="mark" href="#v8_v8_getheapspacestatistics" id="v8_v8_getheapspacestatistics">#</a></span></h3>
258<div class="api_metadata">
259<details class="changelog"><summary>History</summary>
260<table>
261<tbody><tr><th>Version</th><th>Changes</th></tr>
262<tr><td>v7.5.0</td>
263<td><p>Support values exceeding the 32-bit unsigned integer range.</p></td></tr>
264<tr><td>v6.0.0</td>
265<td><p><span>Added in: v6.0.0</span></p></td></tr>
266</tbody></table>
267</details>
268</div>
269<ul>
270<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
271</ul>
272<p>Returns statistics about the V8 heap spaces, i.e. the segments which make up
273the V8 heap. Neither the ordering of heap spaces, nor the availability of a
274heap space can be guaranteed as the statistics are provided via the V8
275<a href="https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4"><code>GetHeapSpaceStatistics</code></a> function and may change from one V8 version to the
276next.</p>
277<p>The value returned is an array of objects containing the following properties:</p>
278<ul>
279<li><code>space_name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
280<li><code>space_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
281<li><code>space_used_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
282<li><code>space_available_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
283<li><code>physical_space_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
284</ul>
285<pre><code class="language-json"><span class="hljs-punctuation">[</span>
286  <span class="hljs-punctuation">{</span>
287    <span class="hljs-attr">"space_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"new_space"</span><span class="hljs-punctuation">,</span>
288    <span class="hljs-attr">"space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2063872</span><span class="hljs-punctuation">,</span>
289    <span class="hljs-attr">"space_used_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">951112</span><span class="hljs-punctuation">,</span>
290    <span class="hljs-attr">"space_available_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">80824</span><span class="hljs-punctuation">,</span>
291    <span class="hljs-attr">"physical_space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2063872</span>
292  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
293  <span class="hljs-punctuation">{</span>
294    <span class="hljs-attr">"space_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"old_space"</span><span class="hljs-punctuation">,</span>
295    <span class="hljs-attr">"space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3090560</span><span class="hljs-punctuation">,</span>
296    <span class="hljs-attr">"space_used_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2493792</span><span class="hljs-punctuation">,</span>
297    <span class="hljs-attr">"space_available_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>
298    <span class="hljs-attr">"physical_space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3090560</span>
299  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
300  <span class="hljs-punctuation">{</span>
301    <span class="hljs-attr">"space_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"code_space"</span><span class="hljs-punctuation">,</span>
302    <span class="hljs-attr">"space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1260160</span><span class="hljs-punctuation">,</span>
303    <span class="hljs-attr">"space_used_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">644256</span><span class="hljs-punctuation">,</span>
304    <span class="hljs-attr">"space_available_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">960</span><span class="hljs-punctuation">,</span>
305    <span class="hljs-attr">"physical_space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1260160</span>
306  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
307  <span class="hljs-punctuation">{</span>
308    <span class="hljs-attr">"space_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"map_space"</span><span class="hljs-punctuation">,</span>
309    <span class="hljs-attr">"space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1094160</span><span class="hljs-punctuation">,</span>
310    <span class="hljs-attr">"space_used_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">201608</span><span class="hljs-punctuation">,</span>
311    <span class="hljs-attr">"space_available_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>
312    <span class="hljs-attr">"physical_space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1094160</span>
313  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
314  <span class="hljs-punctuation">{</span>
315    <span class="hljs-attr">"space_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"large_object_space"</span><span class="hljs-punctuation">,</span>
316    <span class="hljs-attr">"space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>
317    <span class="hljs-attr">"space_used_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>
318    <span class="hljs-attr">"space_available_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1490980608</span><span class="hljs-punctuation">,</span>
319    <span class="hljs-attr">"physical_space_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>
320  <span class="hljs-punctuation">}</span>
321<span class="hljs-punctuation">]</span></code></pre>
322</section><section><h3><code>v8.getHeapStatistics()</code><span><a class="mark" href="#v8_v8_getheapstatistics" id="v8_v8_getheapstatistics">#</a></span></h3>
323<div class="api_metadata">
324<details class="changelog"><summary>History</summary>
325<table>
326<tbody><tr><th>Version</th><th>Changes</th></tr>
327<tr><td>v7.5.0</td>
328<td><p>Support values exceeding the 32-bit unsigned integer range.</p></td></tr>
329<tr><td>v7.2.0</td>
330<td><p>Added <code>malloced_memory</code>, <code>peak_malloced_memory</code>, and <code>does_zap_garbage</code>.</p></td></tr>
331<tr><td>v1.0.0</td>
332<td><p><span>Added in: v1.0.0</span></p></td></tr>
333</tbody></table>
334</details>
335</div>
336<ul>
337<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
338</ul>
339<p>Returns an object with the following properties:</p>
340<ul>
341<li><code>total_heap_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
342<li><code>total_heap_size_executable</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
343<li><code>total_physical_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
344<li><code>total_available_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
345<li><code>used_heap_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
346<li><code>heap_size_limit</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
347<li><code>malloced_memory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
348<li><code>peak_malloced_memory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
349<li><code>does_zap_garbage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
350<li><code>number_of_native_contexts</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
351<li><code>number_of_detached_contexts</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
352</ul>
353<p><code>does_zap_garbage</code> is a 0/1 boolean, which signifies whether the
354<code>--zap_code_space</code> option is enabled or not. This makes V8 overwrite heap
355garbage with a bit pattern. The RSS footprint (resident set size) gets bigger
356because it continuously touches all heap pages and that makes them less likely
357to get swapped out by the operating system.</p>
358<p><code>number_of_native_contexts</code> The value of native_context is the number of the
359top-level contexts currently active. Increase of this number over time indicates
360a memory leak.</p>
361<p><code>number_of_detached_contexts</code> The value of detached_context is the number
362of contexts that were detached and not yet garbage collected. This number
363being non-zero indicates a potential memory leak.</p>
364<!-- eslint-skip -->
365<pre><code class="language-js">{
366  <span class="hljs-attr">total_heap_size</span>: <span class="hljs-number">7326976</span>,
367  <span class="hljs-attr">total_heap_size_executable</span>: <span class="hljs-number">4194304</span>,
368  <span class="hljs-attr">total_physical_size</span>: <span class="hljs-number">7326976</span>,
369  <span class="hljs-attr">total_available_size</span>: <span class="hljs-number">1152656</span>,
370  <span class="hljs-attr">used_heap_size</span>: <span class="hljs-number">3476208</span>,
371  <span class="hljs-attr">heap_size_limit</span>: <span class="hljs-number">1535115264</span>,
372  <span class="hljs-attr">malloced_memory</span>: <span class="hljs-number">16384</span>,
373  <span class="hljs-attr">peak_malloced_memory</span>: <span class="hljs-number">1127496</span>,
374  <span class="hljs-attr">does_zap_garbage</span>: <span class="hljs-number">0</span>,
375  <span class="hljs-attr">number_of_native_contexts</span>: <span class="hljs-number">1</span>,
376  <span class="hljs-attr">number_of_detached_contexts</span>: <span class="hljs-number">0</span>
377}</code></pre>
378</section><section><h3><code>v8.setFlagsFromString(flags)</code><span><a class="mark" href="#v8_v8_setflagsfromstring_flags" id="v8_v8_setflagsfromstring_flags">#</a></span></h3>
379<div class="api_metadata">
380<span>Added in: v1.0.0</span>
381</div>
382<ul>
383<li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
384</ul>
385<p>The <code>v8.setFlagsFromString()</code> method can be used to programmatically set
386V8 command-line flags. This method should be used with care. Changing settings
387after the VM has started may result in unpredictable behavior, including
388crashes and data loss; or it may simply do nothing.</p>
389<p>The V8 options available for a version of Node.js may be determined by running
390<code>node --v8-options</code>.</p>
391<p>Usage:</p>
392<pre><code class="language-js"><span class="hljs-comment">// Print GC events to stdout for one minute.</span>
393<span class="hljs-keyword">const</span> v8 = <span class="hljs-built_in">require</span>(<span class="hljs-string">'v8'</span>);
394v8.<span class="hljs-title function_">setFlagsFromString</span>(<span class="hljs-string">'--trace_gc'</span>);
395<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { v8.<span class="hljs-title function_">setFlagsFromString</span>(<span class="hljs-string">'--notrace_gc'</span>); }, <span class="hljs-number">60e3</span>);</code></pre>
396</section><section><h3><code>v8.stopCoverage()</code><span><a class="mark" href="#v8_v8_stopcoverage" id="v8_v8_stopcoverage">#</a></span></h3>
397<div class="api_metadata">
398<span>Added in: v14.18.0</span>
399</div>
400<p>The <code>v8.stopCoverage()</code> method allows the user to stop the coverage collection
401started by <a href="cli.html#cli_node_v8_coverage_dir"><code>NODE_V8_COVERAGE</code></a>, so that V8 can release the execution count
402records and optimize code. This can be used in conjunction with
403<a href="#v8_v8_takecoverage"><code>v8.takeCoverage()</code></a> if the user wants to collect the coverage on demand.</p>
404</section><section><h3><code>v8.takeCoverage()</code><span><a class="mark" href="#v8_v8_takecoverage" id="v8_v8_takecoverage">#</a></span></h3>
405<div class="api_metadata">
406<span>Added in: v14.18.0</span>
407</div>
408<p>The <code>v8.takeCoverage()</code> method allows the user to write the coverage started by
409<a href="cli.html#cli_node_v8_coverage_dir"><code>NODE_V8_COVERAGE</code></a> to disk on demand. This method can be invoked multiple
410times during the lifetime of the process. Each time the execution counter will
411be reset and a new coverage report will be written to the directory specified
412by <a href="cli.html#cli_node_v8_coverage_dir"><code>NODE_V8_COVERAGE</code></a>.</p>
413<p>When the process is about to exit, one last coverage will still be written to
414disk unless <a href="#v8_v8_stopcoverage"><code>v8.stopCoverage()</code></a> is invoked before the process exits.</p>
415</section><section><h3><code>v8.writeHeapSnapshot([filename])</code><span><a class="mark" href="#v8_v8_writeheapsnapshot_filename" id="v8_v8_writeheapsnapshot_filename">#</a></span></h3>
416<div class="api_metadata">
417<span>Added in: v11.13.0</span>
418</div>
419<ul>
420<li><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The file path where the V8 heap snapshot is to be
421saved. If not specified, a file name with the pattern
422<code>'Heap-${yyyymmdd}-${hhmmss}-${pid}-${thread_id}.heapsnapshot'</code> will be
423generated, where <code>{pid}</code> will be the PID of the Node.js process,
424<code>{thread_id}</code> will be <code>0</code> when <code>writeHeapSnapshot()</code> is called from
425the main Node.js thread or the id of a worker thread.</li>
426<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The filename where the snapshot was saved.</li>
427</ul>
428<p>Generates a snapshot of the current V8 heap and writes it to a JSON
429file. This file is intended to be used with tools such as Chrome
430DevTools. The JSON schema is undocumented and specific to the V8
431engine, and may change from one version of V8 to the next.</p>
432<p>A heap snapshot is specific to a single V8 isolate. When using
433<a href="worker_threads.html">worker threads</a>, a heap snapshot generated from the main thread will
434not contain any information about the workers, and vice versa.</p>
435<pre><code class="language-js"><span class="hljs-keyword">const</span> { writeHeapSnapshot } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'v8'</span>);
436<span class="hljs-keyword">const</span> {
437  <span class="hljs-title class_">Worker</span>,
438  isMainThread,
439  parentPort
440} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'worker_threads'</span>);
441
442<span class="hljs-keyword">if</span> (isMainThread) {
443  <span class="hljs-keyword">const</span> worker = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Worker</span>(__filename);
444
445  worker.<span class="hljs-title function_">once</span>(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">filename</span>) =></span> {
446    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`worker heapdump: <span class="hljs-subst">${filename}</span>`</span>);
447    <span class="hljs-comment">// Now get a heapdump for the main thread.</span>
448    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`main thread heapdump: <span class="hljs-subst">${writeHeapSnapshot()}</span>`</span>);
449  });
450
451  <span class="hljs-comment">// Tell the worker to create a heapdump.</span>
452  worker.<span class="hljs-title function_">postMessage</span>(<span class="hljs-string">'heapdump'</span>);
453} <span class="hljs-keyword">else</span> {
454  parentPort.<span class="hljs-title function_">once</span>(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">message</span>) =></span> {
455    <span class="hljs-keyword">if</span> (message === <span class="hljs-string">'heapdump'</span>) {
456      <span class="hljs-comment">// Generate a heapdump for the worker</span>
457      <span class="hljs-comment">// and return the filename to the parent.</span>
458      parentPort.<span class="hljs-title function_">postMessage</span>(<span class="hljs-title function_">writeHeapSnapshot</span>());
459    }
460  });
461}</code></pre>
462</section><section><h3>Serialization API<span><a class="mark" href="#v8_serialization_api" id="v8_serialization_api">#</a></span></h3>
463<p>The serialization API provides means of serializing JavaScript values in a way
464that is compatible with the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">HTML structured clone algorithm</a>.</p>
465<p>The format is backward-compatible (i.e. safe to store to disk).
466Equal JavaScript values may result in different serialized output.</p>
467<h4><code>v8.serialize(value)</code><span><a class="mark" href="#v8_v8_serialize_value" id="v8_v8_serialize_value">#</a></span></h4>
468<div class="api_metadata">
469<span>Added in: v8.0.0</span>
470</div>
471<ul>
472<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
473<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a></li>
474</ul>
475<p>Uses a <a href="#v8_class_v8_defaultserializer"><code>DefaultSerializer</code></a> to serialize <code>value</code> into a buffer.</p>
476<h4><code>v8.deserialize(buffer)</code><span><a class="mark" href="#v8_v8_deserialize_buffer" id="v8_v8_deserialize_buffer">#</a></span></h4>
477<div class="api_metadata">
478<span>Added in: v8.0.0</span>
479</div>
480<ul>
481<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> A buffer returned by <a href="#v8_v8_serialize_value"><code>serialize()</code></a>.</li>
482</ul>
483<p>Uses a <a href="#v8_class_v8_defaultdeserializer"><code>DefaultDeserializer</code></a> with default options to read a JS value
484from a buffer.</p>
485<h4>Class: <code>v8.Serializer</code><span><a class="mark" href="#v8_class_v8_serializer" id="v8_class_v8_serializer">#</a></span></h4>
486<div class="api_metadata">
487<span>Added in: v8.0.0</span>
488</div>
489<h5><code>new Serializer()</code><span><a class="mark" href="#v8_new_serializer" id="v8_new_serializer">#</a></span></h5>
490<p>Creates a new <code>Serializer</code> object.</p>
491<h5><code>serializer.writeHeader()</code><span><a class="mark" href="#v8_serializer_writeheader" id="v8_serializer_writeheader">#</a></span></h5>
492<p>Writes out a header, which includes the serialization format version.</p>
493<h5><code>serializer.writeValue(value)</code><span><a class="mark" href="#v8_serializer_writevalue_value" id="v8_serializer_writevalue_value">#</a></span></h5>
494<ul>
495<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
496</ul>
497<p>Serializes a JavaScript value and adds the serialized representation to the
498internal buffer.</p>
499<p>This throws an error if <code>value</code> cannot be serialized.</p>
500<h5><code>serializer.releaseBuffer()</code><span><a class="mark" href="#v8_serializer_releasebuffer" id="v8_serializer_releasebuffer">#</a></span></h5>
501<ul>
502<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a></li>
503</ul>
504<p>Returns the stored internal buffer. This serializer should not be used once
505the buffer is released. Calling this method results in undefined behavior
506if a previous write has failed.</p>
507<h5><code>serializer.transferArrayBuffer(id, arrayBuffer)</code><span><a class="mark" href="#v8_serializer_transferarraybuffer_id_arraybuffer" id="v8_serializer_transferarraybuffer_id_arraybuffer">#</a></span></h5>
508<ul>
509<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> A 32-bit unsigned integer.</li>
510<li><code>arrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> An <code>ArrayBuffer</code> instance.</li>
511</ul>
512<p>Marks an <code>ArrayBuffer</code> as having its contents transferred out of band.
513Pass the corresponding <code>ArrayBuffer</code> in the deserializing context to
514<a href="#v8_deserializer_transferarraybuffer_id_arraybuffer"><code>deserializer.transferArrayBuffer()</code></a>.</p>
515<h5><code>serializer.writeUint32(value)</code><span><a class="mark" href="#v8_serializer_writeuint32_value" id="v8_serializer_writeuint32_value">#</a></span></h5>
516<ul>
517<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
518</ul>
519<p>Write a raw 32-bit unsigned integer.
520For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
521<h5><code>serializer.writeUint64(hi, lo)</code><span><a class="mark" href="#v8_serializer_writeuint64_hi_lo" id="v8_serializer_writeuint64_hi_lo">#</a></span></h5>
522<ul>
523<li><code>hi</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
524<li><code>lo</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
525</ul>
526<p>Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
527For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
528<h5><code>serializer.writeDouble(value)</code><span><a class="mark" href="#v8_serializer_writedouble_value" id="v8_serializer_writedouble_value">#</a></span></h5>
529<ul>
530<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
531</ul>
532<p>Write a JS <code>number</code> value.
533For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
534<h5><code>serializer.writeRawBytes(buffer)</code><span><a class="mark" href="#v8_serializer_writerawbytes_buffer" id="v8_serializer_writerawbytes_buffer">#</a></span></h5>
535<ul>
536<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a></li>
537</ul>
538<p>Write raw bytes into the serializer’s internal buffer. The deserializer
539will require a way to compute the length of the buffer.
540For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
541<h5><code>serializer._writeHostObject(object)</code><span><a class="mark" href="#v8_serializer_writehostobject_object" id="v8_serializer_writehostobject_object">#</a></span></h5>
542<ul>
543<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
544</ul>
545<p>This method is called to write some kind of host object, i.e. an object created
546by native C++ bindings. If it is not possible to serialize <code>object</code>, a suitable
547exception should be thrown.</p>
548<p>This method is not present on the <code>Serializer</code> class itself but can be provided
549by subclasses.</p>
550<h5><code>serializer._getDataCloneError(message)</code><span><a class="mark" href="#v8_serializer_getdatacloneerror_message" id="v8_serializer_getdatacloneerror_message">#</a></span></h5>
551<ul>
552<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
553</ul>
554<p>This method is called to generate error objects that will be thrown when an
555object can not be cloned.</p>
556<p>This method defaults to the <a href="errors.html#errors_class_error"><code>Error</code></a> constructor and can be overridden on
557subclasses.</p>
558<h5><code>serializer._getSharedArrayBufferId(sharedArrayBuffer)</code><span><a class="mark" href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer" id="v8_serializer_getsharedarraybufferid_sharedarraybuffer">#</a></span></h5>
559<ul>
560<li><code>sharedArrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer" class="type">&#x3C;SharedArrayBuffer></a></li>
561</ul>
562<p>This method is called when the serializer is going to serialize a
563<code>SharedArrayBuffer</code> object. It must return an unsigned 32-bit integer ID for
564the object, using the same ID if this <code>SharedArrayBuffer</code> has already been
565serialized. When deserializing, this ID will be passed to
566<a href="#v8_deserializer_transferarraybuffer_id_arraybuffer"><code>deserializer.transferArrayBuffer()</code></a>.</p>
567<p>If the object cannot be serialized, an exception should be thrown.</p>
568<p>This method is not present on the <code>Serializer</code> class itself but can be provided
569by subclasses.</p>
570<h5><code>serializer._setTreatArrayBufferViewsAsHostObjects(flag)</code><span><a class="mark" href="#v8_serializer_settreatarraybufferviewsashostobjects_flag" id="v8_serializer_settreatarraybufferviewsashostobjects_flag">#</a></span></h5>
571<ul>
572<li><code>flag</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <strong>Default:</strong> <code>false</code></li>
573</ul>
574<p>Indicate whether to treat <code>TypedArray</code> and <code>DataView</code> objects as
575host objects, i.e. pass them to <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
576<h4>Class: <code>v8.Deserializer</code><span><a class="mark" href="#v8_class_v8_deserializer" id="v8_class_v8_deserializer">#</a></span></h4>
577<div class="api_metadata">
578<span>Added in: v8.0.0</span>
579</div>
580<h5><code>new Deserializer(buffer)</code><span><a class="mark" href="#v8_new_deserializer_buffer" id="v8_new_deserializer_buffer">#</a></span></h5>
581<ul>
582<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> A buffer returned by
583<a href="#v8_serializer_releasebuffer"><code>serializer.releaseBuffer()</code></a>.</li>
584</ul>
585<p>Creates a new <code>Deserializer</code> object.</p>
586<h5><code>deserializer.readHeader()</code><span><a class="mark" href="#v8_deserializer_readheader" id="v8_deserializer_readheader">#</a></span></h5>
587<p>Reads and validates a header (including the format version).
588May, for example, reject an invalid or unsupported wire format. In that case,
589an <code>Error</code> is thrown.</p>
590<h5><code>deserializer.readValue()</code><span><a class="mark" href="#v8_deserializer_readvalue" id="v8_deserializer_readvalue">#</a></span></h5>
591<p>Deserializes a JavaScript value from the buffer and returns it.</p>
592<h5><code>deserializer.transferArrayBuffer(id, arrayBuffer)</code><span><a class="mark" href="#v8_deserializer_transferarraybuffer_id_arraybuffer" id="v8_deserializer_transferarraybuffer_id_arraybuffer">#</a></span></h5>
593<ul>
594<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> A 32-bit unsigned integer.</li>
595<li><code>arrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer" class="type">&#x3C;SharedArrayBuffer></a> An <code>ArrayBuffer</code> instance.</li>
596</ul>
597<p>Marks an <code>ArrayBuffer</code> as having its contents transferred out of band.
598Pass the corresponding <code>ArrayBuffer</code> in the serializing context to
599<a href="#v8_serializer_transferarraybuffer_id_arraybuffer"><code>serializer.transferArrayBuffer()</code></a> (or return the <code>id</code> from
600<a href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer"><code>serializer._getSharedArrayBufferId()</code></a> in the case of <code>SharedArrayBuffer</code>s).</p>
601<h5><code>deserializer.getWireFormatVersion()</code><span><a class="mark" href="#v8_deserializer_getwireformatversion" id="v8_deserializer_getwireformatversion">#</a></span></h5>
602<ul>
603<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
604</ul>
605<p>Reads the underlying wire format version. Likely mostly to be useful to
606legacy code reading old wire format versions. May not be called before
607<code>.readHeader()</code>.</p>
608<h5><code>deserializer.readUint32()</code><span><a class="mark" href="#v8_deserializer_readuint32" id="v8_deserializer_readuint32">#</a></span></h5>
609<ul>
610<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
611</ul>
612<p>Read a raw 32-bit unsigned integer and return it.
613For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
614<h5><code>deserializer.readUint64()</code><span><a class="mark" href="#v8_deserializer_readuint64" id="v8_deserializer_readuint64">#</a></span></h5>
615<ul>
616<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
617</ul>
618<p>Read a raw 64-bit unsigned integer and return it as an array <code>[hi, lo]</code>
619with two 32-bit unsigned integer entries.
620For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
621<h5><code>deserializer.readDouble()</code><span><a class="mark" href="#v8_deserializer_readdouble" id="v8_deserializer_readdouble">#</a></span></h5>
622<ul>
623<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
624</ul>
625<p>Read a JS <code>number</code> value.
626For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
627<h5><code>deserializer.readRawBytes(length)</code><span><a class="mark" href="#v8_deserializer_readrawbytes_length" id="v8_deserializer_readrawbytes_length">#</a></span></h5>
628<ul>
629<li><code>length</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
630<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a></li>
631</ul>
632<p>Read raw bytes from the deserializer’s internal buffer. The <code>length</code> parameter
633must correspond to the length of the buffer that was passed to
634<a href="#v8_serializer_writerawbytes_buffer"><code>serializer.writeRawBytes()</code></a>.
635For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
636<h5><code>deserializer._readHostObject()</code><span><a class="mark" href="#v8_deserializer_readhostobject" id="v8_deserializer_readhostobject">#</a></span></h5>
637<p>This method is called to read some kind of host object, i.e. an object that is
638created by native C++ bindings. If it is not possible to deserialize the data,
639a suitable exception should be thrown.</p>
640<p>This method is not present on the <code>Deserializer</code> class itself but can be
641provided by subclasses.</p>
642<h4>Class: <code>v8.DefaultSerializer</code><span><a class="mark" href="#v8_class_v8_defaultserializer" id="v8_class_v8_defaultserializer">#</a></span></h4>
643<div class="api_metadata">
644<span>Added in: v8.0.0</span>
645</div>
646<p>A subclass of <a href="#v8_class_v8_serializer"><code>Serializer</code></a> that serializes <code>TypedArray</code>
647(in particular <a href="buffer.html"><code>Buffer</code></a>) and <code>DataView</code> objects as host objects, and only
648stores the part of their underlying <code>ArrayBuffer</code>s that they are referring to.</p>
649<h4>Class: <code>v8.DefaultDeserializer</code><span><a class="mark" href="#v8_class_v8_defaultdeserializer" id="v8_class_v8_defaultdeserializer">#</a></span></h4>
650<div class="api_metadata">
651<span>Added in: v8.0.0</span>
652</div>
653<p>A subclass of <a href="#v8_class_v8_deserializer"><code>Deserializer</code></a> corresponding to the format written by
654<a href="#v8_class_v8_defaultserializer"><code>DefaultSerializer</code></a>.</p></section>
655        <!-- API END -->
656      </div>
657    </div>
658  </div>
659  <script>
660    'use strict';
661    {
662      const kCustomPreference = 'customDarkTheme';
663      const userSettings = sessionStorage.getItem(kCustomPreference);
664      const themeToggleButton = document.getElementById('theme-toggle-btn');
665      if (userSettings === null && window.matchMedia) {
666        const mq = window.matchMedia('(prefers-color-scheme: dark)');
667        if ('onchange' in mq) {
668          function mqChangeListener(e) {
669            document.body.classList.toggle('dark-mode', e.matches);
670          }
671          mq.addEventListener('change', mqChangeListener);
672          if (themeToggleButton) {
673            themeToggleButton.addEventListener('click', function() {
674              mq.removeEventListener('change', mqChangeListener);
675            }, { once: true });
676          }
677        }
678        if (mq.matches) {
679          document.body.classList.add('dark-mode');
680        }
681      } else if (userSettings === 'true') {
682        document.body.classList.add('dark-mode');
683      }
684      if (themeToggleButton) {
685        themeToggleButton.hidden = false;
686        themeToggleButton.addEventListener('click', function() {
687          sessionStorage.setItem(
688            kCustomPreference,
689            document.body.classList.toggle('dark-mode')
690          );
691        });
692      }
693    }
694  </script>
695</body>
696</html>
697