Lines Matching full:code
58 <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
92 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
147 <li><a href="#napi_set_instance_data"><code>napi_set_instance_data</code></a></li>
148 <li><a href="#napi_get_instance_data"><code>napi_get_instance_data</code></a></li>
153 <li><a href="#napi_status"><code>napi_status</code></a></li>
154 <li><a href="#napi_extended_error_info"><code>napi_extended_error_info</code></a></li>
155 <li><a href="#napi_env"><code>napi_env</code></a></li>
156 <li><span class="stability_1"><a href="#node_api_nogc_env"><code>node_api_nogc_env</code></a></span…
157 <li><a href="#napi_value"><code>napi_value</code></a></li>
158 <li><a href="#napi_threadsafe_function"><code>napi_threadsafe_function</code></a></li>
159 …i><a href="#napi_threadsafe_function_release_mode"><code>napi_threadsafe_function_release_mode</co…
160 <li><a href="#napi_threadsafe_function_call_mode"><code>napi_threadsafe_function_call_mode</code></…
163 <li><a href="#napi_handle_scope"><code>napi_handle_scope</code></a></li>
164 <li><a href="#napi_escapable_handle_scope"><code>napi_escapable_handle_scope</code></a></li>
165 <li><a href="#napi_ref"><code>napi_ref</code></a></li>
166 <li><a href="#napi_type_tag"><code>napi_type_tag</code></a></li>
167 <li><a href="#napi_async_cleanup_hook_handle"><code>napi_async_cleanup_hook_handle</code></a></li>
172 <li><a href="#napi_callback_info"><code>napi_callback_info</code></a></li>
173 <li><a href="#napi_callback"><code>napi_callback</code></a></li>
174 <li><span class="stability_1"><a href="#node_api_nogc_finalize"><code>node_api_nogc_finalize</code>…
175 <li><a href="#napi_finalize"><code>napi_finalize</code></a></li>
176 <li><a href="#napi_async_execute_callback"><code>napi_async_execute_callback</code></a></li>
177 <li><a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code></a></li>
178 <li><a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a></…
179 <li><a href="#napi_cleanup_hook"><code>napi_cleanup_hook</code></a></li>
180 <li><a href="#napi_async_cleanup_hook"><code>napi_async_cleanup_hook</code></a></li>
189 <li><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a></li>
194 <li><a href="#napi_throw"><code>napi_throw</code></a></li>
195 <li><a href="#napi_throw_error"><code>napi_throw_error</code></a></li>
196 <li><a href="#napi_throw_type_error"><code>napi_throw_type_error</code></a></li>
197 <li><a href="#napi_throw_range_error"><code>napi_throw_range_error</code></a></li>
198 <li><a href="#node_api_throw_syntax_error"><code>node_api_throw_syntax_error</code></a></li>
199 <li><a href="#napi_is_error"><code>napi_is_error</code></a></li>
200 <li><a href="#napi_create_error"><code>napi_create_error</code></a></li>
201 <li><a href="#napi_create_type_error"><code>napi_create_type_error</code></a></li>
202 <li><a href="#napi_create_range_error"><code>napi_create_range_error</code></a></li>
203 <li><a href="#node_api_create_syntax_error"><code>node_api_create_syntax_error</code></a></li>
204 <li><a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></a>…
205 <li><a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a></li>
206 <li><a href="#napi_fatal_exception"><code>napi_fatal_exception</code></a></li>
211 <li><a href="#napi_fatal_error"><code>napi_fatal_error</code></a></li>
220 <li><a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a></li>
221 <li><a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a></li>
222 <li><a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a></…
223 <li><a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>…
224 <li><a href="#napi_escape_handle"><code>napi_escape_handle</code></a></li>
229 <li><a href="#napi_create_reference"><code>napi_create_reference</code></a></li>
230 <li><a href="#napi_delete_reference"><code>napi_delete_reference</code></a></li>
231 <li><a href="#napi_reference_ref"><code>napi_reference_ref</code></a></li>
232 <li><a href="#napi_reference_unref"><code>napi_reference_unref</code></a></li>
233 <li><a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a></li>
238 <li><a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a></li>
239 <li><a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code></a></li>
240 <li><a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a></li>
241 <li><a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a></li>
252 <li><a href="#napi_key_collection_mode"><code>napi_key_collection_mode</code></a></li>
253 <li><a href="#napi_key_filter"><code>napi_key_filter</code></a></li>
254 <li><a href="#napi_key_conversion"><code>napi_key_conversion</code></a></li>
255 <li><a href="#napi_valuetype"><code>napi_valuetype</code></a></li>
256 <li><a href="#napi_typedarray_type"><code>napi_typedarray_type</code></a></li>
261 <li><a href="#napi_create_array"><code>napi_create_array</code></a></li>
262 <li><a href="#napi_create_array_with_length"><code>napi_create_array_with_length</code></a></li>
263 <li><a href="#napi_create_arraybuffer"><code>napi_create_arraybuffer</code></a></li>
264 <li><a href="#napi_create_buffer"><code>napi_create_buffer</code></a></li>
265 <li><a href="#napi_create_buffer_copy"><code>napi_create_buffer_copy</code></a></li>
266 <li><a href="#napi_create_date"><code>napi_create_date</code></a></li>
267 <li><a href="#napi_create_external"><code>napi_create_external</code></a></li>
268 <li><a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a></…
269 <li><a href="#napi_create_external_buffer"><code>napi_create_external_buffer</code></a></li>
270 <li><a href="#napi_create_object"><code>napi_create_object</code></a></li>
271 <li><a href="#napi_create_symbol"><code>napi_create_symbol</code></a></li>
272 <li><a href="#node_api_symbol_for"><code>node_api_symbol_for</code></a></li>
273 <li><a href="#napi_create_typedarray"><code>napi_create_typedarray</code></a></li>
274 <li><a href="#napi_create_dataview"><code>napi_create_dataview</code></a></li>
279 <li><a href="#napi_create_int32"><code>napi_create_int32</code></a></li>
280 <li><a href="#napi_create_uint32"><code>napi_create_uint32</code></a></li>
281 <li><a href="#napi_create_int64"><code>napi_create_int64</code></a></li>
282 <li><a href="#napi_create_double"><code>napi_create_double</code></a></li>
283 <li><a href="#napi_create_bigint_int64"><code>napi_create_bigint_int64</code></a></li>
284 <li><a href="#napi_create_bigint_uint64"><code>napi_create_bigint_uint64</code></a></li>
285 <li><a href="#napi_create_bigint_words"><code>napi_create_bigint_words</code></a></li>
286 <li><a href="#napi_create_string_latin1"><code>napi_create_string_latin1</code></a></li>
287 …><a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
288 <li><a href="#napi_create_string_utf16"><code>napi_create_string_utf16</code></a></li>
289 …"><a href="#node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</co…
290 <li><a href="#napi_create_string_utf8"><code>napi_create_string_utf8</code></a></li>
295 <li><a href="#napi_get_array_length"><code>napi_get_array_length</code></a></li>
296 <li><a href="#napi_get_arraybuffer_info"><code>napi_get_arraybuffer_info</code></a></li>
297 <li><a href="#napi_get_buffer_info"><code>napi_get_buffer_info</code></a></li>
298 <li><a href="#napi_get_prototype"><code>napi_get_prototype</code></a></li>
299 <li><a href="#napi_get_typedarray_info"><code>napi_get_typedarray_info</code></a></li>
300 <li><a href="#napi_get_dataview_info"><code>napi_get_dataview_info</code></a></li>
301 <li><a href="#napi_get_date_value"><code>napi_get_date_value</code></a></li>
302 <li><a href="#napi_get_value_bool"><code>napi_get_value_bool</code></a></li>
303 <li><a href="#napi_get_value_double"><code>napi_get_value_double</code></a></li>
304 <li><a href="#napi_get_value_bigint_int64"><code>napi_get_value_bigint_int64</code></a></li>
305 <li><a href="#napi_get_value_bigint_uint64"><code>napi_get_value_bigint_uint64</code></a></li>
306 <li><a href="#napi_get_value_bigint_words"><code>napi_get_value_bigint_words</code></a></li>
307 <li><a href="#napi_get_value_external"><code>napi_get_value_external</code></a></li>
308 <li><a href="#napi_get_value_int32"><code>napi_get_value_int32</code></a></li>
309 <li><a href="#napi_get_value_int64"><code>napi_get_value_int64</code></a></li>
310 <li><a href="#napi_get_value_string_latin1"><code>napi_get_value_string_latin1</code></a></li>
311 <li><a href="#napi_get_value_string_utf8"><code>napi_get_value_string_utf8</code></a></li>
312 <li><a href="#napi_get_value_string_utf16"><code>napi_get_value_string_utf16</code></a></li>
313 <li><a href="#napi_get_value_uint32"><code>napi_get_value_uint32</code></a></li>
318 <li><a href="#napi_get_boolean"><code>napi_get_boolean</code></a></li>
319 <li><a href="#napi_get_global"><code>napi_get_global</code></a></li>
320 <li><a href="#napi_get_null"><code>napi_get_null</code></a></li>
321 <li><a href="#napi_get_undefined"><code>napi_get_undefined</code></a></li>
328 <li><a href="#napi_coerce_to_bool"><code>napi_coerce_to_bool</code></a></li>
329 <li><a href="#napi_coerce_to_number"><code>napi_coerce_to_number</code></a></li>
330 <li><a href="#napi_coerce_to_object"><code>napi_coerce_to_object</code></a></li>
331 <li><a href="#napi_coerce_to_string"><code>napi_coerce_to_string</code></a></li>
332 <li><a href="#napi_typeof"><code>napi_typeof</code></a></li>
333 <li><a href="#napi_instanceof"><code>napi_instanceof</code></a></li>
334 <li><a href="#napi_is_array"><code>napi_is_array</code></a></li>
335 <li><a href="#napi_is_arraybuffer"><code>napi_is_arraybuffer</code></a></li>
336 <li><a href="#napi_is_buffer"><code>napi_is_buffer</code></a></li>
337 <li><a href="#napi_is_date"><code>napi_is_date</code></a></li>
338 <li><a href="#napi_is_error_1"><code>napi_is_error</code></a></li>
339 <li><a href="#napi_is_typedarray"><code>napi_is_typedarray</code></a></li>
340 <li><a href="#napi_is_dataview"><code>napi_is_dataview</code></a></li>
341 <li><a href="#napi_strict_equals"><code>napi_strict_equals</code></a></li>
342 <li><a href="#napi_detach_arraybuffer"><code>napi_detach_arraybuffer</code></a></li>
343 <li><a href="#napi_is_detached_arraybuffer"><code>napi_is_detached_arraybuffer</code></a></li>
350 <li><a href="#napi_property_attributes"><code>napi_property_attributes</code></a></li>
351 <li><a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a></li>
356 <li><a href="#napi_get_property_names"><code>napi_get_property_names</code></a></li>
357 <li><a href="#napi_get_all_property_names"><code>napi_get_all_property_names</code></a></li>
358 <li><a href="#napi_set_property"><code>napi_set_property</code></a></li>
359 <li><a href="#napi_get_property"><code>napi_get_property</code></a></li>
360 <li><a href="#napi_has_property"><code>napi_has_property</code></a></li>
361 <li><a href="#napi_delete_property"><code>napi_delete_property</code></a></li>
362 <li><a href="#napi_has_own_property"><code>napi_has_own_property</code></a></li>
363 <li><a href="#napi_set_named_property"><code>napi_set_named_property</code></a></li>
364 <li><a href="#napi_get_named_property"><code>napi_get_named_property</code></a></li>
365 <li><a href="#napi_has_named_property"><code>napi_has_named_property</code></a></li>
366 <li><a href="#napi_set_element"><code>napi_set_element</code></a></li>
367 <li><a href="#napi_get_element"><code>napi_get_element</code></a></li>
368 <li><a href="#napi_has_element"><code>napi_has_element</code></a></li>
369 <li><a href="#napi_delete_element"><code>napi_delete_element</code></a></li>
370 <li><a href="#napi_define_properties"><code>napi_define_properties</code></a></li>
371 <li><a href="#napi_object_freeze"><code>napi_object_freeze</code></a></li>
372 <li><a href="#napi_object_seal"><code>napi_object_seal</code></a></li>
379 <li><a href="#napi_call_function"><code>napi_call_function</code></a></li>
380 <li><a href="#napi_create_function"><code>napi_create_function</code></a></li>
381 <li><a href="#napi_get_cb_info"><code>napi_get_cb_info</code></a></li>
382 <li><a href="#napi_get_new_target"><code>napi_get_new_target</code></a></li>
383 <li><a href="#napi_new_instance"><code>napi_new_instance</code></a></li>
388 <li><a href="#napi_define_class"><code>napi_define_class</code></a></li>
389 <li><a href="#napi_wrap"><code>napi_wrap</code></a></li>
390 <li><a href="#napi_unwrap"><code>napi_unwrap</code></a></li>
391 <li><a href="#napi_remove_wrap"><code>napi_remove_wrap</code></a></li>
392 <li><a href="#napi_type_tag_object"><code>napi_type_tag_object</code></a></li>
393 <li><a href="#napi_check_object_type_tag"><code>napi_check_object_type_tag</code></a></li>
394 <li><a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>
396 …an class="stability_1"><a href="#node_api_post_finalizer"><code>node_api_post_finalizer</code></a>…
403 <li><a href="#napi_create_async_work"><code>napi_create_async_work</code></a></li>
404 <li><a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a></li>
405 <li><a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a></li>
406 <li><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a></li>
411 <li><a href="#napi_async_init"><code>napi_async_init</code></a></li>
412 <li><a href="#napi_async_destroy"><code>napi_async_destroy</code></a></li>
413 <li><a href="#napi_make_callback"><code>napi_make_callback</code></a></li>
414 <li><a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a></li>
415 <li><a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a></li>
420 <li><a href="#napi_get_node_version"><code>napi_get_node_version</code></a></li>
421 <li><a href="#napi_get_version"><code>napi_get_version</code></a></li>
426 <li><a href="#napi_adjust_external_memory"><code>napi_adjust_external_memory</code></a></li>
431 <li><a href="#napi_create_promise"><code>napi_create_promise</code></a></li>
432 <li><a href="#napi_resolve_deferred"><code>napi_resolve_deferred</code></a></li>
433 <li><a href="#napi_reject_deferred"><code>napi_reject_deferred</code></a></li>
434 <li><a href="#napi_is_promise"><code>napi_is_promise</code></a></li>
439 <li><a href="#napi_run_script"><code>napi_run_script</code></a></li>
444 <li><a href="#napi_get_uv_event_loop"><code>napi_get_uv_event_loop</code></a></li>
452 <li><a href="#napi_create_threadsafe_function"><code>napi_create_threadsafe_function</code></a></li>
453 <li><a href="#napi_get_threadsafe_function_context"><code>napi_get_threadsafe_function_context</cod…
454 <li><a href="#napi_call_threadsafe_function"><code>napi_call_threadsafe_function</code></a></li>
455 <li><a href="#napi_acquire_threadsafe_function"><code>napi_acquire_threadsafe_function</code></a></…
456 <li><a href="#napi_release_threadsafe_function"><code>napi_release_threadsafe_function</code></a></…
457 <li><a href="#napi_ref_threadsafe_function"><code>napi_ref_threadsafe_function</code></a></li>
458 <li><a href="#napi_unref_threadsafe_function"><code>napi_unref_threadsafe_function</code></a></li>
463 <li><a href="#node_api_get_module_file_name"><code>node_api_get_module_file_name</code></a></li>
518 <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
552 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
626 <li><a href="#napi_set_instance_data"><code>napi_set_instance_data</code></a></li>
627 <li><a href="#napi_get_instance_data"><code>napi_get_instance_data</code></a></li>
632 <li><a href="#napi_status"><code>napi_status</code></a></li>
633 <li><a href="#napi_extended_error_info"><code>napi_extended_error_info</code></a></li>
634 <li><a href="#napi_env"><code>napi_env</code></a></li>
635 <li><span class="stability_1"><a href="#node_api_nogc_env"><code>node_api_nogc_env</code></a></span…
636 <li><a href="#napi_value"><code>napi_value</code></a></li>
637 <li><a href="#napi_threadsafe_function"><code>napi_threadsafe_function</code></a></li>
638 …i><a href="#napi_threadsafe_function_release_mode"><code>napi_threadsafe_function_release_mode</co…
639 <li><a href="#napi_threadsafe_function_call_mode"><code>napi_threadsafe_function_call_mode</code></…
642 <li><a href="#napi_handle_scope"><code>napi_handle_scope</code></a></li>
643 <li><a href="#napi_escapable_handle_scope"><code>napi_escapable_handle_scope</code></a></li>
644 <li><a href="#napi_ref"><code>napi_ref</code></a></li>
645 <li><a href="#napi_type_tag"><code>napi_type_tag</code></a></li>
646 <li><a href="#napi_async_cleanup_hook_handle"><code>napi_async_cleanup_hook_handle</code></a></li>
651 <li><a href="#napi_callback_info"><code>napi_callback_info</code></a></li>
652 <li><a href="#napi_callback"><code>napi_callback</code></a></li>
653 <li><span class="stability_1"><a href="#node_api_nogc_finalize"><code>node_api_nogc_finalize</code>…
654 <li><a href="#napi_finalize"><code>napi_finalize</code></a></li>
655 <li><a href="#napi_async_execute_callback"><code>napi_async_execute_callback</code></a></li>
656 <li><a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code></a></li>
657 <li><a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a></…
658 <li><a href="#napi_cleanup_hook"><code>napi_cleanup_hook</code></a></li>
659 <li><a href="#napi_async_cleanup_hook"><code>napi_async_cleanup_hook</code></a></li>
668 <li><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a></li>
673 <li><a href="#napi_throw"><code>napi_throw</code></a></li>
674 <li><a href="#napi_throw_error"><code>napi_throw_error</code></a></li>
675 <li><a href="#napi_throw_type_error"><code>napi_throw_type_error</code></a></li>
676 <li><a href="#napi_throw_range_error"><code>napi_throw_range_error</code></a></li>
677 <li><a href="#node_api_throw_syntax_error"><code>node_api_throw_syntax_error</code></a></li>
678 <li><a href="#napi_is_error"><code>napi_is_error</code></a></li>
679 <li><a href="#napi_create_error"><code>napi_create_error</code></a></li>
680 <li><a href="#napi_create_type_error"><code>napi_create_type_error</code></a></li>
681 <li><a href="#napi_create_range_error"><code>napi_create_range_error</code></a></li>
682 <li><a href="#node_api_create_syntax_error"><code>node_api_create_syntax_error</code></a></li>
683 <li><a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></a>…
684 <li><a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a></li>
685 <li><a href="#napi_fatal_exception"><code>napi_fatal_exception</code></a></li>
690 <li><a href="#napi_fatal_error"><code>napi_fatal_error</code></a></li>
699 <li><a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a></li>
700 <li><a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a></li>
701 <li><a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a></…
702 <li><a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>…
703 <li><a href="#napi_escape_handle"><code>napi_escape_handle</code></a></li>
708 <li><a href="#napi_create_reference"><code>napi_create_reference</code></a></li>
709 <li><a href="#napi_delete_reference"><code>napi_delete_reference</code></a></li>
710 <li><a href="#napi_reference_ref"><code>napi_reference_ref</code></a></li>
711 <li><a href="#napi_reference_unref"><code>napi_reference_unref</code></a></li>
712 <li><a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a></li>
717 <li><a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a></li>
718 <li><a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code></a></li>
719 <li><a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a></li>
720 <li><a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a></li>
731 <li><a href="#napi_key_collection_mode"><code>napi_key_collection_mode</code></a></li>
732 <li><a href="#napi_key_filter"><code>napi_key_filter</code></a></li>
733 <li><a href="#napi_key_conversion"><code>napi_key_conversion</code></a></li>
734 <li><a href="#napi_valuetype"><code>napi_valuetype</code></a></li>
735 <li><a href="#napi_typedarray_type"><code>napi_typedarray_type</code></a></li>
740 <li><a href="#napi_create_array"><code>napi_create_array</code></a></li>
741 <li><a href="#napi_create_array_with_length"><code>napi_create_array_with_length</code></a></li>
742 <li><a href="#napi_create_arraybuffer"><code>napi_create_arraybuffer</code></a></li>
743 <li><a href="#napi_create_buffer"><code>napi_create_buffer</code></a></li>
744 <li><a href="#napi_create_buffer_copy"><code>napi_create_buffer_copy</code></a></li>
745 <li><a href="#napi_create_date"><code>napi_create_date</code></a></li>
746 <li><a href="#napi_create_external"><code>napi_create_external</code></a></li>
747 <li><a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a></…
748 <li><a href="#napi_create_external_buffer"><code>napi_create_external_buffer</code></a></li>
749 <li><a href="#napi_create_object"><code>napi_create_object</code></a></li>
750 <li><a href="#napi_create_symbol"><code>napi_create_symbol</code></a></li>
751 <li><a href="#node_api_symbol_for"><code>node_api_symbol_for</code></a></li>
752 <li><a href="#napi_create_typedarray"><code>napi_create_typedarray</code></a></li>
753 <li><a href="#napi_create_dataview"><code>napi_create_dataview</code></a></li>
758 <li><a href="#napi_create_int32"><code>napi_create_int32</code></a></li>
759 <li><a href="#napi_create_uint32"><code>napi_create_uint32</code></a></li>
760 <li><a href="#napi_create_int64"><code>napi_create_int64</code></a></li>
761 <li><a href="#napi_create_double"><code>napi_create_double</code></a></li>
762 <li><a href="#napi_create_bigint_int64"><code>napi_create_bigint_int64</code></a></li>
763 <li><a href="#napi_create_bigint_uint64"><code>napi_create_bigint_uint64</code></a></li>
764 <li><a href="#napi_create_bigint_words"><code>napi_create_bigint_words</code></a></li>
765 <li><a href="#napi_create_string_latin1"><code>napi_create_string_latin1</code></a></li>
766 …><a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
767 <li><a href="#napi_create_string_utf16"><code>napi_create_string_utf16</code></a></li>
768 …"><a href="#node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</co…
769 <li><a href="#napi_create_string_utf8"><code>napi_create_string_utf8</code></a></li>
774 <li><a href="#napi_get_array_length"><code>napi_get_array_length</code></a></li>
775 <li><a href="#napi_get_arraybuffer_info"><code>napi_get_arraybuffer_info</code></a></li>
776 <li><a href="#napi_get_buffer_info"><code>napi_get_buffer_info</code></a></li>
777 <li><a href="#napi_get_prototype"><code>napi_get_prototype</code></a></li>
778 <li><a href="#napi_get_typedarray_info"><code>napi_get_typedarray_info</code></a></li>
779 <li><a href="#napi_get_dataview_info"><code>napi_get_dataview_info</code></a></li>
780 <li><a href="#napi_get_date_value"><code>napi_get_date_value</code></a></li>
781 <li><a href="#napi_get_value_bool"><code>napi_get_value_bool</code></a></li>
782 <li><a href="#napi_get_value_double"><code>napi_get_value_double</code></a></li>
783 <li><a href="#napi_get_value_bigint_int64"><code>napi_get_value_bigint_int64</code></a></li>
784 <li><a href="#napi_get_value_bigint_uint64"><code>napi_get_value_bigint_uint64</code></a></li>
785 <li><a href="#napi_get_value_bigint_words"><code>napi_get_value_bigint_words</code></a></li>
786 <li><a href="#napi_get_value_external"><code>napi_get_value_external</code></a></li>
787 <li><a href="#napi_get_value_int32"><code>napi_get_value_int32</code></a></li>
788 <li><a href="#napi_get_value_int64"><code>napi_get_value_int64</code></a></li>
789 <li><a href="#napi_get_value_string_latin1"><code>napi_get_value_string_latin1</code></a></li>
790 <li><a href="#napi_get_value_string_utf8"><code>napi_get_value_string_utf8</code></a></li>
791 <li><a href="#napi_get_value_string_utf16"><code>napi_get_value_string_utf16</code></a></li>
792 <li><a href="#napi_get_value_uint32"><code>napi_get_value_uint32</code></a></li>
797 <li><a href="#napi_get_boolean"><code>napi_get_boolean</code></a></li>
798 <li><a href="#napi_get_global"><code>napi_get_global</code></a></li>
799 <li><a href="#napi_get_null"><code>napi_get_null</code></a></li>
800 <li><a href="#napi_get_undefined"><code>napi_get_undefined</code></a></li>
807 <li><a href="#napi_coerce_to_bool"><code>napi_coerce_to_bool</code></a></li>
808 <li><a href="#napi_coerce_to_number"><code>napi_coerce_to_number</code></a></li>
809 <li><a href="#napi_coerce_to_object"><code>napi_coerce_to_object</code></a></li>
810 <li><a href="#napi_coerce_to_string"><code>napi_coerce_to_string</code></a></li>
811 <li><a href="#napi_typeof"><code>napi_typeof</code></a></li>
812 <li><a href="#napi_instanceof"><code>napi_instanceof</code></a></li>
813 <li><a href="#napi_is_array"><code>napi_is_array</code></a></li>
814 <li><a href="#napi_is_arraybuffer"><code>napi_is_arraybuffer</code></a></li>
815 <li><a href="#napi_is_buffer"><code>napi_is_buffer</code></a></li>
816 <li><a href="#napi_is_date"><code>napi_is_date</code></a></li>
817 <li><a href="#napi_is_error_1"><code>napi_is_error</code></a></li>
818 <li><a href="#napi_is_typedarray"><code>napi_is_typedarray</code></a></li>
819 <li><a href="#napi_is_dataview"><code>napi_is_dataview</code></a></li>
820 <li><a href="#napi_strict_equals"><code>napi_strict_equals</code></a></li>
821 <li><a href="#napi_detach_arraybuffer"><code>napi_detach_arraybuffer</code></a></li>
822 <li><a href="#napi_is_detached_arraybuffer"><code>napi_is_detached_arraybuffer</code></a></li>
829 <li><a href="#napi_property_attributes"><code>napi_property_attributes</code></a></li>
830 <li><a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a></li>
835 <li><a href="#napi_get_property_names"><code>napi_get_property_names</code></a></li>
836 <li><a href="#napi_get_all_property_names"><code>napi_get_all_property_names</code></a></li>
837 <li><a href="#napi_set_property"><code>napi_set_property</code></a></li>
838 <li><a href="#napi_get_property"><code>napi_get_property</code></a></li>
839 <li><a href="#napi_has_property"><code>napi_has_property</code></a></li>
840 <li><a href="#napi_delete_property"><code>napi_delete_property</code></a></li>
841 <li><a href="#napi_has_own_property"><code>napi_has_own_property</code></a></li>
842 <li><a href="#napi_set_named_property"><code>napi_set_named_property</code></a></li>
843 <li><a href="#napi_get_named_property"><code>napi_get_named_property</code></a></li>
844 <li><a href="#napi_has_named_property"><code>napi_has_named_property</code></a></li>
845 <li><a href="#napi_set_element"><code>napi_set_element</code></a></li>
846 <li><a href="#napi_get_element"><code>napi_get_element</code></a></li>
847 <li><a href="#napi_has_element"><code>napi_has_element</code></a></li>
848 <li><a href="#napi_delete_element"><code>napi_delete_element</code></a></li>
849 <li><a href="#napi_define_properties"><code>napi_define_properties</code></a></li>
850 <li><a href="#napi_object_freeze"><code>napi_object_freeze</code></a></li>
851 <li><a href="#napi_object_seal"><code>napi_object_seal</code></a></li>
858 <li><a href="#napi_call_function"><code>napi_call_function</code></a></li>
859 <li><a href="#napi_create_function"><code>napi_create_function</code></a></li>
860 <li><a href="#napi_get_cb_info"><code>napi_get_cb_info</code></a></li>
861 <li><a href="#napi_get_new_target"><code>napi_get_new_target</code></a></li>
862 <li><a href="#napi_new_instance"><code>napi_new_instance</code></a></li>
867 <li><a href="#napi_define_class"><code>napi_define_class</code></a></li>
868 <li><a href="#napi_wrap"><code>napi_wrap</code></a></li>
869 <li><a href="#napi_unwrap"><code>napi_unwrap</code></a></li>
870 <li><a href="#napi_remove_wrap"><code>napi_remove_wrap</code></a></li>
871 <li><a href="#napi_type_tag_object"><code>napi_type_tag_object</code></a></li>
872 <li><a href="#napi_check_object_type_tag"><code>napi_check_object_type_tag</code></a></li>
873 <li><a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>
875 …an class="stability_1"><a href="#node_api_post_finalizer"><code>node_api_post_finalizer</code></a>…
882 <li><a href="#napi_create_async_work"><code>napi_create_async_work</code></a></li>
883 <li><a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a></li>
884 <li><a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a></li>
885 <li><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a></li>
890 <li><a href="#napi_async_init"><code>napi_async_init</code></a></li>
891 <li><a href="#napi_async_destroy"><code>napi_async_destroy</code></a></li>
892 <li><a href="#napi_make_callback"><code>napi_make_callback</code></a></li>
893 <li><a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a></li>
894 <li><a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a></li>
899 <li><a href="#napi_get_node_version"><code>napi_get_node_version</code></a></li>
900 <li><a href="#napi_get_version"><code>napi_get_version</code></a></li>
905 <li><a href="#napi_adjust_external_memory"><code>napi_adjust_external_memory</code></a></li>
910 <li><a href="#napi_create_promise"><code>napi_create_promise</code></a></li>
911 <li><a href="#napi_resolve_deferred"><code>napi_resolve_deferred</code></a></li>
912 <li><a href="#napi_reject_deferred"><code>napi_reject_deferred</code></a></li>
913 <li><a href="#napi_is_promise"><code>napi_is_promise</code></a></li>
918 <li><a href="#napi_run_script"><code>napi_run_script</code></a></li>
923 <li><a href="#napi_get_uv_event_loop"><code>napi_get_uv_event_loop</code></a></li>
931 <li><a href="#napi_create_threadsafe_function"><code>napi_create_threadsafe_function</code></a></li>
932 <li><a href="#napi_get_threadsafe_function_context"><code>napi_get_threadsafe_function_context</cod…
933 <li><a href="#napi_call_threadsafe_function"><code>napi_call_threadsafe_function</code></a></li>
934 <li><a href="#napi_acquire_threadsafe_function"><code>napi_acquire_threadsafe_function</code></a></…
935 <li><a href="#napi_release_threadsafe_function"><code>napi_release_threadsafe_function</code></a></…
936 <li><a href="#napi_ref_threadsafe_function"><code>napi_ref_threadsafe_function</code></a></li>
937 <li><a href="#napi_unref_threadsafe_function"><code>napi_unref_threadsafe_function</code></a></li>
942 <li><a href="#node_api_get_module_file_name"><code>node_api_get_module_file_name</code></a></li>
963 the native code. Instead of using the V8 or <a href="https://github.com/nodejs/nan">Native Abstract…
970 <li>All Node-API calls return a status code of type <code>napi_status</code>. This
974 <code>napi_value</code>.</li>
975 <li>In case of an error status code, additional information can be obtained
976 using <code>napi_get_last_error_info</code>. More information can be found in the error
982 …r module called <a href="https://github.com/nodejs/node-addon-api"><code>node-addon-api</code></a>.
984 with <code>node-addon-api</code> will depend on the symbols for the Node-API C-based
985 functions exported by Node.js. <code>node-addon-api</code> is a more
986 efficient way to write code that calls Node-API. Take, for example, the
987 following <code>node-addon-api</code> code. The first section shows the
988 <code>node-addon-api</code> code and the second section shows what actually gets
990 <pre><code class="language-cpp">Object obj = Object::<span class="hljs-built_in">New</span>(env);
991 …"hljs-built_in">New</span>(env, <span class="hljs-string">"bar"</span>);</code> <button class="cop…
992 <pre><code class="language-cpp">napi_status status;
1010 }</code> <button class="copy-button">copy</button></pre>
1013 <p>When using <code>node-addon-api</code> instead of the C APIs, start with the API <a href="https:…
1014 for <code>node-addon-api</code>.</p>
1017 Node-API and <code>node-addon-api</code>. Additional media resources can be found on the
1027 <pre><code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> …
1030 …/span> <span class="hljs-string"><node_object_wrap.h></span></span></code> <button class="cop…
1034 …<code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <spa…
1038 …<code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <spa…
1043 …code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span c…
1050 requires a toolchain that can compile C and C++ code into a binary. In
1060 <pre><code class="language-bash">xcode-select --install</code> <button class="copy-button">copy</bu…
1064 <pre><code class="language-bash">npm install --global windows-build-tools</code> <button class="cop…
1081 …ub.com/nodejs/node-addon-examples/tree/main/build_with_cmake"><code>build_with_cmake</code></a> is…
1105 …<a href="https://github.com/nodejs/node/blob/HEAD/src/node_api.h"><code>node_api.h</code></a> which
1107 …code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span c…
1108 <p>This will opt into the default <code>NAPI_VERSION</code> for the given release of Node.js.
1111 <pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">define</span> NAP…
1112 …include</span> <span class="hljs-string"><node_api.h></span></span></code> <button class="cop…
1116 <pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">define</span> NAP…
1117 …include</span> <span class="hljs-string"><node_api.h></span></span></code> <button class="cop…
1119 available to the module code.</p>
1122 <pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">define</span> NAP…
1124 …include</span> <span class="hljs-string"><node_api.h></span></span></code> <button class="cop…
1125 <p>where <code><FEATURE_NAME></code> is the name of an experimental feature that affects both
1186 <p>Each API documented for Node-API will have a header named <code>added in:</code>, and APIs
1187 which are stable will have the additional header <code>Node-API version:</code>.
1189 the Node-API version shown in <code>Node-API version:</code> or higher.
1191 <code>Node-API version:</code> listed or if there is no <code>Node-API version:</code> listed,
1193 <code>#define NAPI_EXPERIMENTAL</code> precedes the inclusion of <code>node_api.h</code>
1194 or <code>js_native_api.h</code>. If an API appears not to be available on
1195 a version of Node.js which is later than the one shown in <code>added in:</code> then
1198 code can be found separately in <code>js_native_api.h</code> and <code>js_native_api_types.h</code>.
1199 The APIs defined in these headers are included in <code>node_api.h</code> and
1200 <code>node_api_types.h</code>. The headers are structured in this way in order to allow
1203 <p>The Node.js-specific parts of an addon can be separated from the code that
1206 below, <code>addon.c</code> and <code>addon.h</code> refer only to <code>js_native_api.h</code>. Th…
1207 that <code>addon.c</code> can be reused to compile against either the Node.js
1209 <p><code>addon_node.c</code> is a separate file that contains the Node.js specific entry point
1210 to the addon and which instantiates the addon by calling into <code>addon.c</code> when the
1212 <pre><code class="language-c"><span class="hljs-comment">// addon.h</span>
1217 …ord">endif</span> <span class="hljs-comment">// _ADDON_H_</span></span></code> <button class="cop…
1218 <pre><code class="language-c"><span class="hljs-comment">// addon.c</span>
1265 }</code> <button class="copy-button">copy</button></pre>
1266 <pre><code class="language-c"><span class="hljs-comment">// addon_node.c</span>
1275 }</code> <button class="copy-button">copy</button></pre>
1278 of an "Agent" as a self-contained environment in which JavaScript code runs.
1297 <h4><code>napi_set_instance_data</code><span><a class="mark" href="#napi_set_instance_data" id="nap…
1302 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_instance_data…
1305 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
1307 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
1308 <li><code>[in] data</code>: The data item to make available to bindings of this instance.</li>
1309 <li><code>[in] finalize_cb</code>: The function to call when the environment is being torn
1310 down. The function receives <code>data</code> so that it might free it.
1311 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
1312 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
1315 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1316 <p>This API associates <code>data</code> with the currently running Node.js environment. <code>data…
1317 can later be retrieved using <code>napi_get_instance_data()</code>. Any existing data
1319 of a previous call to <code>napi_set_instance_data()</code> will be overwritten. If a
1320 <code>finalize_cb</code> was provided by the previous call, it will not be called.</p>
1321 <h4><code>napi_get_instance_data</code><span><a class="mark" href="#napi_get_instance_data" id="nap…
1326 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_instance_data…
1327 …<span class="hljs-type">void</span>** data)</span>;</code> <button class="copy-button">copy</butto…
1329 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
1330 <li><code>[out] data</code>: The data item that was previously associated with the currently
1331 running Node.js environment by a call to <code>napi_set_instance_data()</code>.</li>
1333 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1335 running Node.js environment via <code>napi_set_instance_data()</code>. If no data is set,
1336 the call will succeed and <code>data</code> will be set to <code>NULL</code>.</p>
1341 <h4><code>napi_status</code><span><a class="mark" href="#napi_status" id="napi_status">#</a></span>…
1346 <p>Integral status code indicating the success or failure of a Node-API call.
1348 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1373 } napi_status;</code> <button class="copy-button">copy</button></pre>
1375 it can be obtained by calling <code>napi_get_last_error_info</code>.</p>
1376 <h4><code>napi_extended_error_info</code><span><a class="mark" href="#napi_extended_error_info" id=…
1381 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1386 } napi_extended_error_info;</code> <button class="copy-button">copy</button></pre>
1388 <li><code>error_message</code>: UTF8-encoded string containing a VM-neutral description of
1390 <li><code>engine_reserved</code>: Reserved for VM-specific error details. This is currently
1392 <li><code>engine_error_code</code>: VM-specific error code. This is currently
1394 <li><code>error_code</code>: The Node-API status code that originated with the last error.</li>
1397 <h4><code>napi_env</code><span><a class="mark" href="#napi_env" id="napi_env">#</a></span><a aria-h…
1398 <p><code>napi_env</code> is used to represent a context that the underlying Node-API
1401 making Node-API calls. Specifically, the same <code>napi_env</code> that was passed in when
1403 nested Node-API calls. Caching the <code>napi_env</code> for the purpose of general reuse,
1404 and passing the <code>napi_env</code> between instances of the same addon running on
1405 …href="worker_threads.html#class-worker"><code>Worker</code></a> threads is not allowed. The <code>…
1407 … callbacks given to <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
1408 <a href="#napi_set_instance_data"><code>napi_set_instance_data</code></a>.</p>
1409 <h4><code>node_api_nogc_env</code><span><a class="mark" href="#node_api_nogc_env" id="node_api_nogc…
1411 <p>This variant of <code>napi_env</code> is passed to synchronous finalizers
1412 (<a href="#node_api_nogc_finalize"><code>node_api_nogc_finalize</code></a>). There is a subset of N…
1413 a parameter of type <code>node_api_nogc_env</code> as their first argument. These APIs do
1415 synchronous finalizers. Passing a parameter of type <code>napi_env</code> to these APIs is
1416 allowed, however, passing a parameter of type <code>node_api_nogc_env</code> to APIs that
1422 <h4><code>napi_value</code><span><a class="mark" href="#napi_value" id="napi_value">#</a></span><a …
1424 <h4><code>napi_threadsafe_function</code><span><a class="mark" href="#napi_threadsafe_function" id=…
1431 <code>napi_call_threadsafe_function()</code>.</p>
1432 <h4><code>napi_threadsafe_function_release_mode</code><span><a class="mark" href="#napi_threadsafe_…
1437 <p>A value to be given to <code>napi_release_threadsafe_function()</code> to indicate whether
1438 the thread-safe function is to be closed immediately (<code>napi_tsfn_abort</code>) or
1439 merely released (<code>napi_tsfn_release</code>) and thus available for subsequent use via
1440 <code>napi_acquire_threadsafe_function()</code> and <code>napi_call_threadsafe_function()</code>.</…
1441 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1444 } napi_threadsafe_function_release_mode;</code> <button class="copy-button">copy</button></pre>
1445 <h4><code>napi_threadsafe_function_call_mode</code><span><a class="mark" href="#napi_threadsafe_fun…
1450 <p>A value to be given to <code>napi_call_threadsafe_function()</code> to indicate whether
1453 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1456 } napi_threadsafe_function_call_mode;</code> <button class="copy-button">copy</button></pre>
1458 <h5><code>napi_handle_scope</code><span><a class="mark" href="#napi_handle_scope" id="napi_handle_s…
1464 scope. For any invocations of code outside the execution of a native method
1468 …scopes are created using <a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a>…
1469 using <a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a>. Closing the scop…
1470 that all <code>napi_value</code>s created during the lifetime of the handle scope are no
1473 <h5><code>napi_escapable_handle_scope</code><span><a class="mark" href="#napi_escapable_handle_scop…
1480 <h5><code>napi_ref</code><span><a class="mark" href="#napi_ref" id="napi_ref">#</a></span><a aria-h…
1485 <p>This is the abstraction to use to reference a <code>napi_value</code>. This allows for
1489 <h5><code>napi_type_tag</code><span><a class="mark" href="#napi_type_tag" id="napi_type_tag">#</a><…
1497 <a href="#napi_instanceof"><code>napi_instanceof</code></a>, because the latter can report a false …
1499 conjunction with <a href="#napi_wrap"><code>napi_wrap</code></a> because it ensures that the pointe…
1502 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1505 } napi_type_tag;</code> <button class="copy-button">copy</button></pre>
1506 <h5><code>napi_async_cleanup_hook_handle</code><span><a class="mark" href="#napi_async_cleanup_hook…
1510 …alue returned by <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
1511 to <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a> when t…
1514 <h5><code>napi_callback_info</code><span><a class="mark" href="#napi_callback_info" id="napi_callba…
1522 <h5><code>napi_callback</code><span><a class="mark" href="#napi_callback" id="napi_callback">#</a><…
1530 …code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1532 handle and/or callback scope inside a <code>napi_callback</code> is not necessary.</p>
1533 <h5><code>node_api_nogc_finalize</code><span><a class="mark" href="#node_api_nogc_finalize" id="nod…
1542 object's collection. Currently, <code>node_api_nogc_finalize</code> can be used for
1544 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1546 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
1550 where it cannot execute JavaScript code, only Node-APIs which accept a
1551 <code>node_api_nogc_env</code> as their first parameter may be called.
1552 <a href="#node_api_post_finalizer"><code>node_api_post_finalizer</code></a> can be used to schedule…
1555 … <a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
1556 …node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</code></a> the …
1562 <p>experimental (<code>NAPI_EXPERIMENTAL</code>):</p>
1563 <p>Only Node-API calls that accept a <code>node_api_nogc_env</code> as their first
1566 <code>NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT</code>.</p>
1569 <h5><code>napi_finalize</code><span><a class="mark" href="#napi_finalize" id="napi_finalize">#</a><…
1577 pointers can be used with <a href="#node_api_post_finalizer"><code>node_api_post_finalizer</code></…
1578 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1580 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
1584 <p>experimental (<code>NAPI_EXPERIMENTAL</code> is defined):</p>
1586 …_api_post_finalizer"><code>node_api_post_finalizer</code></a>. <a href="#node_api_nogc_finalize"><…
1588 <code>NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT</code>.</p>
1591 <h5><code>napi_async_execute_callback</code><span><a class="mark" href="#napi_async_execute_callbac…
1598 …code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1601 <code>napi_async_complete_callback</code> instead. Do not use the <code>napi_env</code> parameter as
1603 <h5><code>napi_async_complete_callback</code><span><a class="mark" href="#napi_async_complete_callb…
1610 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1612 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1615 <h5><code>napi_threadsafe_function_call_js</code><span><a class="mark" href="#napi_threadsafe_funct…
1623 necessary for a call into JavaScript, usually via <code>napi_call_function</code>, and then
1625 <p>The data arriving from the secondary thread via the queue is given in the <code>data</code>
1626 parameter and the JavaScript function to call is given in the <code>js_callback</code>
1629 sufficient to call the JavaScript function via <code>napi_call_function</code> rather than
1630 via <code>napi_make_callback</code>.</p>
1632 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1635 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1637 <li><code>[in] env</code>: The environment to use for API calls, or <code>NULL</code> if the thread…
1638 function is being torn down and <code>data</code> may need to be freed.</li>
1639 <li><code>[in] js_callback</code>: The JavaScript function to call, or <code>NULL</code> if the
1640 thread-safe function is being torn down and <code>data</code> may need to be freed. It
1641 may also be <code>NULL</code> if the thread-safe function was created without
1642 <code>js_callback</code>.</li>
1643 <li><code>[in] context</code>: The optional data with which the thread-safe function was
1645 <li><code>[in] data</code>: Data created by the secondary thread. It is the responsibility of
1647 functions) that can be passed as parameters when <code>js_callback</code> is invoked.
1653 <h5><code>napi_cleanup_hook</code><span><a class="mark" href="#napi_cleanup_hook" id="napi_cleanup_…
1658 …n pointer used with <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
1661 …code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1663 <li><code>[in] data</code>: The data that was passed to <a href="#napi_add_env_cleanup_hook"><code>…
1665 <h5><code>napi_async_cleanup_hook</code><span><a class="mark" href="#napi_async_cleanup_hook" id="n…
1669 …ointer used with <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
1672 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1673 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1675 <li><code>[in] handle</code>: The handle that must be passed to
1676 <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a> after com…
1678 <li><code>[in] data</code>: The data that was passed to <a href="#napi_add_async_cleanup_hook"><cod…
1681 end of which <code>handle</code> must be passed in a call to
1682 <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a>.</p>
1688 return type of all API functions is <code>napi_status</code>.</p>
1689 <p>The return value will be <code>napi_ok</code> if the request was successful and
1691 an exception was thrown, the <code>napi_status</code> value for the error
1693 <code>napi_pending_exception</code> will be returned.</p>
1694 <p>In cases where a return value other than <code>napi_ok</code> or
1695 <code>napi_pending_exception</code> is returned, <a href="#napi_is_exception_pending"><code>napi_is…
1698 <p>The full set of possible <code>napi_status</code> values is defined
1699 in <code>napi_api_types.h</code>.</p>
1700 <p>The <code>napi_status</code> return value provides a VM-independent representation of
1704 …ieve this information <a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a>
1705 is provided which returns a <code>napi_extended_error_info</code> structure.
1706 The format of the <code>napi_extended_error_info</code> structure is as follows:</p>
1711 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1716 };</code> <button class="copy-button">copy</button></pre>
1718 <li><code>error_message</code>: Textual representation of the error that occurred.</li>
1719 <li><code>engine_reserved</code>: Opaque handle reserved for engine use only.</li>
1720 <li><code>engine_error_code</code>: VM specific error code.</li>
1721 <li><code>error_code</code>: Node-API status code for the last error.</li>
1723 <p><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a> returns the inform…
1728 <h5><code>napi_get_last_error_info</code><span><a class="mark" href="#napi_get_last_error_info" id=…
1733 <pre><code class="language-c">napi_status
1735 …lass="hljs-type">const</span> napi_extended_error_info** result)</span>;</code> <button class="cop…
1737 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1738 <li><code>[out] result</code>: The <code>napi_extended_error_info</code> structure with more
1741 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1742 <p>This API retrieves a <code>napi_extended_error_info</code> structure with information
1744 <p>The content of the <code>napi_extended_error_info</code> returned is only valid up until
1745 a Node-API function is called on the same <code>env</code>. This includes a call to
1746 <code>napi_is_exception_pending</code> so it may often be necessary to make a copy
1748 in <code>error_message</code> points to a statically-defined string so it is safe to use
1749 that pointer if you have copied it out of the <code>error_message</code> field (which will
1759 <p>If the <code>napi_status</code> returned by a function is <code>napi_ok</code> then no
1761 <code>napi_status</code> returned is anything other than <code>napi_ok</code> or
1762 <code>napi_pending_exception</code>, in order to try to recover and continue
1763 …urning immediately, <a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a>
1767 <code>napi_status</code> of <code>napi_pending_exception</code>. However, this is not the case
1770 In that case, <code>napi_status</code> will reflect the status for the function. It
1777 code where the native method was invoked. The behavior of most Node-API calls
1779 <code>napi_pending_exception</code>, so do as little as possible and then return to
1782 where the native code can catch the exception, take the appropriate action,
1785 cases <a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></…
1787 the last JavaScript <code>Object</code> thrown. If it is determined, after
1789 it can be re-thrown it with <a href="#napi_throw"><code>napi_throw</code></a> where error is the
1791 <p>The following utility functions are also available in case native code
1792 needs to throw an exception or determine if a <code>napi_value</code> is an instance
1793 of a JavaScript <code>Error</code> object: <a href="#napi_throw_error"><code>napi_throw_error</code…
1794 …code>napi_throw_type_error</code></a>, <a href="#napi_throw_range_error"><code>napi_throw_range_er…
1796 code needs to create an <code>Error</code> object: <a href="#napi_create_error"><code>napi_create_e…
1797 …code>napi_create_type_error</code></a>, <a href="#napi_create_range_error"><code>napi_create_range…
1798 where result is the <code>napi_value</code> that refers to the newly created
1799 JavaScript <code>Error</code> object.</p>
1807 (as its good practice), the <code>throw_</code> and <code>create_</code> functions
1808 take an optional code parameter which is the string for the code
1809 to be added to the error object. If the optional parameter is <code>NULL</code>
1810 then no code will be associated with the error. If a code is provided,
1812 <pre><code class="language-text">originalName [code]</code> <button class="copy-button">copy</butto…
1813 <p>where <code>originalName</code> is the original name associated with the error
1814 and <code>code</code> is the code that was provided. For example, if the code
1815 is <code>'ERR_ERROR_1'</code> and a <code>TypeError</code> is being created the name will be:</p>
1816 <pre><code class="language-text">TypeError [ERR_ERROR_1]</code> <button class="copy-button">copy</b…
1817 <h5><code>napi_throw</code><span><a class="mark" href="#napi_throw" id="napi_throw">#</a></span><a …
1822 …code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw</spa…
1824 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1825 <li><code>[in] error</code>: The JavaScript value to be thrown.</li>
1827 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1829 <h5><code>napi_throw_error</code><span><a class="mark" href="#napi_throw_error" id="napi_throw_erro…
1834 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1835 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1836 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1838 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1839 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1840 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1842 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1843 <p>This API throws a JavaScript <code>Error</code> with the text provided.</p>
1844 <h5><code>napi_throw_type_error</code><span><a class="mark" href="#napi_throw_type_error" id="napi_…
1849 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1850 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1851 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1853 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1854 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1855 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1857 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1858 <p>This API throws a JavaScript <code>TypeError</code> with the text provided.</p>
1859 <h5><code>napi_throw_range_error</code><span><a class="mark" href="#napi_throw_range_error" id="nap…
1864 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1865 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1866 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1868 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1869 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1870 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1872 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1873 <p>This API throws a JavaScript <code>RangeError</code> with the text provided.</p>
1874 <h5><code>node_api_throw_syntax_error</code><span><a class="mark" href="#node_api_throw_syntax_erro…
1879 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">node_api_t…
1880 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1881 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1883 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1884 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1885 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1887 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1888 <p>This API throws a JavaScript <code>SyntaxError</code> with the text provided.</p>
1889 <h5><code>napi_is_error</code><span><a class="mark" href="#napi_is_error" id="napi_is_error">#</a><…
1894 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_is_er…
1896 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
1898 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1899 <li><code>[in] value</code>: The <code>napi_value</code> to be checked.</li>
1900 <li><code>[out] result</code>: Boolean value that is set to true if <code>napi_value</code> represe…
1903 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1904 <p>This API queries a <code>napi_value</code> to check if it represents an error object.</p>
1905 <h5><code>napi_create_error</code><span><a class="mark" href="#napi_create_error" id="napi_create_e…
1910 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1911 napi_value code,
1913 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1915 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1916 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1918 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1919 the message for the <code>Error</code>.</li>
1920 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1922 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1923 <p>This API returns a JavaScript <code>Error</code> with the text provided.</p>
1924 <h5><code>napi_create_type_error</code><span><a class="mark" href="#napi_create_type_error" id="nap…
1929 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1930 napi_value code,
1932 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1934 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1935 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1937 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1938 the message for the <code>Error</code>.</li>
1939 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1941 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1942 <p>This API returns a JavaScript <code>TypeError</code> with the text provided.</p>
1943 <h5><code>napi_create_range_error</code><span><a class="mark" href="#napi_create_range_error" id="n…
1948 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1949 napi_value code,
1951 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1953 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1954 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1956 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1957 the message for the <code>Error</code>.</li>
1958 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1960 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1961 <p>This API returns a JavaScript <code>RangeError</code> with the text provided.</p>
1962 <h5><code>node_api_create_syntax_error</code><span><a class="mark" href="#node_api_create_syntax_er…
1967 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">node_api_c…
1968 napi_value code,
1970 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1972 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1973 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1975 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1976 the message for the <code>Error</code>.</li>
1977 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1979 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1980 <p>This API returns a JavaScript <code>SyntaxError</code> with the text provided.</p>
1981 <h5><code>napi_get_and_clear_last_exception</code><span><a class="mark" href="#napi_get_and_clear_l…
1986 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_and_clear_las…
1987 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1989 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1990 <li><code>[out] result</code>: The exception if one is pending, <code>NULL</code> otherwise.</li>
1992 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1994 <h5><code>napi_is_exception_pending</code><span><a class="mark" href="#napi_is_exception_pending" i…
1999 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_exception_pending</…
2001 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2002 <li><code>[out] result</code>: Boolean value that is set to true if an exception is pending.</li>
2004 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2006 <h5><code>napi_fatal_exception</code><span><a class="mark" href="#napi_fatal_exception" id="napi_fa…
2011 …code class="language-c">napi_status <span class="hljs-title function_">napi_fatal_exception</span>…
2013 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2014 <li><code>[in] err</code>: The error that is passed to <code>'uncaughtException'</code>.</li>
2016 <p>Trigger an <code>'uncaughtException'</code> in JavaScript. Useful if an async
2021 <h5><code>napi_fatal_error</code><span><a class="mark" href="#napi_fatal_error" id="napi_fatal_erro…
2026 <pre><code class="language-c">NAPI_NO_RETURN <span class="hljs-type">void</span> <span class="hljs-…
2029 …<span class="hljs-type">size_t</span> message_len)</span>;</code> <button class="copy-button">copy…
2031 <li><code>[in] location</code>: Optional location at which the error occurred.</li>
2032 <li><code>[in] location_len</code>: The length of the location in bytes, or
2033 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
2034 <li><code>[in] message</code>: The message associated with the error.</li>
2035 <li><code>[in] message_len</code>: The length of the message in bytes, or <code>NAPI_AUTO_LENGTH</c…
2042 VM may be returned as <code>napi_values</code>. These handles must hold the
2043 objects 'live' until they are no longer required by the native code,
2044 otherwise the objects could be collected before the native code was
2059 <pre><code class="language-c"><span class="hljs-keyword">for</span> (<span class="hljs-type">int</s…
2066 }</code> <button class="copy-button">copy</button></pre>
2068 substantial resources. In addition, even though the native code could only
2075 …open_handle_scope"><code>napi_open_handle_scope</code></a> and <a href="#napi_close_handle_scope">…
2081 …example, adding calls to <a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a>…
2082 <a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a> would ensure that at mo…
2084 <pre><code class="language-c"><span class="hljs-keyword">for</span> (<span class="hljs-type">int</s…
2100 }</code> <button class="copy-button">copy</button></pre>
2108 <a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a> and
2109 <a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>.</p>
2110 …omote a handle is made through <a href="#napi_escape_handle"><code>napi_escape_handle</code></a> w…
2112 <h5><code>napi_open_handle_scope</code><span><a class="mark" href="#napi_open_handle_scope" id="nap…
2117 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_open_…
2118 … napi_handle_scope* result)</span>;</code> <button class="copy-button">copy</button></pre>
2120 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2121 <li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>
2123 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2125 <h5><code>napi_close_handle_scope</code><span><a class="mark" href="#napi_close_handle_scope" id="n…
2130 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_close…
2131 … napi_handle_scope scope)</span>;</code> <button class="copy-button">copy</button></pre>
2133 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2134 <li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>
2136 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2140 <h5><code>napi_open_escapable_handle_scope</code><span><a class="mark" href="#napi_open_escapable_h…
2145 <pre><code class="language-c">NAPI_EXTERN napi_status
2147 … napi_handle_scope* result)</span>;</code> <button class="copy-button">copy</button></pre>
2149 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2150 <li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>
2152 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2155 <h5><code>napi_close_escapable_handle_scope</code><span><a class="mark" href="#napi_close_escapable…
2160 <pre><code class="language-c">NAPI_EXTERN napi_status
2162 … napi_handle_scope scope)</span>;</code> <button class="copy-button">copy</button></pre>
2164 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2165 <li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>
2167 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2171 <h5><code>napi_escape_handle</code><span><a class="mark" href="#napi_escape_handle" id="napi_escape…
2176 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_escape_handle</sp…
2179 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2181 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2182 <li><code>[in] scope</code>: <code>napi_value</code> representing the current scope.</li>
2183 <li><code>[in] escapee</code>: <code>napi_value</code> representing the JavaScript <code>Object</co…
2185 <li><code>[out] result</code>: <code>napi_value</code> representing the handle to the escaped <code…
2188 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2199 would not be possible with a normal handle returned as a <code>napi_value</code> as
2213 only supported by local symbols created with the <code>napi_create_symbol</code> function
2214 or the JavaScript <code>Symbol()</code> constructor calls. Globally registered symbols
2215 created with the <code>node_api_symbol_for</code> function or JavaScript <code>Symbol.for()</code>
2218 <code>Symbol.iterator</code>. They are also never collected by the garbage collector.</p>
2220 then be modified through <a href="#napi_reference_ref"><code>napi_reference_ref</code></a> and
2221 <a href="#napi_reference_unref"><code>napi_reference_unref</code></a>. If an object is collected wh…
2223 …ed with the reference <a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a>
2224 will return <code>NULL</code> for the returned <code>napi_value</code>. An attempt to call
2225 <a href="#napi_reference_ref"><code>napi_reference_ref</code></a> for a reference whose object has …
2241 <code>napi_delete_reference</code> in addition to <code>napi_reference_unref</code> when possible.<…
2245 <p>Experimental (<code>NAPI_EXPERIMENTAL</code> is defined):</p>
2252 <h5><code>napi_create_reference</code><span><a class="mark" href="#napi_create_reference" id="napi_…
2257 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
2260 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
2262 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2263 <li><code>[in] value</code>: The <code>napi_value</code> for which a reference is being created.</l…
2264 <li><code>[in] initial_refcount</code>: Initial reference count for the new reference.</li>
2265 <li><code>[out] result</code>: <code>napi_ref</code> pointing to the new reference.</li>
2267 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2270 <h5><code>napi_delete_reference</code><span><a class="mark" href="#napi_delete_reference" id="napi_…
2275 …code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_delete_ref…
2277 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2278 <li><code>[in] ref</code>: <code>napi_ref</code> to be deleted.</li>
2280 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2283 <h5><code>napi_reference_ref</code><span><a class="mark" href="#napi_reference_ref" id="napi_refere…
2288 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_refer…
2290 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
2292 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2293 <li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be incremented.…
2294 <li><code>[out] result</code>: The new reference count.</li>
2296 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2299 <h5><code>napi_reference_unref</code><span><a class="mark" href="#napi_reference_unref" id="napi_re…
2304 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_refer…
2306 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
2308 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2309 <li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be decremented.…
2310 <li><code>[out] result</code>: The new reference count.</li>
2312 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2315 <h5><code>napi_get_reference_value</code><span><a class="mark" href="#napi_get_reference_value" id=…
2320 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_get_r…
2322 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2324 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2325 <li><code>[in] ref</code>: The <code>napi_ref</code> for which the corresponding value is
2327 <li><code>[out] result</code>: The <code>napi_value</code> referenced by the <code>napi_ref</code>.…
2329 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2330 <p>If still valid, this API returns the <code>napi_value</code> representing the
2331 JavaScript value associated with the <code>napi_ref</code>. Otherwise, result
2332 will be <code>NULL</code>.</p>
2340 <h5><code>napi_add_env_cleanup_hook</code><span><a class="mark" href="#napi_add_env_cleanup_hook" i…
2345 <pre><code class="language-c">NODE_EXTERN napi_status <span class="hljs-title function_">napi_add_e…
2347 …<span class="hljs-type">void</span>* arg)</span>;</code> <button class="copy-button">copy</button>…
2348 <p>Registers <code>fun</code> as a function to be run with the <code>arg</code> parameter once the
2351 <code>arg</code> values. In that case, it will be called multiple times as well.
2352 Providing the same <code>fun</code> and <code>arg</code> values multiple times is not allowed
2356 …e done by using <a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code><…
2359 …hronous cleanup, <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
2360 <h5><code>napi_remove_env_cleanup_hook</code><span><a class="mark" href="#napi_remove_env_cleanup_h…
2365 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_remov…
2367 …<span class="hljs-type">void</span>* arg)</span>;</code> <button class="copy-button">copy</button>…
2368 <p>Unregisters <code>fun</code> as a function to be run with the <code>arg</code> parameter once the
2372 with <code>napi_add_env_cleanup_hook</code>, otherwise the process will abort.</p>
2373 <h5><code>napi_add_async_cleanup_hook</code><span><a class="mark" href="#napi_add_async_cleanup_hoo…
2379 <td><p>Changed signature of the <code>hook</code> callback.</p></td></tr>
2386 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_add_a…
2390 …napi_async_cleanup_hook_handle* remove_handle)</span>;</code> <button class="copy-button">copy</bu…
2392 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2393 <li><code>[in] hook</code>: The function pointer to call at environment teardown.</li>
2394 <li><code>[in] arg</code>: The pointer to pass to <code>hook</code> when it gets called.</li>
2395 <li><code>[out] remove_handle</code>: Optional handle that refers to the asynchronous cleanup
2398 <p>Registers <code>hook</code>, which is a function of type <a href="#napi_async_cleanup_hook"><cod…
2399 a function to be run with the <code>remove_handle</code> and <code>arg</code> parameters once the
2401 <p>Unlike <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a>, the hook…
2402 …lly matches that of <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
2403 <p>If <code>remove_handle</code> is not <code>NULL</code>, an opaque value will be stored in it
2404 …be passed to <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code>…
2408 <h5><code>napi_remove_async_cleanup_hook</code><span><a class="mark" href="#napi_remove_async_clean…
2414 <td><p>Removed <code>env</code> parameter.</p></td></tr>
2420 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_remov…
2421 …napi_async_cleanup_hook_handle remove_handle)</span>;</code> <button class="copy-button">copy</but…
2423 <li><code>[in] remove_handle</code>: The handle to an asynchronous cleanup hook that was
2424 created with <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a>.</…
2426 <p>Unregisters the cleanup hook corresponding to <code>remove_handle</code>. This will prevent
2428 This must be called on any <code>napi_async_cleanup_hook_handle</code> value obtained
2429 from <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a>.</p>
2433 <a href="worker_threads.html#workerterminate"><code>worker.terminate()</code></a>. When the environ…
2434 registered <code>napi_finalize</code> callbacks of JavaScript objects, thread-safe
2437 <p>The invocation of <code>napi_finalize</code> callbacks is scheduled after the manually
2440 <code>napi_finalize</code> callback, addons should register a cleanup hook with
2441 <code>napi_add_env_cleanup_hook</code> and <code>napi_add_async_cleanup_hook</code> to manually
2445 except that instead of using the <code>NODE_MODULE</code> macro the following
2447 <pre><code class="language-c">NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)</code> <button class="copy-bu…
2448 <p>The next difference is the signature for the <code>Init</code> method. For a Node-API
2450 …code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class="hljs…
2451 <p>The return value from <code>Init</code> is treated as the <code>exports</code> object for the mo…
2452 The <code>Init</code> method is passed an empty object via the <code>exports</code> parameter as a
2453 convenience. If <code>Init</code> returns <code>NULL</code>, the parameter passed as <code>exports<…
2454 exported by the module. Node-API modules cannot modify the <code>module</code> object but
2455 can specify anything as the <code>exports</code> property of the module.</p>
2456 <p>To add the method <code>hello</code> as a function so that it can be called as a method
2458 <pre><code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class=…
2473 }</code> <button class="copy-button">copy</button></pre>
2474 <p>To set a function to be returned by the <code>require()</code> for the addon:</p>
2475 <pre><code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class=…
2481 }</code> <button class="copy-button">copy</button></pre>
2484 <pre><code class="language-c"><span class="hljs-comment">// <span class="hljs-doctag">NOTE:</span> …
2505 }</code> <button class="copy-button">copy</button></pre>
2506 <p>You can also use the <code>NAPI_MODULE_INIT</code> macro, which acts as a shorthand
2507 for <code>NAPI_MODULE</code> and defining an <code>Init</code> function:</p>
2508 <pre><code class="language-c">NAPI_MODULE_INIT(<span class="hljs-comment">/* napi_env env, napi_val…
2519 }</code> <button class="copy-button">copy</button></pre>
2520 <p>The parameters <code>env</code> and <code>exports</code> are provided to the body of the
2521 <code>NAPI_MODULE_INIT</code> macro.</p>
2525 <p>The variables <code>env</code> and <code>exports</code> will be available inside the function bo…
2540 <li>Get global instances including <code>undefined</code> and <code>null</code></li>
2542 <p>Node-API values are represented by the type <code>napi_value</code>.
2543 Any Node-API call that requires a JavaScript value takes in a <code>napi_value</code>.
2544 In some cases, the API does check the type of the <code>napi_value</code> up-front.
2546 the <code>napi_value</code> in question is of the JavaScript type expected by the API.</p>
2548 <h5><code>napi_key_collection_mode</code><span><a class="mark" href="#napi_key_collection_mode" id=…
2553 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2556 } napi_key_collection_mode;</code> <button class="copy-button">copy</button></pre>
2557 <p>Describes the <code>Keys/Properties</code> filter enums:</p>
2558 <p><code>napi_key_collection_mode</code> limits the range of collected properties.</p>
2559 <p><code>napi_key_own_only</code> limits the collected properties to the given
2560 object only. <code>napi_key_include_prototypes</code> will include all keys
2562 <h5><code>napi_key_filter</code><span><a class="mark" href="#napi_key_filter" id="napi_key_filter">…
2567 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2574 } napi_key_filter;</code> <button class="copy-button">copy</button></pre>
2576 <h5><code>napi_key_conversion</code><span><a class="mark" href="#napi_key_conversion" id="napi_key_…
2581 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2584 } napi_key_conversion;</code> <button class="copy-button">copy</button></pre>
2585 <p><code>napi_key_numbers_to_strings</code> will convert integer indices to
2586 strings. <code>napi_key_keep_numbers</code> will return numbers for integer
2588 <h5><code>napi_valuetype</code><span><a class="mark" href="#napi_valuetype" id="napi_valuetype">#</…
2589 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2601 } napi_valuetype;</code> <button class="copy-button">copy</button></pre>
2602 <p>Describes the type of a <code>napi_value</code>. This generally corresponds to the types
2604 In addition to types in that section, <code>napi_valuetype</code> can also represent
2605 <code>Function</code>s and <code>Object</code>s with external data.</p>
2606 <p>A JavaScript value of type <code>napi_external</code> appears in JavaScript as a plain
2608 <h5><code>napi_typedarray_type</code><span><a class="mark" href="#napi_typedarray_type" id="napi_ty…
2609 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2621 } napi_typedarray_type;</code> <button class="copy-button">copy</button></pre>
2622 <p>This represents the underlying binary scalar datatype of the <code>TypedArray</code>.
2626 <h5><code>napi_create_array</code><span><a class="mark" href="#napi_create_array" id="napi_create_a…
2631 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_array</span><sp…
2633 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
2634 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</cod…
2636 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2637 <p>This API returns a Node-API value corresponding to a JavaScript <code>Array</code> type.
2640 <h5><code>napi_create_array_with_length</code><span><a class="mark" href="#napi_create_array_with_l…
2645 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_array_with…
2647 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2649 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2650 <li><code>[in] length</code>: The initial length of the <code>Array</code>.</li>
2651 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</cod…
2653 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2654 <p>This API returns a Node-API value corresponding to a JavaScript <code>Array</code> type.
2655 The <code>Array</code>'s length property is set to the passed-in length parameter.
2660 <a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a>.</p>
2663 <h5><code>napi_create_arraybuffer</code><span><a class="mark" href="#napi_create_arraybuffer" id="n…
2668 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_arraybuffe…
2671 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2673 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2674 <li><code>[in] length</code>: The length in bytes of the array buffer to create.</li>
2675 <li><code>[out] data</code>: Pointer to the underlying byte buffer of the <code>ArrayBuffer</code>.
2676 <code>data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2677 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffe…
2679 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2680 <p>This API returns a Node-API value corresponding to a JavaScript <code>ArrayBuffer</code>.
2681 <code>ArrayBuffer</code>s are used to represent fixed-length binary data buffers. They are
2682 normally used as a backing-buffer for <code>TypedArray</code> objects.
2683 The <code>ArrayBuffer</code> allocated will have an underlying byte buffer whose size is
2684 determined by the <code>length</code> parameter that's passed in.
2687 written to directly from native code. To write to this buffer from JavaScript,
2688 a typed array or <code>DataView</code> object would need to be created.</p>
2689 <p>JavaScript <code>ArrayBuffer</code> objects are described in
2691 <h5><code>napi_create_buffer</code><span><a class="mark" href="#napi_create_buffer" id="napi_create…
2696 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_buffer</sp…
2699 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2701 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2702 <li><code>[in] size</code>: Size in bytes of the underlying buffer.</li>
2703 <li><code>[out] data</code>: Raw pointer to the underlying buffer.
2704 <code>data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2705 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2707 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2708 <p>This API allocates a <code>node::Buffer</code> object. While this is still a
2709 fully-supported data structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2710 <h5><code>napi_create_buffer_copy</code><span><a class="mark" href="#napi_create_buffer_copy" id="n…
2715 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_buffer_cop…
2719 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2721 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2722 <li><code>[in] size</code>: Size in bytes of the input buffer (should be the same as the size
2724 <li><code>[in] data</code>: Raw pointer to the underlying buffer to copy from.</li>
2725 <li><code>[out] result_data</code>: Pointer to the new <code>Buffer</code>'s underlying data buffer.
2726 <code>result_data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2727 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2729 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2730 <p>This API allocates a <code>node::Buffer</code> object and initializes it with data copied
2732 structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2733 <h5><code>napi_create_date</code><span><a class="mark" href="#napi_create_date" id="napi_create_dat…
2738 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_date</span…
2740 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2742 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2743 <li><code>[in] time</code>: ECMAScript time value in milliseconds since 01 January, 1970 UTC.</li>
2744 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Date</code…
2746 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2749 <p>This API allocates a JavaScript <code>Date</code> object.</p>
2750 <p>JavaScript <code>Date</code> objects are described in
2752 <h5><code>napi_create_external</code><span><a class="mark" href="#napi_create_external" id="napi_cr…
2757 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_external</…
2761 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2763 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2764 <li><code>[in] data</code>: Raw pointer to the external data.</li>
2765 <li><code>[in] finalize_cb</code>: Optional callback to call when the external value is being
2766 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2767 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2769 <li><code>[out] result</code>: A <code>napi_value</code> representing an external value.</li>
2771 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2773 is used to pass external data through JavaScript code, so it can be retrieved
2774 later by native code using <a href="#napi_get_value_external"><code>napi_get_value_external</code><…
2775 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2778 properties. It is considered a distinct value type: calling <code>napi_typeof()</code> with
2779 an external value yields <code>napi_external</code>.</p>
2780 <h5><code>napi_create_external_arraybuffer</code><span><a class="mark" href="#napi_create_external_…
2785 <pre><code class="language-c">napi_status
2791 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2793 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2794 <li><code>[in] external_data</code>: Pointer to the underlying byte buffer of the
2795 <code>ArrayBuffer</code>.</li>
2796 <li><code>[in] byte_length</code>: The length in bytes of the underlying buffer.</li>
2797 <li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is b…
2798 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2799 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2801 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffe…
2803 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2806 <code>napi_no_external_buffers_allowed</code> to indicate that external
2811 you may define <code>NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED</code> in your addon before
2815 <p>This API returns a Node-API value corresponding to a JavaScript <code>ArrayBuffer</code>.
2816 The underlying byte buffer of the <code>ArrayBuffer</code> is externally allocated and
2819 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2821 <p>JavaScript <code>ArrayBuffer</code>s are described in
2823 <h5><code>napi_create_external_buffer</code><span><a class="mark" href="#napi_create_external_buffe…
2828 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_external_b…
2833 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2835 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2836 <li><code>[in] length</code>: Size in bytes of the input buffer (should be the same as the
2838 <li><code>[in] data</code>: Raw pointer to the underlying buffer to expose to JavaScript.</li>
2839 <li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is b…
2840 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2841 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2843 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2845 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2848 <code>napi_no_external_buffers_allowed</code> to indicate that external
2853 you may define <code>NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED</code> in your addon before
2857 <p>This API allocates a <code>node::Buffer</code> object and initializes it with data
2859 structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2860 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2862 <p>For Node.js >=4 <code>Buffers</code> are <code>Uint8Array</code>s.</p>
2863 <h5><code>napi_create_object</code><span><a class="mark" href="#napi_create_object" id="napi_create…
2868 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_object</span><s…
2870 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2871 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Object</co…
2873 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2874 <p>This API allocates a default JavaScript <code>Object</code>.
2875 It is the equivalent of doing <code>new Object()</code> in JavaScript.</p>
2876 <p>The JavaScript <code>Object</code> type is described in <a href="https://tc39.github.io/ecma262/…
2878 <h5><code>napi_create_symbol</code><span><a class="mark" href="#napi_create_symbol" id="napi_create…
2883 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_symbol</sp…
2885 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2887 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2888 <li><code>[in] description</code>: Optional <code>napi_value</code> which refers to a JavaScript
2889 <code>string</code> to be set as the description for the symbol.</li>
2890 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>symbol</co…
2892 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2893 <p>This API creates a JavaScript <code>symbol</code> value from a UTF8-encoded C string.</p>
2894 <p>The JavaScript <code>symbol</code> type is described in <a href="https://tc39.github.io/ecma262/…
2896 <h5><code>node_api_symbol_for</code><span><a class="mark" href="#node_api_symbol_for" id="node_api_…
2901 <pre><code class="language-c">napi_status <span class="hljs-title function_">node_api_symbol_for</s…
2904 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2906 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2907 <li><code>[in] utf8description</code>: UTF-8 C string representing the text to be used as the
2909 <li><code>[in] length</code>: The length of the description string in bytes, or
2910 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
2911 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>symbol</co…
2913 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2917 <p>The JavaScript <code>symbol</code> type is described in <a href="https://tc39.github.io/ecma262/…
2919 <h5><code>napi_create_typedarray</code><span><a class="mark" href="#napi_create_typedarray" id="nap…
2924 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_typedarray…
2929 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2931 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2932 <li><code>[in] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</li>
2933 <li><code>[in] length</code>: Number of elements in the <code>TypedArray</code>.</li>
2934 <li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the typed array.</li>
2935 <li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to
2936 start projecting the <code>TypedArray</code>.</li>
2937 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>TypedArray…
2939 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2940 <p>This API creates a JavaScript <code>TypedArray</code> object over an existing
2941 <code>ArrayBuffer</code>. <code>TypedArray</code> objects provide an array-like view over an
2944 <p>It's required that <code>(length * size_of_element) + byte_offset</code> should
2945 be <= the size in bytes of the array passed in. If not, a <code>RangeError</code> exception
2947 <p>JavaScript <code>TypedArray</code> objects are described in
2949 <h5><code>napi_create_dataview</code><span><a class="mark" href="#napi_create_dataview" id="napi_cr…
2954 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_dataview</…
2958 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2960 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2961 <li><code>[in] length</code>: Number of elements in the <code>DataView</code>.</li>
2962 <li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.</…
2963 <li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to
2964 start projecting the <code>DataView</code>.</li>
2965 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>DataView</…
2967 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2968 <p>This API creates a JavaScript <code>DataView</code> object over an existing <code>ArrayBuffer</c…
2969 <code>DataView</code> objects provide an array-like view over an underlying data buffer,
2970 but one which allows items of different size and type in the <code>ArrayBuffer</code>.</p>
2971 <p>It is required that <code>byte_length + byte_offset</code> is less than or equal to the
2972 size in bytes of the array passed in. If not, a <code>RangeError</code> exception is
2974 <p>JavaScript <code>DataView</code> objects are described in
2977 <h5><code>napi_create_int32</code><span><a class="mark" href="#napi_create_int32" id="napi_create_i…
2982 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_int32</span><sp…
2984 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2985 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
2986 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
2988 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2989 <p>This API is used to convert from the C <code>int32_t</code> type to the JavaScript
2990 <code>number</code> type.</p>
2991 <p>The JavaScript <code>number</code> type is described in
2993 <h5><code>napi_create_uint32</code><span><a class="mark" href="#napi_create_uint32" id="napi_create…
2998 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_uint32</span><s…
3000 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3001 <li><code>[in] value</code>: Unsigned integer value to be represented in JavaScript.</li>
3002 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
3004 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3005 <p>This API is used to convert from the C <code>uint32_t</code> type to the JavaScript
3006 <code>number</code> type.</p>
3007 <p>The JavaScript <code>number</code> type is described in
3009 <h5><code>napi_create_int64</code><span><a class="mark" href="#napi_create_int64" id="napi_create_i…
3014 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_int64</span><sp…
3016 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3017 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
3018 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
3020 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3021 <p>This API is used to convert from the C <code>int64_t</code> type to the JavaScript
3022 <code>number</code> type.</p>
3023 <p>The JavaScript <code>number</code> type is described in <a href="https://tc39.github.io/ecma262/…
3024 of the ECMAScript Language Specification. Note the complete range of <code>int64_t</code>
3026 …b.io/ecma262/#sec-number.min_safe_integer"><code>Number.MIN_SAFE_INTEGER</code></a> <code>-(2**53 …
3027 …ub.io/ecma262/#sec-number.max_safe_integer"><code>Number.MAX_SAFE_INTEGER</code></a> <code>(2**53 …
3028 <h5><code>napi_create_double</code><span><a class="mark" href="#napi_create_double" id="napi_create…
3033 …code class="language-c">napi_status <span class="hljs-title function_">napi_create_double</span><s…
3035 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3036 <li><code>[in] value</code>: Double-precision value to be represented in JavaScript.</li>
3037 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
3039 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3040 <p>This API is used to convert from the C <code>double</code> type to the JavaScript
3041 <code>number</code> type.</p>
3042 <p>The JavaScript <code>number</code> type is described in
3044 <h5><code>napi_create_bigint_int64</code><span><a class="mark" href="#napi_create_bigint_int64" id=…
3049 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_int…
3051 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3053 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3054 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
3055 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3057 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3058 <p>This API converts the C <code>int64_t</code> type to the JavaScript <code>BigInt</code> type.</p>
3059 <h5><code>napi_create_bigint_uint64</code><span><a class="mark" href="#napi_create_bigint_uint64" i…
3064 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_uin…
3066 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3068 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3069 <li><code>[in] value</code>: Unsigned integer value to be represented in JavaScript.</li>
3070 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3072 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3073 <p>This API converts the C <code>uint64_t</code> type to the JavaScript <code>BigInt</code> type.</…
3074 <h5><code>napi_create_bigint_words</code><span><a class="mark" href="#napi_create_bigint_words" id=…
3079 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_wor…
3083 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3085 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3086 <li><code>[in] sign_bit</code>: Determines if the resulting <code>BigInt</code> will be positive or
3088 <li><code>[in] word_count</code>: The length of the <code>words</code> array.</li>
3089 <li><code>[in] words</code>: An array of <code>uint64_t</code> little-endian 64-bit words.</li>
3090 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3092 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3093 <p>This API converts an array of unsigned 64-bit words into a single <code>BigInt</code>
3095 <p>The resulting <code>BigInt</code> is calculated as: (–1)<sup><code>sign_bit</code></sup> (<code>…
3096 × (2<sup>64</sup>)<sup>0</sup> + <code>words[1]</code> × (2<sup>64</sup>)<sup>1</sup> + …)</p>
3097 <h5><code>napi_create_string_latin1</code><span><a class="mark" href="#napi_create_string_latin1" i…
3102 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_lat…
3105 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3107 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3108 <li><code>[in] str</code>: Character buffer representing an ISO-8859-1-encoded string.</li>
3109 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3111 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3113 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3114 <p>This API creates a JavaScript <code>string</code> value from an ISO-8859-1-encoded C
3116 <p>The JavaScript <code>string</code> type is described in
3118 <h5><code>node_api_create_external_string_latin1</code><span><a class="mark" href="#node_api_create…
3123 <pre><code class="language-c">napi_status
3130 …<span class="hljs-type">bool</span>* copied)</span>;</code> <button class="copy-button">copy</butt…
3132 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3133 <li><code>[in] str</code>: Character buffer representing an ISO-8859-1-encoded string.</li>
3134 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3136 <li><code>[in] finalize_callback</code>: The function to call when the string is being
3139 <li><code>[in] env</code>: The environment in which the add-on is running. This value
3142 <li><code>[in] data</code>: This is the value <code>str</code> as a <code>void*</code> pointer.</li>
3143 <li><code>[in] finalize_hint</code>: This is the value <code>finalize_hint</code> that was given
3145 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.
3151 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
3153 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3154 <li><code>[out] copied</code>: Whether the string was copied. If it was, the finalizer will
3155 already have been invoked to destroy <code>str</code>.</li>
3157 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3158 <p>This API creates a JavaScript <code>string</code> value from an ISO-8859-1-encoded C
3161 <p>The JavaScript <code>string</code> type is described in
3163 <h5><code>napi_create_string_utf16</code><span><a class="mark" href="#napi_create_string_utf16" id=…
3168 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_utf…
3171 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3173 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3174 <li><code>[in] str</code>: Character buffer representing a UTF16-LE-encoded string.</li>
3175 <li><code>[in] length</code>: The length of the string in two-byte code units, or
3176 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
3177 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3179 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3180 <p>This API creates a JavaScript <code>string</code> value from a UTF16-LE-encoded C string.
3182 <p>The JavaScript <code>string</code> type is described in
3184 <h5><code>node_api_create_external_string_utf16</code><span><a class="mark" href="#node_api_create_…
3189 <pre><code class="language-c">napi_status
3196 …<span class="hljs-type">bool</span>* copied)</span>;</code> <button class="copy-button">copy</butt…
3198 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3199 <li><code>[in] str</code>: Character buffer representing a UTF16-LE-encoded string.</li>
3200 <li><code>[in] length</code>: The length of the string in two-byte code units, or
3201 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
3202 <li><code>[in] finalize_callback</code>: The function to call when the string is being
3205 <li><code>[in] env</code>: The environment in which the add-on is running. This value
3208 <li><code>[in] data</code>: This is the value <code>str</code> as a <code>void*</code> pointer.</li>
3209 <li><code>[in] finalize_hint</code>: This is the value <code>finalize_hint</code> that was given
3211 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.
3217 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
3219 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3220 <li><code>[out] copied</code>: Whether the string was copied. If it was, the finalizer will
3221 already have been invoked to destroy <code>str</code>.</li>
3223 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3224 <p>This API creates a JavaScript <code>string</code> value from a UTF16-LE-encoded C string.
3227 <p>The JavaScript <code>string</code> type is described in
3229 <h5><code>napi_create_string_utf8</code><span><a class="mark" href="#napi_create_string_utf8" id="n…
3234 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_utf…
3237 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3239 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3240 <li><code>[in] str</code>: Character buffer representing a UTF8-encoded string.</li>
3241 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3243 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3245 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3246 <p>This API creates a JavaScript <code>string</code> value from a UTF8-encoded C string.
3248 <p>The JavaScript <code>string</code> type is described in
3251 <h5><code>napi_get_array_length</code><span><a class="mark" href="#napi_get_array_length" id="napi_…
3256 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_array_length<…
3258 …<span class="hljs-type">uint32_t</span>* result)</span></code> <button class="copy-button">copy</b…
3260 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3261 <li><code>[in] value</code>: <code>napi_value</code> representing the JavaScript <code>Array</code>…
3263 <li><code>[out] result</code>: <code>uint32</code> representing length of the array.</li>
3265 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3267 <p><code>Array</code> length is described in <a href="https://tc39.github.io/ecma262/#sec-propertie…
3269 <h5><code>napi_get_arraybuffer_info</code><span><a class="mark" href="#napi_get_arraybuffer_info" i…
3274 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_arraybuffer_i…
3277 …<span class="hljs-type">size_t</span>* byte_length)</span></code> <button class="copy-button">copy…
3279 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3280 <li><code>[in] arraybuffer</code>: <code>napi_value</code> representing the <code>ArrayBuffer</code…
3281 <li><code>[out] data</code>: The underlying data buffer of the <code>ArrayBuffer</code>. If byte_le…
3282 is <code>0</code>, this may be <code>NULL</code> or any other pointer value.</li>
3283 <li><code>[out] byte_length</code>: Length in bytes of the underlying data buffer.</li>
3285 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3286 <p>This API is used to retrieve the underlying data buffer of an <code>ArrayBuffer</code> and
3289 buffer is managed by the <code>ArrayBuffer</code> even after it's returned. A
3291 <a href="#napi_create_reference"><code>napi_create_reference</code></a>, which can be used to guara…
3292 lifetime of the <code>ArrayBuffer</code>. It's also safe to use the returned data buffer
3295 <h5><code>napi_get_buffer_info</code><span><a class="mark" href="#napi_get_buffer_info" id="napi_ge…
3300 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_buffer_info</…
3303 …<span class="hljs-type">size_t</span>* length)</span></code> <button class="copy-button">copy</but…
3305 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3306 <li><code>[in] value</code>: <code>napi_value</code> representing the <code>node::Buffer</code> or …
3308 <li><code>[out] data</code>: The underlying data buffer of the <code>node::Buffer</code> or
3309 <code>Uint8Array</code>. If length is <code>0</code>, this may be <code>NULL</code> or any other po…
3310 <li><code>[out] length</code>: Length in bytes of the underlying data buffer.</li>
3312 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3313 <p>This method returns the identical <code>data</code> and <code>byte_length</code> as
3314 … href="#napi_get_typedarray_info"><code>napi_get_typedarray_info</code></a>. And <code>napi_get_ty…
3315 <code>node::Buffer</code> (a Uint8Array) as the value too.</p>
3316 <p>This API is used to retrieve the underlying data buffer of a <code>node::Buffer</code>
3320 <h5><code>napi_get_prototype</code><span><a class="mark" href="#napi_get_prototype" id="napi_get_pr…
3325 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_prototype</sp…
3327 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3329 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3330 <li><code>[in] object</code>: <code>napi_value</code> representing JavaScript <code>Object</code> w…
3331 to return. This returns the equivalent of <code>Object.getPrototypeOf</code> (which is
3332 not the same as the function's <code>prototype</code> property).</li>
3333 <li><code>[out] result</code>: <code>napi_value</code> representing prototype of the given object.<…
3335 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3336 <h5><code>napi_get_typedarray_info</code><span><a class="mark" href="#napi_get_typedarray_info" id=…
3341 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_typedarray_in…
3347 …<span class="hljs-type">size_t</span>* byte_offset)</span></code> <button class="copy-button">copy…
3349 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3350 <li><code>[in] typedarray</code>: <code>napi_value</code> representing the <code>TypedArray</code> …
3352 <li><code>[out] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</l…
3353 <li><code>[out] length</code>: The number of elements in the <code>TypedArray</code>.</li>
3354 <li><code>[out] data</code>: The data buffer underlying the <code>TypedArray</code> adjusted by
3355 the <code>byte_offset</code> value so that it points to the first element in the
3356 <code>TypedArray</code>. If the length of the array is <code>0</code>, this may be <code>NULL</code…
3358 <li><code>[out] arraybuffer</code>: The <code>ArrayBuffer</code> underlying the <code>TypedArray</c…
3359 <li><code>[out] byte_offset</code>: The byte offset within the underlying native array
3363 <code>data - byte_offset</code>.</li>
3365 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3367 <p>Any of the out parameters may be <code>NULL</code> if that property is unneeded.</p>
3370 <h5><code>napi_get_dataview_info</code><span><a class="mark" href="#napi_get_dataview_info" id="nap…
3375 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_dataview_info…
3380 …<span class="hljs-type">size_t</span>* byte_offset)</span></code> <button class="copy-button">copy…
3382 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3383 <li><code>[in] dataview</code>: <code>napi_value</code> representing the <code>DataView</code> whose
3385 <li><code>[out] byte_length</code>: Number of bytes in the <code>DataView</code>.</li>
3386 <li><code>[out] data</code>: The data buffer underlying the <code>DataView</code>.
3387 If byte_length is <code>0</code>, this may be <code>NULL</code> or any other pointer value.</li>
3388 <li><code>[out] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.<…
3389 <li><code>[out] byte_offset</code>: The byte offset within the data buffer from which
3390 to start projecting the <code>DataView</code>.</li>
3392 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3393 <p>Any of the out parameters may be <code>NULL</code> if that property is unneeded.</p>
3394 <p>This API returns various properties of a <code>DataView</code>.</p>
3395 <h5><code>napi_get_date_value</code><span><a class="mark" href="#napi_get_date_value" id="napi_get_…
3400 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_date_value</s…
3402 …<span class="hljs-type">double</span>* result)</span></code> <button class="copy-button">copy</but…
3404 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3405 <li><code>[in] value</code>: <code>napi_value</code> representing a JavaScript <code>Date</code>.</…
3406 <li><code>[out] result</code>: Time value as a <code>double</code> represented as milliseconds since
3411 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-date <code>napi_value</code> is pass…
3412 in it returns <code>napi_date_expected</code>.</p>
3414 <code>Date</code>.</p>
3415 <h5><code>napi_get_value_bool</code><span><a class="mark" href="#napi_get_value_bool" id="napi_get_…
3420 …code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bool</span><…
3422 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3423 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code>.<…
3424 <li><code>[out] result</code>: C boolean primitive equivalent of the given JavaScript
3425 <code>Boolean</code>.</li>
3427 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-boolean <code>napi_value</code> is
3428 passed in it returns <code>napi_boolean_expected</code>.</p>
3430 <code>Boolean</code>.</p>
3431 <h5><code>napi_get_value_double</code><span><a class="mark" href="#napi_get_value_double" id="napi_…
3436 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_double<…
3438 …<span class="hljs-type">double</span>* result)</span></code> <button class="copy-button">copy</but…
3440 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3441 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3442 <li><code>[out] result</code>: C double primitive equivalent of the given JavaScript
3443 <code>number</code>.</li>
3445 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code> is pa…
3446 in it returns <code>napi_number_expected</code>.</p>
3448 <code>number</code>.</p>
3449 <h5><code>napi_get_value_bigint_int64</code><span><a class="mark" href="#napi_get_value_bigint_int6…
3454 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3457 …<span class="hljs-type">bool</span>* lossless)</span>;</code> <button class="copy-button">copy</bu…
3459 <li><code>[in] env</code>: The environment that the API is invoked under</li>
3460 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3461 <li><code>[out] result</code>: C <code>int64_t</code> primitive equivalent of the given JavaScript
3462 <code>BigInt</code>.</li>
3463 <li><code>[out] lossless</code>: Indicates whether the <code>BigInt</code> value was converted
3466 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>BigInt</code> is passed in it
3467 returns <code>napi_bigint_expected</code>.</p>
3468 <p>This API returns the C <code>int64_t</code> primitive equivalent of the given JavaScript
3469 <code>BigInt</code>. If needed it will truncate the value, setting <code>lossless</code> to <code>f…
3470 <h5><code>napi_get_value_bigint_uint64</code><span><a class="mark" href="#napi_get_value_bigint_uin…
3475 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3478 …<span class="hljs-type">bool</span>* lossless)</span>;</code> <button class="copy-button">copy</bu…
3480 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3481 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3482 <li><code>[out] result</code>: C <code>uint64_t</code> primitive equivalent of the given JavaScript
3483 <code>BigInt</code>.</li>
3484 <li><code>[out] lossless</code>: Indicates whether the <code>BigInt</code> value was converted
3487 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>BigInt</code> is passed in it
3488 returns <code>napi_bigint_expected</code>.</p>
3489 <p>This API returns the C <code>uint64_t</code> primitive equivalent of the given JavaScript
3490 <code>BigInt</code>. If needed it will truncate the value, setting <code>lossless</code> to <code>f…
3491 <h5><code>napi_get_value_bigint_words</code><span><a class="mark" href="#napi_get_value_bigint_word…
3496 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3500 …<span class="hljs-type">uint64_t</span>* words)</span>;</code> <button class="copy-button">copy</b…
3502 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3503 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3504 <li><code>[out] sign_bit</code>: Integer representing if the JavaScript <code>BigInt</code> is posi…
3506 <li><code>[in/out] word_count</code>: Must be initialized to the length of the <code>words</code>
3508 would be needed to store this <code>BigInt</code>.</li>
3509 <li><code>[out] words</code>: Pointer to a pre-allocated 64-bit word array.</li>
3511 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3512 <p>This API converts a single <code>BigInt</code> value into a sign bit, 64-bit little-endian
3513 array, and the number of elements in the array. <code>sign_bit</code> and <code>words</code> may be
3514 both set to <code>NULL</code>, in order to get only <code>word_count</code>.</p>
3515 <h5><code>napi_get_value_external</code><span><a class="mark" href="#napi_get_value_external" id="n…
3520 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_externa…
3522 …<span class="hljs-type">void</span>** result)</span></code> <button class="copy-button">copy</butt…
3524 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3525 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript external value.</li>
3526 <li><code>[out] result</code>: Pointer to the data wrapped by the JavaScript external value.</li>
3528 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-external <code>napi_value</code> is
3529 passed in it returns <code>napi_invalid_arg</code>.</p>
3531 <code>napi_create_external()</code>.</p>
3532 <h5><code>napi_get_value_int32</code><span><a class="mark" href="#napi_get_value_int32" id="napi_ge…
3537 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_int32</…
3539 …<span class="hljs-type">int32_t</span>* result)</span></code> <button class="copy-button">copy</bu…
3541 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3542 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3543 <li><code>[out] result</code>: C <code>int32</code> primitive equivalent of the given JavaScript
3544 <code>number</code>.</li>
3546 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3547 is passed in <code>napi_number_expected</code>.</p>
3548 <p>This API returns the C <code>int32</code> primitive equivalent
3549 of the given JavaScript <code>number</code>.</p>
3553 <p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) s…
3555 <h5><code>napi_get_value_int64</code><span><a class="mark" href="#napi_get_value_int64" id="napi_ge…
3560 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_int64</…
3562 …<span class="hljs-type">int64_t</span>* result)</span></code> <button class="copy-button">copy</bu…
3564 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3565 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3566 <li><code>[out] result</code>: C <code>int64</code> primitive equivalent of the given JavaScript
3567 <code>number</code>.</li>
3569 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3570 is passed in it returns <code>napi_number_expected</code>.</p>
3571 <p>This API returns the C <code>int64</code> primitive equivalent of the given JavaScript
3572 <code>number</code>.</p>
3573 …code>number</code> values outside the range of <a href="https://tc39.github.io/ecma262/#sec-number…
3574 …code>-(2**53 - 1)</code> - <a href="https://tc39.github.io/ecma262/#sec-number.max_safe_integer"><…
3576 <p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) s…
3578 <h5><code>napi_get_value_string_latin1</code><span><a class="mark" href="#napi_get_value_string_lat…
3583 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3587 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3589 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3590 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3591 <li><code>[in] buf</code>: Buffer to write the ISO-8859-1-encoded string into. If <code>NULL</code>…
3593 is returned in <code>result</code>.</li>
3594 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3596 <li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null
3599 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3600 is passed in it returns <code>napi_string_expected</code>.</p>
3603 <h5><code>napi_get_value_string_utf8</code><span><a class="mark" href="#napi_get_value_string_utf8"…
3608 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3612 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3614 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3615 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3616 <li><code>[in] buf</code>: Buffer to write the UTF8-encoded string into. If <code>NULL</code> is pa…
3618 returned in <code>result</code>.</li>
3619 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3621 <li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null
3624 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3625 is passed in it returns <code>napi_string_expected</code>.</p>
3627 <h5><code>napi_get_value_string_utf16</code><span><a class="mark" href="#napi_get_value_string_utf1…
3632 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3636 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3638 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3639 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3640 <li><code>[in] buf</code>: Buffer to write the UTF16-LE-encoded string into. If <code>NULL</code> is
3641 passed in, the length of the string in 2-byte code units and excluding the
3643 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3645 <li><code>[out] result</code>: Number of 2-byte code units copied into the buffer, excluding
3648 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3649 is passed in it returns <code>napi_string_expected</code>.</p>
3651 <h5><code>napi_get_value_uint32</code><span><a class="mark" href="#napi_get_value_uint32" id="napi_…
3656 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_uint32<…
3658 …<span class="hljs-type">uint32_t</span>* result)</span></code> <button class="copy-button">copy</b…
3660 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3661 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3662 <li><code>[out] result</code>: C primitive equivalent of the given <code>napi_value</code> as a
3663 <code>uint32_t</code>.</li>
3665 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3666 is passed in it returns <code>napi_number_expected</code>.</p>
3667 <p>This API returns the C primitive equivalent of the given <code>napi_value</code> as a
3668 <code>uint32_t</code>.</p>
3670 <h5><code>napi_get_boolean</code><span><a class="mark" href="#napi_get_boolean" id="napi_get_boolea…
3675 …code class="language-c">napi_status <span class="hljs-title function_">napi_get_boolean</span><spa…
3677 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3678 <li><code>[in] value</code>: The value of the boolean to retrieve.</li>
3679 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code>…
3682 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3685 <h5><code>napi_get_global</code><span><a class="mark" href="#napi_get_global" id="napi_get_global">…
3690 …code class="language-c">napi_status <span class="hljs-title function_">napi_get_global</span><span…
3692 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3693 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>global</code> …
3695 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3696 <p>This API returns the <code>global</code> object.</p>
3697 <h5><code>napi_get_null</code><span><a class="mark" href="#napi_get_null" id="napi_get_null">#</a><…
3702 …code class="language-c">napi_status <span class="hljs-title function_">napi_get_null</span><span c…
3704 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3705 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>null</code> ob…
3707 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3708 <p>This API returns the <code>null</code> object.</p>
3709 <h5><code>napi_get_undefined</code><span><a class="mark" href="#napi_get_undefined" id="napi_get_un…
3714 …code class="language-c">napi_status <span class="hljs-title function_">napi_get_undefined</span><s…
3716 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3717 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript Undefined value.</li>
3719 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3727 <li>Coerce JavaScript values to specific JavaScript types (such as <code>number</code> or
3728 <code>string</code>).</li>
3732 <h4><code>napi_coerce_to_bool</code><span><a class="mark" href="#napi_coerce_to_bool" id="napi_coer…
3737 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_bool</s…
3739 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3741 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3742 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3743 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Bo…
3745 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3746 <p>This API implements the abstract operation <code>ToBoolean()</code> as defined in
3748 <h4><code>napi_coerce_to_number</code><span><a class="mark" href="#napi_coerce_to_number" id="napi_…
3753 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_number<…
3755 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3757 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3758 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3759 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>nu…
3761 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3762 <p>This API implements the abstract operation <code>ToNumber()</code> as defined in
3764 This function potentially runs JS code if the passed-in value is an
3766 <h4><code>napi_coerce_to_object</code><span><a class="mark" href="#napi_coerce_to_object" id="napi_…
3771 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_object<…
3773 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3775 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3776 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3777 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Ob…
3779 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3780 <p>This API implements the abstract operation <code>ToObject()</code> as defined in
3782 <h4><code>napi_coerce_to_string</code><span><a class="mark" href="#napi_coerce_to_string" id="napi_…
3787 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_string<…
3789 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3791 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3792 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3793 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>st…
3795 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3796 <p>This API implements the abstract operation <code>ToString()</code> as defined in
3798 This function potentially runs JS code if the passed-in value is an
3800 <h4><code>napi_typeof</code><span><a class="mark" href="#napi_typeof" id="napi_typeof">#</a></span>…
3805 …code class="language-c">napi_status <span class="hljs-title function_">napi_typeof</span><span cla…
3807 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3808 <li><code>[in] value</code>: The JavaScript value whose type to query.</li>
3809 <li><code>[out] result</code>: The type of the JavaScript value.</li>
3811 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3813 <li><code>napi_invalid_arg</code> if the type of <code>value</code> is not a known ECMAScript type …
3814 <code>value</code> is not an External value.</li>
3816 <p>This API represents behavior similar to invoking the <code>typeof</code> Operator on
3821 <li>It detects <code>null</code> as a separate type, while ECMAScript <code>typeof</code> would det…
3822 <code>object</code>.</li>
3824 <p>If <code>value</code> has a type that is invalid, an error is returned.</p>
3825 <h4><code>napi_instanceof</code><span><a class="mark" href="#napi_instanceof" id="napi_instanceof">…
3830 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_instanceof</span>…
3833 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3835 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3836 <li><code>[in] object</code>: The JavaScript value to check.</li>
3837 <li><code>[in] constructor</code>: The JavaScript function object of the constructor function
3839 <li><code>[out] result</code>: Boolean that is set to true if <code>object instanceof constructor</…
3842 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3843 <p>This API represents invoking the <code>instanceof</code> Operator on the object as
3845 <h4><code>napi_is_array</code><span><a class="mark" href="#napi_is_array" id="napi_is_array">#</a><…
3850 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_array</span><span c…
3852 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3853 <li><code>[in] value</code>: The JavaScript value to check.</li>
3854 <li><code>[out] result</code>: Whether the given object is an array.</li>
3856 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3857 <p>This API represents invoking the <code>IsArray</code> operation on the object
3859 <h4><code>napi_is_arraybuffer</code><span><a class="mark" href="#napi_is_arraybuffer" id="napi_is_a…
3864 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_arraybuffer</span><…
3866 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3867 <li><code>[in] value</code>: The JavaScript value to check.</li>
3868 <li><code>[out] result</code>: Whether the given object is an <code>ArrayBuffer</code>.</li>
3870 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3871 <p>This API checks if the <code>Object</code> passed in is an array buffer.</p>
3872 <h4><code>napi_is_buffer</code><span><a class="mark" href="#napi_is_buffer" id="napi_is_buffer">#</…
3877 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_buffer</span><span …
3879 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3880 <li><code>[in] value</code>: The JavaScript value to check.</li>
3881 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>node::B…
3882 <code>Uint8Array</code> object.</li>
3884 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3885 <p>This API checks if the <code>Object</code> passed in is a buffer or Uint8Array.
3886 <a href="#napi_is_typedarray"><code>napi_is_typedarray</code></a> should be preferred if the caller…
3888 <h4><code>napi_is_date</code><span><a class="mark" href="#napi_is_date" id="napi_is_date">#</a></sp…
3893 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_date</span><span cl…
3895 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3896 <li><code>[in] value</code>: The JavaScript value to check.</li>
3897 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a JavaScript <c…
3900 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3901 <p>This API checks if the <code>Object</code> passed in is a date.</p>
3902 <h4><code>napi_is_error</code><span><a class="mark" href="#napi_is_error_1" id="napi_is_error_1">#<…
3907 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_error</span><span c…
3909 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3910 <li><code>[in] value</code>: The JavaScript value to check.</li>
3911 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents an <code>Error<…
3913 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3914 <p>This API checks if the <code>Object</code> passed in is an <code>Error</code>.</p>
3915 <h4><code>napi_is_typedarray</code><span><a class="mark" href="#napi_is_typedarray" id="napi_is_typ…
3920 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_typedarray</span><s…
3922 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3923 <li><code>[in] value</code>: The JavaScript value to check.</li>
3924 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>TypedAr…
3926 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3927 <p>This API checks if the <code>Object</code> passed in is a typed array.</p>
3928 <h4><code>napi_is_dataview</code><span><a class="mark" href="#napi_is_dataview" id="napi_is_datavie…
3933 …code class="language-c">napi_status <span class="hljs-title function_">napi_is_dataview</span><spa…
3935 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3936 <li><code>[in] value</code>: The JavaScript value to check.</li>
3937 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>DataVie…
3939 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3940 <p>This API checks if the <code>Object</code> passed in is a <code>DataView</code>.</p>
3941 <h4><code>napi_strict_equals</code><span><a class="mark" href="#napi_strict_equals" id="napi_strict…
3946 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_strict_equals</sp…
3949 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3951 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3952 <li><code>[in] lhs</code>: The JavaScript value to check.</li>
3953 <li><code>[in] rhs</code>: The JavaScript value to check against.</li>
3954 <li><code>[out] result</code>: Whether the two <code>napi_value</code> objects are equal.</li>
3956 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3959 <h4><code>napi_detach_arraybuffer</code><span><a class="mark" href="#napi_detach_arraybuffer" id="n…
3964 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_detach_arraybuffe…
3965 … napi_value arraybuffer)</span></code> <button class="copy-button">copy</button></pre>
3967 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3968 <li><code>[in] arraybuffer</code>: The JavaScript <code>ArrayBuffer</code> to be detached.</li>
3970 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-detachable <code>ArrayBuffer</code> …
3971 passed in it returns <code>napi_detachable_arraybuffer_expected</code>.</p>
3972 <p>Generally, an <code>ArrayBuffer</code> is non-detachable if it has been detached before.
3973 The engine may impose additional conditions on whether an <code>ArrayBuffer</code> is
3974 detachable. For example, V8 requires that the <code>ArrayBuffer</code> be external,
3975 …ated with <a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code…
3976 <p>This API represents the invocation of the <code>ArrayBuffer</code> detach operation as
3978 <h4><code>napi_is_detached_arraybuffer</code><span><a class="mark" href="#napi_is_detached_arraybuf…
3983 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_is_detached_array…
3985 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3987 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3988 <li><code>[in] arraybuffer</code>: The JavaScript <code>ArrayBuffer</code> to be checked.</li>
3989 <li><code>[out] result</code>: Whether the <code>arraybuffer</code> is detached.</li>
3991 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3992 <p>The <code>ArrayBuffer</code> is considered detached if its internal data is <code>null</code>.</…
3993 <p>This API represents the invocation of the <code>ArrayBuffer</code> <code>IsDetachedBuffer</code>
4005 <li>Integer-Indexed: an index value represented by <code>uint32_t</code></li>
4006 <li>JavaScript value: these are represented in Node-API by <code>napi_value</code>. This can
4007 be a <code>napi_value</code> representing a <code>string</code>, <code>number</code>, or <code>symb…
4009 <p>Node-API values are represented by the type <code>napi_value</code>.
4010 Any Node-API call that requires a JavaScript value takes in a <code>napi_value</code>.
4012 <code>napi_value</code> in question is of the JavaScript type expected by the API.</p>
4015 <code>napi_value</code>.</p>
4016 <p>For instance, consider the following JavaScript code snippet:</p>
4017 <pre><code class="language-js"><span class="hljs-keyword">const</span> obj = {};
4018 obj.<span class="hljs-property">myProp</span> = <span class="hljs-number">123</span>;</code> <butto…
4020 <pre><code class="language-c">napi_status status = napi_generic_failure;
4033 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4036 <pre><code class="language-js"><span class="hljs-keyword">const</span> arr = [];
4037 arr[<span class="hljs-number">123</span>] = <span class="hljs-string">'hello'</span>;</code> <butto…
4039 <pre><code class="language-c">napi_status status = napi_generic_failure;
4052 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4055 <pre><code class="language-js"><span class="hljs-keyword">const</span> arr = [];
4056 <span class="hljs-keyword">const</span> value = arr[<span class="hljs-number">123</span>];</code> <…
4058 <pre><code class="language-c">napi_status status = napi_generic_failure;
4067 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4070 <pre><code class="language-js"><span class="hljs-keyword">const</span> obj = {};
4074 });</code> <button class="copy-button">copy</button></pre>
4076 <pre><code class="language-c">napi_status status = napi_status_generic_failure;
4099 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4101 <h5><code>napi_property_attributes</code><span><a class="mark" href="#napi_property_attributes" id=…
4107 <td><p>added <code>napi_default_method</code> and <code>napi_default_property</code>.</p></td></tr>
4111 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
4128 } napi_property_attributes;</code> <button class="copy-button">copy</button></pre>
4129 <p><code>napi_property_attributes</code> are flags used to control the behavior of properties
4130 set on a JavaScript object. Other than <code>napi_static</code> they correspond to the
4135 <li><code>napi_default</code>: No explicit attributes are set on the property. By default, a
4137 <li><code>napi_writable</code>: The property is writable.</li>
4138 <li><code>napi_enumerable</code>: The property is enumerable.</li>
4139 <li><code>napi_configurable</code>: The property is configurable as defined in
4141 <li><code>napi_static</code>: The property will be defined as a static property on a class as
4143 <a href="#napi_define_class"><code>napi_define_class</code></a>. It is ignored by <code>napi_define…
4144 <li><code>napi_default_method</code>: Like a method in a JS class, the property is
4146 <li><code>napi_default_jsproperty</code>: Like a property set via assignment in JavaScript,
4149 <h5><code>napi_property_descriptor</code><span><a class="mark" href="#napi_property_descriptor" id=…
4150 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
4162 } napi_property_descriptor;</code> <button class="copy-button">copy</button></pre>
4164 <li><code>utf8name</code>: Optional string describing the key for the property,
4165 encoded as UTF8. One of <code>utf8name</code> or <code>name</code> must be provided for the
4167 <li><code>name</code>: Optional <code>napi_value</code> that points to a JavaScript string or symbol
4168 to be used as the key for the property. One of <code>utf8name</code> or <code>name</code> must
4170 <li><code>value</code>: The value that's retrieved by a get access of the property if the
4171 property is a data property. If this is passed in, set <code>getter</code>, <code>setter</code>,
4172 <code>method</code> and <code>data</code> to <code>NULL</code> (since these members won't be used).…
4173 <li><code>getter</code>: A function to call when a get access of the property is performed.
4174 If this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since th…
4176 the property is accessed from JavaScript code (or if a get on the property is
4177 performed using a Node-API call). <a href="#napi_callback"><code>napi_callback</code></a> provides …
4178 <li><code>setter</code>: A function to call when a set access of the property is performed.
4179 If this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since th…
4181 the property is set from JavaScript code (or if a set on the property is
4182 performed using a Node-API call). <a href="#napi_callback"><code>napi_callback</code></a> provides …
4183 <li><code>method</code>: Set this to make the property descriptor object's <code>value</code>
4184 property to be a JavaScript function represented by <code>method</code>. If this is
4185 passed in, set <code>value</code>, <code>getter</code> and <code>setter</code> to <code>NULL</code>…
4186 won't be used). <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</li>
4187 <li><code>attributes</code>: The attributes associated with the particular property. See
4188 <a href="#napi_property_attributes"><code>napi_property_attributes</code></a>.</li>
4189 <li><code>data</code>: The callback data passed into <code>method</code>, <code>getter</code> and <…
4193 <h5><code>napi_get_property_names</code><span><a class="mark" href="#napi_get_property_names" id="n…
4198 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_property_name…
4200 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4202 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4203 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4204 <li><code>[out] result</code>: A <code>napi_value</code> representing an array of JavaScript values
4206 iterate over <code>result</code> using <a href="#napi_get_array_length"><code>napi_get_array_length…
4207 and <a href="#napi_get_element"><code>napi_get_element</code></a>.</li>
4209 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4210 <p>This API returns the names of the enumerable properties of <code>object</code> as an array
4211 of strings. The properties of <code>object</code> whose key is a symbol will not be
4213 <h5><code>napi_get_all_property_names</code><span><a class="mark" href="#napi_get_all_property_name…
4218 <pre><code class="language-c">napi_get_all_property_names(napi_env env,
4223 … napi_value* result);</code> <button class="copy-button">copy</button></pre>
4225 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4226 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4227 <li><code>[in] key_mode</code>: Whether to retrieve prototype properties as well.</li>
4228 <li><code>[in] key_filter</code>: Which properties to retrieve
4230 <li><code>[in] key_conversion</code>: Whether to convert numbered property keys to strings.</li>
4231 <li><code>[out] result</code>: A <code>napi_value</code> representing an array of JavaScript values
4232 …operty names of the object. <a href="#napi_get_array_length"><code>napi_get_array_length</code></a>
4233 and <a href="#napi_get_element"><code>napi_get_element</code></a> can be used to iterate over <code…
4235 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4238 <h5><code>napi_set_property</code><span><a class="mark" href="#napi_set_property" id="napi_set_prop…
4243 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_property</spa…
4246 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4248 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4249 <li><code>[in] object</code>: The object on which to set the property.</li>
4250 <li><code>[in] key</code>: The name of the property to set.</li>
4251 <li><code>[in] value</code>: The property value.</li>
4253 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4254 <p>This API set a property on the <code>Object</code> passed in.</p>
4255 <h5><code>napi_get_property</code><span><a class="mark" href="#napi_get_property" id="napi_get_prop…
4260 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_property</spa…
4263 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4265 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4266 <li><code>[in] object</code>: The object from which to retrieve the property.</li>
4267 <li><code>[in] key</code>: The name of the property to retrieve.</li>
4268 <li><code>[out] result</code>: The value of the property.</li>
4270 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4271 <p>This API gets the requested property from the <code>Object</code> passed in.</p>
4272 <h5><code>napi_has_property</code><span><a class="mark" href="#napi_has_property" id="napi_has_prop…
4277 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_property</spa…
4280 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4282 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4283 <li><code>[in] object</code>: The object to query.</li>
4284 <li><code>[in] key</code>: The name of the property whose existence to check.</li>
4285 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4287 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4288 <p>This API checks if the <code>Object</code> passed in has the named property.</p>
4289 <h5><code>napi_delete_property</code><span><a class="mark" href="#napi_delete_property" id="napi_de…
4294 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_property</…
4297 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4299 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4300 <li><code>[in] object</code>: The object to query.</li>
4301 <li><code>[in] key</code>: The name of the property to delete.</li>
4302 <li><code>[out] result</code>: Whether the property deletion succeeded or not. <code>result</code> …
4303 optionally be ignored by passing <code>NULL</code>.</li>
4305 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4306 <p>This API attempts to delete the <code>key</code> own property from <code>object</code>.</p>
4307 <h5><code>napi_has_own_property</code><span><a class="mark" href="#napi_has_own_property" id="napi_…
4312 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_own_property<…
4315 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4317 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4318 <li><code>[in] object</code>: The object to query.</li>
4319 <li><code>[in] key</code>: The name of the own property whose existence to check.</li>
4320 <li><code>[out] result</code>: Whether the own property exists on the object or not.</li>
4322 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4323 <p>This API checks if the <code>Object</code> passed in has the named own property. <code>key</code…
4324 be a <code>string</code> or a <code>symbol</code>, or an error will be thrown. Node-API will not
4326 <h5><code>napi_set_named_property</code><span><a class="mark" href="#napi_set_named_property" id="n…
4331 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_named_propert…
4334 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4336 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4337 <li><code>[in] object</code>: The object on which to set the property.</li>
4338 <li><code>[in] utf8Name</code>: The name of the property to set.</li>
4339 <li><code>[in] value</code>: The property value.</li>
4341 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4342 …ent to calling <a href="#napi_set_property"><code>napi_set_property</code></a> with a <code>napi_v…
4343 created from the string passed in as <code>utf8Name</code>.</p>
4344 <h5><code>napi_get_named_property</code><span><a class="mark" href="#napi_get_named_property" id="n…
4349 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_named_propert…
4352 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4354 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4355 <li><code>[in] object</code>: The object from which to retrieve the property.</li>
4356 <li><code>[in] utf8Name</code>: The name of the property to get.</li>
4357 <li><code>[out] result</code>: The value of the property.</li>
4359 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4360 …ent to calling <a href="#napi_get_property"><code>napi_get_property</code></a> with a <code>napi_v…
4361 created from the string passed in as <code>utf8Name</code>.</p>
4362 <h5><code>napi_has_named_property</code><span><a class="mark" href="#napi_has_named_property" id="n…
4367 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_named_propert…
4370 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4372 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4373 <li><code>[in] object</code>: The object to query.</li>
4374 <li><code>[in] utf8Name</code>: The name of the property whose existence to check.</li>
4375 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4377 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4378 …ent to calling <a href="#napi_has_property"><code>napi_has_property</code></a> with a <code>napi_v…
4379 created from the string passed in as <code>utf8Name</code>.</p>
4380 <h5><code>napi_set_element</code><span><a class="mark" href="#napi_set_element" id="napi_set_elemen…
4385 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_element</span…
4388 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4390 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4391 <li><code>[in] object</code>: The object from which to set the properties.</li>
4392 <li><code>[in] index</code>: The index of the property to set.</li>
4393 <li><code>[in] value</code>: The property value.</li>
4395 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4396 <p>This API sets an element on the <code>Object</code> passed in.</p>
4397 <h5><code>napi_get_element</code><span><a class="mark" href="#napi_get_element" id="napi_get_elemen…
4402 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_element</span…
4405 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4407 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4408 <li><code>[in] object</code>: The object from which to retrieve the property.</li>
4409 <li><code>[in] index</code>: The index of the property to get.</li>
4410 <li><code>[out] result</code>: The value of the property.</li>
4412 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4414 <h5><code>napi_has_element</code><span><a class="mark" href="#napi_has_element" id="napi_has_elemen…
4419 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_element</span…
4422 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4424 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4425 <li><code>[in] object</code>: The object to query.</li>
4426 <li><code>[in] index</code>: The index of the property whose existence to check.</li>
4427 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4429 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4430 <p>This API returns if the <code>Object</code> passed in has an element at the
4432 <h5><code>napi_delete_element</code><span><a class="mark" href="#napi_delete_element" id="napi_dele…
4437 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_element</s…
4440 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4442 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4443 <li><code>[in] object</code>: The object to query.</li>
4444 <li><code>[in] index</code>: The index of the property to delete.</li>
4445 <li><code>[out] result</code>: Whether the element deletion succeeded or not. <code>result</code> c…
4446 optionally be ignored by passing <code>NULL</code>.</li>
4448 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4449 <p>This API attempts to delete the specified <code>index</code> from <code>object</code>.</p>
4450 <h5><code>napi_define_properties</code><span><a class="mark" href="#napi_define_properties" id="nap…
4455 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_define_properties…
4458 …s="hljs-type">const</span> napi_property_descriptor* properties)</span>;</code> <button class="cop…
4460 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4461 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4462 <li><code>[in] property_count</code>: The number of elements in the <code>properties</code> array.<…
4463 <li><code>[in] properties</code>: The array of property descriptors.</li>
4465 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4468 <a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a>). Given an array of s…
4470 <code>DefineOwnProperty()</code> (described in <a href="https://tc39.github.io/ecma262/#sec-ordinar…
4472 <h5><code>napi_object_freeze</code><span><a class="mark" href="#napi_object_freeze" id="napi_object…
4477 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_object_freeze</sp…
4478 … napi_value object)</span>;</code> <button class="copy-button">copy</button></pre>
4480 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4481 <li><code>[in] object</code>: The object to freeze.</li>
4483 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4491 <h5><code>napi_object_seal</code><span><a class="mark" href="#napi_object_seal" id="napi_object_sea…
4496 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_object_seal</span…
4497 … napi_value object)</span>;</code> <button class="copy-button">copy</button></pre>
4499 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4500 <li><code>[in] object</code>: The object to seal.</li>
4502 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4508 <p>Node-API provides a set of APIs that allow JavaScript code to
4509 call back into native code. Node-APIs that support calling back
4510 into native code take in a callback functions represented by
4511 the <code>napi_callback</code> type. When the JavaScript VM calls back to
4512 native code, the <code>napi_callback</code> function provided is invoked. The APIs
4518 <li>Return a <code>napi_value</code> back from the callback.</li>
4521 JavaScript functions from native code. One can either call a function
4524 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> field of the
4525 <code>napi_property_descriptor</code> items can be associated with <code>object</code> and freed
4526 whenever <code>object</code> is garbage-collected by passing both <code>object</code> and the data …
4527 <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.</p>
4528 <h4><code>napi_call_function</code><span><a class="mark" href="#napi_call_function" id="napi_call_f…
4533 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_call_…
4538 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4540 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4541 <li><code>[in] recv</code>: The <code>this</code> value passed to the called function.</li>
4542 <li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function to be invo…
4543 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
4544 <li><code>[in] argv</code>: Array of <code>napi_values</code> representing JavaScript values passed…
4546 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.…
4548 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4551 native code <em>into</em> JavaScript. For the special case of calling into JavaScript
4552 after an async operation, see <a href="#napi_make_callback"><code>napi_make_callback</code></a>.</p>
4555 <pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title f…
4558 …property">AddTwo</span> = <span class="hljs-title class_">AddTwo</span>;</code> <button class="cop…
4560 following code:</p>
4561 <pre><code class="language-c"><span class="hljs-comment">// Get the function named "AddTwo" on the …
4584 …>if</span> (status != napi_ok) <span class="hljs-keyword">return</span>;</code> <button class="cop…
4585 <h4><code>napi_create_function</code><span><a class="mark" href="#napi_create_function" id="napi_cr…
4590 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_function</…
4595 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4597 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4598 <li><code>[in] utf8Name</code>: Optional name of the function encoded as UTF8. This is
4599 visible within JavaScript as the new function object's <code>name</code> property.</li>
4600 <li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or <code>NAPI_AUTO_…
4602 <li><code>[in] cb</code>: The native function which should be called when this function
4603 object is invoked. <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</…
4604 <li><code>[in] data</code>: User-provided data context. This will be passed back into the
4606 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript function object …
4609 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4610 <p>This API allows an add-on author to create a function object in native code.
4611 This is the primary mechanism to allow calling <em>into</em> the add-on's native code
4619 <pre><code class="language-c">napi_value <span class="hljs-title function_">SayHello</span><span cl…
4637 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)</code> <button class="copy-button">copy</button></pre>
4638 <p>Given the above code, the add-on can be used from JavaScript as follows:</p>
4639 <pre><code class="language-js"><span class="hljs-keyword">const</span> myaddon = <span class="hljs-…
4640 myaddon.<span class="hljs-title function_">sayHello</span>();</code> <button class="copy-button">co…
4641 <p>The string passed to <code>require()</code> is the name of the target in <code>binding.gyp</code>
4642 responsible for creating the <code>.node</code> file.</p>
4643 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> parameter c…
4645 <code>result</code> parameter) and freed whenever the function is garbage-collected by
4646 …cript function and the data to <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.<…
4647 <p>JavaScript <code>Function</code>s are described in <a href="https://tc39.github.io/ecma262/#sec-…
4649 <h4><code>napi_get_cb_info</code><span><a class="mark" href="#napi_get_cb_info" id="napi_get_cb_inf…
4654 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_cb_info</span…
4659 …<span class="hljs-type">void</span>** data)</span></code> <button class="copy-button">copy</button…
4661 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4662 <li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>
4663 <li><code>[in-out] argc</code>: Specifies the length of the provided <code>argv</code> array and
4664 receives the actual count of arguments. <code>argc</code> can
4665 optionally be ignored by passing <code>NULL</code>.</li>
4666 <li><code>[out] argv</code>: C array of <code>napi_value</code>s to which the arguments will be
4669 provided than claimed, the rest of <code>argv</code> is filled with <code>napi_value</code> values
4670 that represent <code>undefined</code>. <code>argv</code> can optionally be ignored by
4671 passing <code>NULL</code>.</li>
4672 <li><code>[out] thisArg</code>: Receives the JavaScript <code>this</code> argument for the call.
4673 <code>thisArg</code> can optionally be ignored by passing <code>NULL</code>.</li>
4674 <li><code>[out] data</code>: Receives the data pointer for the callback. <code>data</code> can
4675 optionally be ignored by passing <code>NULL</code>.</li>
4677 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4679 call like the arguments and the <code>this</code> pointer from a given callback info.</p>
4680 <h4><code>napi_get_new_target</code><span><a class="mark" href="#napi_get_new_target" id="napi_get_…
4685 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_new_target</s…
4687 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
4689 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4690 <li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>
4691 <li><code>[out] result</code>: The <code>new.target</code> of the constructor call.</li>
4693 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4694 <p>This API returns the <code>new.target</code> of the constructor call. If the current
4695 callback is not a constructor call, the result is <code>NULL</code>.</p>
4696 <h4><code>napi_new_instance</code><span><a class="mark" href="#napi_new_instance" id="napi_new_inst…
4701 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_new_instance</spa…
4705 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
4707 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4708 <li><code>[in] cons</code>: <code>napi_value</code> representing the JavaScript function to be invo…
4710 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
4711 <li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code> representing the
4712 arguments to the constructor. If <code>argc</code> is zero this parameter may be
4713 omitted by passing in <code>NULL</code>.</li>
4714 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned,
4718 <code>napi_value</code> that represents the constructor for the object. For example,
4720 <pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title f…
4725 …eyword">new</span> <span class="hljs-title class_">MyObject</span>(arg);</code> <button class="cop…
4727 <pre><code class="language-c"><span class="hljs-comment">// Get the constructor function MyObject</…
4743 status = napi_new_instance(env, constructor, argc, argv, &value);</code> <button class="copy-b…
4744 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4749 <li>The <a href="#napi_define_class"><code>napi_define_class</code></a> API defines a JavaScript cl…
4752 <li>When JavaScript code invokes the constructor, the constructor callback
4753 uses <a href="#napi_wrap"><code>napi_wrap</code></a> to wrap a new C++ instance in a JavaScript obj…
4755 <li>When JavaScript code invokes a method or property accessor on the class,
4756 the corresponding <code>napi_callback</code> C++ function is invoked. For an instance
4757 callback, <a href="#napi_unwrap"><code>napi_unwrap</code></a> obtains the C++ instance that is the …
4763 reference to the class constructor for later <code>instanceof</code> checks.</p>
4764 <pre><code class="language-c">napi_value MyClass_constructor = <span class="hljs-literal">NULL</spa…
4774 }</code> <button class="copy-button">copy</button></pre>
4776 <p>There are occasions where <code>napi_instanceof()</code> is insufficient for ensuring that
4779 static methods rather than as the <code>this</code> value of prototype methods. In such
4781 <pre><code class="language-js"><span class="hljs-keyword">const</span> myAddon = <span class="hljs-…
4799 }</code> <button class="copy-button">copy</button></pre>
4800 <p>In the above example <code>myAddon.queryHasRecords()</code> is a method that accepts two
4810 <code>queryHasRecords()</code> has to perform a type validation. Retaining the JavaScript
4812 constructor from which the query handle was instantiated in <code>napi_ref</code>s can
4813 help, because <code>napi_instanceof()</code> can then be used to ensure that the instances
4814 passed into <code>queryHashRecords()</code> are indeed of the correct type.</p>
4815 <p>Unfortunately, <code>napi_instanceof()</code> does not protect against prototype
4819 will pass the <code>napi_instanceof()</code> test for a query handle instance, while still
4823 <code>napi_type_tag</code> structure for storing a type tag. When such a value is passed
4824 …cript object or <a href="#napi_create_external">external</a> stored in a <code>napi_value</code> to
4825 <code>napi_type_tag_object()</code>, the JavaScript object will be "marked" with the
4827 object arrives into a native binding, <code>napi_check_object_type_tag()</code> can be used
4830 of a higher fidelity than <code>napi_instanceof()</code> can provide, because such type-
4833 illustrates the use of <code>napi_type_tag_object()</code> and
4834 <code>napi_check_object_type_tag()</code>.</p>
4835 <pre><code class="language-c"><span class="hljs-comment">// This value is the type tag for a databa…
4899 }</code> <button class="copy-button">copy</button></pre>
4900 <h4><code>napi_define_class</code><span><a class="mark" href="#napi_define_class" id="napi_define_c…
4905 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_define_class</spa…
4912 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4914 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4915 <li><code>[in] utf8name</code>: Name of the JavaScript constructor function. For clarity,
4917 <li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or <code>NAPI_AUTO_…
4919 <li><code>[in] constructor</code>: Callback function that handles constructing instances
4921 with the <a href="#napi_callback"><code>napi_callback</code></a> signature. A C++ class constructor…
4922 used. <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</li>
4923 <li><code>[in] data</code>: Optional data to be passed to the constructor callback as
4924 the <code>data</code> property of the callback info.</li>
4925 <li><code>[in] property_count</code>: Number of items in the <code>properties</code> array argument…
4926 <li><code>[in] properties</code>: Array of property descriptors describing static and
4928 See <code>napi_property_descriptor</code>.</li>
4929 <li><code>[out] result</code>: A <code>napi_value</code> representing the constructor function for
4932 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4936 corresponding C++ class, the callback passed via <code>constructor</code> can be used to
4938 JavaScript object instance being constructed using <a href="#napi_wrap"><code>napi_wrap</code></a>.…
4941 class (defined by property descriptors with the <code>napi_static</code> attribute).</li>
4942 <li>Properties on the constructor function's <code>prototype</code> object. When wrapping a
4945 descriptors without the <code>napi_static</code> attribute after retrieving the C++ class
4947 <a href="#napi_unwrap"><code>napi_unwrap</code></a>.</li>
4949 <p>When wrapping a C++ class, the C++ constructor callback passed via <code>constructor</code>
4952 object. See <a href="#napi_wrap"><code>napi_wrap</code></a> for details.</p>
4953 …nstructor function returned from <a href="#napi_define_class"><code>napi_define_class</code></a> is
4955 code, and/or to check whether provided values are instances of the class. In
4958 <a href="#napi_create_reference"><code>napi_create_reference</code></a>, ensuring that the referenc…
4959 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> parameter o…
4960 the <code>data</code> field of the <code>napi_property_descriptor</code> array items can be associa…
4961 with the resulting JavaScript constructor (which is returned in the <code>result</code>
4963 …cript function and the data to <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.<…
4964 <h4><code>napi_wrap</code><span><a class="mark" href="#napi_wrap" id="napi_wrap">#</a></span><a ari…
4969 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_wrap</span><span …
4974 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
4976 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4977 <li><code>[in] js_object</code>: The JavaScript object that will be the wrapper for the
4979 <li><code>[in] native_object</code>: The native instance that will be wrapped in the
4981 <li><code>[in] finalize_cb</code>: Optional native callback that can be used to free the
4983 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
4984 <li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the
4986 <li><code>[out] result</code>: Optional reference to the wrapped object.</li>
4988 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4990 retrieved later using <code>napi_unwrap()</code>.</p>
4991 <p>When JavaScript code invokes a constructor for a class that was defined using
4992 <code>napi_define_class()</code>, the <code>napi_callback</code> for the constructor is invoked.
4994 <code>napi_wrap()</code> to wrap the newly constructed instance in the already-created
4995 JavaScript object that is the <code>this</code> argument to the constructor callback.
4996 (That <code>this</code> object was created from the constructor function's <code>prototype</code>,
4999 provided that simply deletes the native instance that is received as the <code>data</code>
5005 <a href="#napi_delete_reference"><code>napi_delete_reference</code></a> ONLY in response to the fin…
5011 hasn't been called yet. When using <code>napi_get_reference_value()</code> on weak
5012 references returned by <code>napi_wrap()</code>, you should still handle an empty result.</p>
5013 <p>Calling <code>napi_wrap()</code> a second time on an object will return an error. To
5014 associate another native instance with the object, use <code>napi_remove_wrap()</code>
5016 <h4><code>napi_unwrap</code><span><a class="mark" href="#napi_unwrap" id="napi_unwrap">#</a></span>…
5021 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_unwrap</span><spa…
5023 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5025 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5026 <li><code>[in] js_object</code>: The object associated with the native instance.</li>
5027 <li><code>[out] result</code>: Pointer to the wrapped native instance.</li>
5029 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5031 object using <code>napi_wrap()</code>.</p>
5032 <p>When JavaScript code invokes a method or property accessor on the class, the
5033 corresponding <code>napi_callback</code> is invoked. If the callback is for an instance
5034 method or accessor, then the <code>this</code> argument to the callback is the wrapper
5036 then by calling <code>napi_unwrap()</code> on the wrapper object.</p>
5037 <h4><code>napi_remove_wrap</code><span><a class="mark" href="#napi_remove_wrap" id="napi_remove_wra…
5042 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_remove_wrap</span…
5044 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5046 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5047 <li><code>[in] js_object</code>: The object associated with the native instance.</li>
5048 <li><code>[out] result</code>: Pointer to the wrapped native instance.</li>
5050 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5052 object <code>js_object</code> using <code>napi_wrap()</code> and removes the wrapping. If a finalize
5055 <h4><code>napi_type_tag_object</code><span><a class="mark" href="#napi_type_tag_object" id="napi_ty…
5060 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_type_tag_object</…
5062 …<span class="hljs-type">const</span> napi_type_tag* type_tag)</span>;</code> <button class="copy-b…
5064 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5065 <li><code>[in] js_object</code>: The JavaScript object or <a href="#napi_create_external">external<…
5066 <li><code>[in] type_tag</code>: The tag with which the object is to be marked.</li>
5068 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5069 <p>Associates the value of the <code>type_tag</code> pointer with the JavaScript object or
5070 <a href="#napi_create_external">external</a>. <code>napi_check_object_type_tag()</code> can then be…
5074 <code>napi_invalid_arg</code>.</p>
5075 <h4><code>napi_check_object_type_tag</code><span><a class="mark" href="#napi_check_object_type_tag"…
5080 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_check_object_type…
5083 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
5085 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5086 <li><code>[in] js_object</code>: The JavaScript object or <a href="#napi_create_external">external<…
5088 <li><code>[in] type_tag</code>: The tag with which to compare any tag found on the object.</li>
5089 <li><code>[out] result</code>: Whether the type tag given matched the type tag on the
5090 object. <code>false</code> is also returned if no type tag was found on the object.</li>
5092 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5093 <p>Compares the pointer given as <code>type_tag</code> with any that can be found on
5094 <code>js_object</code>. If no tag is found on <code>js_object</code> or, if a tag is found but it d…
5095 not match <code>type_tag</code>, then <code>result</code> is set to <code>false</code>. If a tag is…
5096 matches <code>type_tag</code>, then <code>result</code> is set to <code>true</code>.</p>
5097 <h4><code>napi_add_finalizer</code><span><a class="mark" href="#napi_add_finalizer" id="napi_add_fi…
5102 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_add_finalizer</sp…
5107 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
5109 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5110 <li><code>[in] js_object</code>: The JavaScript object to which the native data will be
5112 <li><code>[in] finalize_data</code>: Optional data to be passed to <code>finalize_cb</code>.</li>
5113 <li><code>[in] finalize_cb</code>: Native callback that will be used to free the
5115 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
5116 <li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the
5118 <li><code>[out] result</code>: Optional reference to the JavaScript object.</li>
5120 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5121 <p>Adds a <code>napi_finalize</code> callback which will be called when the JavaScript object
5122 in <code>js_object</code> has been garbage-collected.</p>
5125 <a href="#napi_delete_reference"><code>napi_delete_reference</code></a> ONLY in response to the fin…
5129 <h5><code>node_api_post_finalizer</code><span><a class="mark" href="#node_api_post_finalizer" id="n…
5134 <pre><code class="language-c">napi_status <span class="hljs-title function_">node_api_post_finalize…
5137 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
5139 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5140 <li><code>[in] finalize_cb</code>: Native callback that will be used to free the
5142 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
5143 <li><code>[in] finalize_data</code>: Optional data to be passed to <code>finalize_cb</code>.</li>
5144 <li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the
5147 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5148 <p>Schedules a <code>napi_finalize</code> callback to be called asynchronously in the
5153 <p><code>node_api_post_finalizer</code> helps to work around this limitation by allowing the
5163 <p>Node-API defines the <code>napi_async_work</code> structure which is used to manage
5165 …_create_async_work"><code>napi_create_async_work</code></a> and <a href="#napi_delete_async_work">…
5166 <p>The <code>execute</code> and <code>complete</code> callbacks are functions that will be
5169 <p>The <code>execute</code> function should avoid making any Node-API calls
5171 JavaScript objects. Most often, any code that needs to make Node-API
5172 calls should be made in <code>complete</code> callback instead.
5173 Avoid using the <code>napi_env</code> parameter in the execute callback as
5176 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
5180 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
5181 <p>When these methods are invoked, the <code>data</code> parameter passed will be the
5182 addon-provided <code>void*</code> data that was passed into the
5183 <code>napi_create_async_work</code> call.</p>
5185 for execution using the <a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a> fun…
5186 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_queue_async_work<…
5187 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5188 <p><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a> can be used if the wor…
5190 … calling <a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a>, the <code>comp…
5191 will be invoked with a status value of <code>napi_cancelled</code>.
5192 The work should not be deleted before the <code>complete</code>
5194 <h4><code>napi_create_async_work</code><span><a class="mark" href="#napi_create_async_work" id="nap…
5200 <td><p>Added <code>async_resource</code> and <code>async_resource_name</code> parameters.</p></td><…
5207 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_async_work…
5213 … napi_async_work* result)</span>;</code> <button class="copy-button">copy</button></pre>
5215 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5216 <li><code>[in] async_resource</code>: An optional object associated with the async work
5217 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5218 <li><code>[in] async_resource_name</code>: Identifier for the kind of resource that is being
5219 provided for diagnostic information exposed by the <code>async_hooks</code> API.</li>
5220 <li><code>[in] execute</code>: The native function which should be called to execute the
5223 <li><code>[in] complete</code>: The native function which will be called when the
5225 …nt loop thread. <a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code><…
5227 <li><code>[in] data</code>: User-provided data context. This will be passed back into the
5229 <li><code>[out] result</code>: <code>napi_async_work*</code> which is the handle to the newly creat…
5232 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5234 It should be freed using <a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a> …
5236 <p><code>async_resource_name</code> should be a null-terminated, UTF-8-encoded string.</p>
5237 <p>The <code>async_resource_name</code> identifier is provided by the user and should be
5240 the <a href="async_hooks.html#type"><code>async_hooks</code> documentation</a> for more information…
5241 <h4><code>napi_delete_async_work</code><span><a class="mark" href="#napi_delete_async_work" id="nap…
5246 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_async_work…
5247 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5249 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5250 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5252 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5255 <h4><code>napi_queue_async_work</code><span><a class="mark" href="#napi_queue_async_work" id="napi_…
5260 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_queue_async_work<…
5261 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5263 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5264 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5266 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5269 with the same <code>napi_async_work</code> item or the result will be undefined.</p>
5270 <h4><code>napi_cancel_async_work</code><span><a class="mark" href="#napi_cancel_async_work" id="nap…
5275 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_cancel_async_work…
5276 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5278 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5279 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5281 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5284 cancelled and <code>napi_generic_failure</code> will be returned. If successful,
5285 the <code>complete</code> callback will be invoked with a status value of
5286 <code>napi_cancelled</code>. The work should not be deleted before the <code>complete</code>
5294 <h4><code>napi_async_init</code><span><a class="mark" href="#napi_async_init" id="napi_async_init">…
5299 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_async_init</span>…
5302 … napi_async_context* result)</span></code> <button class="copy-button">copy</button></pre>
5304 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5305 <li><code>[in] async_resource</code>: Object associated with the async work
5306 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5307 …async_hooks.html#async_hooksexecutionasyncresource"><code>async_hooks.executionAsyncResource()</co…
5308 <li><code>[in] async_resource_name</code>: Identifier for the kind of resource that is being
5309 provided for diagnostic information exposed by the <code>async_hooks</code> API.</li>
5310 <li><code>[out] result</code>: The initialized async context.</li>
5312 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5313 <p>The <code>async_resource</code> object needs to be kept alive until
5314 <a href="#napi_async_destroy"><code>napi_async_destroy</code></a> to keep <code>async_hooks</code> …
5315 order to retain ABI compatibility with previous versions, <code>napi_async_context</code>s
5316 are not maintaining the strong reference to the <code>async_resource</code> objects to
5317 avoid introducing causing memory leaks. However, if the <code>async_resource</code> is
5318 garbage collected by JavaScript engine before the <code>napi_async_context</code> was
5319 destroyed by <code>napi_async_destroy</code>, calling <code>napi_async_context</code> related APIs
5320 …i_open_callback_scope"><code>napi_open_callback_scope</code></a> and <a href="#napi_make_callback"…
5321 problems like loss of async context when using the <code>AsyncLocalStorage</code> API.</p>
5322 <p>In order to retain ABI compatibility with previous versions, passing <code>NULL</code>
5323 for <code>async_resource</code> does not result in an error. However, this is not
5324 recommended as this will result in undesirable behavior with <code>async_hooks</code>
5325 …yncid-type-triggerasyncid-resource"><code>init</code> hooks</a> and <code>async_hooks.executionAsy…
5326 now required by the underlying <code>async_hooks</code> implementation in order to provide
5328 <h4><code>napi_async_destroy</code><span><a class="mark" href="#napi_async_destroy" id="napi_async_…
5333 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_async_destroy</sp…
5334 … napi_async_context async_context)</span>;</code> <button class="copy-button">copy</button></pre>
5336 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5337 <li><code>[in] async_context</code>: The async context to be destroyed.</li>
5339 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5341 <h4><code>napi_make_callback</code><span><a class="mark" href="#napi_make_callback" id="napi_make_c…
5347 <td><p>Added <code>async_context</code> parameter.</p></td></tr>
5354 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_make_…
5360 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
5362 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5363 <li><code>[in] async_context</code>: Context for the async operation that is
5365 obtained from <a href="#napi_async_init"><code>napi_async_init</code></a>.
5366 In order to retain ABI compatibility with previous versions, passing <code>NULL</code>
5367 for <code>async_context</code> does not result in an error. However, this results
5369 async context when using the <code>AsyncLocalStorage</code> API.</li>
5370 <li><code>[in] recv</code>: The <code>this</code> value passed to the called function.</li>
5371 <li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function to be invo…
5372 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
5373 <li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code> representing the
5374 arguments to the function. If <code>argc</code> is zero this parameter may be
5375 omitted by passing in <code>NULL</code>.</li>
5376 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.…
5378 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5380 add-on. This API is similar to <code>napi_call_function</code>. However, it is used to call
5381 <em>from</em> native code back <em>into</em> JavaScript <em>after</em> returning from an async
5383 wrapper around <code>node::MakeCallback</code>.</p>
5384 <p>Note it is <em>not</em> necessary to use <code>napi_make_callback</code> from within a
5385 <code>napi_async_complete_callback</code>; in that situation the callback's async
5386 context has already been set up, so a direct call to <code>napi_call_function</code>
5387 is sufficient and appropriate. Use of the <code>napi_make_callback</code> function
5389 <code>napi_create_async_work</code>.</p>
5390 <p>Any <code>process.nextTick</code>s or Promises scheduled on the microtask queue by
5392 <h4><code>napi_open_callback_scope</code><span><a class="mark" href="#napi_open_callback_scope" id=…
5397 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_open_…
5400 … napi_callback_scope* result)</span></code> <button class="copy-button">copy</button></pre>
5402 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5403 <li><code>[in] resource_object</code>: An object associated with the async work
5404 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5406 <code>async_resource</code> parameter in <a href="#napi_async_init"><code>napi_async_init</code></a…
5407 <li><code>[in] context</code>: Context for the async operation that is invoking the callback.
5408 …e a value previously obtained from <a href="#napi_async_init"><code>napi_async_init</code></a>.</l…
5409 <li><code>[out] result</code>: The newly created scope.</li>
5414 the stack the <a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a> and
5415 <a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a> functions can be us…
5417 <h4><code>napi_close_callback_scope</code><span><a class="mark" href="#napi_close_callback_scope" i…
5422 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_close…
5423 … napi_callback_scope scope)</span></code> <button class="copy-button">copy</button></pre>
5425 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5426 <li><code>[in] scope</code>: The scope to be closed.</li>
5430 <h4><code>napi_get_node_version</code><span><a class="mark" href="#napi_get_node_version" id="napi_…
5435 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
5443 …span class="hljs-type">const</span> napi_node_version** version)</span>;</code> <button class="cop…
5445 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5446 <li><code>[out] version</code>: A pointer to version information for Node.js itself.</li>
5448 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5449 <p>This function fills the <code>version</code> struct with the major, minor, and patch
5450 version of Node.js that is currently running, and the <code>release</code> field with the
5451 value of <a href="process.html#processrelease"><code>process.release.name</code></a>.</p>
5453 <h4><code>napi_get_version</code><span><a class="mark" href="#napi_get_version" id="napi_get_versio…
5458 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_version</span…
5459 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
5461 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5462 <li><code>[out] result</code>: The highest version of Node-API supported.</li>
5464 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5473 <li>Call <code>napi_get_version()</code> to determine if the API is available.</li>
5474 <li>If available, dynamically load a pointer to the function using <code>uv_dlsym()</code>.</li>
5480 <h4><code>napi_adjust_external_memory</code><span><a class="mark" href="#napi_adjust_external_memor…
5485 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_adjus…
5487 …<span class="hljs-type">int64_t</span>* result)</span>;</code> <button class="copy-button">copy</b…
5489 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5490 <li><code>[in] change_in_bytes</code>: The change in externally allocated memory that is kept
5492 <li><code>[out] result</code>: The adjusted value</li>
5494 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5501 <p>Node-API provides facilities for creating <code>Promise</code> objects as described in
5503 objects. When a promise is created by <code>napi_create_promise()</code>, a "deferred"
5504 object is created and returned alongside the <code>Promise</code>. The deferred object is
5505 bound to the created <code>Promise</code> and is the only means to resolve or reject the
5506 <code>Promise</code> using <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</co…
5507 deferred object that is created by <code>napi_create_promise()</code> is freed by
5508 <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code>. The <code>Promise</cod…
5511 <pre><code class="language-c">napi_deferred deferred;
5523 <span class="hljs-keyword">return</span> promise;</code> <button class="copy-button">copy</button><…
5524 <p>The above function <code>do_something_asynchronous()</code> would perform its asynchronous
5527 <pre><code class="language-c">napi_deferred deferred;
5545 deferred = <span class="hljs-literal">NULL</span>;</code> <button class="copy-button">copy</button>…
5546 <h4><code>napi_create_promise</code><span><a class="mark" href="#napi_create_promise" id="napi_crea…
5551 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_promise</s…
5553 … napi_value* promise)</span>;</code> <button class="copy-button">copy</button></pre>
5555 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5556 <li><code>[out] deferred</code>: A newly created deferred object which can later be passed to
5557 <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code> to resolve resp. reject
5559 <li><code>[out] promise</code>: The JavaScript promise associated with the deferred object.</li>
5561 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5563 <h4><code>napi_resolve_deferred</code><span><a class="mark" href="#napi_resolve_deferred" id="napi_…
5568 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_resolve_deferred<…
5570 … napi_value resolution)</span>;</code> <button class="copy-button">copy</button></pre>
5572 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5573 <li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>
5574 <li><code>[in] resolution</code>: The value with which to resolve the promise.</li>
5580 <code>napi_create_promise()</code> and the deferred object returned from that call must
5583 <h4><code>napi_reject_deferred</code><span><a class="mark" href="#napi_reject_deferred" id="napi_re…
5588 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_reject_deferred</…
5590 … napi_value rejection)</span>;</code> <button class="copy-button">copy</button></pre>
5592 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5593 <li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>
5594 <li><code>[in] rejection</code>: The value with which to reject the promise.</li>
5600 <code>napi_create_promise()</code> and the deferred object returned from that call must
5603 <h4><code>napi_is_promise</code><span><a class="mark" href="#napi_is_promise" id="napi_is_promise">…
5608 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_is_promise</span>…
5610 …<span class="hljs-type">bool</span>* is_promise)</span>;</code> <button class="copy-button">copy</…
5612 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5613 <li><code>[in] value</code>: The value to examine</li>
5614 <li><code>[out] is_promise</code>: Flag indicating whether <code>promise</code> is a native promise
5620 <h4><code>napi_run_script</code><span><a class="mark" href="#napi_run_script" id="napi_run_script">…
5625 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_run_s…
5627 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
5629 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5630 <li><code>[in] script</code>: A JavaScript string containing the script to execute.</li>
5631 <li><code>[out] result</code>: The value resulting from having executed the script.</li>
5633 <p>This function executes a string of JavaScript code and returns its result with
5636 <li>Unlike <code>eval</code>, this function does not allow the script to access the current
5638 …odule-scope">module scope</a>, meaning that pseudo-globals such as <code>require</code> will not be
5640 <li>The script can access the <a href="globals.html">global scope</a>. Function and <code>var</code…
5641 in the script will be added to the <a href="globals.html#global"><code>global</code></a> object. Va…
5642 made using <code>let</code> and <code>const</code> will be visible globally, but will not be added
5643 to the <a href="globals.html#global"><code>global</code></a> object.</li>
5644 <li>The value of <code>this</code> is <a href="globals.html#global"><code>global</code></a> within …
5648 a specific <code>napi_env</code>.</p>
5649 <h4><code>napi_get_uv_event_loop</code><span><a class="mark" href="#napi_get_uv_event_loop" id="nap…
5654 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_get_u…
5655 …<span class="hljs-keyword">struct</span> uv_loop_s** loop)</span>;</code> <button class="copy-butt…
5657 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5658 <li><code>[out] loop</code>: The current libuv loop instance.</li>
5663 require a <code>napi_env</code>, <code>napi_value</code>, or <code>napi_ref</code> must not be call…
5670 <p>These APIs provide the type <code>napi_threadsafe_function</code> as well as APIs to
5672 <code>napi_create_threadsafe_function()</code> creates a persistent reference to a
5673 <code>napi_value</code> that holds a JavaScript function which can be called from multiple
5677 <p>Upon creation of a <code>napi_threadsafe_function</code> a <code>napi_finalize</code> callback c…
5681 threads e.g. by calling <code>uv_thread_join()</code>. <strong>Aside from the main loop thread,
5684 <p>The <code>context</code> given during the call to <code>napi_create_threadsafe_function()</code>…
5686 <code>napi_get_threadsafe_function_context()</code>.</p>
5688 <p><code>napi_call_threadsafe_function()</code> can be used for initiating a call into
5689 JavaScript. <code>napi_call_threadsafe_function()</code> accepts a parameter which controls
5690 whether the API behaves blockingly. If set to <code>napi_tsfn_nonblocking</code>, the API
5691 behaves non-blockingly, returning <code>napi_queue_full</code> if the queue was full,
5693 <code>napi_tsfn_blocking</code>, the API blocks until space becomes available in the queue.
5694 <code>napi_call_threadsafe_function()</code> never blocks if the thread-safe function was
5696 <p><code>napi_call_threadsafe_function()</code> should not be called with <code>napi_tsfn_blocking<…
5700 <code>call_js_cb</code> parameter. <code>call_js_cb</code> is invoked on the main thread once for e…
5702 <code>napi_call_threadsafe_function()</code>. If such a callback is not given, a default
5704 The <code>call_js_cb</code> callback receives the JavaScript function to call as a
5705 <code>napi_value</code> in its parameters, as well as the <code>void*</code> context pointer used w…
5706 creating the <code>napi_threadsafe_function</code>, and the next data pointer that was
5708 as <code>napi_call_function()</code> to call into JavaScript.</p>
5709 …>The callback may also be invoked with <code>env</code> and <code>call_js_cb</code> both set to <c…
5713 <p>It is not necessary to call into JavaScript via <code>napi_make_callback()</code> because
5714 Node-API runs <code>call_js_cb</code> in a context appropriate for callbacks.</p>
5720 <p>Threads can be added to and removed from a <code>napi_threadsafe_function</code> object
5722 threads upon creation, <code>napi_acquire_threadsafe_function</code> can be called to
5724 Similarly, <code>napi_release_threadsafe_function</code> can be called to indicate that an
5726 <p><code>napi_threadsafe_function</code> objects are destroyed when every thread which uses
5727 the object has called <code>napi_release_threadsafe_function()</code> or has received a
5728 return status of <code>napi_closing</code> in response to a call to
5729 <code>napi_call_threadsafe_function</code>. The queue is emptied before the
5730 <code>napi_threadsafe_function</code> is destroyed. <code>napi_release_threadsafe_function()</code>
5732 <code>napi_threadsafe_function</code>, because after the call completes, there is no
5733 guarantee that the <code>napi_threadsafe_function</code> is still allocated. For the same
5735 after receiving a return value of <code>napi_closing</code> in response to a call to
5736 <code>napi_call_threadsafe_function</code>. Data associated with the
5737 <code>napi_threadsafe_function</code> can be freed in its <code>napi_finalize</code> callback which
5738 was passed to <code>napi_create_threadsafe_function()</code>. The parameter
5739 <code>initial_thread_count</code> of <code>napi_create_threadsafe_function</code> marks the initial
5741 <code>napi_acquire_threadsafe_function</code> multiple times at creation.</p>
5742 <p>Once the number of threads making use of a <code>napi_threadsafe_function</code> reaches
5744 <code>napi_acquire_threadsafe_function()</code>. In fact, all subsequent API calls
5745 associated with it, except <code>napi_release_threadsafe_function()</code>, will return an
5746 error value of <code>napi_closing</code>.</p>
5747 <p>The thread-safe function can be "aborted" by giving a value of <code>napi_tsfn_abort</code>
5748 to <code>napi_release_threadsafe_function()</code>. This will cause all subsequent APIs
5750 <code>napi_release_threadsafe_function()</code> to return <code>napi_closing</code> even before its
5751 reference count reaches zero. In particular, <code>napi_call_threadsafe_function()</code>
5752 will return <code>napi_closing</code>, thus informing the threads that it is no longer
5755 of <code>napi_closing</code> from <code>napi_call_threadsafe_function()</code> a thread must not use
5763 prevent the event loop from exiting. The APIs <code>napi_ref_threadsafe_function</code> and
5764 <code>napi_unref_threadsafe_function</code> exist for this purpose.</p>
5765 <p>Neither does <code>napi_unref_threadsafe_function</code> mark the thread-safe functions as
5766 able to be destroyed nor does <code>napi_ref_threadsafe_function</code> prevent it from
5768 <h4><code>napi_create_threadsafe_function</code><span><a class="mark" href="#napi_create_threadsafe…
5774 <td><p>Made <code>func</code> parameter optional with custom <code>call_js_cb</code>.</p></td></tr>
5781 <pre><code class="language-c">NAPI_EXTERN napi_status
5792 … napi_threadsafe_function* result)</span>;</code> <button class="copy-button">copy</button></pre>
5794 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5795 <li><code>[in] func</code>: An optional JavaScript function to call from another thread. It
5796 must be provided if <code>NULL</code> is passed to <code>call_js_cb</code>.</li>
5797 <li><code>[in] async_resource</code>: An optional object associated with the async work that
5798 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5799 <li><code>[in] async_resource_name</code>: A JavaScript string to provide an identifier for
5801 by the <code>async_hooks</code> API.</li>
5802 <li><code>[in] max_queue_size</code>: Maximum size of the queue. <code>0</code> for no limit.</li>
5803 <li><code>[in] initial_thread_count</code>: The initial number of acquisitions, i.e. the
5806 <li><code>[in] thread_finalize_data</code>: Optional data to be passed to <code>thread_finalize_cb<…
5807 <li><code>[in] thread_finalize_cb</code>: Optional function to call when the
5808 <code>napi_threadsafe_function</code> is being destroyed.</li>
5809 <li><code>[in] context</code>: Optional data to attach to the resulting
5810 <code>napi_threadsafe_function</code>.</li>
5811 <li><code>[in] call_js_cb</code>: Optional callback which calls the JavaScript function in
5814 parameters and with <code>undefined</code> as its <code>this</code> value.
5815 <a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a> provi…
5816 <li><code>[out] result</code>: The asynchronous thread-safe JavaScript function.</li>
5821 <p>Experimental (<code>NAPI_EXPERIMENTAL</code> is defined):</p>
5822 <p>Uncaught exceptions thrown in <code>call_js_cb</code> are handled with the
5823 <a href="process.html#event-uncaughtexception"><code>'uncaughtException'</code></a> event, instead …
5826 <h4><code>napi_get_threadsafe_function_context</code><span><a class="mark" href="#napi_get_threadsa…
5831 <pre><code class="language-c">NAPI_EXTERN napi_status
5833 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5835 <li><code>[in] func</code>: The thread-safe function for which to retrieve the context.</li>
5836 <li><code>[out] result</code>: The location where to store the context.</li>
5838 <p>This API may be called from any thread which makes use of <code>func</code>.</p>
5839 <h4><code>napi_call_threadsafe_function</code><span><a class="mark" href="#napi_call_threadsafe_fun…
5845 <td><p>Support for <code>napi_would_deadlock</code> has been reverted.</p></td></tr>
5847 <td><p>Return <code>napi_would_deadlock</code> when called with <code>napi_tsfn_blocking</code> fro…
5854 <pre><code class="language-c">NAPI_EXTERN napi_status
5857 …napi_threadsafe_function_call_mode is_blocking)</span>;</code> <button class="copy-button">copy</b…
5859 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to invoke.</li>
5860 <li><code>[in] data</code>: Data to send into JavaScript via the callback <code>call_js_cb</code>
5862 <li><code>[in] is_blocking</code>: Flag whose value can be either <code>napi_tsfn_blocking</code> to
5864 <code>napi_tsfn_nonblocking</code> to indicate that the call should return immediately
5865 with a status of <code>napi_queue_full</code> whenever the queue is full.</li>
5867 <p>This API should not be called with <code>napi_tsfn_blocking</code> from a JavaScript
5870 <p>This API will return <code>napi_closing</code> if <code>napi_release_threadsafe_function()</code…
5871 called with <code>abort</code> set to <code>napi_tsfn_abort</code> from any thread. The value is on…
5872 added to the queue if the API returns <code>napi_ok</code>.</p>
5873 <p>This API may be called from any thread which makes use of <code>func</code>.</p>
5874 <h4><code>napi_acquire_threadsafe_function</code><span><a class="mark" href="#napi_acquire_threadsa…
5879 <pre><code class="language-c">NAPI_EXTERN napi_status
5880 …</span><span class="hljs-params">(napi_threadsafe_function func)</span>;</code> <button class="cop…
5882 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to start making
5885 <p>A thread should call this API before passing <code>func</code> to any other thread-safe
5886 function APIs to indicate that it will be making use of <code>func</code>. This prevents
5887 <code>func</code> from being destroyed when all other threads have stopped making use of
5889 <p>This API may be called from any thread which will start making use of <code>func</code>.</p>
5890 <h4><code>napi_release_threadsafe_function</code><span><a class="mark" href="#napi_release_threadsa…
5895 <pre><code class="language-c">NAPI_EXTERN napi_status
5897 …napi_threadsafe_function_release_mode mode)</span>;</code> <button class="copy-button">copy</butto…
5899 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function whose reference
5901 <li><code>[in] mode</code>: Flag whose value can be either <code>napi_tsfn_release</code> to indica…
5903 function, or <code>napi_tsfn_abort</code> to indicate that in addition to the current
5905 function. If set to <code>napi_tsfn_abort</code>, further calls to
5906 <code>napi_call_threadsafe_function()</code> will return <code>napi_closing</code>, and no further
5909 …hread should call this API when it stops making use of <code>func</code>. Passing <code>func</code>
5911 <code>func</code> may have been destroyed.</p>
5912 <p>This API may be called from any thread which will stop making use of <code>func</code>.</p>
5913 <h4><code>napi_ref_threadsafe_function</code><span><a class="mark" href="#napi_ref_threadsafe_funct…
5918 <pre><code class="language-c">NAPI_EXTERN napi_status
5919 …s-params">(node_api_nogc_env env, napi_threadsafe_function func)</span>;</code> <button class="cop…
5921 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5922 <li><code>[in] func</code>: The thread-safe function to reference.</li>
5925 …exit until <code>func</code> has been destroyed. Similar to <a href="https://docs.libuv.org/en/v1.…
5927 <p>Neither does <code>napi_unref_threadsafe_function</code> mark the thread-safe functions as
5928 able to be destroyed nor does <code>napi_ref_threadsafe_function</code> prevent it from
5929 being destroyed. <code>napi_acquire_threadsafe_function</code> and
5930 <code>napi_release_threadsafe_function</code> are available for that purpose.</p>
5932 <h4><code>napi_unref_threadsafe_function</code><span><a class="mark" href="#napi_unref_threadsafe_f…
5937 <pre><code class="language-c">NAPI_EXTERN napi_status
5938 …s-params">(node_api_nogc_env env, napi_threadsafe_function func)</span>;</code> <button class="cop…
5940 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5941 <li><code>[in] func</code>: The thread-safe function to unreference.</li>
5944 …exit before <code>func</code> is destroyed. Similar to <a href="https://docs.libuv.org/en/v1.x/han…
5948 <h4><code>node_api_get_module_file_name</code><span><a class="mark" href="#node_api_get_module_file…
5953 <pre><code class="language-c">NAPI_EXTERN napi_status
5955 </code> <button class="copy-button">copy</button></pre>
5957 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5958 <li><code>[out] result</code>: A URL containing the absolute path of the
5960 file system it will start with <code>file://</code>. The string is null-terminated and
5961 owned by <code>env</code> and must thus not be modified or freed.</li>
5963 <p><code>result</code> may be an empty string if the add-on loading process fails to establish