• Home
  • Raw
  • Download

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><a href="#napi_value"><code>napi_value</code></a></li>
157 <li><a href="#napi_threadsafe_function"><code>napi_threadsafe_function</code></a></li>
158 …i><a href="#napi_threadsafe_function_release_mode"><code>napi_threadsafe_function_release_mode</co…
159 <li><a href="#napi_threadsafe_function_call_mode"><code>napi_threadsafe_function_call_mode</code></…
162 <li><a href="#napi_handle_scope"><code>napi_handle_scope</code></a></li>
163 <li><a href="#napi_escapable_handle_scope"><code>napi_escapable_handle_scope</code></a></li>
164 <li><a href="#napi_ref"><code>napi_ref</code></a></li>
165 <li><a href="#napi_type_tag"><code>napi_type_tag</code></a></li>
166 <li><a href="#napi_async_cleanup_hook_handle"><code>napi_async_cleanup_hook_handle</code></a></li>
171 <li><a href="#napi_callback_info"><code>napi_callback_info</code></a></li>
172 <li><a href="#napi_callback"><code>napi_callback</code></a></li>
173 <li><a href="#napi_finalize"><code>napi_finalize</code></a></li>
174 <li><a href="#napi_async_execute_callback"><code>napi_async_execute_callback</code></a></li>
175 <li><a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code></a></li>
176 <li><a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a></…
177 <li><a href="#napi_cleanup_hook"><code>napi_cleanup_hook</code></a></li>
178 <li><a href="#napi_async_cleanup_hook"><code>napi_async_cleanup_hook</code></a></li>
187 <li><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a></li>
192 <li><a href="#napi_throw"><code>napi_throw</code></a></li>
193 <li><a href="#napi_throw_error"><code>napi_throw_error</code></a></li>
194 <li><a href="#napi_throw_type_error"><code>napi_throw_type_error</code></a></li>
195 <li><a href="#napi_throw_range_error"><code>napi_throw_range_error</code></a></li>
196 <li><a href="#node_api_throw_syntax_error"><code>node_api_throw_syntax_error</code></a></li>
197 <li><a href="#napi_is_error"><code>napi_is_error</code></a></li>
198 <li><a href="#napi_create_error"><code>napi_create_error</code></a></li>
199 <li><a href="#napi_create_type_error"><code>napi_create_type_error</code></a></li>
200 <li><a href="#napi_create_range_error"><code>napi_create_range_error</code></a></li>
201 <li><a href="#node_api_create_syntax_error"><code>node_api_create_syntax_error</code></a></li>
202 <li><a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></a>…
203 <li><a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a></li>
204 <li><a href="#napi_fatal_exception"><code>napi_fatal_exception</code></a></li>
209 <li><a href="#napi_fatal_error"><code>napi_fatal_error</code></a></li>
218 <li><a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a></li>
219 <li><a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a></li>
220 <li><a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a></…
221 <li><a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>…
222 <li><a href="#napi_escape_handle"><code>napi_escape_handle</code></a></li>
227 <li><a href="#napi_create_reference"><code>napi_create_reference</code></a></li>
228 <li><a href="#napi_delete_reference"><code>napi_delete_reference</code></a></li>
229 <li><a href="#napi_reference_ref"><code>napi_reference_ref</code></a></li>
230 <li><a href="#napi_reference_unref"><code>napi_reference_unref</code></a></li>
231 <li><a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a></li>
236 <li><a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a></li>
237 <li><a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code></a></li>
238 <li><a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a></li>
239 <li><a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a></li>
250 <li><a href="#napi_key_collection_mode"><code>napi_key_collection_mode</code></a></li>
251 <li><a href="#napi_key_filter"><code>napi_key_filter</code></a></li>
252 <li><a href="#napi_key_conversion"><code>napi_key_conversion</code></a></li>
253 <li><a href="#napi_valuetype"><code>napi_valuetype</code></a></li>
254 <li><a href="#napi_typedarray_type"><code>napi_typedarray_type</code></a></li>
259 <li><a href="#napi_create_array"><code>napi_create_array</code></a></li>
260 <li><a href="#napi_create_array_with_length"><code>napi_create_array_with_length</code></a></li>
261 <li><a href="#napi_create_arraybuffer"><code>napi_create_arraybuffer</code></a></li>
262 <li><a href="#napi_create_buffer"><code>napi_create_buffer</code></a></li>
263 <li><a href="#napi_create_buffer_copy"><code>napi_create_buffer_copy</code></a></li>
264 <li><a href="#napi_create_date"><code>napi_create_date</code></a></li>
265 <li><a href="#napi_create_external"><code>napi_create_external</code></a></li>
266 <li><a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a></…
267 <li><a href="#napi_create_external_buffer"><code>napi_create_external_buffer</code></a></li>
268 <li><a href="#napi_create_object"><code>napi_create_object</code></a></li>
269 <li><a href="#napi_create_symbol"><code>napi_create_symbol</code></a></li>
270 <li><a href="#node_api_symbol_for"><code>node_api_symbol_for</code></a></li>
271 <li><a href="#napi_create_typedarray"><code>napi_create_typedarray</code></a></li>
272 <li><a href="#napi_create_dataview"><code>napi_create_dataview</code></a></li>
277 <li><a href="#napi_create_int32"><code>napi_create_int32</code></a></li>
278 <li><a href="#napi_create_uint32"><code>napi_create_uint32</code></a></li>
279 <li><a href="#napi_create_int64"><code>napi_create_int64</code></a></li>
280 <li><a href="#napi_create_double"><code>napi_create_double</code></a></li>
281 <li><a href="#napi_create_bigint_int64"><code>napi_create_bigint_int64</code></a></li>
282 <li><a href="#napi_create_bigint_uint64"><code>napi_create_bigint_uint64</code></a></li>
283 <li><a href="#napi_create_bigint_words"><code>napi_create_bigint_words</code></a></li>
284 <li><a href="#napi_create_string_latin1"><code>napi_create_string_latin1</code></a></li>
285 …><a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
286 <li><a href="#napi_create_string_utf16"><code>napi_create_string_utf16</code></a></li>
287 …"><a href="#node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</co…
288 <li><a href="#napi_create_string_utf8"><code>napi_create_string_utf8</code></a></li>
293 <li><a href="#napi_get_array_length"><code>napi_get_array_length</code></a></li>
294 <li><a href="#napi_get_arraybuffer_info"><code>napi_get_arraybuffer_info</code></a></li>
295 <li><a href="#napi_get_buffer_info"><code>napi_get_buffer_info</code></a></li>
296 <li><a href="#napi_get_prototype"><code>napi_get_prototype</code></a></li>
297 <li><a href="#napi_get_typedarray_info"><code>napi_get_typedarray_info</code></a></li>
298 <li><a href="#napi_get_dataview_info"><code>napi_get_dataview_info</code></a></li>
299 <li><a href="#napi_get_date_value"><code>napi_get_date_value</code></a></li>
300 <li><a href="#napi_get_value_bool"><code>napi_get_value_bool</code></a></li>
301 <li><a href="#napi_get_value_double"><code>napi_get_value_double</code></a></li>
302 <li><a href="#napi_get_value_bigint_int64"><code>napi_get_value_bigint_int64</code></a></li>
303 <li><a href="#napi_get_value_bigint_uint64"><code>napi_get_value_bigint_uint64</code></a></li>
304 <li><a href="#napi_get_value_bigint_words"><code>napi_get_value_bigint_words</code></a></li>
305 <li><a href="#napi_get_value_external"><code>napi_get_value_external</code></a></li>
306 <li><a href="#napi_get_value_int32"><code>napi_get_value_int32</code></a></li>
307 <li><a href="#napi_get_value_int64"><code>napi_get_value_int64</code></a></li>
308 <li><a href="#napi_get_value_string_latin1"><code>napi_get_value_string_latin1</code></a></li>
309 <li><a href="#napi_get_value_string_utf8"><code>napi_get_value_string_utf8</code></a></li>
310 <li><a href="#napi_get_value_string_utf16"><code>napi_get_value_string_utf16</code></a></li>
311 <li><a href="#napi_get_value_uint32"><code>napi_get_value_uint32</code></a></li>
316 <li><a href="#napi_get_boolean"><code>napi_get_boolean</code></a></li>
317 <li><a href="#napi_get_global"><code>napi_get_global</code></a></li>
318 <li><a href="#napi_get_null"><code>napi_get_null</code></a></li>
319 <li><a href="#napi_get_undefined"><code>napi_get_undefined</code></a></li>
326 <li><a href="#napi_coerce_to_bool"><code>napi_coerce_to_bool</code></a></li>
327 <li><a href="#napi_coerce_to_number"><code>napi_coerce_to_number</code></a></li>
328 <li><a href="#napi_coerce_to_object"><code>napi_coerce_to_object</code></a></li>
329 <li><a href="#napi_coerce_to_string"><code>napi_coerce_to_string</code></a></li>
330 <li><a href="#napi_typeof"><code>napi_typeof</code></a></li>
331 <li><a href="#napi_instanceof"><code>napi_instanceof</code></a></li>
332 <li><a href="#napi_is_array"><code>napi_is_array</code></a></li>
333 <li><a href="#napi_is_arraybuffer"><code>napi_is_arraybuffer</code></a></li>
334 <li><a href="#napi_is_buffer"><code>napi_is_buffer</code></a></li>
335 <li><a href="#napi_is_date"><code>napi_is_date</code></a></li>
336 <li><a href="#napi_is_error_1"><code>napi_is_error</code></a></li>
337 <li><a href="#napi_is_typedarray"><code>napi_is_typedarray</code></a></li>
338 <li><a href="#napi_is_dataview"><code>napi_is_dataview</code></a></li>
339 <li><a href="#napi_strict_equals"><code>napi_strict_equals</code></a></li>
340 <li><a href="#napi_detach_arraybuffer"><code>napi_detach_arraybuffer</code></a></li>
341 <li><a href="#napi_is_detached_arraybuffer"><code>napi_is_detached_arraybuffer</code></a></li>
348 <li><a href="#napi_property_attributes"><code>napi_property_attributes</code></a></li>
349 <li><a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a></li>
354 <li><a href="#napi_get_property_names"><code>napi_get_property_names</code></a></li>
355 <li><a href="#napi_get_all_property_names"><code>napi_get_all_property_names</code></a></li>
356 <li><a href="#napi_set_property"><code>napi_set_property</code></a></li>
357 <li><a href="#napi_get_property"><code>napi_get_property</code></a></li>
358 <li><a href="#napi_has_property"><code>napi_has_property</code></a></li>
359 <li><a href="#napi_delete_property"><code>napi_delete_property</code></a></li>
360 <li><a href="#napi_has_own_property"><code>napi_has_own_property</code></a></li>
361 <li><a href="#napi_set_named_property"><code>napi_set_named_property</code></a></li>
362 <li><a href="#napi_get_named_property"><code>napi_get_named_property</code></a></li>
363 <li><a href="#napi_has_named_property"><code>napi_has_named_property</code></a></li>
364 <li><a href="#napi_set_element"><code>napi_set_element</code></a></li>
365 <li><a href="#napi_get_element"><code>napi_get_element</code></a></li>
366 <li><a href="#napi_has_element"><code>napi_has_element</code></a></li>
367 <li><a href="#napi_delete_element"><code>napi_delete_element</code></a></li>
368 <li><a href="#napi_define_properties"><code>napi_define_properties</code></a></li>
369 <li><a href="#napi_object_freeze"><code>napi_object_freeze</code></a></li>
370 <li><a href="#napi_object_seal"><code>napi_object_seal</code></a></li>
377 <li><a href="#napi_call_function"><code>napi_call_function</code></a></li>
378 <li><a href="#napi_create_function"><code>napi_create_function</code></a></li>
379 <li><a href="#napi_get_cb_info"><code>napi_get_cb_info</code></a></li>
380 <li><a href="#napi_get_new_target"><code>napi_get_new_target</code></a></li>
381 <li><a href="#napi_new_instance"><code>napi_new_instance</code></a></li>
386 <li><a href="#napi_define_class"><code>napi_define_class</code></a></li>
387 <li><a href="#napi_wrap"><code>napi_wrap</code></a></li>
388 <li><a href="#napi_unwrap"><code>napi_unwrap</code></a></li>
389 <li><a href="#napi_remove_wrap"><code>napi_remove_wrap</code></a></li>
390 <li><a href="#napi_type_tag_object"><code>napi_type_tag_object</code></a></li>
391 <li><a href="#napi_check_object_type_tag"><code>napi_check_object_type_tag</code></a></li>
392 <li><a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a></li>
397 <li><a href="#napi_create_async_work"><code>napi_create_async_work</code></a></li>
398 <li><a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a></li>
399 <li><a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a></li>
400 <li><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a></li>
405 <li><a href="#napi_async_init"><code>napi_async_init</code></a></li>
406 <li><a href="#napi_async_destroy"><code>napi_async_destroy</code></a></li>
407 <li><a href="#napi_make_callback"><code>napi_make_callback</code></a></li>
408 <li><a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a></li>
409 <li><a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a></li>
414 <li><a href="#napi_get_node_version"><code>napi_get_node_version</code></a></li>
415 <li><a href="#napi_get_version"><code>napi_get_version</code></a></li>
420 <li><a href="#napi_adjust_external_memory"><code>napi_adjust_external_memory</code></a></li>
425 <li><a href="#napi_create_promise"><code>napi_create_promise</code></a></li>
426 <li><a href="#napi_resolve_deferred"><code>napi_resolve_deferred</code></a></li>
427 <li><a href="#napi_reject_deferred"><code>napi_reject_deferred</code></a></li>
428 <li><a href="#napi_is_promise"><code>napi_is_promise</code></a></li>
433 <li><a href="#napi_run_script"><code>napi_run_script</code></a></li>
438 <li><a href="#napi_get_uv_event_loop"><code>napi_get_uv_event_loop</code></a></li>
446 <li><a href="#napi_create_threadsafe_function"><code>napi_create_threadsafe_function</code></a></li>
447 <li><a href="#napi_get_threadsafe_function_context"><code>napi_get_threadsafe_function_context</cod…
448 <li><a href="#napi_call_threadsafe_function"><code>napi_call_threadsafe_function</code></a></li>
449 <li><a href="#napi_acquire_threadsafe_function"><code>napi_acquire_threadsafe_function</code></a></…
450 <li><a href="#napi_release_threadsafe_function"><code>napi_release_threadsafe_function</code></a></…
451 <li><a href="#napi_ref_threadsafe_function"><code>napi_ref_threadsafe_function</code></a></li>
452 <li><a href="#napi_unref_threadsafe_function"><code>napi_unref_threadsafe_function</code></a></li>
457 <li><a href="#node_api_get_module_file_name"><code>node_api_get_module_file_name</code></a></li>
512 <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
546 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
619 <li><a href="#napi_set_instance_data"><code>napi_set_instance_data</code></a></li>
620 <li><a href="#napi_get_instance_data"><code>napi_get_instance_data</code></a></li>
625 <li><a href="#napi_status"><code>napi_status</code></a></li>
626 <li><a href="#napi_extended_error_info"><code>napi_extended_error_info</code></a></li>
627 <li><a href="#napi_env"><code>napi_env</code></a></li>
628 <li><a href="#napi_value"><code>napi_value</code></a></li>
629 <li><a href="#napi_threadsafe_function"><code>napi_threadsafe_function</code></a></li>
630 …i><a href="#napi_threadsafe_function_release_mode"><code>napi_threadsafe_function_release_mode</co…
631 <li><a href="#napi_threadsafe_function_call_mode"><code>napi_threadsafe_function_call_mode</code></…
634 <li><a href="#napi_handle_scope"><code>napi_handle_scope</code></a></li>
635 <li><a href="#napi_escapable_handle_scope"><code>napi_escapable_handle_scope</code></a></li>
636 <li><a href="#napi_ref"><code>napi_ref</code></a></li>
637 <li><a href="#napi_type_tag"><code>napi_type_tag</code></a></li>
638 <li><a href="#napi_async_cleanup_hook_handle"><code>napi_async_cleanup_hook_handle</code></a></li>
643 <li><a href="#napi_callback_info"><code>napi_callback_info</code></a></li>
644 <li><a href="#napi_callback"><code>napi_callback</code></a></li>
645 <li><a href="#napi_finalize"><code>napi_finalize</code></a></li>
646 <li><a href="#napi_async_execute_callback"><code>napi_async_execute_callback</code></a></li>
647 <li><a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code></a></li>
648 <li><a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a></…
649 <li><a href="#napi_cleanup_hook"><code>napi_cleanup_hook</code></a></li>
650 <li><a href="#napi_async_cleanup_hook"><code>napi_async_cleanup_hook</code></a></li>
659 <li><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a></li>
664 <li><a href="#napi_throw"><code>napi_throw</code></a></li>
665 <li><a href="#napi_throw_error"><code>napi_throw_error</code></a></li>
666 <li><a href="#napi_throw_type_error"><code>napi_throw_type_error</code></a></li>
667 <li><a href="#napi_throw_range_error"><code>napi_throw_range_error</code></a></li>
668 <li><a href="#node_api_throw_syntax_error"><code>node_api_throw_syntax_error</code></a></li>
669 <li><a href="#napi_is_error"><code>napi_is_error</code></a></li>
670 <li><a href="#napi_create_error"><code>napi_create_error</code></a></li>
671 <li><a href="#napi_create_type_error"><code>napi_create_type_error</code></a></li>
672 <li><a href="#napi_create_range_error"><code>napi_create_range_error</code></a></li>
673 <li><a href="#node_api_create_syntax_error"><code>node_api_create_syntax_error</code></a></li>
674 <li><a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></a>…
675 <li><a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a></li>
676 <li><a href="#napi_fatal_exception"><code>napi_fatal_exception</code></a></li>
681 <li><a href="#napi_fatal_error"><code>napi_fatal_error</code></a></li>
690 <li><a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a></li>
691 <li><a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a></li>
692 <li><a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a></…
693 <li><a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>…
694 <li><a href="#napi_escape_handle"><code>napi_escape_handle</code></a></li>
699 <li><a href="#napi_create_reference"><code>napi_create_reference</code></a></li>
700 <li><a href="#napi_delete_reference"><code>napi_delete_reference</code></a></li>
701 <li><a href="#napi_reference_ref"><code>napi_reference_ref</code></a></li>
702 <li><a href="#napi_reference_unref"><code>napi_reference_unref</code></a></li>
703 <li><a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a></li>
708 <li><a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a></li>
709 <li><a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code></a></li>
710 <li><a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a></li>
711 <li><a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a></li>
722 <li><a href="#napi_key_collection_mode"><code>napi_key_collection_mode</code></a></li>
723 <li><a href="#napi_key_filter"><code>napi_key_filter</code></a></li>
724 <li><a href="#napi_key_conversion"><code>napi_key_conversion</code></a></li>
725 <li><a href="#napi_valuetype"><code>napi_valuetype</code></a></li>
726 <li><a href="#napi_typedarray_type"><code>napi_typedarray_type</code></a></li>
731 <li><a href="#napi_create_array"><code>napi_create_array</code></a></li>
732 <li><a href="#napi_create_array_with_length"><code>napi_create_array_with_length</code></a></li>
733 <li><a href="#napi_create_arraybuffer"><code>napi_create_arraybuffer</code></a></li>
734 <li><a href="#napi_create_buffer"><code>napi_create_buffer</code></a></li>
735 <li><a href="#napi_create_buffer_copy"><code>napi_create_buffer_copy</code></a></li>
736 <li><a href="#napi_create_date"><code>napi_create_date</code></a></li>
737 <li><a href="#napi_create_external"><code>napi_create_external</code></a></li>
738 <li><a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a></…
739 <li><a href="#napi_create_external_buffer"><code>napi_create_external_buffer</code></a></li>
740 <li><a href="#napi_create_object"><code>napi_create_object</code></a></li>
741 <li><a href="#napi_create_symbol"><code>napi_create_symbol</code></a></li>
742 <li><a href="#node_api_symbol_for"><code>node_api_symbol_for</code></a></li>
743 <li><a href="#napi_create_typedarray"><code>napi_create_typedarray</code></a></li>
744 <li><a href="#napi_create_dataview"><code>napi_create_dataview</code></a></li>
749 <li><a href="#napi_create_int32"><code>napi_create_int32</code></a></li>
750 <li><a href="#napi_create_uint32"><code>napi_create_uint32</code></a></li>
751 <li><a href="#napi_create_int64"><code>napi_create_int64</code></a></li>
752 <li><a href="#napi_create_double"><code>napi_create_double</code></a></li>
753 <li><a href="#napi_create_bigint_int64"><code>napi_create_bigint_int64</code></a></li>
754 <li><a href="#napi_create_bigint_uint64"><code>napi_create_bigint_uint64</code></a></li>
755 <li><a href="#napi_create_bigint_words"><code>napi_create_bigint_words</code></a></li>
756 <li><a href="#napi_create_string_latin1"><code>napi_create_string_latin1</code></a></li>
757 …><a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
758 <li><a href="#napi_create_string_utf16"><code>napi_create_string_utf16</code></a></li>
759 …"><a href="#node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</co…
760 <li><a href="#napi_create_string_utf8"><code>napi_create_string_utf8</code></a></li>
765 <li><a href="#napi_get_array_length"><code>napi_get_array_length</code></a></li>
766 <li><a href="#napi_get_arraybuffer_info"><code>napi_get_arraybuffer_info</code></a></li>
767 <li><a href="#napi_get_buffer_info"><code>napi_get_buffer_info</code></a></li>
768 <li><a href="#napi_get_prototype"><code>napi_get_prototype</code></a></li>
769 <li><a href="#napi_get_typedarray_info"><code>napi_get_typedarray_info</code></a></li>
770 <li><a href="#napi_get_dataview_info"><code>napi_get_dataview_info</code></a></li>
771 <li><a href="#napi_get_date_value"><code>napi_get_date_value</code></a></li>
772 <li><a href="#napi_get_value_bool"><code>napi_get_value_bool</code></a></li>
773 <li><a href="#napi_get_value_double"><code>napi_get_value_double</code></a></li>
774 <li><a href="#napi_get_value_bigint_int64"><code>napi_get_value_bigint_int64</code></a></li>
775 <li><a href="#napi_get_value_bigint_uint64"><code>napi_get_value_bigint_uint64</code></a></li>
776 <li><a href="#napi_get_value_bigint_words"><code>napi_get_value_bigint_words</code></a></li>
777 <li><a href="#napi_get_value_external"><code>napi_get_value_external</code></a></li>
778 <li><a href="#napi_get_value_int32"><code>napi_get_value_int32</code></a></li>
779 <li><a href="#napi_get_value_int64"><code>napi_get_value_int64</code></a></li>
780 <li><a href="#napi_get_value_string_latin1"><code>napi_get_value_string_latin1</code></a></li>
781 <li><a href="#napi_get_value_string_utf8"><code>napi_get_value_string_utf8</code></a></li>
782 <li><a href="#napi_get_value_string_utf16"><code>napi_get_value_string_utf16</code></a></li>
783 <li><a href="#napi_get_value_uint32"><code>napi_get_value_uint32</code></a></li>
788 <li><a href="#napi_get_boolean"><code>napi_get_boolean</code></a></li>
789 <li><a href="#napi_get_global"><code>napi_get_global</code></a></li>
790 <li><a href="#napi_get_null"><code>napi_get_null</code></a></li>
791 <li><a href="#napi_get_undefined"><code>napi_get_undefined</code></a></li>
798 <li><a href="#napi_coerce_to_bool"><code>napi_coerce_to_bool</code></a></li>
799 <li><a href="#napi_coerce_to_number"><code>napi_coerce_to_number</code></a></li>
800 <li><a href="#napi_coerce_to_object"><code>napi_coerce_to_object</code></a></li>
801 <li><a href="#napi_coerce_to_string"><code>napi_coerce_to_string</code></a></li>
802 <li><a href="#napi_typeof"><code>napi_typeof</code></a></li>
803 <li><a href="#napi_instanceof"><code>napi_instanceof</code></a></li>
804 <li><a href="#napi_is_array"><code>napi_is_array</code></a></li>
805 <li><a href="#napi_is_arraybuffer"><code>napi_is_arraybuffer</code></a></li>
806 <li><a href="#napi_is_buffer"><code>napi_is_buffer</code></a></li>
807 <li><a href="#napi_is_date"><code>napi_is_date</code></a></li>
808 <li><a href="#napi_is_error_1"><code>napi_is_error</code></a></li>
809 <li><a href="#napi_is_typedarray"><code>napi_is_typedarray</code></a></li>
810 <li><a href="#napi_is_dataview"><code>napi_is_dataview</code></a></li>
811 <li><a href="#napi_strict_equals"><code>napi_strict_equals</code></a></li>
812 <li><a href="#napi_detach_arraybuffer"><code>napi_detach_arraybuffer</code></a></li>
813 <li><a href="#napi_is_detached_arraybuffer"><code>napi_is_detached_arraybuffer</code></a></li>
820 <li><a href="#napi_property_attributes"><code>napi_property_attributes</code></a></li>
821 <li><a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a></li>
826 <li><a href="#napi_get_property_names"><code>napi_get_property_names</code></a></li>
827 <li><a href="#napi_get_all_property_names"><code>napi_get_all_property_names</code></a></li>
828 <li><a href="#napi_set_property"><code>napi_set_property</code></a></li>
829 <li><a href="#napi_get_property"><code>napi_get_property</code></a></li>
830 <li><a href="#napi_has_property"><code>napi_has_property</code></a></li>
831 <li><a href="#napi_delete_property"><code>napi_delete_property</code></a></li>
832 <li><a href="#napi_has_own_property"><code>napi_has_own_property</code></a></li>
833 <li><a href="#napi_set_named_property"><code>napi_set_named_property</code></a></li>
834 <li><a href="#napi_get_named_property"><code>napi_get_named_property</code></a></li>
835 <li><a href="#napi_has_named_property"><code>napi_has_named_property</code></a></li>
836 <li><a href="#napi_set_element"><code>napi_set_element</code></a></li>
837 <li><a href="#napi_get_element"><code>napi_get_element</code></a></li>
838 <li><a href="#napi_has_element"><code>napi_has_element</code></a></li>
839 <li><a href="#napi_delete_element"><code>napi_delete_element</code></a></li>
840 <li><a href="#napi_define_properties"><code>napi_define_properties</code></a></li>
841 <li><a href="#napi_object_freeze"><code>napi_object_freeze</code></a></li>
842 <li><a href="#napi_object_seal"><code>napi_object_seal</code></a></li>
849 <li><a href="#napi_call_function"><code>napi_call_function</code></a></li>
850 <li><a href="#napi_create_function"><code>napi_create_function</code></a></li>
851 <li><a href="#napi_get_cb_info"><code>napi_get_cb_info</code></a></li>
852 <li><a href="#napi_get_new_target"><code>napi_get_new_target</code></a></li>
853 <li><a href="#napi_new_instance"><code>napi_new_instance</code></a></li>
858 <li><a href="#napi_define_class"><code>napi_define_class</code></a></li>
859 <li><a href="#napi_wrap"><code>napi_wrap</code></a></li>
860 <li><a href="#napi_unwrap"><code>napi_unwrap</code></a></li>
861 <li><a href="#napi_remove_wrap"><code>napi_remove_wrap</code></a></li>
862 <li><a href="#napi_type_tag_object"><code>napi_type_tag_object</code></a></li>
863 <li><a href="#napi_check_object_type_tag"><code>napi_check_object_type_tag</code></a></li>
864 <li><a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a></li>
869 <li><a href="#napi_create_async_work"><code>napi_create_async_work</code></a></li>
870 <li><a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a></li>
871 <li><a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a></li>
872 <li><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a></li>
877 <li><a href="#napi_async_init"><code>napi_async_init</code></a></li>
878 <li><a href="#napi_async_destroy"><code>napi_async_destroy</code></a></li>
879 <li><a href="#napi_make_callback"><code>napi_make_callback</code></a></li>
880 <li><a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a></li>
881 <li><a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a></li>
886 <li><a href="#napi_get_node_version"><code>napi_get_node_version</code></a></li>
887 <li><a href="#napi_get_version"><code>napi_get_version</code></a></li>
892 <li><a href="#napi_adjust_external_memory"><code>napi_adjust_external_memory</code></a></li>
897 <li><a href="#napi_create_promise"><code>napi_create_promise</code></a></li>
898 <li><a href="#napi_resolve_deferred"><code>napi_resolve_deferred</code></a></li>
899 <li><a href="#napi_reject_deferred"><code>napi_reject_deferred</code></a></li>
900 <li><a href="#napi_is_promise"><code>napi_is_promise</code></a></li>
905 <li><a href="#napi_run_script"><code>napi_run_script</code></a></li>
910 <li><a href="#napi_get_uv_event_loop"><code>napi_get_uv_event_loop</code></a></li>
918 <li><a href="#napi_create_threadsafe_function"><code>napi_create_threadsafe_function</code></a></li>
919 <li><a href="#napi_get_threadsafe_function_context"><code>napi_get_threadsafe_function_context</cod…
920 <li><a href="#napi_call_threadsafe_function"><code>napi_call_threadsafe_function</code></a></li>
921 <li><a href="#napi_acquire_threadsafe_function"><code>napi_acquire_threadsafe_function</code></a></…
922 <li><a href="#napi_release_threadsafe_function"><code>napi_release_threadsafe_function</code></a></…
923 <li><a href="#napi_ref_threadsafe_function"><code>napi_ref_threadsafe_function</code></a></li>
924 <li><a href="#napi_unref_threadsafe_function"><code>napi_unref_threadsafe_function</code></a></li>
929 <li><a href="#node_api_get_module_file_name"><code>node_api_get_module_file_name</code></a></li>
950 the native code. Instead of using the V8 or <a href="https://github.com/nodejs/nan">Native Abstract…
957 <li>All Node-API calls return a status code of type <code>napi_status</code>. This
961 <code>napi_value</code>.</li>
962 <li>In case of an error status code, additional information can be obtained
963 using <code>napi_get_last_error_info</code>. More information can be found in the error
969 …r module called <a href="https://github.com/nodejs/node-addon-api"><code>node-addon-api</code></a>.
971 with <code>node-addon-api</code> will depend on the symbols for the Node-API C-based
972 functions exported by Node.js. <code>node-addon-api</code> is a more
973 efficient way to write code that calls Node-API. Take, for example, the
974 following <code>node-addon-api</code> code. The first section shows the
975 <code>node-addon-api</code> code and the second section shows what actually gets
977 <pre><code class="language-cpp">Object obj = Object::<span class="hljs-built_in">New</span>(env);
978 …"hljs-built_in">New</span>(env, <span class="hljs-string">"bar"</span>);</code> <button class="cop…
979 <pre><code class="language-cpp">napi_status status;
997 }</code> <button class="copy-button">copy</button></pre>
1000 <p>When using <code>node-addon-api</code> instead of the C APIs, start with the API <a href="https:…
1001 for <code>node-addon-api</code>.</p>
1004 Node-API and <code>node-addon-api</code>. Additional media resources can be found on the
1014 <pre><code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> …
1017 …/span> <span class="hljs-string">&#x3C;node_object_wrap.h></span></span></code> <button class="cop…
1021 …<code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <spa…
1025 …<code class="language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <spa…
1030code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span c…
1037 requires a toolchain that can compile C and C++ code into a binary. In
1047 <pre><code class="language-bash">xcode-select --install</code> <button class="copy-button">copy</bu…
1051 <pre><code class="language-bash">npm install --global windows-build-tools</code> <button class="cop…
1091 …<a href="https://github.com/nodejs/node/blob/HEAD/src/node_api.h"><code>node_api.h</code></a> which
1093code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span c…
1094 <p>This will opt into the default <code>NAPI_VERSION</code> for the given release of Node.js.
1097 <pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">define</span> NAP…
1098 …include</span> <span class="hljs-string">&#x3C;node_api.h></span></span></code> <button class="cop…
1102 <pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">define</span> NAP…
1103 …include</span> <span class="hljs-string">&#x3C;node_api.h></span></span></code> <button class="cop…
1105 available to the module code.</p>
1217 <p>Each API documented for Node-API will have a header named <code>added in:</code>, and APIs
1218 which are stable will have the additional header <code>Node-API version:</code>.
1220 the Node-API version shown in <code>Node-API version:</code> or higher.
1222 <code>Node-API version:</code> listed or if there is no <code>Node-API version:</code> listed,
1224 <code>#define NAPI_EXPERIMENTAL</code> precedes the inclusion of <code>node_api.h</code>
1225 or <code>js_native_api.h</code>. If an API appears not to be available on
1226 a version of Node.js which is later than the one shown in <code>added in:</code> then
1229 code can be found separately in <code>js_native_api.h</code> and <code>js_native_api_types.h</code>.
1230 The APIs defined in these headers are included in <code>node_api.h</code> and
1231 <code>node_api_types.h</code>. The headers are structured in this way in order to allow
1234 <p>The Node.js-specific parts of an addon can be separated from the code that
1237 below, <code>addon.c</code> and <code>addon.h</code> refer only to <code>js_native_api.h</code>. Th…
1238 that <code>addon.c</code> can be reused to compile against either the Node.js
1240 <p><code>addon_node.c</code> is a separate file that contains the Node.js specific entry point
1241 to the addon and which instantiates the addon by calling into <code>addon.c</code> when the
1243 <pre><code class="language-c"><span class="hljs-comment">// addon.h</span>
1248 …ord">endif</span> <span class="hljs-comment">// _ADDON_H_</span></span></code> <button class="cop…
1249 <pre><code class="language-c"><span class="hljs-comment">// addon.c</span>
1295 }</code> <button class="copy-button">copy</button></pre>
1296 <pre><code class="language-c"><span class="hljs-comment">// addon_node.c</span>
1305 }</code> <button class="copy-button">copy</button></pre>
1308 of an "Agent" as a self-contained environment in which JavaScript code runs.
1327 <h4><code>napi_set_instance_data</code><span><a class="mark" href="#napi_set_instance_data" id="nap…
1332 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_instance_data…
1335 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
1337 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
1338 <li><code>[in] data</code>: The data item to make available to bindings of this instance.</li>
1339 <li><code>[in] finalize_cb</code>: The function to call when the environment is being torn
1340 down. The function receives <code>data</code> so that it might free it.
1341 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
1342 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
1345 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1346 <p>This API associates <code>data</code> with the currently running Node.js environment. <code>data…
1347 can later be retrieved using <code>napi_get_instance_data()</code>. Any existing data
1349 of a previous call to <code>napi_set_instance_data()</code> will be overwritten. If a
1350 <code>finalize_cb</code> was provided by the previous call, it will not be called.</p>
1351 <h4><code>napi_get_instance_data</code><span><a class="mark" href="#napi_get_instance_data" id="nap…
1356 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_instance_data…
1357 …<span class="hljs-type">void</span>** data)</span>;</code> <button class="copy-button">copy</butto…
1359 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
1360 <li><code>[out] data</code>: The data item that was previously associated with the currently
1361 running Node.js environment by a call to <code>napi_set_instance_data()</code>.</li>
1363 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1365 running Node.js environment via <code>napi_set_instance_data()</code>. If no data is set,
1366 the call will succeed and <code>data</code> will be set to <code>NULL</code>.</p>
1371 <h4><code>napi_status</code><span><a class="mark" href="#napi_status" id="napi_status">#</a></span>…
1376 <p>Integral status code indicating the success or failure of a Node-API call.
1378 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1403 } napi_status;</code> <button class="copy-button">copy</button></pre>
1405 it can be obtained by calling <code>napi_get_last_error_info</code>.</p>
1406 <h4><code>napi_extended_error_info</code><span><a class="mark" href="#napi_extended_error_info" id=…
1411 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1416 } napi_extended_error_info;</code> <button class="copy-button">copy</button></pre>
1418 <li><code>error_message</code>: UTF8-encoded string containing a VM-neutral description of
1420 <li><code>engine_reserved</code>: Reserved for VM-specific error details. This is currently
1422 <li><code>engine_error_code</code>: VM-specific error code. This is currently
1424 <li><code>error_code</code>: The Node-API status code that originated with the last error.</li>
1427 <h4><code>napi_env</code><span><a class="mark" href="#napi_env" id="napi_env">#</a></span><a aria-h…
1428 <p><code>napi_env</code> is used to represent a context that the underlying Node-API
1431 making Node-API calls. Specifically, the same <code>napi_env</code> that was passed in when
1433 nested Node-API calls. Caching the <code>napi_env</code> for the purpose of general reuse,
1434 and passing the <code>napi_env</code> between instances of the same addon running on
1435 …href="worker_threads.html#class-worker"><code>Worker</code></a> threads is not allowed. The <code>…
1437 … callbacks given to <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
1438 <a href="#napi_set_instance_data"><code>napi_set_instance_data</code></a>.</p>
1439 <h4><code>napi_value</code><span><a class="mark" href="#napi_value" id="napi_value">#</a></span><a …
1441 <h4><code>napi_threadsafe_function</code><span><a class="mark" href="#napi_threadsafe_function" id=…
1448 <code>napi_call_threadsafe_function()</code>.</p>
1449 <h4><code>napi_threadsafe_function_release_mode</code><span><a class="mark" href="#napi_threadsafe_…
1454 <p>A value to be given to <code>napi_release_threadsafe_function()</code> to indicate whether
1455 the thread-safe function is to be closed immediately (<code>napi_tsfn_abort</code>) or
1456 merely released (<code>napi_tsfn_release</code>) and thus available for subsequent use via
1457 <code>napi_acquire_threadsafe_function()</code> and <code>napi_call_threadsafe_function()</code>.</…
1458 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1461 } napi_threadsafe_function_release_mode;</code> <button class="copy-button">copy</button></pre>
1462 <h4><code>napi_threadsafe_function_call_mode</code><span><a class="mark" href="#napi_threadsafe_fun…
1467 <p>A value to be given to <code>napi_call_threadsafe_function()</code> to indicate whether
1470 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1473 } napi_threadsafe_function_call_mode;</code> <button class="copy-button">copy</button></pre>
1475 <h5><code>napi_handle_scope</code><span><a class="mark" href="#napi_handle_scope" id="napi_handle_s…
1481 scope. For any invocations of code outside the execution of a native method
1485 …scopes are created using <a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a>…
1486 using <a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a>. Closing the scop…
1487 that all <code>napi_value</code>s created during the lifetime of the handle scope are no
1490 <h5><code>napi_escapable_handle_scope</code><span><a class="mark" href="#napi_escapable_handle_scop…
1497 <h5><code>napi_ref</code><span><a class="mark" href="#napi_ref" id="napi_ref">#</a></span><a aria-h…
1502 <p>This is the abstraction to use to reference a <code>napi_value</code>. This allows for
1506 <h5><code>napi_type_tag</code><span><a class="mark" href="#napi_type_tag" id="napi_type_tag">#</a><…
1514 <a href="#napi_instanceof"><code>napi_instanceof</code></a>, because the latter can report a false …
1516 conjunction with <a href="#napi_wrap"><code>napi_wrap</code></a> because it ensures that the pointe…
1519 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1522 } napi_type_tag;</code> <button class="copy-button">copy</button></pre>
1523 <h5><code>napi_async_cleanup_hook_handle</code><span><a class="mark" href="#napi_async_cleanup_hook…
1527 …alue returned by <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
1528 to <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a> when t…
1531 <h5><code>napi_callback_info</code><span><a class="mark" href="#napi_callback_info" id="napi_callba…
1539 <h5><code>napi_callback</code><span><a class="mark" href="#napi_callback" id="napi_callback">#</a><…
1547code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1549 handle and/or callback scope inside a <code>napi_callback</code> is not necessary.</p>
1550 <h5><code>napi_finalize</code><span><a class="mark" href="#napi_finalize" id="napi_finalize">#</a><…
1559 called upon the object's collection. Currently, <code>napi_finalize</code> can be used for
1561 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1563 …<span class="hljs-type">void</span>* finalize_hint)</span>;</code> <button class="copy-button">cop…
1567 where it cannot execute JavaScript code, some Node-API calls may return
1568 <code>napi_pending_exception</code> even when there is no exception pending.</p>
1569 … <a href="#node_api_create_external_string_latin1"><code>node_api_create_external_string_latin1</c…
1570 …node_api_create_external_string_utf16"><code>node_api_create_external_string_utf16</code></a> the …
1576 <p>experimental (<code>NAPI_EXPERIMENTAL</code> is defined):</p>
1577 <p>Node-API calls made from a finalizer will return <code>napi_cannot_run_js</code> when
1579 <code>napi_exception_pending</code> if there is a pending exception.</p>
1582 <h5><code>napi_async_execute_callback</code><span><a class="mark" href="#napi_async_execute_callbac…
1589code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1592 <code>napi_async_complete_callback</code> instead. Do not use the <code>napi_env</code> parameter as
1594 <h5><code>napi_async_complete_callback</code><span><a class="mark" href="#napi_async_complete_callb…
1601 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1603 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1606 <h5><code>napi_threadsafe_function_call_js</code><span><a class="mark" href="#napi_threadsafe_funct…
1614 necessary for a call into JavaScript, usually via <code>napi_call_function</code>, and then
1616 <p>The data arriving from the secondary thread via the queue is given in the <code>data</code>
1617 parameter and the JavaScript function to call is given in the <code>js_callback</code>
1620 sufficient to call the JavaScript function via <code>napi_call_function</code> rather than
1621 via <code>napi_make_callback</code>.</p>
1623 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1626 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1628 <li><code>[in] env</code>: The environment to use for API calls, or <code>NULL</code> if the thread…
1629 function is being torn down and <code>data</code> may need to be freed.</li>
1630 <li><code>[in] js_callback</code>: The JavaScript function to call, or <code>NULL</code> if the
1631 thread-safe function is being torn down and <code>data</code> may need to be freed. It
1632 may also be <code>NULL</code> if the thread-safe function was created without
1633 <code>js_callback</code>.</li>
1634 <li><code>[in] context</code>: The optional data with which the thread-safe function was
1636 <li><code>[in] data</code>: Data created by the secondary thread. It is the responsibility of
1638 functions) that can be passed as parameters when <code>js_callback</code> is invoked.
1644 <h5><code>napi_cleanup_hook</code><span><a class="mark" href="#napi_cleanup_hook" id="napi_cleanup_…
1649 …n pointer used with <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
1652code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title function…
1654 <li><code>[in] data</code>: The data that was passed to <a href="#napi_add_env_cleanup_hook"><code>…
1656 <h5><code>napi_async_cleanup_hook</code><span><a class="mark" href="#napi_async_cleanup_hook" id="n…
1660 …ointer used with <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
1663 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
1664 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
1666 <li><code>[in] handle</code>: The handle that must be passed to
1667 <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a> after com…
1669 <li><code>[in] data</code>: The data that was passed to <a href="#napi_add_async_cleanup_hook"><cod…
1672 end of which <code>handle</code> must be passed in a call to
1673 <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code></a>.</p>
1679 return type of all API functions is <code>napi_status</code>.</p>
1680 <p>The return value will be <code>napi_ok</code> if the request was successful and
1682 an exception was thrown, the <code>napi_status</code> value for the error
1684 <code>napi_pending_exception</code> will be returned.</p>
1685 <p>In cases where a return value other than <code>napi_ok</code> or
1686 <code>napi_pending_exception</code> is returned, <a href="#napi_is_exception_pending"><code>napi_is…
1689 <p>The full set of possible <code>napi_status</code> values is defined
1690 in <code>napi_api_types.h</code>.</p>
1691 <p>The <code>napi_status</code> return value provides a VM-independent representation of
1695 …ieve this information <a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a>
1696 is provided which returns a <code>napi_extended_error_info</code> structure.
1697 The format of the <code>napi_extended_error_info</code> structure is as follows:</p>
1702 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
1707 };</code> <button class="copy-button">copy</button></pre>
1709 <li><code>error_message</code>: Textual representation of the error that occurred.</li>
1710 <li><code>engine_reserved</code>: Opaque handle reserved for engine use only.</li>
1711 <li><code>engine_error_code</code>: VM specific error code.</li>
1712 <li><code>error_code</code>: Node-API status code for the last error.</li>
1714 <p><a href="#napi_get_last_error_info"><code>napi_get_last_error_info</code></a> returns the inform…
1719 <h5><code>napi_get_last_error_info</code><span><a class="mark" href="#napi_get_last_error_info" id=…
1724 <pre><code class="language-c">napi_status
1726 …lass="hljs-type">const</span> napi_extended_error_info** result)</span>;</code> <button class="cop…
1728 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1729 <li><code>[out] result</code>: The <code>napi_extended_error_info</code> structure with more
1732 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1733 <p>This API retrieves a <code>napi_extended_error_info</code> structure with information
1735 <p>The content of the <code>napi_extended_error_info</code> returned is only valid up until
1736 a Node-API function is called on the same <code>env</code>. This includes a call to
1737 <code>napi_is_exception_pending</code> so it may often be necessary to make a copy
1739 in <code>error_message</code> points to a statically-defined string so it is safe to use
1740 that pointer if you have copied it out of the <code>error_message</code> field (which will
1750 <p>If the <code>napi_status</code> returned by a function is <code>napi_ok</code> then no
1752 <code>napi_status</code> returned is anything other than <code>napi_ok</code> or
1753 <code>napi_pending_exception</code>, in order to try to recover and continue
1754 …urning immediately, <a href="#napi_is_exception_pending"><code>napi_is_exception_pending</code></a>
1758 <code>napi_status</code> of <code>napi_pending_exception</code>. However, this is not the case
1761 In that case, <code>napi_status</code> will reflect the status for the function. It
1768 code where the native method was invoked. The behavior of most Node-API calls
1770 <code>napi_pending_exception</code>, so do as little as possible and then return to
1773 where the native code can catch the exception, take the appropriate action,
1776 cases <a href="#napi_get_and_clear_last_exception"><code>napi_get_and_clear_last_exception</code></…
1778 the last JavaScript <code>Object</code> thrown. If it is determined, after
1780 it can be re-thrown it with <a href="#napi_throw"><code>napi_throw</code></a> where error is the
1782 <p>The following utility functions are also available in case native code
1783 needs to throw an exception or determine if a <code>napi_value</code> is an instance
1784 of a JavaScript <code>Error</code> object: <a href="#napi_throw_error"><code>napi_throw_error</code
1785code>napi_throw_type_error</code></a>, <a href="#napi_throw_range_error"><code>napi_throw_range_er…
1787 code needs to create an <code>Error</code> object: <a href="#napi_create_error"><code>napi_create_e…
1788code>napi_create_type_error</code></a>, <a href="#napi_create_range_error"><code>napi_create_range…
1789 where result is the <code>napi_value</code> that refers to the newly created
1790 JavaScript <code>Error</code> object.</p>
1798 (as its good practice), the <code>throw_</code> and <code>create_</code> functions
1799 take an optional code parameter which is the string for the code
1800 to be added to the error object. If the optional parameter is <code>NULL</code>
1801 then no code will be associated with the error. If a code is provided,
1803 <pre><code class="language-text">originalName [code]</code> <button class="copy-button">copy</butto…
1804 <p>where <code>originalName</code> is the original name associated with the error
1805 and <code>code</code> is the code that was provided. For example, if the code
1806 is <code>'ERR_ERROR_1'</code> and a <code>TypeError</code> is being created the name will be:</p>
1807 <pre><code class="language-text">TypeError [ERR_ERROR_1]</code> <button class="copy-button">copy</b…
1808 <h5><code>napi_throw</code><span><a class="mark" href="#napi_throw" id="napi_throw">#</a></span><a …
1813code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw</spa…
1815 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1816 <li><code>[in] error</code>: The JavaScript value to be thrown.</li>
1818 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1820 <h5><code>napi_throw_error</code><span><a class="mark" href="#napi_throw_error" id="napi_throw_erro…
1825 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1826 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1827 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1829 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1830 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1831 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1833 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1834 <p>This API throws a JavaScript <code>Error</code> with the text provided.</p>
1835 <h5><code>napi_throw_type_error</code><span><a class="mark" href="#napi_throw_type_error" id="napi_…
1840 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1841 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1842 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1844 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1845 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1846 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1848 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1849 <p>This API throws a JavaScript <code>TypeError</code> with the text provided.</p>
1850 <h5><code>napi_throw_range_error</code><span><a class="mark" href="#napi_throw_range_error" id="nap…
1855 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_throw…
1856 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1857 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1859 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1860 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1861 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1863 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1864 <p>This API throws a JavaScript <code>RangeError</code> with the text provided.</p>
1865 <h5><code>node_api_throw_syntax_error</code><span><a class="mark" href="#node_api_throw_syntax_erro…
1870 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">node_api_t…
1871 … <span class="hljs-type">const</span> <span class="hljs-type">char</span>* code,
1872 …ljs-type">const</span> <span class="hljs-type">char</span>* msg)</span>;</code> <button class="cop…
1874 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1875 <li><code>[in] code</code>: Optional error code to be set on the error.</li>
1876 <li><code>[in] msg</code>: C string representing the text to be associated with the error.</li>
1878 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1879 <p>This API throws a JavaScript <code>SyntaxError</code> with the text provided.</p>
1880 <h5><code>napi_is_error</code><span><a class="mark" href="#napi_is_error" id="napi_is_error">#</a><…
1885 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_is_er…
1887 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
1889 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1890 <li><code>[in] value</code>: The <code>napi_value</code> to be checked.</li>
1891 <li><code>[out] result</code>: Boolean value that is set to true if <code>napi_value</code> represe…
1894 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1895 <p>This API queries a <code>napi_value</code> to check if it represents an error object.</p>
1896 <h5><code>napi_create_error</code><span><a class="mark" href="#napi_create_error" id="napi_create_e…
1901 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1902 napi_value code,
1904 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1906 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1907 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1909 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1910 the message for the <code>Error</code>.</li>
1911 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1913 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1914 <p>This API returns a JavaScript <code>Error</code> with the text provided.</p>
1915 <h5><code>napi_create_type_error</code><span><a class="mark" href="#napi_create_type_error" id="nap…
1920 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1921 napi_value code,
1923 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1925 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1926 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1928 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1929 the message for the <code>Error</code>.</li>
1930 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1932 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1933 <p>This API returns a JavaScript <code>TypeError</code> with the text provided.</p>
1934 <h5><code>napi_create_range_error</code><span><a class="mark" href="#napi_create_range_error" id="n…
1939 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
1940 napi_value code,
1942 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1944 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1945 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1947 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1948 the message for the <code>Error</code>.</li>
1949 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1951 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1952 <p>This API returns a JavaScript <code>RangeError</code> with the text provided.</p>
1953 <h5><code>node_api_create_syntax_error</code><span><a class="mark" href="#node_api_create_syntax_er…
1958 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">node_api_c…
1959 napi_value code,
1961 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1963 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1964 <li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to …
1966 <li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>string</code>…
1967 the message for the <code>Error</code>.</li>
1968 <li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>
1970 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1971 <p>This API returns a JavaScript <code>SyntaxError</code> with the text provided.</p>
1972 <h5><code>napi_get_and_clear_last_exception</code><span><a class="mark" href="#napi_get_and_clear_l…
1977 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_and_clear_las…
1978 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
1980 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1981 <li><code>[out] result</code>: The exception if one is pending, <code>NULL</code> otherwise.</li>
1983 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1985 <h5><code>napi_is_exception_pending</code><span><a class="mark" href="#napi_is_exception_pending" i…
1990code class="language-c">napi_status <span class="hljs-title function_">napi_is_exception_pending</…
1992 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
1993 <li><code>[out] result</code>: Boolean value that is set to true if an exception is pending.</li>
1995 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
1997 <h5><code>napi_fatal_exception</code><span><a class="mark" href="#napi_fatal_exception" id="napi_fa…
2002code class="language-c">napi_status <span class="hljs-title function_">napi_fatal_exception</span>…
2004 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2005 <li><code>[in] err</code>: The error that is passed to <code>'uncaughtException'</code>.</li>
2007 <p>Trigger an <code>'uncaughtException'</code> in JavaScript. Useful if an async
2012 <h5><code>napi_fatal_error</code><span><a class="mark" href="#napi_fatal_error" id="napi_fatal_erro…
2017 <pre><code class="language-c">NAPI_NO_RETURN <span class="hljs-type">void</span> <span class="hljs-…
2020 …<span class="hljs-type">size_t</span> message_len)</span>;</code> <button class="copy-button">copy…
2022 <li><code>[in] location</code>: Optional location at which the error occurred.</li>
2023 <li><code>[in] location_len</code>: The length of the location in bytes, or
2024 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
2025 <li><code>[in] message</code>: The message associated with the error.</li>
2026 <li><code>[in] message_len</code>: The length of the message in bytes, or <code>NAPI_AUTO_LENGTH</c…
2033 VM may be returned as <code>napi_values</code>. These handles must hold the
2034 objects 'live' until they are no longer required by the native code,
2035 otherwise the objects could be collected before the native code was
2050 <pre><code class="language-c"><span class="hljs-keyword">for</span> (<span class="hljs-type">int</s…
2057 }</code> <button class="copy-button">copy</button></pre>
2059 substantial resources. In addition, even though the native code could only
2066 …open_handle_scope"><code>napi_open_handle_scope</code></a> and <a href="#napi_close_handle_scope">…
2072 …example, adding calls to <a href="#napi_open_handle_scope"><code>napi_open_handle_scope</code></a>…
2073 <a href="#napi_close_handle_scope"><code>napi_close_handle_scope</code></a> would ensure that at mo…
2075 <pre><code class="language-c"><span class="hljs-keyword">for</span> (<span class="hljs-type">int</s…
2091 }</code> <button class="copy-button">copy</button></pre>
2099 <a href="#napi_open_escapable_handle_scope"><code>napi_open_escapable_handle_scope</code></a> and
2100 <a href="#napi_close_escapable_handle_scope"><code>napi_close_escapable_handle_scope</code></a>.</p>
2101 …omote a handle is made through <a href="#napi_escape_handle"><code>napi_escape_handle</code></a> w…
2103 <h5><code>napi_open_handle_scope</code><span><a class="mark" href="#napi_open_handle_scope" id="nap…
2108 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_open_…
2109 … napi_handle_scope* result)</span>;</code> <button class="copy-button">copy</button></pre>
2111 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2112 <li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>
2114 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2116 <h5><code>napi_close_handle_scope</code><span><a class="mark" href="#napi_close_handle_scope" id="n…
2121 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_close…
2122 … napi_handle_scope scope)</span>;</code> <button class="copy-button">copy</button></pre>
2124 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2125 <li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>
2127 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2131 <h5><code>napi_open_escapable_handle_scope</code><span><a class="mark" href="#napi_open_escapable_h…
2136 <pre><code class="language-c">NAPI_EXTERN napi_status
2138 … napi_handle_scope* result)</span>;</code> <button class="copy-button">copy</button></pre>
2140 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2141 <li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>
2143 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2146 <h5><code>napi_close_escapable_handle_scope</code><span><a class="mark" href="#napi_close_escapable…
2151 <pre><code class="language-c">NAPI_EXTERN napi_status
2153 … napi_handle_scope scope)</span>;</code> <button class="copy-button">copy</button></pre>
2155 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2156 <li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>
2158 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2162 <h5><code>napi_escape_handle</code><span><a class="mark" href="#napi_escape_handle" id="napi_escape…
2167 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_escape_handle</sp…
2170 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2172 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2173 <li><code>[in] scope</code>: <code>napi_value</code> representing the current scope.</li>
2174 <li><code>[in] escapee</code>: <code>napi_value</code> representing the JavaScript <code>Object</co…
2176 <li><code>[out] result</code>: <code>napi_value</code> representing the handle to the escaped <code
2179 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2190 would not be possible with a normal handle returned as a <code>napi_value</code> as
2204 only supported by local symbols created with the <code>napi_create_symbol</code> function
2205 or the JavaScript <code>Symbol()</code> constructor calls. Globally registered symbols
2206 created with the <code>node_api_symbol_for</code> function or JavaScript <code>Symbol.for()</code>
2209 <code>Symbol.iterator</code>. They are also never collected by the garbage collector.</p>
2211 then be modified through <a href="#napi_reference_ref"><code>napi_reference_ref</code></a> and
2212 <a href="#napi_reference_unref"><code>napi_reference_unref</code></a>. If an object is collected wh…
2214 …ed with the reference <a href="#napi_get_reference_value"><code>napi_get_reference_value</code></a>
2215 will return <code>NULL</code> for the returned <code>napi_value</code>. An attempt to call
2216 <a href="#napi_reference_ref"><code>napi_reference_ref</code></a> for a reference whose object has …
2232 <code>napi_delete_reference</code> in addition to <code>napi_reference_unref</code> when possible.<…
2236 <p>Experimental (<code>NAPI_EXPERIMENTAL</code> is defined):</p>
2243 <h5><code>napi_create_reference</code><span><a class="mark" href="#napi_create_reference" id="napi_…
2248 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_creat…
2251 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
2253 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2254 <li><code>[in] value</code>: The <code>napi_value</code> for which a reference is being created.</l…
2255 <li><code>[in] initial_refcount</code>: Initial reference count for the new reference.</li>
2256 <li><code>[out] result</code>: <code>napi_ref</code> pointing to the new reference.</li>
2258 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2261 <h5><code>napi_delete_reference</code><span><a class="mark" href="#napi_delete_reference" id="napi_…
2266code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_delete_ref…
2268 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2269 <li><code>[in] ref</code>: <code>napi_ref</code> to be deleted.</li>
2271 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2274 <h5><code>napi_reference_ref</code><span><a class="mark" href="#napi_reference_ref" id="napi_refere…
2279 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_refer…
2281 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
2283 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2284 <li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be incremented.…
2285 <li><code>[out] result</code>: The new reference count.</li>
2287 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2290 <h5><code>napi_reference_unref</code><span><a class="mark" href="#napi_reference_unref" id="napi_re…
2295 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_refer…
2297 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
2299 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2300 <li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be decremented.…
2301 <li><code>[out] result</code>: The new reference count.</li>
2303 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2306 <h5><code>napi_get_reference_value</code><span><a class="mark" href="#napi_get_reference_value" id=…
2311 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_get_r…
2313 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2315 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2316 <li><code>[in] ref</code>: The <code>napi_ref</code> for which the corresponding value is
2318 <li><code>[out] result</code>: The <code>napi_value</code> referenced by the <code>napi_ref</code>.…
2320 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2321 <p>If still valid, this API returns the <code>napi_value</code> representing the
2322 JavaScript value associated with the <code>napi_ref</code>. Otherwise, result
2323 will be <code>NULL</code>.</p>
2331 <h5><code>napi_add_env_cleanup_hook</code><span><a class="mark" href="#napi_add_env_cleanup_hook" i…
2336 <pre><code class="language-c">NODE_EXTERN napi_status <span class="hljs-title function_">napi_add_e…
2338 …<span class="hljs-type">void</span>* arg)</span>;</code> <button class="copy-button">copy</button>…
2339 <p>Registers <code>fun</code> as a function to be run with the <code>arg</code> parameter once the
2342 <code>arg</code> values. In that case, it will be called multiple times as well.
2343 Providing the same <code>fun</code> and <code>arg</code> values multiple times is not allowed
2347 …e done by using <a href="#napi_remove_env_cleanup_hook"><code>napi_remove_env_cleanup_hook</code><…
2350 …hronous cleanup, <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></…
2351 <h5><code>napi_remove_env_cleanup_hook</code><span><a class="mark" href="#napi_remove_env_cleanup_h…
2356 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_remov…
2358 …<span class="hljs-type">void</span>* arg)</span>;</code> <button class="copy-button">copy</button>…
2359 <p>Unregisters <code>fun</code> as a function to be run with the <code>arg</code> parameter once the
2363 with <code>napi_add_env_cleanup_hook</code>, otherwise the process will abort.</p>
2364 <h5><code>napi_add_async_cleanup_hook</code><span><a class="mark" href="#napi_add_async_cleanup_hoo…
2370 <td><p>Changed signature of the <code>hook</code> callback.</p></td></tr>
2377 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_add_a…
2381 …napi_async_cleanup_hook_handle* remove_handle)</span>;</code> <button class="copy-button">copy</bu…
2383 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2384 <li><code>[in] hook</code>: The function pointer to call at environment teardown.</li>
2385 <li><code>[in] arg</code>: The pointer to pass to <code>hook</code> when it gets called.</li>
2386 <li><code>[out] remove_handle</code>: Optional handle that refers to the asynchronous cleanup
2389 <p>Registers <code>hook</code>, which is a function of type <a href="#napi_async_cleanup_hook"><cod…
2390 a function to be run with the <code>remove_handle</code> and <code>arg</code> parameters once the
2392 <p>Unlike <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a>, the hook…
2393 …lly matches that of <a href="#napi_add_env_cleanup_hook"><code>napi_add_env_cleanup_hook</code></a…
2394 <p>If <code>remove_handle</code> is not <code>NULL</code>, an opaque value will be stored in it
2395 …be passed to <a href="#napi_remove_async_cleanup_hook"><code>napi_remove_async_cleanup_hook</code>…
2399 <h5><code>napi_remove_async_cleanup_hook</code><span><a class="mark" href="#napi_remove_async_clean…
2405 <td><p>Removed <code>env</code> parameter.</p></td></tr>
2411 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_remov…
2412 …napi_async_cleanup_hook_handle remove_handle)</span>;</code> <button class="copy-button">copy</but…
2414 <li><code>[in] remove_handle</code>: The handle to an asynchronous cleanup hook that was
2415 created with <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a>.</…
2417 <p>Unregisters the cleanup hook corresponding to <code>remove_handle</code>. This will prevent
2419 This must be called on any <code>napi_async_cleanup_hook_handle</code> value obtained
2420 from <a href="#napi_add_async_cleanup_hook"><code>napi_add_async_cleanup_hook</code></a>.</p>
2424 <a href="worker_threads.html#workerterminate"><code>worker.terminate()</code></a>. When the environ…
2425 registered <code>napi_finalize</code> callbacks of JavaScript objects, thread-safe
2428 <p>The invocation of <code>napi_finalize</code> callbacks is scheduled after the manually
2431 <code>napi_finalize</code> callback, addons should register a cleanup hook with
2432 <code>napi_add_env_cleanup_hook</code> and <code>napi_add_async_cleanup_hook</code> to manually
2436 except that instead of using the <code>NODE_MODULE</code> macro the following
2438 <pre><code class="language-c">NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)</code> <button class="copy-bu…
2439 <p>The next difference is the signature for the <code>Init</code> method. For a Node-API
2441code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class="hljs…
2442 <p>The return value from <code>Init</code> is treated as the <code>exports</code> object for the mo…
2443 The <code>Init</code> method is passed an empty object via the <code>exports</code> parameter as a
2444 convenience. If <code>Init</code> returns <code>NULL</code>, the parameter passed as <code>exports<…
2445 exported by the module. Node-API modules cannot modify the <code>module</code> object but
2446 can specify anything as the <code>exports</code> property of the module.</p>
2447 <p>To add the method <code>hello</code> as a function so that it can be called as a method
2449 <pre><code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class=…
2464 }</code> <button class="copy-button">copy</button></pre>
2465 <p>To set a function to be returned by the <code>require()</code> for the addon:</p>
2466 <pre><code class="language-c">napi_value <span class="hljs-title function_">Init</span><span class=…
2472 }</code> <button class="copy-button">copy</button></pre>
2475 <pre><code class="language-c"><span class="hljs-comment">// <span class="hljs-doctag">NOTE:</span> …
2496 }</code> <button class="copy-button">copy</button></pre>
2497 <p>You can also use the <code>NAPI_MODULE_INIT</code> macro, which acts as a shorthand
2498 for <code>NAPI_MODULE</code> and defining an <code>Init</code> function:</p>
2499 <pre><code class="language-c">NAPI_MODULE_INIT() {
2510 }</code> <button class="copy-button">copy</button></pre>
2514 <p>The variables <code>env</code> and <code>exports</code> will be available inside the function bo…
2529 <li>Get global instances including <code>undefined</code> and <code>null</code></li>
2531 <p>Node-API values are represented by the type <code>napi_value</code>.
2532 Any Node-API call that requires a JavaScript value takes in a <code>napi_value</code>.
2533 In some cases, the API does check the type of the <code>napi_value</code> up-front.
2535 the <code>napi_value</code> in question is of the JavaScript type expected by the API.</p>
2537 <h5><code>napi_key_collection_mode</code><span><a class="mark" href="#napi_key_collection_mode" id=…
2542 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2545 } napi_key_collection_mode;</code> <button class="copy-button">copy</button></pre>
2546 <p>Describes the <code>Keys/Properties</code> filter enums:</p>
2547 <p><code>napi_key_collection_mode</code> limits the range of collected properties.</p>
2548 <p><code>napi_key_own_only</code> limits the collected properties to the given
2549 object only. <code>napi_key_include_prototypes</code> will include all keys
2551 <h5><code>napi_key_filter</code><span><a class="mark" href="#napi_key_filter" id="napi_key_filter">…
2556 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2563 } napi_key_filter;</code> <button class="copy-button">copy</button></pre>
2565 <h5><code>napi_key_conversion</code><span><a class="mark" href="#napi_key_conversion" id="napi_key_…
2570 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2573 } napi_key_conversion;</code> <button class="copy-button">copy</button></pre>
2574 <p><code>napi_key_numbers_to_strings</code> will convert integer indices to
2575 strings. <code>napi_key_keep_numbers</code> will return numbers for integer
2577 <h5><code>napi_valuetype</code><span><a class="mark" href="#napi_valuetype" id="napi_valuetype">#</…
2578 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2590 } napi_valuetype;</code> <button class="copy-button">copy</button></pre>
2591 <p>Describes the type of a <code>napi_value</code>. This generally corresponds to the types
2593 In addition to types in that section, <code>napi_valuetype</code> can also represent
2594 <code>Function</code>s and <code>Object</code>s with external data.</p>
2595 <p>A JavaScript value of type <code>napi_external</code> appears in JavaScript as a plain
2597 <h5><code>napi_typedarray_type</code><span><a class="mark" href="#napi_typedarray_type" id="napi_ty…
2598 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
2610 } napi_typedarray_type;</code> <button class="copy-button">copy</button></pre>
2611 <p>This represents the underlying binary scalar datatype of the <code>TypedArray</code>.
2615 <h5><code>napi_create_array</code><span><a class="mark" href="#napi_create_array" id="napi_create_a…
2620code class="language-c">napi_status <span class="hljs-title function_">napi_create_array</span><sp…
2622 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
2623 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</cod…
2625 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2626 <p>This API returns a Node-API value corresponding to a JavaScript <code>Array</code> type.
2629 <h5><code>napi_create_array_with_length</code><span><a class="mark" href="#napi_create_array_with_l…
2634 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_array_with…
2636 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2638 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2639 <li><code>[in] length</code>: The initial length of the <code>Array</code>.</li>
2640 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</cod…
2642 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2643 <p>This API returns a Node-API value corresponding to a JavaScript <code>Array</code> type.
2644 The <code>Array</code>'s length property is set to the passed-in length parameter.
2649 <a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code></a>.</p>
2652 <h5><code>napi_create_arraybuffer</code><span><a class="mark" href="#napi_create_arraybuffer" id="n…
2657 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_arraybuffe…
2660 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2662 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2663 <li><code>[in] length</code>: The length in bytes of the array buffer to create.</li>
2664 <li><code>[out] data</code>: Pointer to the underlying byte buffer of the <code>ArrayBuffer</code>.
2665 <code>data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2666 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffe…
2668 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2669 <p>This API returns a Node-API value corresponding to a JavaScript <code>ArrayBuffer</code>.
2670 <code>ArrayBuffer</code>s are used to represent fixed-length binary data buffers. They are
2671 normally used as a backing-buffer for <code>TypedArray</code> objects.
2672 The <code>ArrayBuffer</code> allocated will have an underlying byte buffer whose size is
2673 determined by the <code>length</code> parameter that's passed in.
2676 written to directly from native code. To write to this buffer from JavaScript,
2677 a typed array or <code>DataView</code> object would need to be created.</p>
2678 <p>JavaScript <code>ArrayBuffer</code> objects are described in
2680 <h5><code>napi_create_buffer</code><span><a class="mark" href="#napi_create_buffer" id="napi_create…
2685 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_buffer</sp…
2688 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2690 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2691 <li><code>[in] size</code>: Size in bytes of the underlying buffer.</li>
2692 <li><code>[out] data</code>: Raw pointer to the underlying buffer.
2693 <code>data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2694 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2696 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2697 <p>This API allocates a <code>node::Buffer</code> object. While this is still a
2698 fully-supported data structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2699 <h5><code>napi_create_buffer_copy</code><span><a class="mark" href="#napi_create_buffer_copy" id="n…
2704 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_buffer_cop…
2708 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2710 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2711 <li><code>[in] size</code>: Size in bytes of the input buffer (should be the same as the size
2713 <li><code>[in] data</code>: Raw pointer to the underlying buffer to copy from.</li>
2714 <li><code>[out] result_data</code>: Pointer to the new <code>Buffer</code>'s underlying data buffer.
2715 <code>result_data</code> can optionally be ignored by passing <code>NULL</code>.</li>
2716 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2718 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2719 <p>This API allocates a <code>node::Buffer</code> object and initializes it with data copied
2721 structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2722 <h5><code>napi_create_date</code><span><a class="mark" href="#napi_create_date" id="napi_create_dat…
2727 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_date</span…
2729 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
2731 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2732 <li><code>[in] time</code>: ECMAScript time value in milliseconds since 01 January, 1970 UTC.</li>
2733 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Date</code
2735 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2738 <p>This API allocates a JavaScript <code>Date</code> object.</p>
2739 <p>JavaScript <code>Date</code> objects are described in
2741 <h5><code>napi_create_external</code><span><a class="mark" href="#napi_create_external" id="napi_cr…
2746 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_external</…
2750 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2752 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2753 <li><code>[in] data</code>: Raw pointer to the external data.</li>
2754 <li><code>[in] finalize_cb</code>: Optional callback to call when the external value is being
2755 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2756 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2758 <li><code>[out] result</code>: A <code>napi_value</code> representing an external value.</li>
2760 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2762 is used to pass external data through JavaScript code, so it can be retrieved
2763 later by native code using <a href="#napi_get_value_external"><code>napi_get_value_external</code><…
2764 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2767 properties. It is considered a distinct value type: calling <code>napi_typeof()</code> with
2768 an external value yields <code>napi_external</code>.</p>
2769 <h5><code>napi_create_external_arraybuffer</code><span><a class="mark" href="#napi_create_external_…
2774 <pre><code class="language-c">napi_status
2780 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2782 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2783 <li><code>[in] external_data</code>: Pointer to the underlying byte buffer of the
2784 <code>ArrayBuffer</code>.</li>
2785 <li><code>[in] byte_length</code>: The length in bytes of the underlying buffer.</li>
2786 <li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is b…
2787 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2788 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2790 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffe…
2792 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2795 <code>napi_no_external_buffers_allowed</code> to indicate that external
2800 you may define <code>NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED</code> in your addon before
2804 <p>This API returns a Node-API value corresponding to a JavaScript <code>ArrayBuffer</code>.
2805 The underlying byte buffer of the <code>ArrayBuffer</code> is externally allocated and
2808 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2810 <p>JavaScript <code>ArrayBuffer</code>s are described in
2812 <h5><code>napi_create_external_buffer</code><span><a class="mark" href="#napi_create_external_buffe…
2817 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_external_b…
2822 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2824 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2825 <li><code>[in] length</code>: Size in bytes of the input buffer (should be the same as the
2827 <li><code>[in] data</code>: Raw pointer to the underlying buffer to expose to JavaScript.</li>
2828 <li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is b…
2829 collected. <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
2830 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
2832 <li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.<…
2834 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2837 <code>napi_no_external_buffers_allowed</code> to indicate that external
2842 you may define <code>NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED</code> in your addon before
2846 <p>This API allocates a <code>node::Buffer</code> object and initializes it with data
2848 structure, in most cases using a <code>TypedArray</code> will suffice.</p>
2849 <p>The API adds a <code>napi_finalize</code> callback which will be called when the JavaScript
2851 <p>For Node.js >=4 <code>Buffers</code> are <code>Uint8Array</code>s.</p>
2852 <h5><code>napi_create_object</code><span><a class="mark" href="#napi_create_object" id="napi_create…
2857code class="language-c">napi_status <span class="hljs-title function_">napi_create_object</span><s…
2859 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2860 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Object</co…
2862 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2863 <p>This API allocates a default JavaScript <code>Object</code>.
2864 It is the equivalent of doing <code>new Object()</code> in JavaScript.</p>
2865 <p>The JavaScript <code>Object</code> type is described in <a href="https://tc39.github.io/ecma262/…
2867 <h5><code>napi_create_symbol</code><span><a class="mark" href="#napi_create_symbol" id="napi_create…
2872 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_symbol</sp…
2874 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2876 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2877 <li><code>[in] description</code>: Optional <code>napi_value</code> which refers to a JavaScript
2878 <code>string</code> to be set as the description for the symbol.</li>
2879 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>symbol</co…
2881 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2882 <p>This API creates a JavaScript <code>symbol</code> value from a UTF8-encoded C string.</p>
2883 <p>The JavaScript <code>symbol</code> type is described in <a href="https://tc39.github.io/ecma262/…
2885 <h5><code>node_api_symbol_for</code><span><a class="mark" href="#node_api_symbol_for" id="node_api_…
2890 <pre><code class="language-c">napi_status <span class="hljs-title function_">node_api_symbol_for</s…
2893 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2895 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2896 <li><code>[in] utf8description</code>: UTF-8 C string representing the text to be used as the
2898 <li><code>[in] length</code>: The length of the description string in bytes, or
2899 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
2900 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>symbol</co…
2902 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2906 <p>The JavaScript <code>symbol</code> type is described in <a href="https://tc39.github.io/ecma262/…
2908 <h5><code>napi_create_typedarray</code><span><a class="mark" href="#napi_create_typedarray" id="nap…
2913 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_typedarray…
2918 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2920 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2921 <li><code>[in] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</li>
2922 <li><code>[in] length</code>: Number of elements in the <code>TypedArray</code>.</li>
2923 <li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the typed array.</li>
2924 <li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to
2925 start projecting the <code>TypedArray</code>.</li>
2926 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>TypedArray…
2928 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2929 <p>This API creates a JavaScript <code>TypedArray</code> object over an existing
2930 <code>ArrayBuffer</code>. <code>TypedArray</code> objects provide an array-like view over an
2933 <p>It's required that <code>(length * size_of_element) + byte_offset</code> should
2934 be &#x3C;= the size in bytes of the array passed in. If not, a <code>RangeError</code> exception
2936 <p>JavaScript <code>TypedArray</code> objects are described in
2938 <h5><code>napi_create_dataview</code><span><a class="mark" href="#napi_create_dataview" id="napi_cr…
2943 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_dataview</…
2947 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
2949 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2950 <li><code>[in] length</code>: Number of elements in the <code>DataView</code>.</li>
2951 <li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.</…
2952 <li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to
2953 start projecting the <code>DataView</code>.</li>
2954 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>DataView</
2956 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2957 <p>This API creates a JavaScript <code>DataView</code> object over an existing <code>ArrayBuffer</c…
2958 <code>DataView</code> objects provide an array-like view over an underlying data buffer,
2959 but one which allows items of different size and type in the <code>ArrayBuffer</code>.</p>
2960 <p>It is required that <code>byte_length + byte_offset</code> is less than or equal to the
2961 size in bytes of the array passed in. If not, a <code>RangeError</code> exception is
2963 <p>JavaScript <code>DataView</code> objects are described in
2966 <h5><code>napi_create_int32</code><span><a class="mark" href="#napi_create_int32" id="napi_create_i…
2971code class="language-c">napi_status <span class="hljs-title function_">napi_create_int32</span><sp…
2973 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2974 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
2975 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
2977 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2978 <p>This API is used to convert from the C <code>int32_t</code> type to the JavaScript
2979 <code>number</code> type.</p>
2980 <p>The JavaScript <code>number</code> type is described in
2982 <h5><code>napi_create_uint32</code><span><a class="mark" href="#napi_create_uint32" id="napi_create…
2987code class="language-c">napi_status <span class="hljs-title function_">napi_create_uint32</span><s…
2989 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
2990 <li><code>[in] value</code>: Unsigned integer value to be represented in JavaScript.</li>
2991 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
2993 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
2994 <p>This API is used to convert from the C <code>uint32_t</code> type to the JavaScript
2995 <code>number</code> type.</p>
2996 <p>The JavaScript <code>number</code> type is described in
2998 <h5><code>napi_create_int64</code><span><a class="mark" href="#napi_create_int64" id="napi_create_i…
3003code class="language-c">napi_status <span class="hljs-title function_">napi_create_int64</span><sp…
3005 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3006 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
3007 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
3009 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3010 <p>This API is used to convert from the C <code>int64_t</code> type to the JavaScript
3011 <code>number</code> type.</p>
3012 <p>The JavaScript <code>number</code> type is described in <a href="https://tc39.github.io/ecma262/…
3013 of the ECMAScript Language Specification. Note the complete range of <code>int64_t</code>
3015 …b.io/ecma262/#sec-number.min_safe_integer"><code>Number.MIN_SAFE_INTEGER</code></a> <code>-(2**53 …
3016 …ub.io/ecma262/#sec-number.max_safe_integer"><code>Number.MAX_SAFE_INTEGER</code></a> <code>(2**53 …
3017 <h5><code>napi_create_double</code><span><a class="mark" href="#napi_create_double" id="napi_create…
3022code class="language-c">napi_status <span class="hljs-title function_">napi_create_double</span><s…
3024 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3025 <li><code>[in] value</code>: Double-precision value to be represented in JavaScript.</li>
3026 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>number</co…
3028 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3029 <p>This API is used to convert from the C <code>double</code> type to the JavaScript
3030 <code>number</code> type.</p>
3031 <p>The JavaScript <code>number</code> type is described in
3033 <h5><code>napi_create_bigint_int64</code><span><a class="mark" href="#napi_create_bigint_int64" id=…
3038 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_int…
3040 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3042 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3043 <li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>
3044 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3046 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3047 <p>This API converts the C <code>int64_t</code> type to the JavaScript <code>BigInt</code> type.</p>
3048 <h5><code>napi_create_bigint_uint64</code><span><a class="mark" href="#napi_create_bigint_uint64" i…
3053 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_uin…
3055 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3057 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3058 <li><code>[in] value</code>: Unsigned integer value to be represented in JavaScript.</li>
3059 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3061 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3062 <p>This API converts the C <code>uint64_t</code> type to the JavaScript <code>BigInt</code> type.</…
3063 <h5><code>napi_create_bigint_words</code><span><a class="mark" href="#napi_create_bigint_words" id=…
3068 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_bigint_wor…
3072 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3074 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3075 <li><code>[in] sign_bit</code>: Determines if the resulting <code>BigInt</code> will be positive or
3077 <li><code>[in] word_count</code>: The length of the <code>words</code> array.</li>
3078 <li><code>[in] words</code>: An array of <code>uint64_t</code> little-endian 64-bit words.</li>
3079 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>BigInt</co…
3081 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3082 <p>This API converts an array of unsigned 64-bit words into a single <code>BigInt</code>
3084 <p>The resulting <code>BigInt</code> is calculated as: (–1)<sup><code>sign_bit</code></sup> (<code>…
3085 × (2<sup>64</sup>)<sup>0</sup> + <code>words[1]</code> × (2<sup>64</sup>)<sup>1</sup> + …)</p>
3086 <h5><code>napi_create_string_latin1</code><span><a class="mark" href="#napi_create_string_latin1" i…
3091 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_lat…
3094 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
3096 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3097 <li><code>[in] str</code>: Character buffer representing an ISO-8859-1-encoded string.</li>
3098 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3100 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3102 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3103 <p>This API creates a JavaScript <code>string</code> value from an ISO-8859-1-encoded C
3105 <p>The JavaScript <code>string</code> type is described in
3107 <h5><code>node_api_create_external_string_latin1</code><span><a class="mark" href="#node_api_create…
3112 <pre><code class="language-c">napi_status
3119 …<span class="hljs-type">bool</span>* copied)</span>;</code> <button class="copy-button">copy</butt…
3121 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3122 <li><code>[in] str</code>: Character buffer representing an ISO-8859-1-encoded string.</li>
3123 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3125 <li><code>[in] finalize_callback</code>: The function to call when the string is being
3128 <li><code>[in] env</code>: The environment in which the add-on is running. This value
3131 <li><code>[in] data</code>: This is the value <code>str</code> as a <code>void*</code> pointer.</li>
3132 <li><code>[in] finalize_hint</code>: This is the value <code>finalize_hint</code> that was given
3134 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.
3140 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
3142 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3143 <li><code>[out] copied</code>: Whether the string was copied. If it was, the finalizer will
3144 already have been invoked to destroy <code>str</code>.</li>
3146 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3147 <p>This API creates a JavaScript <code>string</code> value from an ISO-8859-1-encoded C
3150 <p>The JavaScript <code>string</code> type is described in
3152 <h5><code>napi_create_string_utf16</code><span><a class="mark" href="#napi_create_string_utf16" id=…
3157 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_utf…
3160 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3162 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3163 <li><code>[in] str</code>: Character buffer representing a UTF16-LE-encoded string.</li>
3164 <li><code>[in] length</code>: The length of the string in two-byte code units, or
3165 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
3166 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3168 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3169 <p>This API creates a JavaScript <code>string</code> value from a UTF16-LE-encoded C string.
3171 <p>The JavaScript <code>string</code> type is described in
3173 <h5><code>node_api_create_external_string_utf16</code><span><a class="mark" href="#node_api_create_…
3178 <pre><code class="language-c">napi_status
3185 …<span class="hljs-type">bool</span>* copied)</span>;</code> <button class="copy-button">copy</butt…
3187 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3188 <li><code>[in] str</code>: Character buffer representing a UTF16-LE-encoded string.</li>
3189 <li><code>[in] length</code>: The length of the string in two-byte code units, or
3190 <code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>
3191 <li><code>[in] finalize_callback</code>: The function to call when the string is being
3194 <li><code>[in] env</code>: The environment in which the add-on is running. This value
3197 <li><code>[in] data</code>: This is the value <code>str</code> as a <code>void*</code> pointer.</li>
3198 <li><code>[in] finalize_hint</code>: This is the value <code>finalize_hint</code> that was given
3200 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.
3206 <li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback during
3208 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3209 <li><code>[out] copied</code>: Whether the string was copied. If it was, the finalizer will
3210 already have been invoked to destroy <code>str</code>.</li>
3212 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3213 <p>This API creates a JavaScript <code>string</code> value from a UTF16-LE-encoded C string.
3216 <p>The JavaScript <code>string</code> type is described in
3218 <h5><code>napi_create_string_utf8</code><span><a class="mark" href="#napi_create_string_utf8" id="n…
3223 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_string_utf…
3226 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3228 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3229 <li><code>[in] str</code>: Character buffer representing a UTF8-encoded string.</li>
3230 <li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code> i…
3232 <li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>string</co…
3234 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3235 <p>This API creates a JavaScript <code>string</code> value from a UTF8-encoded C string.
3237 <p>The JavaScript <code>string</code> type is described in
3240 <h5><code>napi_get_array_length</code><span><a class="mark" href="#napi_get_array_length" id="napi_…
3245 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_array_length<…
3247 …<span class="hljs-type">uint32_t</span>* result)</span></code> <button class="copy-button">copy</b…
3249 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3250 <li><code>[in] value</code>: <code>napi_value</code> representing the JavaScript <code>Array</code>…
3252 <li><code>[out] result</code>: <code>uint32</code> representing length of the array.</li>
3254 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3256 <p><code>Array</code> length is described in <a href="https://tc39.github.io/ecma262/#sec-propertie…
3258 <h5><code>napi_get_arraybuffer_info</code><span><a class="mark" href="#napi_get_arraybuffer_info" i…
3263 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_arraybuffer_i…
3266 …<span class="hljs-type">size_t</span>* byte_length)</span></code> <button class="copy-button">copy…
3268 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3269 <li><code>[in] arraybuffer</code>: <code>napi_value</code> representing the <code>ArrayBuffer</code
3270 <li><code>[out] data</code>: The underlying data buffer of the <code>ArrayBuffer</code>. If byte_le…
3271 is <code>0</code>, this may be <code>NULL</code> or any other pointer value.</li>
3272 <li><code>[out] byte_length</code>: Length in bytes of the underlying data buffer.</li>
3274 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3275 <p>This API is used to retrieve the underlying data buffer of an <code>ArrayBuffer</code> and
3278 buffer is managed by the <code>ArrayBuffer</code> even after it's returned. A
3280 <a href="#napi_create_reference"><code>napi_create_reference</code></a>, which can be used to guara…
3281 lifetime of the <code>ArrayBuffer</code>. It's also safe to use the returned data buffer
3284 <h5><code>napi_get_buffer_info</code><span><a class="mark" href="#napi_get_buffer_info" id="napi_ge…
3289 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_buffer_info</…
3292 …<span class="hljs-type">size_t</span>* length)</span></code> <button class="copy-button">copy</but…
3294 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3295 <li><code>[in] value</code>: <code>napi_value</code> representing the <code>node::Buffer</code> bei…
3296 <li><code>[out] data</code>: The underlying data buffer of the <code>node::Buffer</code>.
3297 If length is <code>0</code>, this may be <code>NULL</code> or any other pointer value.</li>
3298 <li><code>[out] length</code>: Length in bytes of the underlying data buffer.</li>
3300 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3301 <p>This API is used to retrieve the underlying data buffer of a <code>node::Buffer</code>
3305 <h5><code>napi_get_prototype</code><span><a class="mark" href="#napi_get_prototype" id="napi_get_pr…
3310 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_prototype</sp…
3312 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3314 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3315 <li><code>[in] object</code>: <code>napi_value</code> representing JavaScript <code>Object</code> w…
3316 to return. This returns the equivalent of <code>Object.getPrototypeOf</code> (which is
3317 not the same as the function's <code>prototype</code> property).</li>
3318 <li><code>[out] result</code>: <code>napi_value</code> representing prototype of the given object.<…
3320 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3321 <h5><code>napi_get_typedarray_info</code><span><a class="mark" href="#napi_get_typedarray_info" id=…
3326 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_typedarray_in…
3332 …<span class="hljs-type">size_t</span>* byte_offset)</span></code> <button class="copy-button">copy…
3334 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3335 <li><code>[in] typedarray</code>: <code>napi_value</code> representing the <code>TypedArray</code> …
3337 <li><code>[out] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</l…
3338 <li><code>[out] length</code>: The number of elements in the <code>TypedArray</code>.</li>
3339 <li><code>[out] data</code>: The data buffer underlying the <code>TypedArray</code> adjusted by
3340 the <code>byte_offset</code> value so that it points to the first element in the
3341 <code>TypedArray</code>. If the length of the array is <code>0</code>, this may be <code>NULL</code
3343 <li><code>[out] arraybuffer</code>: The <code>ArrayBuffer</code> underlying the <code>TypedArray</c…
3344 <li><code>[out] byte_offset</code>: The byte offset within the underlying native array
3348 <code>data - byte_offset</code>.</li>
3350 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3352 <p>Any of the out parameters may be <code>NULL</code> if that property is unneeded.</p>
3355 <h5><code>napi_get_dataview_info</code><span><a class="mark" href="#napi_get_dataview_info" id="nap…
3360 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_dataview_info…
3365 …<span class="hljs-type">size_t</span>* byte_offset)</span></code> <button class="copy-button">copy…
3367 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3368 <li><code>[in] dataview</code>: <code>napi_value</code> representing the <code>DataView</code> whose
3370 <li><code>[out] byte_length</code>: Number of bytes in the <code>DataView</code>.</li>
3371 <li><code>[out] data</code>: The data buffer underlying the <code>DataView</code>.
3372 If byte_length is <code>0</code>, this may be <code>NULL</code> or any other pointer value.</li>
3373 <li><code>[out] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.<…
3374 <li><code>[out] byte_offset</code>: The byte offset within the data buffer from which
3375 to start projecting the <code>DataView</code>.</li>
3377 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3378 <p>Any of the out parameters may be <code>NULL</code> if that property is unneeded.</p>
3379 <p>This API returns various properties of a <code>DataView</code>.</p>
3380 <h5><code>napi_get_date_value</code><span><a class="mark" href="#napi_get_date_value" id="napi_get_…
3385 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_date_value</s…
3387 …<span class="hljs-type">double</span>* result)</span></code> <button class="copy-button">copy</but…
3389 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3390 <li><code>[in] value</code>: <code>napi_value</code> representing a JavaScript <code>Date</code>.</…
3391 <li><code>[out] result</code>: Time value as a <code>double</code> represented as milliseconds since
3396 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-date <code>napi_value</code> is pass…
3397 in it returns <code>napi_date_expected</code>.</p>
3399 <code>Date</code>.</p>
3400 <h5><code>napi_get_value_bool</code><span><a class="mark" href="#napi_get_value_bool" id="napi_get_…
3405code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bool</span><…
3407 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3408 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code>.<…
3409 <li><code>[out] result</code>: C boolean primitive equivalent of the given JavaScript
3410 <code>Boolean</code>.</li>
3412 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-boolean <code>napi_value</code> is
3413 passed in it returns <code>napi_boolean_expected</code>.</p>
3415 <code>Boolean</code>.</p>
3416 <h5><code>napi_get_value_double</code><span><a class="mark" href="#napi_get_value_double" id="napi_…
3421 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_double<…
3423 …<span class="hljs-type">double</span>* result)</span></code> <button class="copy-button">copy</but…
3425 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3426 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3427 <li><code>[out] result</code>: C double primitive equivalent of the given JavaScript
3428 <code>number</code>.</li>
3430 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code> is pa…
3431 in it returns <code>napi_number_expected</code>.</p>
3433 <code>number</code>.</p>
3434 <h5><code>napi_get_value_bigint_int64</code><span><a class="mark" href="#napi_get_value_bigint_int6…
3439 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3442 …<span class="hljs-type">bool</span>* lossless)</span>;</code> <button class="copy-button">copy</bu…
3444 <li><code>[in] env</code>: The environment that the API is invoked under</li>
3445 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3446 <li><code>[out] result</code>: C <code>int64_t</code> primitive equivalent of the given JavaScript
3447 <code>BigInt</code>.</li>
3448 <li><code>[out] lossless</code>: Indicates whether the <code>BigInt</code> value was converted
3451 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>BigInt</code> is passed in it
3452 returns <code>napi_bigint_expected</code>.</p>
3453 <p>This API returns the C <code>int64_t</code> primitive equivalent of the given JavaScript
3454 <code>BigInt</code>. If needed it will truncate the value, setting <code>lossless</code> to <code>f…
3455 <h5><code>napi_get_value_bigint_uint64</code><span><a class="mark" href="#napi_get_value_bigint_uin…
3460 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3463 …<span class="hljs-type">bool</span>* lossless)</span>;</code> <button class="copy-button">copy</bu…
3465 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3466 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3467 <li><code>[out] result</code>: C <code>uint64_t</code> primitive equivalent of the given JavaScript
3468 <code>BigInt</code>.</li>
3469 <li><code>[out] lossless</code>: Indicates whether the <code>BigInt</code> value was converted
3472 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>BigInt</code> is passed in it
3473 returns <code>napi_bigint_expected</code>.</p>
3474 <p>This API returns the C <code>uint64_t</code> primitive equivalent of the given JavaScript
3475 <code>BigInt</code>. If needed it will truncate the value, setting <code>lossless</code> to <code>f…
3476 <h5><code>napi_get_value_bigint_words</code><span><a class="mark" href="#napi_get_value_bigint_word…
3481 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_bigint_…
3485 …<span class="hljs-type">uint64_t</span>* words)</span>;</code> <button class="copy-button">copy</b…
3487 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3488 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>BigInt</code>.</…
3489 <li><code>[out] sign_bit</code>: Integer representing if the JavaScript <code>BigInt</code> is posi…
3491 <li><code>[in/out] word_count</code>: Must be initialized to the length of the <code>words</code>
3493 would be needed to store this <code>BigInt</code>.</li>
3494 <li><code>[out] words</code>: Pointer to a pre-allocated 64-bit word array.</li>
3496 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3497 <p>This API converts a single <code>BigInt</code> value into a sign bit, 64-bit little-endian
3498 array, and the number of elements in the array. <code>sign_bit</code> and <code>words</code> may be
3499 both set to <code>NULL</code>, in order to get only <code>word_count</code>.</p>
3500 <h5><code>napi_get_value_external</code><span><a class="mark" href="#napi_get_value_external" id="n…
3505 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_externa…
3507 …<span class="hljs-type">void</span>** result)</span></code> <button class="copy-button">copy</butt…
3509 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3510 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript external value.</li>
3511 <li><code>[out] result</code>: Pointer to the data wrapped by the JavaScript external value.</li>
3513 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-external <code>napi_value</code> is
3514 passed in it returns <code>napi_invalid_arg</code>.</p>
3516 <code>napi_create_external()</code>.</p>
3517 <h5><code>napi_get_value_int32</code><span><a class="mark" href="#napi_get_value_int32" id="napi_ge…
3522 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_int32</…
3524 …<span class="hljs-type">int32_t</span>* result)</span></code> <button class="copy-button">copy</bu…
3526 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3527 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3528 <li><code>[out] result</code>: C <code>int32</code> primitive equivalent of the given JavaScript
3529 <code>number</code>.</li>
3531 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3532 is passed in <code>napi_number_expected</code>.</p>
3533 <p>This API returns the C <code>int32</code> primitive equivalent
3534 of the given JavaScript <code>number</code>.</p>
3538 <p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) s…
3540 <h5><code>napi_get_value_int64</code><span><a class="mark" href="#napi_get_value_int64" id="napi_ge…
3545 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_int64</…
3547 …<span class="hljs-type">int64_t</span>* result)</span></code> <button class="copy-button">copy</bu…
3549 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3550 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3551 <li><code>[out] result</code>: C <code>int64</code> primitive equivalent of the given JavaScript
3552 <code>number</code>.</li>
3554 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3555 is passed in it returns <code>napi_number_expected</code>.</p>
3556 <p>This API returns the C <code>int64</code> primitive equivalent of the given JavaScript
3557 <code>number</code>.</p>
3558code>number</code> values outside the range of <a href="https://tc39.github.io/ecma262/#sec-number…
3559code>-(2**53 - 1)</code> - <a href="https://tc39.github.io/ecma262/#sec-number.max_safe_integer"><
3561 <p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) s…
3563 <h5><code>napi_get_value_string_latin1</code><span><a class="mark" href="#napi_get_value_string_lat…
3568 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3572 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3574 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3575 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3576 <li><code>[in] buf</code>: Buffer to write the ISO-8859-1-encoded string into. If <code>NULL</code>…
3578 is returned in <code>result</code>.</li>
3579 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3581 <li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null
3584 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3585 is passed in it returns <code>napi_string_expected</code>.</p>
3588 <h5><code>napi_get_value_string_utf8</code><span><a class="mark" href="#napi_get_value_string_utf8"…
3593 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3597 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3599 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3600 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3601 <li><code>[in] buf</code>: Buffer to write the UTF8-encoded string into. If <code>NULL</code> is pa…
3603 returned in <code>result</code>.</li>
3604 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3606 <li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null
3609 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3610 is passed in it returns <code>napi_string_expected</code>.</p>
3612 <h5><code>napi_get_value_string_utf16</code><span><a class="mark" href="#napi_get_value_string_utf1…
3617 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_string_…
3621 …<span class="hljs-type">size_t</span>* result)</span></code> <button class="copy-button">copy</but…
3623 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3624 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>
3625 <li><code>[in] buf</code>: Buffer to write the UTF16-LE-encoded string into. If <code>NULL</code> is
3626 passed in, the length of the string in 2-byte code units and excluding the
3628 <li><code>[in] bufsize</code>: Size of the destination buffer. When this value is
3630 <li><code>[out] result</code>: Number of 2-byte code units copied into the buffer, excluding
3633 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>string</code> <code>napi_value…
3634 is passed in it returns <code>napi_string_expected</code>.</p>
3636 <h5><code>napi_get_value_uint32</code><span><a class="mark" href="#napi_get_value_uint32" id="napi_…
3641 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_value_uint32<…
3643 …<span class="hljs-type">uint32_t</span>* result)</span></code> <button class="copy-button">copy</b…
3645 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3646 <li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>number</code>.</…
3647 <li><code>[out] result</code>: C primitive equivalent of the given <code>napi_value</code> as a
3648 <code>uint32_t</code>.</li>
3650 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>
3651 is passed in it returns <code>napi_number_expected</code>.</p>
3652 <p>This API returns the C primitive equivalent of the given <code>napi_value</code> as a
3653 <code>uint32_t</code>.</p>
3655 <h5><code>napi_get_boolean</code><span><a class="mark" href="#napi_get_boolean" id="napi_get_boolea…
3660code class="language-c">napi_status <span class="hljs-title function_">napi_get_boolean</span><spa…
3662 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3663 <li><code>[in] value</code>: The value of the boolean to retrieve.</li>
3664 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code>…
3667 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3670 <h5><code>napi_get_global</code><span><a class="mark" href="#napi_get_global" id="napi_get_global">…
3675code class="language-c">napi_status <span class="hljs-title function_">napi_get_global</span><span…
3677 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3678 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>global</code> …
3680 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3681 <p>This API returns the <code>global</code> object.</p>
3682 <h5><code>napi_get_null</code><span><a class="mark" href="#napi_get_null" id="napi_get_null">#</a><…
3687code class="language-c">napi_status <span class="hljs-title function_">napi_get_null</span><span c…
3689 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3690 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>null</code> ob…
3692 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3693 <p>This API returns the <code>null</code> object.</p>
3694 <h5><code>napi_get_undefined</code><span><a class="mark" href="#napi_get_undefined" id="napi_get_un…
3699code class="language-c">napi_status <span class="hljs-title function_">napi_get_undefined</span><s…
3701 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3702 <li><code>[out] result</code>: <code>napi_value</code> representing JavaScript Undefined value.</li>
3704 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3712 <li>Coerce JavaScript values to specific JavaScript types (such as <code>number</code> or
3713 <code>string</code>).</li>
3717 <h4><code>napi_coerce_to_bool</code><span><a class="mark" href="#napi_coerce_to_bool" id="napi_coer…
3722 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_bool</s…
3724 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3726 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3727 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3728 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Bo…
3730 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3731 <p>This API implements the abstract operation <code>ToBoolean()</code> as defined in
3733 <h4><code>napi_coerce_to_number</code><span><a class="mark" href="#napi_coerce_to_number" id="napi_…
3738 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_number<…
3740 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3742 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3743 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3744 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>nu…
3746 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3747 <p>This API implements the abstract operation <code>ToNumber()</code> as defined in
3749 This function potentially runs JS code if the passed-in value is an
3751 <h4><code>napi_coerce_to_object</code><span><a class="mark" href="#napi_coerce_to_object" id="napi_…
3756 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_object<…
3758 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3760 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3761 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3762 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Ob…
3764 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3765 <p>This API implements the abstract operation <code>ToObject()</code> as defined in
3767 <h4><code>napi_coerce_to_string</code><span><a class="mark" href="#napi_coerce_to_string" id="napi_…
3772 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_coerce_to_string<…
3774 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
3776 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3777 <li><code>[in] value</code>: The JavaScript value to coerce.</li>
3778 <li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>st…
3780 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3781 <p>This API implements the abstract operation <code>ToString()</code> as defined in
3783 This function potentially runs JS code if the passed-in value is an
3785 <h4><code>napi_typeof</code><span><a class="mark" href="#napi_typeof" id="napi_typeof">#</a></span>…
3790code class="language-c">napi_status <span class="hljs-title function_">napi_typeof</span><span cla…
3792 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3793 <li><code>[in] value</code>: The JavaScript value whose type to query.</li>
3794 <li><code>[out] result</code>: The type of the JavaScript value.</li>
3796 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3798 <li><code>napi_invalid_arg</code> if the type of <code>value</code> is not a known ECMAScript type …
3799 <code>value</code> is not an External value.</li>
3801 <p>This API represents behavior similar to invoking the <code>typeof</code> Operator on
3806 <li>It detects <code>null</code> as a separate type, while ECMAScript <code>typeof</code> would det…
3807 <code>object</code>.</li>
3809 <p>If <code>value</code> has a type that is invalid, an error is returned.</p>
3810 <h4><code>napi_instanceof</code><span><a class="mark" href="#napi_instanceof" id="napi_instanceof">…
3815 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_instanceof</span>…
3818 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3820 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3821 <li><code>[in] object</code>: The JavaScript value to check.</li>
3822 <li><code>[in] constructor</code>: The JavaScript function object of the constructor function
3824 <li><code>[out] result</code>: Boolean that is set to true if <code>object instanceof constructor</
3827 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3828 <p>This API represents invoking the <code>instanceof</code> Operator on the object as
3830 <h4><code>napi_is_array</code><span><a class="mark" href="#napi_is_array" id="napi_is_array">#</a><…
3835code class="language-c">napi_status <span class="hljs-title function_">napi_is_array</span><span c…
3837 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3838 <li><code>[in] value</code>: The JavaScript value to check.</li>
3839 <li><code>[out] result</code>: Whether the given object is an array.</li>
3841 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3842 <p>This API represents invoking the <code>IsArray</code> operation on the object
3844 <h4><code>napi_is_arraybuffer</code><span><a class="mark" href="#napi_is_arraybuffer" id="napi_is_a…
3849code class="language-c">napi_status <span class="hljs-title function_">napi_is_arraybuffer</span><…
3851 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3852 <li><code>[in] value</code>: The JavaScript value to check.</li>
3853 <li><code>[out] result</code>: Whether the given object is an <code>ArrayBuffer</code>.</li>
3855 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3856 <p>This API checks if the <code>Object</code> passed in is an array buffer.</p>
3857 <h4><code>napi_is_buffer</code><span><a class="mark" href="#napi_is_buffer" id="napi_is_buffer">#</…
3862code class="language-c">napi_status <span class="hljs-title function_">napi_is_buffer</span><span …
3864 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3865 <li><code>[in] value</code>: The JavaScript value to check.</li>
3866 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>node::B…
3869 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3870 <p>This API checks if the <code>Object</code> passed in is a buffer.</p>
3871 <h4><code>napi_is_date</code><span><a class="mark" href="#napi_is_date" id="napi_is_date">#</a></sp…
3876code class="language-c">napi_status <span class="hljs-title function_">napi_is_date</span><span cl…
3878 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3879 <li><code>[in] value</code>: The JavaScript value to check.</li>
3880 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a JavaScript <c…
3883 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3884 <p>This API checks if the <code>Object</code> passed in is a date.</p>
3885 <h4><code>napi_is_error</code><span><a class="mark" href="#napi_is_error_1" id="napi_is_error_1">#<…
3890code class="language-c">napi_status <span class="hljs-title function_">napi_is_error</span><span c…
3892 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3893 <li><code>[in] value</code>: The JavaScript value to check.</li>
3894 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents an <code>Error<…
3896 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3897 <p>This API checks if the <code>Object</code> passed in is an <code>Error</code>.</p>
3898 <h4><code>napi_is_typedarray</code><span><a class="mark" href="#napi_is_typedarray" id="napi_is_typ…
3903code class="language-c">napi_status <span class="hljs-title function_">napi_is_typedarray</span><s…
3905 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3906 <li><code>[in] value</code>: The JavaScript value to check.</li>
3907 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>TypedAr…
3909 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3910 <p>This API checks if the <code>Object</code> passed in is a typed array.</p>
3911 <h4><code>napi_is_dataview</code><span><a class="mark" href="#napi_is_dataview" id="napi_is_datavie…
3916code class="language-c">napi_status <span class="hljs-title function_">napi_is_dataview</span><spa…
3918 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3919 <li><code>[in] value</code>: The JavaScript value to check.</li>
3920 <li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>DataVie…
3922 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3923 <p>This API checks if the <code>Object</code> passed in is a <code>DataView</code>.</p>
3924 <h4><code>napi_strict_equals</code><span><a class="mark" href="#napi_strict_equals" id="napi_strict…
3929 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_strict_equals</sp…
3932 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3934 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3935 <li><code>[in] lhs</code>: The JavaScript value to check.</li>
3936 <li><code>[in] rhs</code>: The JavaScript value to check against.</li>
3937 <li><code>[out] result</code>: Whether the two <code>napi_value</code> objects are equal.</li>
3939 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3942 <h4><code>napi_detach_arraybuffer</code><span><a class="mark" href="#napi_detach_arraybuffer" id="n…
3947 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_detach_arraybuffe…
3948 … napi_value arraybuffer)</span></code> <button class="copy-button">copy</button></pre>
3950 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3951 <li><code>[in] arraybuffer</code>: The JavaScript <code>ArrayBuffer</code> to be detached.</li>
3953 <p>Returns <code>napi_ok</code> if the API succeeded. If a non-detachable <code>ArrayBuffer</code> …
3954 passed in it returns <code>napi_detachable_arraybuffer_expected</code>.</p>
3955 <p>Generally, an <code>ArrayBuffer</code> is non-detachable if it has been detached before.
3956 The engine may impose additional conditions on whether an <code>ArrayBuffer</code> is
3957 detachable. For example, V8 requires that the <code>ArrayBuffer</code> be external,
3958 …ated with <a href="#napi_create_external_arraybuffer"><code>napi_create_external_arraybuffer</code
3959 <p>This API represents the invocation of the <code>ArrayBuffer</code> detach operation as
3961 <h4><code>napi_is_detached_arraybuffer</code><span><a class="mark" href="#napi_is_detached_arraybuf…
3966 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_is_detached_array…
3968 …<span class="hljs-type">bool</span>* result)</span></code> <button class="copy-button">copy</butto…
3970 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
3971 <li><code>[in] arraybuffer</code>: The JavaScript <code>ArrayBuffer</code> to be checked.</li>
3972 <li><code>[out] result</code>: Whether the <code>arraybuffer</code> is detached.</li>
3974 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
3975 <p>The <code>ArrayBuffer</code> is considered detached if its internal data is <code>null</code>.</…
3976 <p>This API represents the invocation of the <code>ArrayBuffer</code> <code>IsDetachedBuffer</code>
3988 <li>Integer-Indexed: an index value represented by <code>uint32_t</code></li>
3989 <li>JavaScript value: these are represented in Node-API by <code>napi_value</code>. This can
3990 be a <code>napi_value</code> representing a <code>string</code>, <code>number</code>, or <code>symb…
3992 <p>Node-API values are represented by the type <code>napi_value</code>.
3993 Any Node-API call that requires a JavaScript value takes in a <code>napi_value</code>.
3995 <code>napi_value</code> in question is of the JavaScript type expected by the API.</p>
3998 <code>napi_value</code>.</p>
3999 <p>For instance, consider the following JavaScript code snippet:</p>
4000 <pre><code class="language-js"><span class="hljs-keyword">const</span> obj = {};
4001 obj.<span class="hljs-property">myProp</span> = <span class="hljs-number">123</span>;</code> <butto…
4003 <pre><code class="language-c">napi_status status = napi_generic_failure;
4016 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4019 <pre><code class="language-js"><span class="hljs-keyword">const</span> arr = [];
4020 arr[<span class="hljs-number">123</span>] = <span class="hljs-string">'hello'</span>;</code> <butto…
4022 <pre><code class="language-c">napi_status status = napi_generic_failure;
4035 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4038 <pre><code class="language-js"><span class="hljs-keyword">const</span> arr = [];
4039 <span class="hljs-keyword">const</span> value = arr[<span class="hljs-number">123</span>];</code> <…
4041 <pre><code class="language-c">napi_status status = napi_generic_failure;
4050 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4053 <pre><code class="language-js"><span class="hljs-keyword">const</span> obj = {};
4057 });</code> <button class="copy-button">copy</button></pre>
4059 <pre><code class="language-c">napi_status status = napi_status_generic_failure;
4082 …an> (status != napi_ok) <span class="hljs-keyword">return</span> status;</code> <button class="cop…
4084 <h5><code>napi_property_attributes</code><span><a class="mark" href="#napi_property_attributes" id=…
4090 <td><p>added <code>napi_default_method</code> and <code>napi_default_property</code>.</p></td></tr>
4094 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
4111 } napi_property_attributes;</code> <button class="copy-button">copy</button></pre>
4112 <p><code>napi_property_attributes</code> are flags used to control the behavior of properties
4113 set on a JavaScript object. Other than <code>napi_static</code> they correspond to the
4118 <li><code>napi_default</code>: No explicit attributes are set on the property. By default, a
4120 <li><code>napi_writable</code>: The property is writable.</li>
4121 <li><code>napi_enumerable</code>: The property is enumerable.</li>
4122 <li><code>napi_configurable</code>: The property is configurable as defined in
4124 <li><code>napi_static</code>: The property will be defined as a static property on a class as
4126 <a href="#napi_define_class"><code>napi_define_class</code></a>. It is ignored by <code>napi_define…
4127 <li><code>napi_default_method</code>: Like a method in a JS class, the property is
4129 <li><code>napi_default_jsproperty</code>: Like a property set via assignment in JavaScript,
4132 <h5><code>napi_property_descriptor</code><span><a class="mark" href="#napi_property_descriptor" id=…
4133 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
4145 } napi_property_descriptor;</code> <button class="copy-button">copy</button></pre>
4147 <li><code>utf8name</code>: Optional string describing the key for the property,
4148 encoded as UTF8. One of <code>utf8name</code> or <code>name</code> must be provided for the
4150 <li><code>name</code>: Optional <code>napi_value</code> that points to a JavaScript string or symbol
4151 to be used as the key for the property. One of <code>utf8name</code> or <code>name</code> must
4153 <li><code>value</code>: The value that's retrieved by a get access of the property if the
4154 property is a data property. If this is passed in, set <code>getter</code>, <code>setter</code>,
4155 <code>method</code> and <code>data</code> to <code>NULL</code> (since these members won't be used).…
4156 <li><code>getter</code>: A function to call when a get access of the property is performed.
4157 If this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since th…
4159 the property is accessed from JavaScript code (or if a get on the property is
4160 performed using a Node-API call). <a href="#napi_callback"><code>napi_callback</code></a> provides …
4161 <li><code>setter</code>: A function to call when a set access of the property is performed.
4162 If this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since th…
4164 the property is set from JavaScript code (or if a set on the property is
4165 performed using a Node-API call). <a href="#napi_callback"><code>napi_callback</code></a> provides …
4166 <li><code>method</code>: Set this to make the property descriptor object's <code>value</code>
4167 property to be a JavaScript function represented by <code>method</code>. If this is
4168 passed in, set <code>value</code>, <code>getter</code> and <code>setter</code> to <code>NULL</code>…
4169 won't be used). <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</li>
4170 <li><code>attributes</code>: The attributes associated with the particular property. See
4171 <a href="#napi_property_attributes"><code>napi_property_attributes</code></a>.</li>
4172 <li><code>data</code>: The callback data passed into <code>method</code>, <code>getter</code> and <
4176 <h5><code>napi_get_property_names</code><span><a class="mark" href="#napi_get_property_names" id="n…
4181 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_property_name…
4183 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4185 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4186 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4187 <li><code>[out] result</code>: A <code>napi_value</code> representing an array of JavaScript values
4189 iterate over <code>result</code> using <a href="#napi_get_array_length"><code>napi_get_array_length…
4190 and <a href="#napi_get_element"><code>napi_get_element</code></a>.</li>
4192 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4193 <p>This API returns the names of the enumerable properties of <code>object</code> as an array
4194 of strings. The properties of <code>object</code> whose key is a symbol will not be
4196 <h5><code>napi_get_all_property_names</code><span><a class="mark" href="#napi_get_all_property_name…
4201 <pre><code class="language-c">napi_get_all_property_names(napi_env env,
4206 … napi_value* result);</code> <button class="copy-button">copy</button></pre>
4208 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4209 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4210 <li><code>[in] key_mode</code>: Whether to retrieve prototype properties as well.</li>
4211 <li><code>[in] key_filter</code>: Which properties to retrieve
4213 <li><code>[in] key_conversion</code>: Whether to convert numbered property keys to strings.</li>
4214 <li><code>[out] result</code>: A <code>napi_value</code> representing an array of JavaScript values
4215 …operty names of the object. <a href="#napi_get_array_length"><code>napi_get_array_length</code></a>
4216 and <a href="#napi_get_element"><code>napi_get_element</code></a> can be used to iterate over <code
4218 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4221 <h5><code>napi_set_property</code><span><a class="mark" href="#napi_set_property" id="napi_set_prop…
4226 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_property</spa…
4229 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4231 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4232 <li><code>[in] object</code>: The object on which to set the property.</li>
4233 <li><code>[in] key</code>: The name of the property to set.</li>
4234 <li><code>[in] value</code>: The property value.</li>
4236 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4237 <p>This API set a property on the <code>Object</code> passed in.</p>
4238 <h5><code>napi_get_property</code><span><a class="mark" href="#napi_get_property" id="napi_get_prop…
4243 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_property</spa…
4246 … napi_value* result)</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 from which to retrieve the property.</li>
4250 <li><code>[in] key</code>: The name of the property to retrieve.</li>
4251 <li><code>[out] result</code>: The value of the property.</li>
4253 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4254 <p>This API gets the requested property from the <code>Object</code> passed in.</p>
4255 <h5><code>napi_has_property</code><span><a class="mark" href="#napi_has_property" id="napi_has_prop…
4260 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_property</spa…
4263 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
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 to query.</li>
4267 <li><code>[in] key</code>: The name of the property whose existence to check.</li>
4268 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4270 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4271 <p>This API checks if the <code>Object</code> passed in has the named property.</p>
4272 <h5><code>napi_delete_property</code><span><a class="mark" href="#napi_delete_property" id="napi_de…
4277 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_property</…
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 to delete.</li>
4285 <li><code>[out] result</code>: Whether the property deletion succeeded or not. <code>result</code> …
4286 optionally be ignored by passing <code>NULL</code>.</li>
4288 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4289 <p>This API attempts to delete the <code>key</code> own property from <code>object</code>.</p>
4290 <h5><code>napi_has_own_property</code><span><a class="mark" href="#napi_has_own_property" id="napi_…
4295 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_own_property<…
4298 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4300 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4301 <li><code>[in] object</code>: The object to query.</li>
4302 <li><code>[in] key</code>: The name of the own property whose existence to check.</li>
4303 <li><code>[out] result</code>: Whether the own property exists on the object or not.</li>
4305 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4306 <p>This API checks if the <code>Object</code> passed in has the named own property. <code>key</code
4307 be a <code>string</code> or a <code>symbol</code>, or an error will be thrown. Node-API will not
4309 <h5><code>napi_set_named_property</code><span><a class="mark" href="#napi_set_named_property" id="n…
4314 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_named_propert…
4317 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4319 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4320 <li><code>[in] object</code>: The object on which to set the property.</li>
4321 <li><code>[in] utf8Name</code>: The name of the property to set.</li>
4322 <li><code>[in] value</code>: The property value.</li>
4324 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4325 …ent to calling <a href="#napi_set_property"><code>napi_set_property</code></a> with a <code>napi_v…
4326 created from the string passed in as <code>utf8Name</code>.</p>
4327 <h5><code>napi_get_named_property</code><span><a class="mark" href="#napi_get_named_property" id="n…
4332 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_named_propert…
4335 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4337 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4338 <li><code>[in] object</code>: The object from which to retrieve the property.</li>
4339 <li><code>[in] utf8Name</code>: The name of the property to get.</li>
4340 <li><code>[out] result</code>: The value of the property.</li>
4342 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4343 …ent to calling <a href="#napi_get_property"><code>napi_get_property</code></a> with a <code>napi_v…
4344 created from the string passed in as <code>utf8Name</code>.</p>
4345 <h5><code>napi_has_named_property</code><span><a class="mark" href="#napi_has_named_property" id="n…
4350 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_named_propert…
4353 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4355 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4356 <li><code>[in] object</code>: The object to query.</li>
4357 <li><code>[in] utf8Name</code>: The name of the property whose existence to check.</li>
4358 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4360 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4361 …ent to calling <a href="#napi_has_property"><code>napi_has_property</code></a> with a <code>napi_v…
4362 created from the string passed in as <code>utf8Name</code>.</p>
4363 <h5><code>napi_set_element</code><span><a class="mark" href="#napi_set_element" id="napi_set_elemen…
4368 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_set_element</span…
4371 … napi_value value)</span>;</code> <button class="copy-button">copy</button></pre>
4373 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4374 <li><code>[in] object</code>: The object from which to set the properties.</li>
4375 <li><code>[in] index</code>: The index of the property to set.</li>
4376 <li><code>[in] value</code>: The property value.</li>
4378 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4379 <p>This API sets an element on the <code>Object</code> passed in.</p>
4380 <h5><code>napi_get_element</code><span><a class="mark" href="#napi_get_element" id="napi_get_elemen…
4385 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_element</span…
4388 … napi_value* result)</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 retrieve the property.</li>
4392 <li><code>[in] index</code>: The index of the property to get.</li>
4393 <li><code>[out] result</code>: The value of the property.</li>
4395 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4397 <h5><code>napi_has_element</code><span><a class="mark" href="#napi_has_element" id="napi_has_elemen…
4402 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_has_element</span…
4405 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
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 to query.</li>
4409 <li><code>[in] index</code>: The index of the property whose existence to check.</li>
4410 <li><code>[out] result</code>: Whether the property exists on the object or not.</li>
4412 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4413 <p>This API returns if the <code>Object</code> passed in has an element at the
4415 <h5><code>napi_delete_element</code><span><a class="mark" href="#napi_delete_element" id="napi_dele…
4420 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_element</s…
4423 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
4425 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4426 <li><code>[in] object</code>: The object to query.</li>
4427 <li><code>[in] index</code>: The index of the property to delete.</li>
4428 <li><code>[out] result</code>: Whether the element deletion succeeded or not. <code>result</code> c…
4429 optionally be ignored by passing <code>NULL</code>.</li>
4431 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4432 <p>This API attempts to delete the specified <code>index</code> from <code>object</code>.</p>
4433 <h5><code>napi_define_properties</code><span><a class="mark" href="#napi_define_properties" id="nap…
4438 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_define_properties…
4441 …s="hljs-type">const</span> napi_property_descriptor* properties)</span>;</code> <button class="cop…
4443 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4444 <li><code>[in] object</code>: The object from which to retrieve the properties.</li>
4445 <li><code>[in] property_count</code>: The number of elements in the <code>properties</code> array.<…
4446 <li><code>[in] properties</code>: The array of property descriptors.</li>
4448 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4451 <a href="#napi_property_descriptor"><code>napi_property_descriptor</code></a>). Given an array of s…
4453 <code>DefineOwnProperty()</code> (described in <a href="https://tc39.github.io/ecma262/#sec-ordinar…
4455 <h5><code>napi_object_freeze</code><span><a class="mark" href="#napi_object_freeze" id="napi_object…
4460 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_object_freeze</sp…
4461 … napi_value object)</span>;</code> <button class="copy-button">copy</button></pre>
4463 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4464 <li><code>[in] object</code>: The object to freeze.</li>
4466 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4474 <h5><code>napi_object_seal</code><span><a class="mark" href="#napi_object_seal" id="napi_object_sea…
4479 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_object_seal</span…
4480 … napi_value object)</span>;</code> <button class="copy-button">copy</button></pre>
4482 <li><code>[in] env</code>: The environment that the Node-API call is invoked under.</li>
4483 <li><code>[in] object</code>: The object to seal.</li>
4485 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4491 <p>Node-API provides a set of APIs that allow JavaScript code to
4492 call back into native code. Node-APIs that support calling back
4493 into native code take in a callback functions represented by
4494 the <code>napi_callback</code> type. When the JavaScript VM calls back to
4495 native code, the <code>napi_callback</code> function provided is invoked. The APIs
4501 <li>Return a <code>napi_value</code> back from the callback.</li>
4504 JavaScript functions from native code. One can either call a function
4507 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> field of the
4508 <code>napi_property_descriptor</code> items can be associated with <code>object</code> and freed
4509 whenever <code>object</code> is garbage-collected by passing both <code>object</code> and the data …
4510 <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.</p>
4511 <h4><code>napi_call_function</code><span><a class="mark" href="#napi_call_function" id="napi_call_f…
4516 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_call_…
4521 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4523 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4524 <li><code>[in] recv</code>: The <code>this</code> value passed to the called function.</li>
4525 <li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function to be invo…
4526 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
4527 <li><code>[in] argv</code>: Array of <code>napi_values</code> representing JavaScript values passed…
4529 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.…
4531 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4534 native code <em>into</em> JavaScript. For the special case of calling into JavaScript
4535 after an async operation, see <a href="#napi_make_callback"><code>napi_make_callback</code></a>.</p>
4538 <pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title f…
4541 …property">AddTwo</span> = <span class="hljs-title class_">AddTwo</span>;</code> <button class="cop…
4543 following code:</p>
4544 <pre><code class="language-c"><span class="hljs-comment">// Get the function named "AddTwo" on the …
4567 …>if</span> (status != napi_ok) <span class="hljs-keyword">return</span>;</code> <button class="cop…
4568 <h4><code>napi_create_function</code><span><a class="mark" href="#napi_create_function" id="napi_cr…
4573 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_function</…
4578 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4580 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4581 <li><code>[in] utf8Name</code>: Optional name of the function encoded as UTF8. This is
4582 visible within JavaScript as the new function object's <code>name</code> property.</li>
4583 <li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or <code>NAPI_AUTO_…
4585 <li><code>[in] cb</code>: The native function which should be called when this function
4586 object is invoked. <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</…
4587 <li><code>[in] data</code>: User-provided data context. This will be passed back into the
4589 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript function object …
4592 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4593 <p>This API allows an add-on author to create a function object in native code.
4594 This is the primary mechanism to allow calling <em>into</em> the add-on's native code
4602 <pre><code class="language-c">napi_value <span class="hljs-title function_">SayHello</span><span cl…
4620 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)</code> <button class="copy-button">copy</button></pre>
4621 <p>Given the above code, the add-on can be used from JavaScript as follows:</p>
4622 <pre><code class="language-js"><span class="hljs-keyword">const</span> myaddon = <span class="hljs-…
4623 myaddon.<span class="hljs-title function_">sayHello</span>();</code> <button class="copy-button">co…
4624 <p>The string passed to <code>require()</code> is the name of the target in <code>binding.gyp</code>
4625 responsible for creating the <code>.node</code> file.</p>
4626 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> parameter c…
4628 <code>result</code> parameter) and freed whenever the function is garbage-collected by
4629 …cript function and the data to <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.<…
4630 <p>JavaScript <code>Function</code>s are described in <a href="https://tc39.github.io/ecma262/#sec-…
4632 <h4><code>napi_get_cb_info</code><span><a class="mark" href="#napi_get_cb_info" id="napi_get_cb_inf…
4637 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_cb_info</span…
4642 …<span class="hljs-type">void</span>** data)</span></code> <button class="copy-button">copy</button…
4644 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4645 <li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>
4646 <li><code>[in-out] argc</code>: Specifies the length of the provided <code>argv</code> array and
4647 receives the actual count of arguments. <code>argc</code> can
4648 optionally be ignored by passing <code>NULL</code>.</li>
4649 <li><code>[out] argv</code>: C array of <code>napi_value</code>s to which the arguments will be
4652 provided than claimed, the rest of <code>argv</code> is filled with <code>napi_value</code> values
4653 that represent <code>undefined</code>. <code>argv</code> can optionally be ignored by
4654 passing <code>NULL</code>.</li>
4655 <li><code>[out] thisArg</code>: Receives the JavaScript <code>this</code> argument for the call.
4656 <code>thisArg</code> can optionally be ignored by passing <code>NULL</code>.</li>
4657 <li><code>[out] data</code>: Receives the data pointer for the callback. <code>data</code> can
4658 optionally be ignored by passing <code>NULL</code>.</li>
4660 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4662 call like the arguments and the <code>this</code> pointer from a given callback info.</p>
4663 <h4><code>napi_get_new_target</code><span><a class="mark" href="#napi_get_new_target" id="napi_get_…
4668 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_new_target</s…
4670 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
4672 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4673 <li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>
4674 <li><code>[out] result</code>: The <code>new.target</code> of the constructor call.</li>
4676 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4677 <p>This API returns the <code>new.target</code> of the constructor call. If the current
4678 callback is not a constructor call, the result is <code>NULL</code>.</p>
4679 <h4><code>napi_new_instance</code><span><a class="mark" href="#napi_new_instance" id="napi_new_inst…
4684 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_new_instance</spa…
4688 … napi_value* result)</span></code> <button class="copy-button">copy</button></pre>
4690 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4691 <li><code>[in] cons</code>: <code>napi_value</code> representing the JavaScript function to be invo…
4693 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
4694 <li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code> representing the
4695 arguments to the constructor. If <code>argc</code> is zero this parameter may be
4696 omitted by passing in <code>NULL</code>.</li>
4697 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned,
4701 <code>napi_value</code> that represents the constructor for the object. For example,
4703 <pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title f…
4708 …eyword">new</span> <span class="hljs-title class_">MyObject</span>(arg);</code> <button class="cop…
4710 <pre><code class="language-c"><span class="hljs-comment">// Get the constructor function MyObject</…
4726 status = napi_new_instance(env, constructor, argc, argv, &#x26;value);</code> <button class="copy-b…
4727 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4732 <li>The <a href="#napi_define_class"><code>napi_define_class</code></a> API defines a JavaScript cl…
4735 <li>When JavaScript code invokes the constructor, the constructor callback
4736 uses <a href="#napi_wrap"><code>napi_wrap</code></a> to wrap a new C++ instance in a JavaScript obj…
4738 <li>When JavaScript code invokes a method or property accessor on the class,
4739 the corresponding <code>napi_callback</code> C++ function is invoked. For an instance
4740 callback, <a href="#napi_unwrap"><code>napi_unwrap</code></a> obtains the C++ instance that is the …
4746 reference to the class constructor for later <code>instanceof</code> checks.</p>
4747 <pre><code class="language-c">napi_value MyClass_constructor = <span class="hljs-literal">NULL</spa…
4757 }</code> <button class="copy-button">copy</button></pre>
4759 <p>There are occasions where <code>napi_instanceof()</code> is insufficient for ensuring that
4762 static methods rather than as the <code>this</code> value of prototype methods. In such
4764 <pre><code class="language-js"><span class="hljs-keyword">const</span> myAddon = <span class="hljs-…
4782 }</code> <button class="copy-button">copy</button></pre>
4783 <p>In the above example <code>myAddon.queryHasRecords()</code> is a method that accepts two
4793 <code>queryHasRecords()</code> has to perform a type validation. Retaining the JavaScript
4795 constructor from which the query handle was instantiated in <code>napi_ref</code>s can
4796 help, because <code>napi_instanceof()</code> can then be used to ensure that the instances
4797 passed into <code>queryHashRecords()</code> are indeed of the correct type.</p>
4798 <p>Unfortunately, <code>napi_instanceof()</code> does not protect against prototype
4802 will pass the <code>napi_instanceof()</code> test for a query handle instance, while still
4806 <code>napi_type_tag</code> structure for storing a type tag. When such a value is passed
4807 …cript object or <a href="#napi_create_external">external</a> stored in a <code>napi_value</code> to
4808 <code>napi_type_tag_object()</code>, the JavaScript object will be "marked" with the
4810 object arrives into a native binding, <code>napi_check_object_type_tag()</code> can be used
4813 of a higher fidelity than <code>napi_instanceof()</code> can provide, because such type-
4816 illustrates the use of <code>napi_type_tag_object()</code> and
4817 <code>napi_check_object_type_tag()</code>.</p>
4818 <pre><code class="language-c"><span class="hljs-comment">// This value is the type tag for a databa…
4882 }</code> <button class="copy-button">copy</button></pre>
4883 <h4><code>napi_define_class</code><span><a class="mark" href="#napi_define_class" id="napi_define_c…
4888 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_define_class</spa…
4895 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
4897 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4898 <li><code>[in] utf8name</code>: Name of the JavaScript constructor function. For clarity,
4900 <li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or <code>NAPI_AUTO_…
4902 <li><code>[in] constructor</code>: Callback function that handles constructing instances
4904 with the <a href="#napi_callback"><code>napi_callback</code></a> signature. A C++ class constructor…
4905 used. <a href="#napi_callback"><code>napi_callback</code></a> provides more details.</li>
4906 <li><code>[in] data</code>: Optional data to be passed to the constructor callback as
4907 the <code>data</code> property of the callback info.</li>
4908 <li><code>[in] property_count</code>: Number of items in the <code>properties</code> array argument…
4909 <li><code>[in] properties</code>: Array of property descriptors describing static and
4911 See <code>napi_property_descriptor</code>.</li>
4912 <li><code>[out] result</code>: A <code>napi_value</code> representing the constructor function for
4915 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4919 corresponding C++ class, the callback passed via <code>constructor</code> can be used to
4921 JavaScript object instance being constructed using <a href="#napi_wrap"><code>napi_wrap</code></a>.…
4924 class (defined by property descriptors with the <code>napi_static</code> attribute).</li>
4925 <li>Properties on the constructor function's <code>prototype</code> object. When wrapping a
4928 descriptors without the <code>napi_static</code> attribute after retrieving the C++ class
4930 <a href="#napi_unwrap"><code>napi_unwrap</code></a>.</li>
4932 <p>When wrapping a C++ class, the C++ constructor callback passed via <code>constructor</code>
4935 object. See <a href="#napi_wrap"><code>napi_wrap</code></a> for details.</p>
4936 …nstructor function returned from <a href="#napi_define_class"><code>napi_define_class</code></a> is
4938 code, and/or to check whether provided values are instances of the class. In
4941 <a href="#napi_create_reference"><code>napi_create_reference</code></a>, ensuring that the referenc…
4942 <p>Any non-<code>NULL</code> data which is passed to this API via the <code>data</code> parameter o…
4943 the <code>data</code> field of the <code>napi_property_descriptor</code> array items can be associa…
4944 with the resulting JavaScript constructor (which is returned in the <code>result</code>
4946 …cript function and the data to <a href="#napi_add_finalizer"><code>napi_add_finalizer</code></a>.<…
4947 <h4><code>napi_wrap</code><span><a class="mark" href="#napi_wrap" id="napi_wrap">#</a></span><a ari…
4952 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_wrap</span><span …
4957 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
4959 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
4960 <li><code>[in] js_object</code>: The JavaScript object that will be the wrapper for the
4962 <li><code>[in] native_object</code>: The native instance that will be wrapped in the
4964 <li><code>[in] finalize_cb</code>: Optional native callback that can be used to free the
4966 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
4967 <li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the
4969 <li><code>[out] result</code>: Optional reference to the wrapped object.</li>
4971 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
4973 retrieved later using <code>napi_unwrap()</code>.</p>
4974 <p>When JavaScript code invokes a constructor for a class that was defined using
4975 <code>napi_define_class()</code>, the <code>napi_callback</code> for the constructor is invoked.
4977 <code>napi_wrap()</code> to wrap the newly constructed instance in the already-created
4978 JavaScript object that is the <code>this</code> argument to the constructor callback.
4979 (That <code>this</code> object was created from the constructor function's <code>prototype</code>,
4982 provided that simply deletes the native instance that is received as the <code>data</code>
4988 <a href="#napi_delete_reference"><code>napi_delete_reference</code></a> ONLY in response to the fin…
4994 hasn't been called yet. When using <code>napi_get_reference_value()</code> on weak
4995 references returned by <code>napi_wrap()</code>, you should still handle an empty result.</p>
4996 <p>Calling <code>napi_wrap()</code> a second time on an object will return an error. To
4997 associate another native instance with the object, use <code>napi_remove_wrap()</code>
4999 <h4><code>napi_unwrap</code><span><a class="mark" href="#napi_unwrap" id="napi_unwrap">#</a></span>…
5004 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_unwrap</span><spa…
5006 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5008 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5009 <li><code>[in] js_object</code>: The object associated with the native instance.</li>
5010 <li><code>[out] result</code>: Pointer to the wrapped native instance.</li>
5012 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5014 object using <code>napi_wrap()</code>.</p>
5015 <p>When JavaScript code invokes a method or property accessor on the class, the
5016 corresponding <code>napi_callback</code> is invoked. If the callback is for an instance
5017 method or accessor, then the <code>this</code> argument to the callback is the wrapper
5019 then by calling <code>napi_unwrap()</code> on the wrapper object.</p>
5020 <h4><code>napi_remove_wrap</code><span><a class="mark" href="#napi_remove_wrap" id="napi_remove_wra…
5025 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_remove_wrap</span…
5027 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5029 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5030 <li><code>[in] js_object</code>: The object associated with the native instance.</li>
5031 <li><code>[out] result</code>: Pointer to the wrapped native instance.</li>
5033 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5035 object <code>js_object</code> using <code>napi_wrap()</code> and removes the wrapping. If a finalize
5038 <h4><code>napi_type_tag_object</code><span><a class="mark" href="#napi_type_tag_object" id="napi_ty…
5043 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_type_tag_object</…
5045 …<span class="hljs-type">const</span> napi_type_tag* type_tag)</span>;</code> <button class="copy-b…
5047 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5048 <li><code>[in] js_object</code>: The JavaScript object or <a href="#napi_create_external">external<…
5049 <li><code>[in] type_tag</code>: The tag with which the object is to be marked.</li>
5051 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5052 <p>Associates the value of the <code>type_tag</code> pointer with the JavaScript object or
5053 <a href="#napi_create_external">external</a>. <code>napi_check_object_type_tag()</code> can then be…
5057 <code>napi_invalid_arg</code>.</p>
5058 <h4><code>napi_check_object_type_tag</code><span><a class="mark" href="#napi_check_object_type_tag"…
5063 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_check_object_type…
5066 …<span class="hljs-type">bool</span>* result)</span>;</code> <button class="copy-button">copy</butt…
5068 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5069 <li><code>[in] js_object</code>: The JavaScript object or <a href="#napi_create_external">external<…
5071 <li><code>[in] type_tag</code>: The tag with which to compare any tag found on the object.</li>
5072 <li><code>[out] result</code>: Whether the type tag given matched the type tag on the
5073 object. <code>false</code> is also returned if no type tag was found on the object.</li>
5075 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5076 <p>Compares the pointer given as <code>type_tag</code> with any that can be found on
5077 <code>js_object</code>. If no tag is found on <code>js_object</code> or, if a tag is found but it d…
5078 not match <code>type_tag</code>, then <code>result</code> is set to <code>false</code>. If a tag is…
5079 matches <code>type_tag</code>, then <code>result</code> is set to <code>true</code>.</p>
5080 <h4><code>napi_add_finalizer</code><span><a class="mark" href="#napi_add_finalizer" id="napi_add_fi…
5085 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_add_finalizer</sp…
5090 … napi_ref* result)</span>;</code> <button class="copy-button">copy</button></pre>
5092 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5093 <li><code>[in] js_object</code>: The JavaScript object to which the native data will be
5095 <li><code>[in] finalize_data</code>: Optional data to be passed to <code>finalize_cb</code>.</li>
5096 <li><code>[in] finalize_cb</code>: Native callback that will be used to free the
5098 <a href="#napi_finalize"><code>napi_finalize</code></a> provides more details.</li>
5099 <li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the
5101 <li><code>[out] result</code>: Optional reference to the JavaScript object.</li>
5103 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5104 <p>Adds a <code>napi_finalize</code> callback which will be called when the JavaScript object
5105 in <code>js_object</code> has been garbage-collected.</p>
5108 <a href="#napi_delete_reference"><code>napi_delete_reference</code></a> ONLY in response to the fin…
5119 <p>Node-API defines the <code>napi_async_work</code> structure which is used to manage
5121 …_create_async_work"><code>napi_create_async_work</code></a> and <a href="#napi_delete_async_work">…
5122 <p>The <code>execute</code> and <code>complete</code> callbacks are functions that will be
5125 <p>The <code>execute</code> function should avoid making any Node-API calls
5127 JavaScript objects. Most often, any code that needs to make Node-API
5128 calls should be made in <code>complete</code> callback instead.
5129 Avoid using the <code>napi_env</code> parameter in the execute callback as
5132 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-title fun…
5136 …<span class="hljs-type">void</span>* data)</span>;</code> <button class="copy-button">copy</button…
5137 <p>When these methods are invoked, the <code>data</code> parameter passed will be the
5138 addon-provided <code>void*</code> data that was passed into the
5139 <code>napi_create_async_work</code> call.</p>
5141 for execution using the <a href="#napi_queue_async_work"><code>napi_queue_async_work</code></a> fun…
5142 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_queue_async_work<…
5143 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5144 <p><a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a> can be used if the wor…
5146 … calling <a href="#napi_cancel_async_work"><code>napi_cancel_async_work</code></a>, the <code>comp…
5147 will be invoked with a status value of <code>napi_cancelled</code>.
5148 The work should not be deleted before the <code>complete</code>
5150 <h4><code>napi_create_async_work</code><span><a class="mark" href="#napi_create_async_work" id="nap…
5156 <td><p>Added <code>async_resource</code> and <code>async_resource_name</code> parameters.</p></td><…
5163 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_async_work…
5169 … napi_async_work* result)</span>;</code> <button class="copy-button">copy</button></pre>
5171 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5172 <li><code>[in] async_resource</code>: An optional object associated with the async work
5173 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5174 <li><code>[in] async_resource_name</code>: Identifier for the kind of resource that is being
5175 provided for diagnostic information exposed by the <code>async_hooks</code> API.</li>
5176 <li><code>[in] execute</code>: The native function which should be called to execute the
5179 <li><code>[in] complete</code>: The native function which will be called when the
5181 …nt loop thread. <a href="#napi_async_complete_callback"><code>napi_async_complete_callback</code><…
5183 <li><code>[in] data</code>: User-provided data context. This will be passed back into the
5185 <li><code>[out] result</code>: <code>napi_async_work*</code> which is the handle to the newly creat…
5188 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5190 It should be freed using <a href="#napi_delete_async_work"><code>napi_delete_async_work</code></a> …
5192 <p><code>async_resource_name</code> should be a null-terminated, UTF-8-encoded string.</p>
5193 <p>The <code>async_resource_name</code> identifier is provided by the user and should be
5196 the <a href="async_hooks.html#type"><code>async_hooks</code> documentation</a> for more information…
5197 <h4><code>napi_delete_async_work</code><span><a class="mark" href="#napi_delete_async_work" id="nap…
5202 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_delete_async_work…
5203 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5205 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5206 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5208 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5211 <h4><code>napi_queue_async_work</code><span><a class="mark" href="#napi_queue_async_work" id="napi_…
5216 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_queue_async_work<…
5217 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5219 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5220 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5222 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5225 with the same <code>napi_async_work</code> item or the result will be undefined.</p>
5226 <h4><code>napi_cancel_async_work</code><span><a class="mark" href="#napi_cancel_async_work" id="nap…
5231 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_cancel_async_work…
5232 … napi_async_work work)</span>;</code> <button class="copy-button">copy</button></pre>
5234 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5235 <li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.…
5237 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5240 cancelled and <code>napi_generic_failure</code> will be returned. If successful,
5241 the <code>complete</code> callback will be invoked with a status value of
5242 <code>napi_cancelled</code>. The work should not be deleted before the <code>complete</code>
5250 <h4><code>napi_async_init</code><span><a class="mark" href="#napi_async_init" id="napi_async_init">…
5255 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_async_init</span>…
5258 … napi_async_context* result)</span></code> <button class="copy-button">copy</button></pre>
5260 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5261 <li><code>[in] async_resource</code>: Object associated with the async work
5262 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5263 …async_hooks.html#async_hooksexecutionasyncresource"><code>async_hooks.executionAsyncResource()</co…
5264 <li><code>[in] async_resource_name</code>: Identifier for the kind of resource that is being
5265 provided for diagnostic information exposed by the <code>async_hooks</code> API.</li>
5266 <li><code>[out] result</code>: The initialized async context.</li>
5268 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5269 <p>The <code>async_resource</code> object needs to be kept alive until
5270 <a href="#napi_async_destroy"><code>napi_async_destroy</code></a> to keep <code>async_hooks</code> …
5271 order to retain ABI compatibility with previous versions, <code>napi_async_context</code>s
5272 are not maintaining the strong reference to the <code>async_resource</code> objects to
5273 avoid introducing causing memory leaks. However, if the <code>async_resource</code> is
5274 garbage collected by JavaScript engine before the <code>napi_async_context</code> was
5275 destroyed by <code>napi_async_destroy</code>, calling <code>napi_async_context</code> related APIs
5276 …i_open_callback_scope"><code>napi_open_callback_scope</code></a> and <a href="#napi_make_callback"…
5277 problems like loss of async context when using the <code>AsyncLocalStorage</code> API.</p>
5278 <p>In order to retain ABI compatibility with previous versions, passing <code>NULL</code>
5279 for <code>async_resource</code> does not result in an error. However, this is not
5280 recommended as this will result poor results with <code>async_hooks</code>
5281 …yncid-type-triggerasyncid-resource"><code>init</code> hooks</a> and <code>async_hooks.executionAsy…
5282 now required by the underlying <code>async_hooks</code> implementation in order to provide
5284 <h4><code>napi_async_destroy</code><span><a class="mark" href="#napi_async_destroy" id="napi_async_…
5289 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_async_destroy</sp…
5290 … napi_async_context async_context)</span>;</code> <button class="copy-button">copy</button></pre>
5292 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5293 <li><code>[in] async_context</code>: The async context to be destroyed.</li>
5295 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5297 <h4><code>napi_make_callback</code><span><a class="mark" href="#napi_make_callback" id="napi_make_c…
5303 <td><p>Added <code>async_context</code> parameter.</p></td></tr>
5310 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_make_…
5316 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
5318 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5319 <li><code>[in] async_context</code>: Context for the async operation that is
5321 obtained from <a href="#napi_async_init"><code>napi_async_init</code></a>.
5322 In order to retain ABI compatibility with previous versions, passing <code>NULL</code>
5323 for <code>async_context</code> does not result in an error. However, this results
5325 async context when using the <code>AsyncLocalStorage</code> API.</li>
5326 <li><code>[in] recv</code>: The <code>this</code> value passed to the called function.</li>
5327 <li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function to be invo…
5328 <li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>
5329 <li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code> representing the
5330 arguments to the function. If <code>argc</code> is zero this parameter may be
5331 omitted by passing in <code>NULL</code>.</li>
5332 <li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.…
5334 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5336 add-on. This API is similar to <code>napi_call_function</code>. However, it is used to call
5337 <em>from</em> native code back <em>into</em> JavaScript <em>after</em> returning from an async
5339 wrapper around <code>node::MakeCallback</code>.</p>
5340 <p>Note it is <em>not</em> necessary to use <code>napi_make_callback</code> from within a
5341 <code>napi_async_complete_callback</code>; in that situation the callback's async
5342 context has already been set up, so a direct call to <code>napi_call_function</code>
5343 is sufficient and appropriate. Use of the <code>napi_make_callback</code> function
5345 <code>napi_create_async_work</code>.</p>
5346 <p>Any <code>process.nextTick</code>s or Promises scheduled on the microtask queue by
5348 <h4><code>napi_open_callback_scope</code><span><a class="mark" href="#napi_open_callback_scope" id=…
5353 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_open_…
5356 … napi_callback_scope* result)</span></code> <button class="copy-button">copy</button></pre>
5358 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5359 <li><code>[in] resource_object</code>: An object associated with the async work
5360 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5362 <code>async_resource</code> parameter in <a href="#napi_async_init"><code>napi_async_init</code></a…
5363 <li><code>[in] context</code>: Context for the async operation that is invoking the callback.
5364 …e a value previously obtained from <a href="#napi_async_init"><code>napi_async_init</code></a>.</l…
5365 <li><code>[out] result</code>: The newly created scope.</li>
5370 the stack the <a href="#napi_open_callback_scope"><code>napi_open_callback_scope</code></a> and
5371 <a href="#napi_close_callback_scope"><code>napi_close_callback_scope</code></a> functions can be us…
5373 <h4><code>napi_close_callback_scope</code><span><a class="mark" href="#napi_close_callback_scope" i…
5378 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_close…
5379 … napi_callback_scope scope)</span></code> <button class="copy-button">copy</button></pre>
5381 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5382 <li><code>[in] scope</code>: The scope to be closed.</li>
5386 <h4><code>napi_get_node_version</code><span><a class="mark" href="#napi_get_node_version" id="napi_…
5391 <pre><code class="language-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><s…
5399 …span class="hljs-type">const</span> napi_node_version** version)</span>;</code> <button class="cop…
5401 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5402 <li><code>[out] version</code>: A pointer to version information for Node.js itself.</li>
5404 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5405 <p>This function fills the <code>version</code> struct with the major, minor, and patch
5406 version of Node.js that is currently running, and the <code>release</code> field with the
5407 value of <a href="process.html#processrelease"><code>process.release.name</code></a>.</p>
5409 <h4><code>napi_get_version</code><span><a class="mark" href="#napi_get_version" id="napi_get_versio…
5414 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_get_version</span…
5415 …<span class="hljs-type">uint32_t</span>* result)</span>;</code> <button class="copy-button">copy</…
5417 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5418 <li><code>[out] result</code>: The highest version of Node-API supported.</li>
5420 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5429 <li>Call <code>napi_get_version()</code> to determine if the API is available.</li>
5430 <li>If available, dynamically load a pointer to the function using <code>uv_dlsym()</code>.</li>
5436 <h4><code>napi_adjust_external_memory</code><span><a class="mark" href="#napi_adjust_external_memor…
5441 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_adjus…
5443 …<span class="hljs-type">int64_t</span>* result)</span>;</code> <button class="copy-button">copy</b…
5445 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5446 <li><code>[in] change_in_bytes</code>: The change in externally allocated memory that is kept
5448 <li><code>[out] result</code>: The adjusted value</li>
5450 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5457 <p>Node-API provides facilities for creating <code>Promise</code> objects as described in
5459 objects. When a promise is created by <code>napi_create_promise()</code>, a "deferred"
5460 object is created and returned alongside the <code>Promise</code>. The deferred object is
5461 bound to the created <code>Promise</code> and is the only means to resolve or reject the
5462 <code>Promise</code> using <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</co…
5463 deferred object that is created by <code>napi_create_promise()</code> is freed by
5464 <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code>. The <code>Promise</cod…
5467 <pre><code class="language-c">napi_deferred deferred;
5479 <span class="hljs-keyword">return</span> promise;</code> <button class="copy-button">copy</button><…
5480 <p>The above function <code>do_something_asynchronous()</code> would perform its asynchronous
5483 <pre><code class="language-c">napi_deferred deferred;
5501 deferred = <span class="hljs-literal">NULL</span>;</code> <button class="copy-button">copy</button>…
5502 <h4><code>napi_create_promise</code><span><a class="mark" href="#napi_create_promise" id="napi_crea…
5507 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_create_promise</s…
5509 … napi_value* promise)</span>;</code> <button class="copy-button">copy</button></pre>
5511 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5512 <li><code>[out] deferred</code>: A newly created deferred object which can later be passed to
5513 <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code> to resolve resp. reject
5515 <li><code>[out] promise</code>: The JavaScript promise associated with the deferred object.</li>
5517 <p>Returns <code>napi_ok</code> if the API succeeded.</p>
5519 <h4><code>napi_resolve_deferred</code><span><a class="mark" href="#napi_resolve_deferred" id="napi_…
5524 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_resolve_deferred<…
5526 … napi_value resolution)</span>;</code> <button class="copy-button">copy</button></pre>
5528 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5529 <li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>
5530 <li><code>[in] resolution</code>: The value with which to resolve the promise.</li>
5536 <code>napi_create_promise()</code> and the deferred object returned from that call must
5539 <h4><code>napi_reject_deferred</code><span><a class="mark" href="#napi_reject_deferred" id="napi_re…
5544 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_reject_deferred</…
5546 … napi_value rejection)</span>;</code> <button class="copy-button">copy</button></pre>
5548 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5549 <li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>
5550 <li><code>[in] rejection</code>: The value with which to reject the promise.</li>
5556 <code>napi_create_promise()</code> and the deferred object returned from that call must
5559 <h4><code>napi_is_promise</code><span><a class="mark" href="#napi_is_promise" id="napi_is_promise">…
5564 <pre><code class="language-c">napi_status <span class="hljs-title function_">napi_is_promise</span>…
5566 …<span class="hljs-type">bool</span>* is_promise)</span>;</code> <button class="copy-button">copy</…
5568 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5569 <li><code>[in] value</code>: The value to examine</li>
5570 <li><code>[out] is_promise</code>: Flag indicating whether <code>promise</code> is a native promise
5576 <h4><code>napi_run_script</code><span><a class="mark" href="#napi_run_script" id="napi_run_script">…
5581 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_run_s…
5583 … napi_value* result)</span>;</code> <button class="copy-button">copy</button></pre>
5585 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5586 <li><code>[in] script</code>: A JavaScript string containing the script to execute.</li>
5587 <li><code>[out] result</code>: The value resulting from having executed the script.</li>
5589 <p>This function executes a string of JavaScript code and returns its result with
5592 <li>Unlike <code>eval</code>, this function does not allow the script to access the current
5594 …odule-scope">module scope</a>, meaning that pseudo-globals such as <code>require</code> will not be
5596 <li>The script can access the <a href="globals.html">global scope</a>. Function and <code>var</code
5597 in the script will be added to the <a href="globals.html#global"><code>global</code></a> object. Va…
5598 made using <code>let</code> and <code>const</code> will be visible globally, but will not be added
5599 to the <a href="globals.html#global"><code>global</code></a> object.</li>
5600 <li>The value of <code>this</code> is <a href="globals.html#global"><code>global</code></a> within …
5604 a specific <code>napi_env</code>.</p>
5605 <h4><code>napi_get_uv_event_loop</code><span><a class="mark" href="#napi_get_uv_event_loop" id="nap…
5610 <pre><code class="language-c">NAPI_EXTERN napi_status <span class="hljs-title function_">napi_get_u…
5611 …<span class="hljs-keyword">struct</span> uv_loop_s** loop)</span>;</code> <button class="copy-butt…
5613 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5614 <li><code>[out] loop</code>: The current libuv loop instance.</li>
5619 require a <code>napi_env</code>, <code>napi_value</code>, or <code>napi_ref</code> must not be call…
5626 <p>These APIs provide the type <code>napi_threadsafe_function</code> as well as APIs to
5628 <code>napi_create_threadsafe_function()</code> creates a persistent reference to a
5629 <code>napi_value</code> that holds a JavaScript function which can be called from multiple
5633 <p>Upon creation of a <code>napi_threadsafe_function</code> a <code>napi_finalize</code> callback c…
5637 threads e.g. by calling <code>uv_thread_join()</code>. <strong>Aside from the main loop thread,
5640 <p>The <code>context</code> given during the call to <code>napi_create_threadsafe_function()</code>…
5642 <code>napi_get_threadsafe_function_context()</code>.</p>
5644 <p><code>napi_call_threadsafe_function()</code> can be used for initiating a call into
5645 JavaScript. <code>napi_call_threadsafe_function()</code> accepts a parameter which controls
5646 whether the API behaves blockingly. If set to <code>napi_tsfn_nonblocking</code>, the API
5647 behaves non-blockingly, returning <code>napi_queue_full</code> if the queue was full,
5649 <code>napi_tsfn_blocking</code>, the API blocks until space becomes available in the queue.
5650 <code>napi_call_threadsafe_function()</code> never blocks if the thread-safe function was
5652 <p><code>napi_call_threadsafe_function()</code> should not be called with <code>napi_tsfn_blocking<…
5656 <code>call_js_cb</code> parameter. <code>call_js_cb</code> is invoked on the main thread once for e…
5658 <code>napi_call_threadsafe_function()</code>. If such a callback is not given, a default
5660 The <code>call_js_cb</code> callback receives the JavaScript function to call as a
5661 <code>napi_value</code> in its parameters, as well as the <code>void*</code> context pointer used w…
5662 creating the <code>napi_threadsafe_function</code>, and the next data pointer that was
5664 as <code>napi_call_function()</code> to call into JavaScript.</p>
5665 …>The callback may also be invoked with <code>env</code> and <code>call_js_cb</code> both set to <c…
5669 <p>It is not necessary to call into JavaScript via <code>napi_make_callback()</code> because
5670 Node-API runs <code>call_js_cb</code> in a context appropriate for callbacks.</p>
5676 <p>Threads can be added to and removed from a <code>napi_threadsafe_function</code> object
5678 threads upon creation, <code>napi_acquire_threadsafe_function</code> can be called to
5680 Similarly, <code>napi_release_threadsafe_function</code> can be called to indicate that an
5682 <p><code>napi_threadsafe_function</code> objects are destroyed when every thread which uses
5683 the object has called <code>napi_release_threadsafe_function()</code> or has received a
5684 return status of <code>napi_closing</code> in response to a call to
5685 <code>napi_call_threadsafe_function</code>. The queue is emptied before the
5686 <code>napi_threadsafe_function</code> is destroyed. <code>napi_release_threadsafe_function()</code>
5688 <code>napi_threadsafe_function</code>, because after the call completes, there is no
5689 guarantee that the <code>napi_threadsafe_function</code> is still allocated. For the same
5691 after receiving a return value of <code>napi_closing</code> in response to a call to
5692 <code>napi_call_threadsafe_function</code>. Data associated with the
5693 <code>napi_threadsafe_function</code> can be freed in its <code>napi_finalize</code> callback which
5694 was passed to <code>napi_create_threadsafe_function()</code>. The parameter
5695 <code>initial_thread_count</code> of <code>napi_create_threadsafe_function</code> marks the initial
5697 <code>napi_acquire_threadsafe_function</code> multiple times at creation.</p>
5698 <p>Once the number of threads making use of a <code>napi_threadsafe_function</code> reaches
5700 <code>napi_acquire_threadsafe_function()</code>. In fact, all subsequent API calls
5701 associated with it, except <code>napi_release_threadsafe_function()</code>, will return an
5702 error value of <code>napi_closing</code>.</p>
5703 <p>The thread-safe function can be "aborted" by giving a value of <code>napi_tsfn_abort</code>
5704 to <code>napi_release_threadsafe_function()</code>. This will cause all subsequent APIs
5706 <code>napi_release_threadsafe_function()</code> to return <code>napi_closing</code> even before its
5707 reference count reaches zero. In particular, <code>napi_call_threadsafe_function()</code>
5708 will return <code>napi_closing</code>, thus informing the threads that it is no longer
5711 of <code>napi_closing</code> from <code>napi_call_threadsafe_function()</code> a thread must not use
5719 prevent the event loop from exiting. The APIs <code>napi_ref_threadsafe_function</code> and
5720 <code>napi_unref_threadsafe_function</code> exist for this purpose.</p>
5721 <p>Neither does <code>napi_unref_threadsafe_function</code> mark the thread-safe functions as
5722 able to be destroyed nor does <code>napi_ref_threadsafe_function</code> prevent it from
5724 <h4><code>napi_create_threadsafe_function</code><span><a class="mark" href="#napi_create_threadsafe…
5730 <td><p>Made <code>func</code> parameter optional with custom <code>call_js_cb</code>.</p></td></tr>
5737 <pre><code class="language-c">NAPI_EXTERN napi_status
5748 … napi_threadsafe_function* result)</span>;</code> <button class="copy-button">copy</button></pre>
5750 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5751 <li><code>[in] func</code>: An optional JavaScript function to call from another thread. It
5752 must be provided if <code>NULL</code> is passed to <code>call_js_cb</code>.</li>
5753 <li><code>[in] async_resource</code>: An optional object associated with the async work that
5754 …e passed to possible <code>async_hooks</code> <a href="async_hooks.html#initasyncid-type-triggeras…
5755 <li><code>[in] async_resource_name</code>: A JavaScript string to provide an identifier for
5757 by the <code>async_hooks</code> API.</li>
5758 <li><code>[in] max_queue_size</code>: Maximum size of the queue. <code>0</code> for no limit.</li>
5759 <li><code>[in] initial_thread_count</code>: The initial number of acquisitions, i.e. the
5762 <li><code>[in] thread_finalize_data</code>: Optional data to be passed to <code>thread_finalize_cb<…
5763 <li><code>[in] thread_finalize_cb</code>: Optional function to call when the
5764 <code>napi_threadsafe_function</code> is being destroyed.</li>
5765 <li><code>[in] context</code>: Optional data to attach to the resulting
5766 <code>napi_threadsafe_function</code>.</li>
5767 <li><code>[in] call_js_cb</code>: Optional callback which calls the JavaScript function in
5770 parameters and with <code>undefined</code> as its <code>this</code> value.
5771 <a href="#napi_threadsafe_function_call_js"><code>napi_threadsafe_function_call_js</code></a> provi…
5772 <li><code>[out] result</code>: The asynchronous thread-safe JavaScript function.</li>
5774 <h4><code>napi_get_threadsafe_function_context</code><span><a class="mark" href="#napi_get_threadsa…
5779 <pre><code class="language-c">NAPI_EXTERN napi_status
5781 …<span class="hljs-type">void</span>** result)</span>;</code> <button class="copy-button">copy</but…
5783 <li><code>[in] func</code>: The thread-safe function for which to retrieve the context.</li>
5784 <li><code>[out] result</code>: The location where to store the context.</li>
5786 <p>This API may be called from any thread which makes use of <code>func</code>.</p>
5787 <h4><code>napi_call_threadsafe_function</code><span><a class="mark" href="#napi_call_threadsafe_fun…
5793 <td><p>Support for <code>napi_would_deadlock</code> has been reverted.</p></td></tr>
5795 <td><p>Return <code>napi_would_deadlock</code> when called with <code>napi_tsfn_blocking</code> fro…
5802 <pre><code class="language-c">NAPI_EXTERN napi_status
5805 …napi_threadsafe_function_call_mode is_blocking)</span>;</code> <button class="copy-button">copy</b…
5807 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to invoke.</li>
5808 <li><code>[in] data</code>: Data to send into JavaScript via the callback <code>call_js_cb</code>
5810 <li><code>[in] is_blocking</code>: Flag whose value can be either <code>napi_tsfn_blocking</code> to
5812 <code>napi_tsfn_nonblocking</code> to indicate that the call should return immediately
5813 with a status of <code>napi_queue_full</code> whenever the queue is full.</li>
5815 <p>This API should not be called with <code>napi_tsfn_blocking</code> from a JavaScript
5818 <p>This API will return <code>napi_closing</code> if <code>napi_release_threadsafe_function()</code
5819 called with <code>abort</code> set to <code>napi_tsfn_abort</code> from any thread. The value is on…
5820 added to the queue if the API returns <code>napi_ok</code>.</p>
5821 <p>This API may be called from any thread which makes use of <code>func</code>.</p>
5822 <h4><code>napi_acquire_threadsafe_function</code><span><a class="mark" href="#napi_acquire_threadsa…
5827 <pre><code class="language-c">NAPI_EXTERN napi_status
5828 …</span><span class="hljs-params">(napi_threadsafe_function func)</span>;</code> <button class="cop…
5830 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to start making
5833 <p>A thread should call this API before passing <code>func</code> to any other thread-safe
5834 function APIs to indicate that it will be making use of <code>func</code>. This prevents
5835 <code>func</code> from being destroyed when all other threads have stopped making use of
5837 <p>This API may be called from any thread which will start making use of <code>func</code>.</p>
5838 <h4><code>napi_release_threadsafe_function</code><span><a class="mark" href="#napi_release_threadsa…
5843 <pre><code class="language-c">NAPI_EXTERN napi_status
5845 …napi_threadsafe_function_release_mode mode)</span>;</code> <button class="copy-button">copy</butto…
5847 <li><code>[in] func</code>: The asynchronous thread-safe JavaScript function whose reference
5849 <li><code>[in] mode</code>: Flag whose value can be either <code>napi_tsfn_release</code> to indica…
5851 function, or <code>napi_tsfn_abort</code> to indicate that in addition to the current
5853 function. If set to <code>napi_tsfn_abort</code>, further calls to
5854 <code>napi_call_threadsafe_function()</code> will return <code>napi_closing</code>, and no further
5857 …hread should call this API when it stops making use of <code>func</code>. Passing <code>func</code>
5859 <code>func</code> may have been destroyed.</p>
5860 <p>This API may be called from any thread which will stop making use of <code>func</code>.</p>
5861 <h4><code>napi_ref_threadsafe_function</code><span><a class="mark" href="#napi_ref_threadsafe_funct…
5866 <pre><code class="language-c">NAPI_EXTERN napi_status
5867 …lass="hljs-params">(napi_env env, napi_threadsafe_function func)</span>;</code> <button class="cop…
5869 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5870 <li><code>[in] func</code>: The thread-safe function to reference.</li>
5873 …exit until <code>func</code> has been destroyed. Similar to <a href="https://docs.libuv.org/en/v1.…
5875 <p>Neither does <code>napi_unref_threadsafe_function</code> mark the thread-safe functions as
5876 able to be destroyed nor does <code>napi_ref_threadsafe_function</code> prevent it from
5877 being destroyed. <code>napi_acquire_threadsafe_function</code> and
5878 <code>napi_release_threadsafe_function</code> are available for that purpose.</p>
5880 <h4><code>napi_unref_threadsafe_function</code><span><a class="mark" href="#napi_unref_threadsafe_f…
5885 <pre><code class="language-c">NAPI_EXTERN napi_status
5886 …lass="hljs-params">(napi_env env, napi_threadsafe_function func)</span>;</code> <button class="cop…
5888 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5889 <li><code>[in] func</code>: The thread-safe function to unreference.</li>
5892 …exit before <code>func</code> is destroyed. Similar to <a href="https://docs.libuv.org/en/v1.x/han…
5896 <h4><code>node_api_get_module_file_name</code><span><a class="mark" href="#node_api_get_module_file…
5901 <pre><code class="language-c">NAPI_EXTERN napi_status
5903 </code> <button class="copy-button">copy</button></pre>
5905 <li><code>[in] env</code>: The environment that the API is invoked under.</li>
5906 <li><code>[out] result</code>: A URL containing the absolute path of the
5908 file system it will start with <code>file://</code>. The string is null-terminated and
5909 owned by <code>env</code> and must thus not be modified or freed.</li>
5911 <p><code>result</code> may be an empty string if the add-on loading process fails to establish