1# Node-API Data Types and APIs 2 3## Data Types 4 5### napi_status 6 7Enum indicating the execution status of a Node-API call. 8 9Each time a Node-API function is called, a value of **napi_status** is returned indicating the execution result. 10 11```c 12typedef enum { 13 napi_ok, 14 napi_invalid_arg, 15 napi_object_expected, 16 napi_string_expected, 17 napi_name_expected, 18 napi_function_expected, 19 napi_number_expected, 20 napi_boolean_expected, 21 napi_array_expected, 22 napi_generic_failure, 23 napi_pending_exception, 24 napi_cancelled, 25 napi_escape_called_twice, 26 napi_handle_scope_mismatch, 27 napi_callback_scope_mismatch, 28 napi_queue_full, 29 napi_closing, 30 napi_bigint_expected, 31 napi_date_expected, 32 napi_arraybuffer_expected, 33 napi_detachable_arraybuffer_expected, 34 napi_would_deadlock, /* unused */ 35 napi_no_external_buffers_allowed, 36 napi_cannot_run_js 37} napi_status; 38``` 39 40### napi_extended_error_info 41 42Struct that holds detailed error information when a Node-API call fails. 43 44```c 45typedef struct { 46 const char *error_message; 47 void *engine_reserved; 48 uint32_t engine_error_code; 49 napi_status error_code; 50} napi_extended_error_info; 51``` 52 53### napi_value 54 55A C struct pointer acting as a reference to a JS object. A **napi_value** holds a JS object. **handle_scope** is used to manage the lifetime of **napi_value** handles. The JS object held by a **napi_value** in the scope will not be released. If the **napi_value** is out of the scope, it becomes invalid and will no longer hold the JS object. 56 57### napi_env 58 59- Context used by the underlying Node-API implementation. It is passed to the native functions when they are invoked, and must be passed back when Node-API calls are made. 60 61- **napi_env** becomes invalid when the JS thread bound with **napi_env** exits. 62 63- Avoid caching **napi_env** or passing **napi_env** between instances of the same addon running on different worker threads. 64 65### napi_threadsafe_function 66 67Pointer that represents a JS function that can be called asynchronously from multiple threads. It can be used to pass the asynchronous (async for short) operation result to the JS environment, such as reading data from another thread or performing compute-intensive operations. In addition, it can be used to call functions in C++ code from a JS environment for execution in another thread. By using **napi_threadsafe_function**, you can implement efficient interaction between JS and C++ code while maintaining thread safety. 68 69### napi_threadsafe_function_release_mode 70 71Enum that indicates when to release the thread-safe function. 72 73```c 74typedef enum { 75 napi_tsfn_release, 76 napi_tsfn_abort 77} napi_threadsafe_function_release_mode; 78``` 79 80Its value is passed to **napi_release_threadsafe_function**. 81 82```cpp 83napi_release_threadsafe_function(napi_threadsafe_function func, 84 napi_threadsafe_function_release_mode mode); 85``` 86 87- If the value is **napi_tsfn_release**, the current thread will not call this thread-safe function. 88 89- If the value is **napi_tsfn_abort**, only the current thread can call this thread-safe function. 90 In this case, using **napi_call_threadsafe_function** to call this function will return **napi_closing**, and this function will not be placed in the queue. 91 92### napi_threadsafe_function_call_mode 93 94Enum that indicates whether the call should be blocked when the queue associated with the thread-safe function is full. 95 96The data struct is as follows: 97 98```c 99typedef enum { 100 napi_tsfn_nonblocking, 101 napi_tsfn_blocking 102} napi_threadsafe_function_call_mode; 103``` 104 105- **napi_tsfn_nonblocking**: Leave **napi_call_threadsafe_function** unblocked. If the queue is full, **napi_queue_full** is returned to prevent data from being added to the queue. 106 107- **napi_tsfn_blocking**: Block **napi_call_threadsafe_function** until there is available space in the queue. 108 109### Memory Management Types 110 111Node-API provides the following memory management types: 112 113**napi_handle_scope** 114 115Data used to manage the lifecycle of JS objects. It allows JS objects to remain active within a certain range for use in JS code. When **napi_handle_scope** is created, all JS objects created in this range remain active until the scope ends. This prevents released objects from being used in JS code, which improves code reliability and performance. 116 117**napi_escapable_handle_scope** 118 119- It is created by **napi_open_escapable_handle_scope** and closed by **napi_close_escapable_handle_scope**. 120 121- It is a special type of handle range used to return values created within the scope of **escapable_handle_scope** to a parent scope. 122 123- You can use **napi_escape_handle** to promote **escape_handle_scope** to a JS object so that it is valid for the lifetime of the outer scope. 124 125**napi_ref** 126 127Reference to **napi_value**, which allows you to manage the lifecycle of JS values. 128 129**napi_type_tag** 130 131Struct containing two unsigned 64-bit integers to identify the type of a Node-API value. 132 133```c 134typedef struct { 135 uint64_t lower; 136 uint64_t upper; 137} napi_type_tag; 138``` 139 140- It is a 128-bit value stored as two unsigned 64-bit integers. It is used to tag JS objects to ensure that they are of a certain type. 141 142- This is a stronger check than **napi_instanceof** because **napi_instanceof** may report a false positive if the object's prototype is manipulated. 143 144- The combination of **type_tag** and **napi_wrap** is useful because it ensures that the pointer retrieved from a wrapped object can be safely converted to the native type corresponding to the type tag that had been previously applied to the JS object. 145 146**napi_async_cleanup_hook_handle** 147 148Value used to add a callback for an async operation. It is mainly used to perform a cleanup operation when an async operation is complete or canceled, for example, releasing a resource or canceling an operation. Using **napi_async_cleanup_hook_handle** ensures that related resources are correctly released and cleaned up when an async operation is complete or canceled, thereby avoiding problems such as memory leakage. 149 150### Callback Types 151 152Node-API provides the following callback types: 153 154**napi_callback_info** 155 156Data type passed to **napi_get_cb_info** to obtain JS input parameters. 157 158**napi_callback** 159 160User-defined native function, which is exposed to JS via Node-API. Generally, no handle or callback scope is created inside this callback. 161 162The basic usage is as follows: 163 164```c 165typedef napi_value (*napi_callback)(napi_env, napi_callback_info); 166``` 167 168**napi_finalize** 169 170Function pointer passed to **napi_create_threadsafe_function** and **napi_set_instance_data**. **napi_finalize** is called when an object is reclaimed. 171 172**napi_async_execute_callback** 173 174Function pointer used in **napi_create_async_work**. 175 176- An async native function is called from a worker pool thread and can be executed in parallel with the main event loop thread. 177 178- Avoid making Node-API calls that execute JS code or interact with JS objects when implementing this callback. 179 180- Node-API calls should be executed in **napi_async_complete_callback**. 181 182**napi_async_complete_callback** 183 184Function pointer used when an async operation is complete. When an async operation is required, you can use **napi_create_async_work** to create an async work and specify **napi_async_complete_callback**. When the async work is complete, the callback will be automatically invoked for subsequent processing. Parameters of the callback include the status of the async operation and a return value, based on which corresponding processing can be performed. 185 186**napi_threadsafe_function_call_js** 187 188Function pointer used in the main thread to interact with the JS code in an independent thread to implement more complex scenarios. It is used in **napi_create_threadsafe_function(napi_env env, ..., napi_threadsafe_function_call_js call_js_cb, ...)**. 189 190**napi_cleanup_hook** 191 192Function pointer used with **napi_add_env_cleanup_hook**. It will be called when the environment is destroyed. 193 194**napi_async_cleanup_hook** 195 196Function pointer used with **napi_add_async_cleanup_hook**. It will be called when the environment is destroyed. 197 198### QoS 199 200Enum indicating the thread scheduling priority. 201 202```c 203typedef enum { 204 napi_qos_background = 0, 205 napi_qos_utility = 1, 206 napi_qos_default = 2, 207 napi_qos_user_initiated = 3, 208} napi_qos_t; 209``` 210 211| QoS| Use Scenario| 212| -------- | -------- | 213| napi_qos_background | Low priority for works invisible to users, such as data synchronization and backup.| 214| napi_qos_utility | Medium priority for works that do not require immediate response, such as downloading or importing data.| 215| napi_qos_default | Default priority.| 216| napi_qos_user_initiated | High priority for user-triggered works with visible progress, for example, opening a file.| 217 218### Event Loop Modes 219 220Node-API provides two modes for running the underlying event loop. The two modes are defined as follows: 221 222```c 223typedef enum { 224 napi_event_mode_default = 0, 225 napi_event_mode_nowait = 1, 226} napi_event_mode; 227``` 228 229| Event Loop Mode| Description| 230| -------- | -------- | 231| napi_event_mode_default | Run the underlying event loop while blocking the current thread, and exit the event loop only when there is no task in the loop.| 232| napi_event_mode_nowait | Run the underlying event loop without blocking the current thread. Process a task and exit the event loop after the task is complete. If there is no task in the event loop, exit the event loop immediately.| 233 234### Thread-safe Task Priority 235 236Node-API defines the priorities of thread-safe tasks, as listed below. The tasks in the underlying task queue are executed in sequence based on their priorities. 237 238```c 239typedef enum { 240 napi_priority_immediate = 0, 241 napi_priority_high = 1, 242 napi_priority_low = 2, 243 napi_priority_idle = 3, 244} napi_task_priority; 245``` 246 247| Task Priority| Description| 248| -------- | -------- | 249| napi_priority_immediate | Highest priority.| 250| napi_priority_high | Priority lower than **napi_priority_immediate**.| 251| napi_priority_low | Priority lower than **napi_priority_high**.| 252| napi_priority_idle | Lowest priority.| 253 254## APIs 255 256Node-API is extended based on the native modules provided by Node.js. The following lists the APIs supported currently. 257 258### Async Thread-Safe APIs 259 260| API| Description| 261| -------- | -------- | 262| napi_create_threadsafe_function | Creates a thread-safe function.| 263| napi_get_threadsafe_function_context | Obtains the context of a thread-safe function.| 264| napi_call_threadsafe_function | Calls a thread-safe function.| 265| napi_acquire_threadsafe_function | Acquires a thread-safe function.| 266| napi_release_threadsafe_function | Releases a thread-safe function.| 267| napi_ref_threadsafe_function | Indicates that the event loop running on the main thread should not exit until the thread-safe function is destroyed.| 268| napi_unref_threadsafe_function | Indicates that the event loop running on the main thread may exit before the thread-safe function is destroyed.| 269 270### Buffer 271 272| API| Description| 273| -------- | -------- | 274| napi_create_buffer | Creates a JS **Buffer** of the specified size.| 275| napi_create_buffer_copy | Creates a JS **Buffer** of the specified size and initializes it with the given data.| 276| napi_create_external_buffer | Creates a JS **Buffer** of the specified size and initializes it with the given data.| 277| napi_get_buffer_info | Obtains the underlying data of a JS **Buffer** and its length.| 278| napi_is_buffer | Checks whether the given JS value is a **Buffer** object.| 279| napi_create_external_arraybuffer | Creates a JS **ArrayBuffer** with external data.| 280 281### String 282 283| API| Description| 284| -------- | -------- | 285| napi_create_string_utf16 | Creates a JS string from a UTF16-encoded C string.| 286| napi_get_value_string_utf16 | Obtains the UTF16-encoded string corresponding to the given JS value.| 287| napi_create_string_latin1 | Creates a JS string from an ISO-8859-1-encoded C string.| 288| napi_create_string_utf8 | Creates a JS string from a UTF8-encoded C string.| 289| napi_get_value_string_latin1 | Obtains the ISO-8859-1-encoded string corresponding to the given JS value.| 290| napi_get_value_string_utf8 | Obtains the UTF8-encoded string corresponding to the given JS value.| 291 292### Date 293 294| API| Description| 295| -------- | -------- | 296| napi_create_date | Creates a JS **Date** object from C double data.| 297| napi_get_date_value | Obtains the C double equivalent of the given JS **Date** object.| 298| napi_is_date | Checks whether the given JS value is a JS **Date** object.| 299 300### ArrayBuffer 301 302| API| Description| 303| -------- | -------- | 304| napi_get_arraybuffer_info | Obtains the underlying data buffer of an **ArrayBuffer** and its length.| 305| napi_is_arraybuffer | Checks whether the given JS value is an **ArrayBuffer** object.| 306| napi_detach_arraybuffer | Detaches the underlying data of the given **ArrayBuffer**.| 307| napi_is_detached_arraybuffer | Checks whether the given **ArrayBuffer** has been detached.| 308| napi_create_arraybuffer | Creates a JS **ArrayBuffer** object of the specified size.| 309 310### Module 311 312| API| Description| 313| -------- | -------- | 314| napi_module_register | Registers a native module.| 315 316### Lifecycle Management 317 318| API| Description| 319| -------- | -------- | 320| napi_open_handle_scope | Opens a scope. You can use **napi_close_handle_scope** to close it.| 321| napi_close_handle_scope | Closes the scope passed in. After a scope is closed, all references declared in it are closed.| 322| napi_open_escapable_handle_scope | Opens an escapable handle scope, from which the declared values can be returned to the parent scope. You can use **napi_close_escapable_handle_scope** to close it.| 323| napi_close_escapable_handle_scope | Closes the escapable handle scope passed in.| 324| napi_escape_handle | Promotes the handle to the JS object so that it is valid for the lifetime of the parent scope.| 325| napi_create_reference | Creates a reference for an object to extend its lifespan. The caller needs to manage the reference lifespan.| 326| napi_delete_reference | Deletes the reference passed in.| 327| napi_reference_ref | Increments the reference count passed in and returns the new count.| 328| napi_reference_unref | Decrements the reference count passed in and returns the new count.| 329| napi_get_reference_value | Obtains the JS object associated with the reference.| 330| napi_add_finalizer | Adds a **napi_finalize** callback, which will be called when the JS object is garbage-collected.| 331 332### Promise 333 334| API| Description| 335| -------- | -------- | 336| napi_create_promise | Creates a deferred object and a JS promise.| 337| napi_resolve_deferred | Resolves a promise by way of the deferred object associated.| 338| napi_reject_deferred | Rejects a promise by way of the deferred object associated.| 339| napi_is_promise | Checks whether the given **napi_value** is a promise object.| 340 341### Array 342 343| API| Description| 344| -------- | -------- | 345| napi_create_array | Creates a JS **Array**.| 346| napi_create_array_with_length | Creates a JS **Array** of the specified length.| 347| napi_get_array_length | Obtains the length of an array.| 348| napi_is_array | Checks whether the given JS value is an **Array** object.| 349| napi_set_element | Sets an element at the specified index of the given **Object**.| 350| napi_get_element | Obtains the element at the specified index of the given **Object**.| 351| napi_has_element | Checks whether the given **Object** has an element at the specified index.| 352| napi_delete_element | Deletes the element at the specified index of the given **Object**.| 353| napi_create_typedarray | Creates a JS **TypedArray** from an existing **ArrayBuffer**.| 354| napi_is_typedarray | Checks whether a JS value is an **TypeArray** object.| 355| napi_get_typedarray_info | Obtains the properties of a **TypedArray**.| 356| napi_create_dataview | Creates a JS **DataView** from an existing **ArrayBuffer**.| 357| napi_is_dataview | Checks whether a JS value is an **DataView** object.| 358| napi_get_dataview_info | Obtains the properties of a **DataView**.| 359 360### Primitives 361 362| API| Description| 363| -------- | -------- | 364| napi_get_boolean | Obtains a JS Boolean object based on the given C Boolean value.| 365| napi_get_global | Obtains the **global** object.| 366| napi_get_null | Obtains the **null** object.| 367| napi_get_undefined | Obtains the **undefined** object.| 368| napi_coerce_to_bool | Forcibly converts a JS value into a JS Boolean value.| 369| napi_coerce_to_number | Forcibly converts a JS value into a JS number.| 370| napi_coerce_to_object | Forcibly converts a JS value into a JS object.| 371| napi_coerce_to_string | Forcibly converts a JS value into a JS string.| 372 373### Class 374 375| API| Description| 376| -------- | -------- | 377| napi_new_instance | Creates an instance based on the given constructor.| 378| napi_get_new_target | Obtains the **new.target** of the constructor call.| 379| napi_define_class | Defines a JS class corresponding to the C++ class.| 380| napi_wrap | Wraps a native object into an ArkTS object. This API allows the methods and properties of a native object to be called from ArkTS.| 381| napi_unwrap | Unwraps the native object from an ArkTS object.| 382| napi_remove_wrap | Removes the wrapping after the native object is unwrapped from an ArkTS object.| 383 384### Object 385 386| API| Description| 387| -------- | -------- | 388| napi_get_prototype | Obtains the prototype of a JS object.| 389| napi_create_object | Creates a default JS object.| 390| napi_object_freeze | Freezes an object.| 391| napi_object_seal | Seals an object.| 392| napi_typeof | Obtains the JS type of a JS value.| 393| napi_instanceof | Checks whether the given object is an instance of the specified constructor.| 394| napi_type_tag_object | Associates the value of the tag pointer with a JS object.| 395| napi_check_object_type_tag | Checks whether a tag pointer is associated with a JS object.| 396 397### BigInt 398 399| API| Description| 400| -------- | -------- | 401| napi_create_bigint_int64 | Creates a JS BigInt from C int64 data.| 402| napi_create_bigint_uint64 | Creates a JS BigInt from C uint64 data.| 403| napi_create_bigint_words | Creates a single JS BigInt from a C uint64 array.| 404| napi_get_value_bigint_int64 | Obtains the C int64 equivalent of a JS BigInt.| 405| napi_get_value_bigint_uint64 | Obtains the C uint64 equivalent of a JS BigInt.| 406| napi_get_value_bigint_words | Obtains information from a JS BigInt, including the sign bit, 64-bit little-endian array, and number of elements in the array.| 407 408### Exceptions and Errors 409 410| API| Description| 411| -------- | -------- | 412| napi_throw | Throws a JS value.| 413| napi_throw_error | Throws an ArkTS **Error** object with text information.| 414| napi_throw_type_error | Throws a JS type error with text information.| 415| napi_throw_range_error | Throws a JS range error with text information.| 416| napi_is_error | Checks whether **napi_value** indicates an error object.| 417| napi_create_error | Creates a JS **Error** with text information.| 418| napi_create_type_error | Creates a JS **TypeError** with text information.| 419| napi_create_range_error | Creates a JS **RangeError** with text information.| 420| napi_get_and_clear_last_exception | Obtains and clears the latest exception.| 421| napi_is_exception_pending | Checks whether an exception occurs.| 422| napi_fatal_error | Raises a fatal error to terminate the process immediately.| 423| napi_get_last_error_info | Obtains the **napi_extended_error_info** struct, which contains the latest error information.| 424| napi_fatal_exception | Throws a fatal exception, terminates the process, and generates a crash log.| 425 426### Property 427 428| API| Description| 429| -------- | -------- | 430| napi_get_property_names | Obtains the names of the enumerable properties of an object in an array of strings.| 431| napi_set_property | Sets a property for an object.| 432| napi_get_property | Obtains the requested property of an object.| 433| napi_has_property | Checks whether an object has the specified property.| 434| napi_delete_property | Deletes a property from an object.| 435| napi_has_own_property | Checks whether an object has the own property specified by **key**.| 436| napi_set_named_property | Sets a property with the specified name for an object.| 437| napi_get_named_property | Obtains the property with the specified name in an object.| 438| napi_has_named_property | Checks whether an object has the property with the specified name.| 439| napi_define_properties | Defines multiple properties for an object.| 440| napi_get_all_property_names | Obtains an array containing the names of all the available properties of this object.| 441 442### Async Works 443 444| API| Description| 445| -------- | -------- | 446| napi_create_async_work | Creates a work object that executes logic asynchronously.| 447| napi_delete_async_work | Releases an async work object.| 448| napi_queue_async_work | Adds an async work object to the queue so that it can be scheduled for execution.| 449| napi_cancel_async_work | Cancels a queued async work if it has not been started.| 450 451### Custom Async Operations 452 453| API| Description| 454| -------- | -------- | 455| napi_async_init | Creates an async context. The capabilities related to **async_hook** are not supported.| 456| napi_make_callback | Allows a JS function to be called in the async context. The capabilities related to **async_hook** are not supported.| 457| napi_async_destroy | Destroys the previously created async context. The capabilities related to **async_hook** are not supported.| 458| napi_open_callback_scope | Opens a callback scope. The capabilities related to **async_hook** are not supported.| 459| napi_close_callback_scope | Closes the callback scope. The capabilities related to **async_hook** are not supported.| 460 461### Comparing JS Values 462 463| API| Description| 464| -------- | -------- | 465| napi_strict_equals | Checks whether two JS values are strictly equal.| 466 467### UV 468 469| API| Description| 470| -------- | -------- | 471| napi_get_uv_event_loop | Obtains the current libuv loop instance.| 472 473### Function Invocation 474 475| API| Description| 476| -------- | -------- | 477| napi_call_function | Calls a JS function from a C/C++ addon.| 478| napi_get_cb_info | Obtains detailed information about the call, such as the parameters and **this** pointer, from the given callback info.| 479 480### Extended Capabilities 481 482[Node-API extended symbols](../reference/native-lib/napi.md#node-api-extended-symbols) 483 484| API| Description| 485| -------- | -------- | 486| napi_queue_async_work_with_qos | Adds an async work object to the queue and schedules it based on the QoS passed in.| 487| napi_run_script_path | Runs an .abc file.| 488| napi_load_module | Loads an .abc file as a module. This API returns the namespace of the module.| 489| napi_load_module_with_info | Loads an .abc file as a module. This API returns the namespace of the module, which can be used in the newly created ArkTS runtime environment.| 490| napi_create_object_with_properties | Creates a JS object using the given **napi_property_descriptor**. The key of the descriptor must be a string and cannot be converted into a number.| 491| napi_create_object_with_named_properties | Creates a JS object using the given **napi_value**s and keys. The key must be a string and cannot be converted into a number.| 492| napi_coerce_to_native_binding_object | Forcibly binds a JS object and a native object.| 493| napi_create_ark_runtime|Creates an ArkTS runtime environment.| 494| napi_destroy_ark_runtime|Destroys an ArkTS runtime environment.| 495| napi_run_event_loop | Runs the underlying event loop.| 496| napi_stop_event_loop | Stops the underlying event loop.| 497| napi_serialize | Converts an ArkTS object into native data.| 498| napi_deserialize | Converts native data into an ArkTS object.| 499| napi_delete_serialization_data | Deletes serialized data.| 500| napi_call_threadsafe_function_with_priority|Calls a task with the specified priority and enqueuing mode into the ArkTS main thread.| 501| napi_is_sendable|Checks whether the given JS value is sendable.| 502| napi_define_sendable_class|Create a **sendable** class.| 503| napi_create_sendable_object_with_properties | Creates a sendable object with the given **napi_property_descriptor**.| 504| napi_create_sendable_array | Creates a sendable array.| 505| napi_create_sendable_array_with_length | Creates a sendable array of the specified length.| 506| napi_create_sendable_arraybuffer | Creates a sendable ArrayBuffer.| 507| napi_create_sendable_typedarray | Creates a sendable TypedArray.| 508| napi_wrap_sendable | Wraps a native instance into an ArkTS object.| 509| napi_wrap_sendable_with_size | Wraps a native instance into an ArkTS object with the specified size.| 510| napi_unwrap_sendable | Unwraps the native instance from an ArkTS object.| 511| napi_remove_wrap_sendable | Removes the native instance from an ArkTS object.| 512 513#### napi_queue_async_work_with_qos 514 515```c 516napi_status napi_queue_async_work_with_qos(napi_env env, 517 napi_async_work work, 518 napi_qos_t qos); 519``` 520 521This API has the same usage as **napi_queue_async_work**. The difference is you can specify the QoS for the work to run. 522 523#### napi_run_script_path 524 525```c 526napi_status napi_run_script_path(napi_env env, 527 const char* abcPath, 528 napi_value* result); 529``` 530 531#### napi_load_module 532 533```c 534napi_status napi_load_module(napi_env env, 535 const char* path, 536 napi_value* result); 537``` 538 539#### napi_create_object_with_properties 540 541```c 542napi_status napi_create_object_with_properties(napi_env env, 543 napi_value* result, 544 size_t property_count, 545 const napi_property_descriptor* properties); 546``` 547 548#### napi_create_object_with_named_properties 549 550```c 551napi_status napi_create_object_with_named_properties(napi_env env, 552 napi_value* result, 553 size_t property_count, 554 const char** keys, 555 const napi_value* values); 556``` 557 558#### napi_coerce_to_native_binding_object 559 560```c 561napi_status napi_coerce_to_native_binding_object(napi_env env, 562 napi_value js_object, 563 napi_native_binding_detach_callback detach_cb, 564 napi_native_binding_attach_callback attach_cb, 565 void* native_object, 566 void* hint); 567``` 568 569#### napi_run_event_loop 570 571```c 572napi_status napi_run_event_loop(napi_env env, napi_event_mode mode); 573``` 574 575#### napi_stop_event_loop 576 577```c 578napi_status napi_stop_event_loop(napi_env env); 579``` 580 581#### napi_serialize 582 583```c 584napi_status napi_serialize(napi_env env, 585 napi_value object, 586 napi_value transfer_list, 587 napi_value clone_list, 588 void** result); 589``` 590 591#### napi_deserialize 592 593```c 594napi_status napi_deserialize(napi_env env, void* buffer, napi_value* object); 595``` 596 597#### napi_delete_serialization_data 598 599```c 600napi_status napi_delete_serialization_data(napi_env env, void* buffer); 601``` 602 603#### napi_call_threadsafe_function_with_priority 604 605```c 606napi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func, 607 void *data, 608 napi_task_priority priority, 609 bool isTail); 610``` 611 612#### napi_is_sendable 613 614```c 615napi_status napi_is_sendable(napi_env env, napi_value value, bool* result); 616``` 617 618#### napi_define_sendable_class 619 620```c 621napi_status napi_define_sendable_class(napi_env env, 622 const char* utf8name, 623 size_t length, 624 napi_callback constructor, 625 void* data, 626 size_t property_count, 627 const napi_property_descriptor* properties, 628 napi_value parent, 629 napi_value* result); 630 631``` 632 633#### napi_create_sendable_object_with_properties 634 635```c 636napi_status napi_create_sendable_object_with_properties(napi_env env, 637 size_t property_count, 638 const napi_property_descriptor* properties, 639 napi_value* result); 640``` 641 642#### napi_create_sendable_array 643 644```c 645napi_status napi_create_sendable_array(napi_env env, napi_value* result); 646``` 647 648#### napi_create_sendable_array_with_length 649 650```c 651napi_status napi_create_sendable_array_with_length(napi_env env, size_t length, napi_value* result); 652``` 653 654#### napi_create_sendable_arraybuffer 655 656```c 657napi_status napi_create_sendable_arraybuffer(napi_env env, size_t byte_length, void** data, napi_value* result); 658``` 659 660#### napi_create_sendable_typedarray 661 662```c 663napi_status napi_create_sendable_typedarray(napi_env env, 664 napi_typedarray_type type, 665 size_t length, 666 napi_value arraybuffer, 667 size_t byte_offset, 668 napi_value* result); 669``` 670 671#### napi_wrap_sendable 672 673```c 674napi_status napi_wrap_sendable(napi_env env, 675 napi_value js_object, 676 void* native_object, 677 napi_finalize finalize_cb, 678 void* finalize_hint); 679``` 680 681#### napi_wrap_sendable_with_size 682 683```c 684napi_status napi_wrap_sendable_with_size(napi_env env, 685 napi_value js_object, 686 void* native_object, 687 napi_finalize finalize_cb, 688 void* finalize_hint, 689 size_t native_binding_size); 690``` 691 692#### napi_unwrap_sendable 693 694```c 695napi_status napi_unwrap_sendable(napi_env env, napi_value js_object, void** result); 696``` 697 698#### napi_remove_wrap_sendable 699 700```c 701napi_status napi_remove_wrap_sendable(napi_env env, napi_value js_object, void** result); 702``` 703 704### Environment Lifecycle 705 706| API| Description| 707| -------- | -------- | 708| napi_set_instance_data | Associates data with the currently running environment.| 709| napi_get_instance_data | Retrieves the data that was previously associated with the currently running environment.| 710 711### Object Lifetime Management 712 713| API| Description| 714| -------- | -------- | 715| napi_add_env_cleanup_hook | Adds a cleanup hook function for releasing resources when the environment exits.| 716| napi_remove_env_cleanup_hook | Removes a cleanup hook function.| 717| napi_add_async_cleanup_hook | Adds an async cleanup hook function for releasing resources when the environment exits.| 718| napi_remove_async_cleanup_hook | Removes an async cleanup hook function.| 719 720### ArkTS Runtime Environment 721 722| API| Description| 723| -------- | -------- | 724| napi_create_ark_runtime | Creates an ArkTS runtime environment.| 725| napi_destroy_ark_runtime | Destroys the ArkTS runtime environment.| 726 727### Other Utilities 728 729| API| Description| 730| -------- | -------- | 731| node_api_get_module_file_name | Obtains the absolute path of the module to be loaded.| 732