1e41f4b71Sopenharmony_ci# Node-API 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Introduction 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciNode-API provides APIs to encapsulate JavaScript (JS) capabilities as native addons. It is independent of the underlying JS and is maintained as part of Node.js. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Supported Capabilities 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciNode-API insulates addons from changes in the underlying JS engine and allows the modules compiled for one major version to run on later major versions without recompilation. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciThe OpenHarmony Node-API component optimizes the Node-API implementation and provides interaction with underlying engines such as ArkJS. Currently, the OpenHarmony Node-API component does not support all Node-API APIs. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Including Node-API Capabilities 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciTo use Node-API, include the following header file: 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci```cpp 18e41f4b71Sopenharmony_ci#include <napi/native_api.h> 19e41f4b71Sopenharmony_ci``` 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciAdd the following dynamic link library to **CMakeLists.txt**: 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci``` 24e41f4b71Sopenharmony_cilibace_napi.z.so 25e41f4b71Sopenharmony_ci``` 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## Symbols Exported from the Node-API Library 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciThe usage and behavior of the APIs exported from the Node-API standard library are the same as those of Node.js. For details about the API declaration and parameter constraints, see [Node-API](https://nodejs.org/docs/latest-v8.x/api/n-api.html) documentation. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci|Symbol Type|Symbol|Description|Start API Version| 32e41f4b71Sopenharmony_ci| --- | --- | --- | --- | 33e41f4b71Sopenharmony_ci|FUNC|napi_module_register|Registers a native module.|10| 34e41f4b71Sopenharmony_ci|FUNC|napi_get_last_error_info|Obtains the **napi_extended_error_info** struct, which contains the latest error information.|10| 35e41f4b71Sopenharmony_ci|FUNC|napi_throw|Throws a JS value.|10| 36e41f4b71Sopenharmony_ci|FUNC|napi_throw_error|Throws a JS **Error** with text information.|10| 37e41f4b71Sopenharmony_ci|FUNC|napi_throw_type_error|Throws a JS **TypeError** with text information.|10| 38e41f4b71Sopenharmony_ci|FUNC|napi_throw_range_error|Throws a JS **RangeError** with text information.|10| 39e41f4b71Sopenharmony_ci|FUNC|napi_is_error|Checks whether **napi_value** indicates an error object.|10| 40e41f4b71Sopenharmony_ci|FUNC|napi_create_error|Creates a JS **Error** with text information.|10| 41e41f4b71Sopenharmony_ci|FUNC|napi_create_type_error|Creates a JS **TypeError** with text information.|10| 42e41f4b71Sopenharmony_ci|FUNC|napi_create_range_error|Creates a JS **RangeError** with text information.|10| 43e41f4b71Sopenharmony_ci|FUNC|napi_get_and_clear_last_exception|Obtains and clears the latest exception.|10| 44e41f4b71Sopenharmony_ci|FUNC|napi_is_exception_pending|Checks whether an exception occurs.|10| 45e41f4b71Sopenharmony_ci|FUNC|napi_fatal_error|Raises a fatal error to terminate the process immediately.|10| 46e41f4b71Sopenharmony_ci|FUNC|napi_open_handle_scope|Opens a scope.|10| 47e41f4b71Sopenharmony_ci|FUNC|napi_close_handle_scope|Closes the scope passed in. After the scope is closed, all references declared in it are closed.|10| 48e41f4b71Sopenharmony_ci|FUNC|napi_open_escapable_handle_scope|Opens an escapable handle scope from which the declared values can be returned to the outer scope.|10| 49e41f4b71Sopenharmony_ci|FUNC|napi_close_escapable_handle_scope|Closes the escapable handle scope passed in.|10| 50e41f4b71Sopenharmony_ci|FUNC|napi_escape_handle|Promotes the handle to the input JS object so that it is valid for the lifespan of its outer scope.|10| 51e41f4b71Sopenharmony_ci|FUNC|napi_create_reference|Creates a reference for an **Object** to extend its lifespan. The caller needs to manage the reference lifespan.|10| 52e41f4b71Sopenharmony_ci|FUNC|napi_delete_reference|Deletes the reference passed in.|10| 53e41f4b71Sopenharmony_ci|FUNC|napi_reference_ref|Increments the reference count for the reference passed in and returns the count.|10| 54e41f4b71Sopenharmony_ci|FUNC|napi_reference_unref|Decrements the reference count for the reference passed in and returns the count.|10| 55e41f4b71Sopenharmony_ci|FUNC|napi_get_reference_value|Obtains the JS **Object** associated with the reference.|10| 56e41f4b71Sopenharmony_ci|FUNC|napi_create_array|Creates a JS array.|10| 57e41f4b71Sopenharmony_ci|FUNC|napi_create_array_with_length|Creates a JS array of the specified length.|10| 58e41f4b71Sopenharmony_ci|FUNC|napi_create_arraybuffer|Creates a JS ArrayBuffer of the specified size.|10| 59e41f4b71Sopenharmony_ci|FUNC|napi_create_external|Allocates a JS value with external data.|10| 60e41f4b71Sopenharmony_ci|FUNC|napi_create_external_arraybuffer|Allocates a JS ArrayBuffer with external data.|10| 61e41f4b71Sopenharmony_ci|FUNC|napi_create_object|Creates a default JS object.|10| 62e41f4b71Sopenharmony_ci|FUNC|napi_create_symbol|Creates a JS symbol.|10| 63e41f4b71Sopenharmony_ci|FUNC|napi_create_typedarray|Creates a JS TypeArray from an existing ArrayBuffer.|10| 64e41f4b71Sopenharmony_ci|FUNC|napi_create_dataview|Creates a JS DataView from an existing ArrayBuffer.|10| 65e41f4b71Sopenharmony_ci|FUNC|napi_create_int32|Creates a JS number from C int32_t data.|10| 66e41f4b71Sopenharmony_ci|FUNC|napi_create_uint32|Creates a JS number from C uint32_t data.|10| 67e41f4b71Sopenharmony_ci|FUNC|napi_create_int64|Creates a JS number from C int64_t data.|10| 68e41f4b71Sopenharmony_ci|FUNC|napi_create_double|Creates a JS number from C double data.|10| 69e41f4b71Sopenharmony_ci|FUNC|napi_create_string_latin1|Creates a JS string from an ISO-8859-1-encoded C string.|10| 70e41f4b71Sopenharmony_ci|FUNC|napi_create_string_utf8|Creates a JS string from a UTF8-encoded C string.|10| 71e41f4b71Sopenharmony_ci|FUNC|napi_create_string_utf16|Creates a JS string from a UTF16-encoded C string.|10| 72e41f4b71Sopenharmony_ci|FUNC|napi_get_array_length|Obtains the array length.|10| 73e41f4b71Sopenharmony_ci|FUNC|napi_get_arraybuffer_info|Obtains the underlying data buffer of **ArrayBuffer** and its length.|10| 74e41f4b71Sopenharmony_ci|FUNC|napi_get_prototype|Obtains the prototype of a JS object.|10| 75e41f4b71Sopenharmony_ci|FUNC|napi_get_typedarray_info|Obtains properties of a **TypedArray**.|10| 76e41f4b71Sopenharmony_ci|FUNC|napi_get_dataview_info|Obtains properties of a **DataView**.|10| 77e41f4b71Sopenharmony_ci|FUNC|napi_get_value_bool|Obtains the C Boolean equivalent of a JS Boolean value.|10| 78e41f4b71Sopenharmony_ci|FUNC|napi_get_value_double|Obtains the C double equivalent of a JS number.|10| 79e41f4b71Sopenharmony_ci|FUNC|napi_get_value_external|Obtains the external data pointer previously passed through **napi_create_external()**.|10| 80e41f4b71Sopenharmony_ci|FUNC|napi_get_value_int32|Obtains the C int32 equivalent of a JS number.|10| 81e41f4b71Sopenharmony_ci|FUNC|napi_get_value_int64|Obtains the C int64 equivalent of a JS number.|10| 82e41f4b71Sopenharmony_ci|FUNC|napi_get_value_string_latin1|Obtains the ISO-8859-1-encoded string corresponding to the given JS value.|10| 83e41f4b71Sopenharmony_ci|FUNC|napi_get_value_string_utf8|Obtains the UTF8-encoded string corresponding to the given JS value.|10| 84e41f4b71Sopenharmony_ci|FUNC|napi_get_value_string_utf16|Obtains the UTF16-encoded string corresponding to the given JS value.|10| 85e41f4b71Sopenharmony_ci|FUNC|napi_get_value_uint32|Obtains the C uint32 equivalent of a JS number.|10| 86e41f4b71Sopenharmony_ci|FUNC|napi_get_boolean|Obtains a JS Boolean object based on a C Boolean value.|10| 87e41f4b71Sopenharmony_ci|FUNC|napi_get_global|Obtains the **global** object.|10| 88e41f4b71Sopenharmony_ci|FUNC|napi_get_null|Obtains the **null** object.|10| 89e41f4b71Sopenharmony_ci|FUNC|napi_get_undefined|Obtains the **undefined** object.|10| 90e41f4b71Sopenharmony_ci|FUNC|napi_coerce_to_bool|Forcibly converts a JS value to a JS Boolean value.|10| 91e41f4b71Sopenharmony_ci|FUNC|napi_coerce_to_number|Forcibly converts a JS value to a JS number.|10| 92e41f4b71Sopenharmony_ci|FUNC|napi_coerce_to_object|Forcibly converts a JS value to a JS object.|10| 93e41f4b71Sopenharmony_ci|FUNC|napi_coerce_to_string|Forcibly converts a JS value to a JS string.|10| 94e41f4b71Sopenharmony_ci|FUNC|napi_typeof|Obtains the JS type of a JS value.|10| 95e41f4b71Sopenharmony_ci|FUNC|napi_instanceof|Checks whether an object is an instance of the specified constructor.|10| 96e41f4b71Sopenharmony_ci|FUNC|napi_is_array|Checks whether a JS value is an array.|10| 97e41f4b71Sopenharmony_ci|FUNC|napi_is_arraybuffer|Checks whether a JS value is a ArrayBuffer.|10| 98e41f4b71Sopenharmony_ci|FUNC|napi_is_typedarray|Checks whether a JS value is a TypedArray.|10| 99e41f4b71Sopenharmony_ci|FUNC|napi_is_dataview|Checks whether a JS value is a DataView.|10| 100e41f4b71Sopenharmony_ci|FUNC|napi_is_date|Checks whether a JS value is a JS **Date** object.|10| 101e41f4b71Sopenharmony_ci|FUNC|napi_strict_equals|Checks whether two JS values are strictly equal.|10| 102e41f4b71Sopenharmony_ci|FUNC|napi_get_property_names|Obtains the names of the enumerable properties of an object in an array of strings.|10| 103e41f4b71Sopenharmony_ci|FUNC|napi_set_property|Sets a property for an object.|10| 104e41f4b71Sopenharmony_ci|FUNC|napi_get_property|Obtains the requested property of an object.|10| 105e41f4b71Sopenharmony_ci|FUNC|napi_has_property|Checks whether an object has the specified property.|10| 106e41f4b71Sopenharmony_ci|FUNC|napi_delete_property|Deletes the **key** property from an object.|10| 107e41f4b71Sopenharmony_ci|FUNC|napi_has_own_property|Checks whether an object has the own property named **key**.|10| 108e41f4b71Sopenharmony_ci|FUNC|napi_set_named_property|Sets a property with the given name for an object.|10| 109e41f4b71Sopenharmony_ci|FUNC|napi_get_named_property|Obtains the property with the given name in an object.|10| 110e41f4b71Sopenharmony_ci|FUNC|napi_has_named_property|Checks whether an object has the property with the given name.|10| 111e41f4b71Sopenharmony_ci|FUNC|napi_set_element|Sets an element at the specified index of an object.|10| 112e41f4b71Sopenharmony_ci|FUNC|napi_get_element|Obtains the element at the specified index of an object.|10| 113e41f4b71Sopenharmony_ci|FUNC|napi_has_element|Obtains the element if the object has an element at the specified index.|10| 114e41f4b71Sopenharmony_ci|FUNC|napi_delete_element|Deletes the element at the specified index of an object.|10| 115e41f4b71Sopenharmony_ci|FUNC|napi_define_properties|Defines multiple properties for an object.|10| 116e41f4b71Sopenharmony_ci|FUNC|napi_type_tag_object|Associates the value of a tag pointer with an object.|10| 117e41f4b71Sopenharmony_ci|FUNC|napi_check_object_type_tag|Checks whether a tag pointer is associated with a JS object.|10| 118e41f4b71Sopenharmony_ci|FUNC|napi_call_function|Calls a JS function object in a native method, that is, native calls JS.|10| 119e41f4b71Sopenharmony_ci|FUNC|napi_create_function|Creates a function object in native code for JS to call.|10| 120e41f4b71Sopenharmony_ci|FUNC|napi_get_cb_info|Obtains detailed information about the call, such as the parameters and **this** pointer, from the given callback information.|10| 121e41f4b71Sopenharmony_ci|FUNC|napi_get_new_target|Obtains the **new.target** of the constructor call.|10| 122e41f4b71Sopenharmony_ci|FUNC|napi_new_instance|Creates an instance based on the given constructor.|10| 123e41f4b71Sopenharmony_ci|FUNC|napi_define_class|Defines a JS class corresponding to the C++ class.|10| 124e41f4b71Sopenharmony_ci|FUNC|napi_wrap|Wraps a native instance in a JS object.|10| 125e41f4b71Sopenharmony_ci|FUNC|napi_unwrap|Unwraps the native instance from a JS object.|10| 126e41f4b71Sopenharmony_ci|FUNC|napi_remove_wrap|Removes the native instance from the JS object.|10| 127e41f4b71Sopenharmony_ci|FUNC|napi_create_async_work|Creates a work object that executes logic asynchronously.|10| 128e41f4b71Sopenharmony_ci|FUNC|napi_delete_async_work|Releases an async work object.|10| 129e41f4b71Sopenharmony_ci|FUNC|napi_queue_async_work|Adds an async work object to the queue so that it can be scheduled for execution.|10| 130e41f4b71Sopenharmony_ci|FUNC|napi_cancel_async_work|Cancels the queued async work if it has not been started.|10| 131e41f4b71Sopenharmony_ci|FUNC|napi_async_init|Creates an async context. The capabilities related to **async_hook** are not supported.|11| 132e41f4b71Sopenharmony_ci|FUNC|napi_make_callback|Allows a JS function to be called in the async context. The capabilities related to **async_hook** are not supported.|11| 133e41f4b71Sopenharmony_ci|FUNC|napi_async_destroy|Destroys an async context. The capabilities related to **async_hook** are not supported.|11| 134e41f4b71Sopenharmony_ci|FUNC|napi_open_callback_scope|Opens a callback scope. The capabilities related to **async_hook** are not supported.|11| 135e41f4b71Sopenharmony_ci|FUNC|napi_close_callback_scope|Closes a callback scope. The capabilities related to **async_hook** are not supported.|11| 136e41f4b71Sopenharmony_ci|FUNC|napi_get_node_version|Obtains the current Node-API version.|10| 137e41f4b71Sopenharmony_ci|FUNC|napi_get_version|Obtains the latest Node-API version supported when the Node.js runtime.|10| 138e41f4b71Sopenharmony_ci|FUNC|napi_create_promise|Creates a deferred object and a JS promise.|10| 139e41f4b71Sopenharmony_ci|FUNC|napi_resolve_deferred|Resolves a deferred object that is associated with a JS promise.|10| 140e41f4b71Sopenharmony_ci|FUNC|napi_reject_deferred|Rejects a deferred object that is associated with a JS promise.|10| 141e41f4b71Sopenharmony_ci|FUNC|napi_is_promise|Checks whether the given JS value is a promise object.|10| 142e41f4b71Sopenharmony_ci|FUNC|napi_get_uv_event_loop|Obtains the current libuv loop instance.|10| 143e41f4b71Sopenharmony_ci|FUNC|napi_create_threadsafe_function|Creates a thread-safe function.|10| 144e41f4b71Sopenharmony_ci|FUNC|napi_get_threadsafe_function_context|Obtains the context of a thread-safe function.|10| 145e41f4b71Sopenharmony_ci|FUNC|napi_call_threadsafe_function|Calls a thread-safe function.|10| 146e41f4b71Sopenharmony_ci|FUNC|napi_acquire_threadsafe_function|Acquires a thread-safe function.|10| 147e41f4b71Sopenharmony_ci|FUNC|napi_release_threadsafe_function|Releases a thread-safe function.|10| 148e41f4b71Sopenharmony_ci|FUNC|napi_ref_threadsafe_function|Indicates that the event loop running on the main thread should not exit until the thread-safe function is destroyed.|10| 149e41f4b71Sopenharmony_ci|FUNC|napi_unref_threadsafe_function|Indicates that the event loop running on the main thread may exit before the thread-safe function is destroyed.|10| 150e41f4b71Sopenharmony_ci|FUNC|napi_create_date|Creates a JS **Date** object from C double data.|10| 151e41f4b71Sopenharmony_ci|FUNC|napi_get_date_value|Obtains the C double equivalent of the given JS **Date**.|10| 152e41f4b71Sopenharmony_ci|FUNC|napi_create_bigint_int64|Creates a JS BigInt from C int64 data.|10| 153e41f4b71Sopenharmony_ci|FUNC|napi_create_bigint_uint64|Creates a JS BigInt from C uint64 data.|10| 154e41f4b71Sopenharmony_ci|FUNC|napi_create_bigint_words|Creates a single JS BigInt from a C uint64 array.|10| 155e41f4b71Sopenharmony_ci|FUNC|napi_get_value_bigint_int64|Obtains the C int64 equivalent of the given JS BigInt.|10| 156e41f4b71Sopenharmony_ci|FUNC|napi_get_value_bigint_uint64|Obtains the C uint64 equivalent of the given JS BigInt.|10| 157e41f4b71Sopenharmony_ci|FUNC|napi_get_value_bigint_words|Obtains information from the given JS BigInt, including the sign bit, 64-bit little-endian array, and number of elements in the array.|10| 158e41f4b71Sopenharmony_ci|FUNC|napi_create_buffer|Creates a JS **Buffer** instance of the specified size.|10| 159e41f4b71Sopenharmony_ci|FUNC|napi_create_buffer_copy|Creates a JS **Buffer** instance of the specified size, and initializes it with data copied from the passed-in buffer.|10| 160e41f4b71Sopenharmony_ci|FUNC|napi_create_external_buffer|Creates a JS **Buffer** instance of the specified size, and initializes it with the given data. The **Buffer** instance created can include extra.|10| 161e41f4b71Sopenharmony_ci|FUNC|napi_get_buffer_info|Obtains the underlying data of **Buffer** and its length.|10| 162e41f4b71Sopenharmony_ci|FUNC|napi_is_buffer|Checks whether the given JS value is a **Buffer** object.|10| 163e41f4b71Sopenharmony_ci|FUNC|napi_object_freeze|Freezes the given object.|10| 164e41f4b71Sopenharmony_ci|FUNC|napi_object_seal|Seals the given object.|10| 165e41f4b71Sopenharmony_ci|FUNC|napi_get_all_property_names|Obtains an array containing the names of all the available properties of this object.|10| 166e41f4b71Sopenharmony_ci|FUNC|napi_detach_arraybuffer|Detaches the underlying data of the given ArrayBuffer.|10| 167e41f4b71Sopenharmony_ci|FUNC|napi_is_detached_arraybuffer|Checks whether the given ArrayBuffer has been detached.|10| 168e41f4b71Sopenharmony_ci|FUNC|napi_set_instance_data|Associates data with the currently running environment.|11| 169e41f4b71Sopenharmony_ci|FUNC|napi_get_instance_data|Retrieves the data that was previously associated with the currently running environment.|11| 170e41f4b71Sopenharmony_ci|FUNC|napi_add_env_cleanup_hook|Registers a clean-up hook for releasing resources when the environment exits.|11| 171e41f4b71Sopenharmony_ci|FUNC|napi_remove_env_cleanup_hook|Unregisters the clean-up hook.|11| 172e41f4b71Sopenharmony_ci|FUNC|napi_add_async_cleanup_hook|Registers an async clean-up hook for releasing resources when the environment exits.|11| 173e41f4b71Sopenharmony_ci|FUNC|napi_remove_async_cleanup_hook|Unregisters the async clean-up hook.|11| 174e41f4b71Sopenharmony_ci|FUNC|node_api_get_module_file_name|Obtains the absolute path of the location, from which the addon is loaded.|11| 175e41f4b71Sopenharmony_ci|FUNC|napi_add_finalizer|Adds a **napi_finalize** callback, which will be called when the JS object in **js_Object** is garbage-collected.|11| 176e41f4b71Sopenharmony_ci|FUNC|napi_fatal_exception|Throws **UncaughtException** to JS.|12| 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci## Symbols Not Exported from the Node-API Library 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci|Symbol Type|Symbol|Description| 181e41f4b71Sopenharmony_ci| --- | --- | --- | 182e41f4b71Sopenharmony_ci|FUNC|napi_run_script|Runs an object as JS code.| 183e41f4b71Sopenharmony_ci|FUNC|napi_adjust_external_memory|Adjusts the external memory held by a JS object.| 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci## Node-API Extended Symbols 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci|Symbol Type|Symbol|Description|Start API Version| 188e41f4b71Sopenharmony_ci| --- | --- | --- | --- | 189e41f4b71Sopenharmony_ci|FUNC|napi_queue_async_work_with_qos|Adds an async work object to the queue so that it can be scheduled for execution based on the QoS priority passed in.|10| 190e41f4b71Sopenharmony_ci|FUNC|napi_run_script_path|Runs an ABC file.|10| 191e41f4b71Sopenharmony_ci|FUNC|napi_load_module|Loads an .abc file as a module. This API returns the namespace of the module.|11| 192e41f4b71Sopenharmony_ci|FUNC|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.|11| 193e41f4b71Sopenharmony_ci|FUNC|napi_create_object_with_named_properties|Creates a JS object using the given **napi_value** and key. The key must be a string and cannot be converted into a number.|11| 194e41f4b71Sopenharmony_ci|FUNC|napi_coerce_to_native_binding_object|Forcibly binds a JS object and a native object.|11| 195e41f4b71Sopenharmony_ci|FUNC|napi_create_ark_runtime|Creates an ArkTS runtime environment.|12| 196e41f4b71Sopenharmony_ci|FUNC|napi_destroy_ark_runtime|Destroys the ArkTS runtime environment.|12| 197e41f4b71Sopenharmony_ci|FUNC|napi_run_event_loop|Runs the underlying event loop.|12| 198e41f4b71Sopenharmony_ci|FUNC|napi_stop_event_loop|Stops the underlying event loop.|12| 199e41f4b71Sopenharmony_ci|FUNC|napi_load_module_with_info|Loads an .abc file as a module. This API returns the namespace of the module. It can be used in a newly created ArkTS runtime environment.|12| 200e41f4b71Sopenharmony_ci|FUNC|napi_serialize|Converts an ArkTS object into native data.|12| 201e41f4b71Sopenharmony_ci|FUNC|napi_deserialize|Converts native data into an ArkTS object.|12| 202e41f4b71Sopenharmony_ci|FUNC|napi_delete_serialization_data|Deletes serialized data.|12| 203e41f4b71Sopenharmony_ci|FUNC|napi_call_threadsafe_function_with_priority|Calls a task with the specified priority and enqueuing mode into the ArkTS main thread.|12| 204e41f4b71Sopenharmony_ci|FUNC|napi_is_sendable|Checks whether the given JS value is sendable.|12| 205e41f4b71Sopenharmony_ci|FUNC|napi_define_sendable_class|Creates a sendable class.|12| 206e41f4b71Sopenharmony_ci|FUNC|napi_create_sendable_object_with_properties | Creates a sendable object with the given **napi_property_descriptor**.|12| 207e41f4b71Sopenharmony_ci|FUNC|napi_create_sendable_array | Creates a sendable array.|12| 208e41f4b71Sopenharmony_ci|FUNC|napi_create_sendable_array_with_length | Creates a sendable array of the specified length.|12| 209e41f4b71Sopenharmony_ci|FUNC|napi_create_sendable_arraybuffer | Creates a sendable ArrayBuffer.|12| 210e41f4b71Sopenharmony_ci|FUNC|napi_create_sendable_typedarray | Creates a sendable TypedArray.|12| 211e41f4b71Sopenharmony_ci|FUNC|napi_wrap_sendable | Wraps a native instance into an ArkTS object.|12| 212e41f4b71Sopenharmony_ci|FUNC|napi_wrap_sendable_with_size | Wraps a native instance into an ArkTS object with the specified size.|12| 213e41f4b71Sopenharmony_ci|FUNC|napi_unwrap_sendable | Unwraps the native instance from an ArkTS object.|12| 214e41f4b71Sopenharmony_ci|FUNC|napi_remove_wrap_sendable | Removes the native instance from an ArkTS object.|12| 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci### napi_qos_t 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci```cpp 219e41f4b71Sopenharmony_citypedef enum { 220e41f4b71Sopenharmony_ci napi_qos_background = 0, // Low priority for works invisible to users, such as data synchronization and backup. 221e41f4b71Sopenharmony_ci napi_qos_utility = 1, // Medium priority for works that do not require immediate response, such as downloading or importing data. 222e41f4b71Sopenharmony_ci napi_qos_default = 2, // Default priority. 223e41f4b71Sopenharmony_ci napi_qos_user_initiated = 3, // High priority for user-triggered works with visible progress, for example, opening a file. 224e41f4b71Sopenharmony_ci} napi_qos_t; 225e41f4b71Sopenharmony_ci``` 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Description** 228e41f4b71Sopenharmony_ciEnumerates the QoS levels, which determine the priority of thread scheduling. 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci### napi_event_mode 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci```cpp 233e41f4b71Sopenharmony_citypedef enum { 234e41f4b71Sopenharmony_ci napi_event_mode_default = 0, // Run the underlying event loop while blocking the current thread, and exit the event loop only when there is no task in the loop. 235e41f4b71Sopenharmony_ci napi_event_mode_nowait = 1, // 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. 236e41f4b71Sopenharmony_ci} napi_event_mode; 237e41f4b71Sopenharmony_ci``` 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Description** 240e41f4b71Sopenharmony_ciEnumerates the modes for running the underlying event loop. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci### napi_queue_async_work_with_qos 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci```cpp 245e41f4b71Sopenharmony_cinapi_status napi_queue_async_work_with_qos(napi_env env, 246e41f4b71Sopenharmony_ci napi_async_work work, 247e41f4b71Sopenharmony_ci napi_qos_t qos); 248e41f4b71Sopenharmony_ci``` 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Description** 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciAdds an async work object to the queue so that it can be scheduled for execution based on the QoS priority passed in. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**Parameters** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci- **work**: handle to the async work object to schedule. This object is created by **napi_create_async_work**. 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci- **qos**: priority of the task to schedule. 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**Return value** 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci### napi_run_script_path 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci```cpp 269e41f4b71Sopenharmony_cinapi_status napi_run_script_path(napi_env env, 270e41f4b71Sopenharmony_ci const char* abcPath, 271e41f4b71Sopenharmony_ci napi_value* result); 272e41f4b71Sopenharmony_ci``` 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci**Description** 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ciRuns an .abc file. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Parameters** 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci- **abcPath**: JS path of the script to run. The value is a string that specifies the location of the script file to run. 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci- **result**: pointer to **napi_value**, which holds the script execution result. 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci**Return value** 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci### napi_load_module 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci```cpp 293e41f4b71Sopenharmony_cinapi_status napi_load_module(napi_env env, 294e41f4b71Sopenharmony_ci const char* path, 295e41f4b71Sopenharmony_ci napi_value* result); 296e41f4b71Sopenharmony_ci``` 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Description** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciLoads a system module or a customized module. This API returns the namespace of the module loaded. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci**Parameters** 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci- **path**: name of the system module to load or path of the customized module to load. 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci- **result**: pointer to **napi_value**, which holds the module loading result. 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**Return value** 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci### napi_create_object_with_properties 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci```cpp 317e41f4b71Sopenharmony_cinapi_status napi_create_object_with_properties(napi_env env, 318e41f4b71Sopenharmony_ci napi_value* result, 319e41f4b71Sopenharmony_ci size_t property_count, 320e41f4b71Sopenharmony_ci const napi_property_descriptor* properties); 321e41f4b71Sopenharmony_ci``` 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci**Description** 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ciCreates a JS object using the given **napi_property_descriptor**.<br>**napi_property_descriptor** defines a property, including the property attributes and the methods used to obtain and set the property. By passing **napi_property_descriptor**, you can define the properties when creating an object. 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci The key in **napi_property_descriptor** must be a string that cannot be converted into a number. 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci**Parameters** 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci- **result**: pointer to **napi_value**, which holds the created object. 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci- **property_count**: number of properties to be added to the object. 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci- **properties**: pointer to a **napi_property_descriptor** array containing information about the properties to be added to the object. 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**Return value** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci### napi_create_object_with_named_properties 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci```cpp 346e41f4b71Sopenharmony_cinapi_status napi_create_object_with_named_properties(napi_env env, 347e41f4b71Sopenharmony_ci napi_value* result, 348e41f4b71Sopenharmony_ci size_t property_count, 349e41f4b71Sopenharmony_ci const char** keys, 350e41f4b71Sopenharmony_ci const napi_value* values); 351e41f4b71Sopenharmony_ci``` 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**Description** 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ciCreates a JS object using the given **napi_value**s and keys. The key must be a string and cannot be converted into a number. 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**Parameters** 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci- **result**: pointer to **napi_value**, which holds the created object. 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci- **property_count**: number of properties to be added to the object. 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci- **keys**: pointer to a const char array containing the keys of the properties to add. 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci- **values**: pointer to a **napi_value** array containing the properties to add. The keys and properties are in one-to-one mapping. 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**Return value** 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci### napi_coerce_to_native_binding_object 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci```cpp 376e41f4b71Sopenharmony_cinapi_status napi_coerce_to_native_binding_object(napi_env env, 377e41f4b71Sopenharmony_ci napi_value js_object, 378e41f4b71Sopenharmony_ci napi_native_binding_detach_callback detach_cb, 379e41f4b71Sopenharmony_ci napi_native_binding_attach_callback attach_cb, 380e41f4b71Sopenharmony_ci void* native_object, 381e41f4b71Sopenharmony_ci void* hint); 382e41f4b71Sopenharmony_ci``` 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**Description** 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ciConverts a JS object into an object carrying native information by forcibly binding callbacks and callback data to the JS object. 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci**Parameters** 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci- **js_object**: JS object to convert. 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci- **detach_cb**: callback to be invoked to perform cleanup operations when the object is detached during serialization. 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci- **attach_cb**: callback to be invoked when the object is attached during serialization. 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci- **native_object**: parameters to be passed to the callbacks. This object cannot be empty. 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci- **hint**: pointer to the additional information to be passed to the callbacks. 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci**Return value** 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci### napi_create_ark_runtime 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci```cpp 409e41f4b71Sopenharmony_cinapi_status napi_create_ark_runtime(napi_env *env) 410e41f4b71Sopenharmony_ci``` 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Description** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ciCreates an ArkTS runtime environment. 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**Parameters** 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**Return value** 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci### napi_destroy_ark_runtime 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci```cpp 427e41f4b71Sopenharmony_cinapi_status napi_destroy_ark_runtime(napi_env *env) 428e41f4b71Sopenharmony_ci``` 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci**Description** 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ciDestroys an ArkTS runtime environment. 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**Parameters** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci**Return value** 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci### napi_run_event_loop 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci```cpp 445e41f4b71Sopenharmony_cinapi_status napi_run_event_loop(napi_env env, napi_event_mode mode) 446e41f4b71Sopenharmony_ci``` 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**Description** 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ciRuns the underlying event loop. 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**Parameters** 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 455e41f4b71Sopenharmony_ci- **mode**: event mode for running the event loop. 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**Return value** 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci### napi_stop_event_loop 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci```cpp 464e41f4b71Sopenharmony_cinapi_status napi_stop_event_loop(napi_env env) 465e41f4b71Sopenharmony_ci``` 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci**Description** 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ciStops the underlying event loop. 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**Parameters** 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**Return value** 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci### napi_load_module_with_info 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci```cpp 482e41f4b71Sopenharmony_cinapi_status napi_load_module_with_info(napi_env env, 483e41f4b71Sopenharmony_ci const char* path, 484e41f4b71Sopenharmony_ci const char* module_info, 485e41f4b71Sopenharmony_ci napi_value* result) 486e41f4b71Sopenharmony_ci``` 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**Description** 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ciLoads an .abc file as a module. This API returns the namespace of the module. It can be used in a newly created ArkTS runtime environment. 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci**Parameters** 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci- **path**: path of the module to load. 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci- **module_info**: module information. The value is a string containing module information. The module information contains detailed module information, such as the version, author, and related description. 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci- **result**: pointer to **napi_value**, which holds the module loading result. 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci**Return value** 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci### napi_serialize 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci```cpp 509e41f4b71Sopenharmony_cinapi_status napi_serialize(napi_env env, 510e41f4b71Sopenharmony_ci napi_value object, 511e41f4b71Sopenharmony_ci napi_value transfer_list, 512e41f4b71Sopenharmony_ci napi_value clone_list, 513e41f4b71Sopenharmony_ci void** result) 514e41f4b71Sopenharmony_ci``` 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci**Description** 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ciConverts an ArkTS object into native data. 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci**Parameters** 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci- **object**: JS object to be serialized. 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci- **transfer_list**: list of JS objects to be passed during serialization. 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci- **clone_list**: list of JS objects to be cloned during serialization. 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci- **result**: pointer to the serialization result. After the call is complete, the pointer to the native data converted is stored in this position. 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**Return value** 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci### napi_deserialize 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci```cpp 539e41f4b71Sopenharmony_cinapi_status napi_deserialize(napi_env env, void* buffer, napi_value* object) 540e41f4b71Sopenharmony_ci``` 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci**Description** 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ciConverts native data into an ArkTS object. 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci**Parameters** 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci- **buffer**: pointer to the binary data, which needs to be deserialized into a JS object. 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci- **object**: pointer to the deserialized JS object. 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci**Return value** 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci### napi_delete_serialization_data 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ci```cpp 561e41f4b71Sopenharmony_cinapi_status napi_delete_serialization_data(napi_env env, void* buffer) 562e41f4b71Sopenharmony_ci``` 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**Description** 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ciDeletes serialized data. 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci**Parameters** 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci- **buffer**: pointer to the buffer that contains the serialized data to delete. If the serialized data is not longer required, you can use this API to delete the data and release the memory occupied. 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**Return value** 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci### napi_call_threadsafe_function_with_priority 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ci```cpp 581e41f4b71Sopenharmony_cinapi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func, 582e41f4b71Sopenharmony_ci void *data, 583e41f4b71Sopenharmony_ci napi_task_priority priority, 584e41f4b71Sopenharmony_ci bool isTail) 585e41f4b71Sopenharmony_ci``` 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**Description** 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ciCalls a task with the specified priority and enqueuing mode into the ArkTS main thread. 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci**Parameters** 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci- **func**: thread-safe function object, which is returned when a thread-safe function is created. 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci- **data**: pointer to the data to be passed to the JS callback function. 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci- **priority**: priority of the task that calls the JS callback function. 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci- **isTail**: whether the task is added to the tail of the task queue. If the value is **true**, the task will be added to the tail of the event loop. If it is **false**, the task will be executed immediately. 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci**Return value** 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci### napi_is_sendable 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci```cpp 608e41f4b71Sopenharmony_cinapi_status napi_is_sendable(napi_env env, napi_value value, bool* result) 609e41f4b71Sopenharmony_ci``` 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci**Description** 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ciChecks whether the given JS value is sendable. 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**Parameters** 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci- **value**: JS value to check. 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci- **result**: pointer of the bool type, indicating whether the JS value is sendable. 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci**Return value** 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci### napi_define_sendable_class 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci```cpp 631e41f4b71Sopenharmony_cinapi_status napi_define_sendable_class(napi_env env, 632e41f4b71Sopenharmony_ci const char* utf8name, 633e41f4b71Sopenharmony_ci size_t length, 634e41f4b71Sopenharmony_ci napi_callback constructor, 635e41f4b71Sopenharmony_ci void* data, 636e41f4b71Sopenharmony_ci size_t property_count, 637e41f4b71Sopenharmony_ci const napi_property_descriptor* properties, 638e41f4b71Sopenharmony_ci napi_value parent, 639e41f4b71Sopenharmony_ci napi_value* result) 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci``` 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci**Description** 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ciCreates a sendable class. 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**Parameters** 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci- **utf8name**: pointer to the name of the class to create. This parameter is of the const char* type. 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci- **length**: length of the class name, in bytes. This parameter is of the size_t type. 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci- **constructor**: constructor of the class. This parameter is of the napi_callback type. 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci- **data**: (optional) pointer to the additional data of the constructor. This parameter is of the void* type. 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci- **property_count**: number of properties of the class. This parameter is of the size_t type. 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci- **properties**: (optional) pointer to the descriptors of the properties. This parameter of the const napi_property_descriptor* type. 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci- **parent**: (optional) parent class of the class to create. This parameter is of the napi_value type. 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci- **result**: pointer to the sendable class created. This parameter is of the napi_value type. 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci**Return value** 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci### napi_create_sendable_object_with_properties 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ci```cpp 675e41f4b71Sopenharmony_cinapi_status napi_create_sendable_object_with_properties(napi_env env, 676e41f4b71Sopenharmony_ci size_t property_count, 677e41f4b71Sopenharmony_ci const napi_property_descriptor* properties, 678e41f4b71Sopenharmony_ci napi_value* result) 679e41f4b71Sopenharmony_ci``` 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci**Description** 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ciCreates a sendable object with the given **napi_property_descriptor**. 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci**Parameters** 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ci- **property_count**: number of properties of the class. This parameter is of the size_t type. 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci- **properties**: pointer to the properties of the sendable object to create. 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci- **result**: pointer to the sendable class created. This parameter is of the napi_value type. 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**Return value** 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci### napi_create_sendable_array 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci```cpp 702e41f4b71Sopenharmony_cinapi_status napi_create_sendable_array(napi_env env, napi_value* result) 703e41f4b71Sopenharmony_ci``` 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci**Description** 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ciCreates a sendable array. 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci**Parameters** 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci- **result**: pointer to the sendable array created. This parameter is of the napi_value type. 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci**Return value** 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci### napi_create_sendable_array_with_length 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci```cpp 722e41f4b71Sopenharmony_cinapi_status napi_create_sendable_array_with_length(napi_env env, size_t length, napi_value* result) 723e41f4b71Sopenharmony_ci``` 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**Description** 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ciCreates a sendable array of the specified length. 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci**Parameters** 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci- **length**: length of the sendable array to create. 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_ci- **result**: pointer to the sendable array created. This parameter is of the napi_value type. 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci**Return value** 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci### napi_create_sendable_arraybuffer 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci```cpp 744e41f4b71Sopenharmony_cinapi_status napi_create_sendable_arraybuffer(napi_env env, size_t byte_length, void** data, napi_value* result) 745e41f4b71Sopenharmony_ci``` 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**Description** 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ciCreates a sendable ArrayBuffer. 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**Parameters** 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci- **byte_length**: length of the ArrayBuffer to create. 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci- **data**: pointer to the byte buffer for storing the ArrayBuffer created. 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci- **result**: pointer to the ArrayBuffer created. This parameter is of the napi_value type. 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**Return value** 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci### napi_create_sendable_typedarray 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci```cpp 768e41f4b71Sopenharmony_cinapi_status napi_create_sendable_typedarray(napi_env env, 769e41f4b71Sopenharmony_ci napi_typedarray_type type, 770e41f4b71Sopenharmony_ci size_t length, 771e41f4b71Sopenharmony_ci napi_value arraybuffer, 772e41f4b71Sopenharmony_ci size_t byte_offset, 773e41f4b71Sopenharmony_ci napi_value* result); 774e41f4b71Sopenharmony_ci``` 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**Description** 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ciCreates a sendable TypedArray. 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci**Parameters** 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci- **type**: type of the TypedArray to create. 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ci- **length**: length of the TypedArray to create. 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci- **arraybuffer**: ArrayBuffer instance to create. 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci- **byte_offset**: offset of the ArrayBuffer. 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci- **result**: pointer to the TypedArray created. This parameter is of the napi_value type. 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci**Return value** 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci### napi_wrap_sendable 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci```cpp 801e41f4b71Sopenharmony_cinapi_status napi_wrap_sendable(napi_env env, 802e41f4b71Sopenharmony_ci napi_value js_object, 803e41f4b71Sopenharmony_ci void* native_object, 804e41f4b71Sopenharmony_ci napi_finalize finalize_cb, 805e41f4b71Sopenharmony_ci void* finalize_hint); 806e41f4b71Sopenharmony_ci``` 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**Description** 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ciWraps a native instance into an ArkTS object. 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci**Parameters** 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci- **js_object**: ArkTS object. 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci- **native_object**: pointer to the native instance to be wrapped in the ArkTS object. 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci- **napi_finalize**: (optional) callback to be invoked when the ArkTS object is destroyed. 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci- **finalize_hint**: (optional) pointer to the callback context, which will be passed to the callback. 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci**Return value** 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci### napi_wrap_sendable_with_size 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci```cpp 831e41f4b71Sopenharmony_cinapi_status napi_wrap_sendable_with_size(napi_env env, 832e41f4b71Sopenharmony_ci napi_value js_object, 833e41f4b71Sopenharmony_ci void* native_object, 834e41f4b71Sopenharmony_ci napi_finalize finalize_cb, 835e41f4b71Sopenharmony_ci void* finalize_hint, 836e41f4b71Sopenharmony_ci size_t native_binding_size); 837e41f4b71Sopenharmony_ci``` 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci**Description** 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ciWraps a native instance into an ArkTS object with the specified size. 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**Parameters** 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci- **js_object**: ArkTS object. 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci- **native_object**: pointer to the native instance to be wrapped in the ArkTS object. 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_ci- **napi_finalize**: (optional) callback to be invoked when the ArkTS object is destroyed. 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci- **finalize_hint**: (optional) pointer to the callback context, which will be passed to the callback. 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci- **native_binding_size**: (optional) size of the native instance wrapped. 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci**Return value** 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci### napi_unwrap_sendable 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci```cpp 864e41f4b71Sopenharmony_cinapi_status napi_unwrap_sendable(napi_env env, napi_value js_object, void** result) 865e41f4b71Sopenharmony_ci``` 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_ci**Description** 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ciUnwraps the native instance from an ArkTS object. 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ci**Parameters** 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci- **js_object**: ArkTS object. 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci- **result**: double pointer to the native instance unwrapped. 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci**Return value** 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci### napi_remove_wrap_sendable 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci```cpp 886e41f4b71Sopenharmony_cinapi_status napi_remove_wrap_sendable(napi_env env, napi_value js_object, void** result) 887e41f4b71Sopenharmony_ci``` 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci**Description** 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ciRemoves the native instance from an ArkTS object. 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**Parameters** 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci- **env**: environment, in which the API is invoked. 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci- **js_object**: ArkTS object. 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci- **result**: double pointer to the native instance removed. 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**Return value** 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ciReturns **napi_ok** if the operation is successful. 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci<!--no_check--> 906