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