17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci#ifndef FOUNDATION_ACE_NAPI_INTERFACES_KITS_NAPI_NATIVE_API_H 177777dab0Sopenharmony_ci#define FOUNDATION_ACE_NAPI_INTERFACES_KITS_NAPI_NATIVE_API_H 187777dab0Sopenharmony_ci 197777dab0Sopenharmony_ci#ifndef NAPI_VERSION 207777dab0Sopenharmony_ci#define NAPI_VERSION 8 217777dab0Sopenharmony_ci#endif 227777dab0Sopenharmony_ci 237777dab0Sopenharmony_ci#ifndef NAPI_EXPERIMENTAL 247777dab0Sopenharmony_ci#define NAPI_EXPERIMENTAL 257777dab0Sopenharmony_ci#endif 267777dab0Sopenharmony_ci 277777dab0Sopenharmony_ci#include "common.h" 287777dab0Sopenharmony_ci#include "node_api.h" 297777dab0Sopenharmony_ci 307777dab0Sopenharmony_ci#ifdef NAPI_TEST 317777dab0Sopenharmony_ci#ifdef _WIN32 327777dab0Sopenharmony_ci#define NAPI_INNER_EXTERN __declspec(dllexport) 337777dab0Sopenharmony_ci#else 347777dab0Sopenharmony_ci#define NAPI_INNER_EXTERN __attribute__((visibility("default"))) 357777dab0Sopenharmony_ci#endif 367777dab0Sopenharmony_ci#else 377777dab0Sopenharmony_ci#ifdef _WIN32 387777dab0Sopenharmony_ci#define NAPI_INNER_EXTERN __declspec(deprecated) 397777dab0Sopenharmony_ci#else 407777dab0Sopenharmony_ci#define NAPI_INNER_EXTERN __attribute__((__deprecated__)) 417777dab0Sopenharmony_ci#endif 427777dab0Sopenharmony_ci#endif 437777dab0Sopenharmony_ci 447777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_fatal_exception(napi_env env, napi_value err); 457777dab0Sopenharmony_ci 467777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_string_utf16(napi_env env, 477777dab0Sopenharmony_ci const char16_t* str, 487777dab0Sopenharmony_ci size_t length, 497777dab0Sopenharmony_ci napi_value* result); 507777dab0Sopenharmony_ci 517777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_string_utf16(napi_env env, 527777dab0Sopenharmony_ci napi_value value, 537777dab0Sopenharmony_ci char16_t* buf, 547777dab0Sopenharmony_ci size_t bufsize, 557777dab0Sopenharmony_ci size_t* result); 567777dab0Sopenharmony_ci 577777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_type_tag_object(napi_env env, 587777dab0Sopenharmony_ci napi_value value, 597777dab0Sopenharmony_ci const napi_type_tag* type_tag); 607777dab0Sopenharmony_ci 617777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_check_object_type_tag(napi_env env, 627777dab0Sopenharmony_ci napi_value value, 637777dab0Sopenharmony_ci const napi_type_tag* type_tag, 647777dab0Sopenharmony_ci bool* result); 657777dab0Sopenharmony_ci 667777dab0Sopenharmony_ciNAPI_INNER_EXTERN napi_status napi_adjust_external_memory(napi_env env, 677777dab0Sopenharmony_ci int64_t change_in_bytes, 687777dab0Sopenharmony_ci int64_t* adjusted_value); 697777dab0Sopenharmony_ci 707777dab0Sopenharmony_ci 717777dab0Sopenharmony_ci#ifdef __cplusplus 727777dab0Sopenharmony_ciextern "C" { 737777dab0Sopenharmony_ci#endif 747777dab0Sopenharmony_ci 757777dab0Sopenharmony_ci/** 767777dab0Sopenharmony_ci * @brief Native detach callback of napi_coerce_to_native_binding_object that can be used to 777777dab0Sopenharmony_ci * detach the js object and the native object. 787777dab0Sopenharmony_ci * 797777dab0Sopenharmony_ci * @since 11 807777dab0Sopenharmony_ci */ 817777dab0Sopenharmony_citypedef void* (*napi_native_binding_detach_callback)(napi_env env, void* native_object, void* hint); 827777dab0Sopenharmony_ci/** 837777dab0Sopenharmony_ci * @brief Native attach callback of napi_coerce_to_native_binding_object that can be used to 847777dab0Sopenharmony_ci * bind the js object and the native object. 857777dab0Sopenharmony_ci * 867777dab0Sopenharmony_ci * @since 11 877777dab0Sopenharmony_ci */ 887777dab0Sopenharmony_citypedef napi_value (*napi_native_binding_attach_callback)(napi_env env, void* native_object, void* hint); 897777dab0Sopenharmony_ci 907777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_run_script_path(napi_env env, const char* path, napi_value* result); 917777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_queue_async_work_with_qos(napi_env env, napi_async_work work, napi_qos_t qos); 927777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_load_module(napi_env env, const char* path, napi_value* result); 937777dab0Sopenharmony_ci 947777dab0Sopenharmony_ci/** 957777dab0Sopenharmony_ci * @brief The module is loaded through the NAPI. By default, the default object is exported from the module. 967777dab0Sopenharmony_ci * 977777dab0Sopenharmony_ci * @param env Current running virtual machine context. 987777dab0Sopenharmony_ci * @param path Path name of the module to be loaded, like @ohos.hilog. 997777dab0Sopenharmony_ci * @param module_info Path names of bundle and module, like com.example.application/entry. 1007777dab0Sopenharmony_ci * @param result Result of loading a module, which is an exported object of the module. 1017777dab0Sopenharmony_ci * @return Returns the function execution status. 1027777dab0Sopenharmony_ci * @since 12 1037777dab0Sopenharmony_ci*/ 1047777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_load_module_with_info(napi_env env, 1057777dab0Sopenharmony_ci const char* path, 1067777dab0Sopenharmony_ci const char* module_info, 1077777dab0Sopenharmony_ci napi_value* result); 1087777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_get_instance_data(napi_env env, void** data); 1097777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_set_instance_data(napi_env env, 1107777dab0Sopenharmony_ci void* data, 1117777dab0Sopenharmony_ci napi_finalize finalize_cb, 1127777dab0Sopenharmony_ci void* finalize_hint); 1137777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env, void (*fun)(void* arg), void* arg); 1147777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env, void (*fun)(void* arg), void* arg); 1157777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle); 1167777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_add_async_cleanup_hook(napi_env env, 1177777dab0Sopenharmony_ci napi_async_cleanup_hook hook, 1187777dab0Sopenharmony_ci void* arg, 1197777dab0Sopenharmony_ci napi_async_cleanup_hook_handle* remove_handle); 1207777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_async_destroy(napi_env env, 1217777dab0Sopenharmony_ci napi_async_context async_context); 1227777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_async_init(napi_env env, 1237777dab0Sopenharmony_ci napi_value async_resource, 1247777dab0Sopenharmony_ci napi_value async_resource_name, 1257777dab0Sopenharmony_ci napi_async_context* result); 1267777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_close_callback_scope(napi_env env, napi_callback_scope scope); 1277777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_open_callback_scope(napi_env env, 1287777dab0Sopenharmony_ci napi_value resource_object, 1297777dab0Sopenharmony_ci napi_async_context context, 1307777dab0Sopenharmony_ci napi_callback_scope* result); 1317777dab0Sopenharmony_ciNAPI_EXTERN napi_status node_api_get_module_file_name(napi_env env, const char** result); 1327777dab0Sopenharmony_ci// Create JSObject with initial properties given by descriptors, note that property key must be String, 1337777dab0Sopenharmony_ci// and must can not convert to element_index, also all keys must not duplicate. 1347777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_object_with_properties(napi_env env, 1357777dab0Sopenharmony_ci napi_value* result, 1367777dab0Sopenharmony_ci size_t property_count, 1377777dab0Sopenharmony_ci const napi_property_descriptor* properties); 1387777dab0Sopenharmony_ci// Create JSObject with initial properties given by keys and values, note that property key must be String, 1397777dab0Sopenharmony_ci// and must can not convert to element_index, also all keys must not duplicate. 1407777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_object_with_named_properties(napi_env env, 1417777dab0Sopenharmony_ci napi_value* result, 1427777dab0Sopenharmony_ci size_t property_count, 1437777dab0Sopenharmony_ci const char** keys, 1447777dab0Sopenharmony_ci const napi_value* values); 1457777dab0Sopenharmony_ci/** 1467777dab0Sopenharmony_ci * @brief This API sets native properties to a object and converts this js object to native binding object. 1477777dab0Sopenharmony_ci * 1487777dab0Sopenharmony_ci * @param[in] env Current running virtual machine context. 1497777dab0Sopenharmony_ci * @param[in] js_object The JavaScript value to coerce. 1507777dab0Sopenharmony_ci * @param[in] detach_cb Native callback that can be used to detach the js object and the native object. 1517777dab0Sopenharmony_ci * @param[in] attach_cb Native callback that can be used to bind the js object and the native object. 1527777dab0Sopenharmony_ci * @param[in] native_object User-provided native instance to pass to thr detach callback and attach callback. 1537777dab0Sopenharmony_ci * @param[in] hint Optional hint to pass to the detach callback and attach callback. 1547777dab0Sopenharmony_ci * @return Return the function execution status. 1557777dab0Sopenharmony_ci * @since 11 1567777dab0Sopenharmony_ci */ 1577777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_coerce_to_native_binding_object(napi_env env, 1587777dab0Sopenharmony_ci napi_value js_object, 1597777dab0Sopenharmony_ci napi_native_binding_detach_callback detach_cb, 1607777dab0Sopenharmony_ci napi_native_binding_attach_callback attach_cb, 1617777dab0Sopenharmony_ci void* native_object, 1627777dab0Sopenharmony_ci void* hint); 1637777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_add_finalizer(napi_env env, 1647777dab0Sopenharmony_ci napi_value js_object, 1657777dab0Sopenharmony_ci void* native_object, 1667777dab0Sopenharmony_ci napi_finalize finalize_cb, 1677777dab0Sopenharmony_ci void* finalize_hint, 1687777dab0Sopenharmony_ci napi_ref* result); 1697777dab0Sopenharmony_ci/** 1707777dab0Sopenharmony_ci * @brief Create the ark runtime. 1717777dab0Sopenharmony_ci * 1727777dab0Sopenharmony_ci * @param env Indicates the ark runtime environment. 1737777dab0Sopenharmony_ci * @since 12 1747777dab0Sopenharmony_ci */ 1757777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_ark_runtime(napi_env* env); 1767777dab0Sopenharmony_ci 1777777dab0Sopenharmony_ci/** 1787777dab0Sopenharmony_ci * @brief Destroy the ark runtime. 1797777dab0Sopenharmony_ci * 1807777dab0Sopenharmony_ci * @param env Indicates the ark runtime environment. 1817777dab0Sopenharmony_ci * @since 12 1827777dab0Sopenharmony_ci */ 1837777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_destroy_ark_runtime(napi_env* env); 1847777dab0Sopenharmony_ci 1857777dab0Sopenharmony_ci/* 1867777dab0Sopenharmony_ci * @brief Defines a sendable class. 1877777dab0Sopenharmony_ci * 1887777dab0Sopenharmony_ci * @param env: The environment that the API is invoked under. 1897777dab0Sopenharmony_ci * @param utf8name: Name of the ArkTS constructor function. 1907777dab0Sopenharmony_ci * @param length: The length of the utf8name in bytes, or NAPI_AUTO_LENGTH if it is null-terminated. 1917777dab0Sopenharmony_ci * @param constructor: Callback function that handles constructing instances of the class. 1927777dab0Sopenharmony_ci * @param data: Optional data to be passed to the constructor callback as the data property of the callback info. 1937777dab0Sopenharmony_ci * @param property_count: Number of items in the properties array argument. 1947777dab0Sopenharmony_ci * @param properties: Array of property descriptors describing static and instance data properties, accessors, and 1957777dab0Sopenharmony_ci * methods on the class. See napi_property_descriptor. 1967777dab0Sopenharmony_ci * @param parent: A napi_value representing the Superclass. 1977777dab0Sopenharmony_ci * @param result: A napi_value representing the constructor function for the class. 1987777dab0Sopenharmony_ci * @return Return the function execution status. 1997777dab0Sopenharmony_ci * @since 12 2007777dab0Sopenharmony_ci */ 2017777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_define_sendable_class(napi_env env, 2027777dab0Sopenharmony_ci const char* utf8name, 2037777dab0Sopenharmony_ci size_t length, 2047777dab0Sopenharmony_ci napi_callback constructor, 2057777dab0Sopenharmony_ci void* data, 2067777dab0Sopenharmony_ci size_t property_count, 2077777dab0Sopenharmony_ci const napi_property_descriptor* properties, 2087777dab0Sopenharmony_ci napi_value parent, 2097777dab0Sopenharmony_ci napi_value* result); 2107777dab0Sopenharmony_ci 2117777dab0Sopenharmony_ci/** 2127777dab0Sopenharmony_ci * @brief Queries a napi_value to check if it is sendable. 2137777dab0Sopenharmony_ci * 2147777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2157777dab0Sopenharmony_ci * @param value The napi_value to be checked. 2167777dab0Sopenharmony_ci * @param result Boolean value that is set to true if napi_value is sendable, false otherwise. 2177777dab0Sopenharmony_ci * @return Return the function execution status. 2187777dab0Sopenharmony_ci * @since 12 2197777dab0Sopenharmony_ci */ 2207777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_is_sendable(napi_env env, napi_value value, bool* result); 2217777dab0Sopenharmony_ci/** 2227777dab0Sopenharmony_ci * @brief Defines a sendable object. 2237777dab0Sopenharmony_ci * 2247777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2257777dab0Sopenharmony_ci * @param property_count The count of object properties. 2267777dab0Sopenharmony_ci * @param properties Object properties. 2277777dab0Sopenharmony_ci * @return Return the function execution status. 2287777dab0Sopenharmony_ci * @since 12 2297777dab0Sopenharmony_ci */ 2307777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_sendable_object_with_properties(napi_env env, size_t property_count, 2317777dab0Sopenharmony_ci const napi_property_descriptor* properties, 2327777dab0Sopenharmony_ci napi_value* result); 2337777dab0Sopenharmony_ci/** 2347777dab0Sopenharmony_ci * @brief Wraps a native instance in a ArkTS object. 2357777dab0Sopenharmony_ci * 2367777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2377777dab0Sopenharmony_ci * @param js_object The ArkTS object that will be the wrapper for the native object. 2387777dab0Sopenharmony_ci * @param native_object The native instance that will be wrapped in the ArkTS object. 2397777dab0Sopenharmony_ci * @param finalize_lib Optional native callback that can be used to free the native instance when the ArkTS object 2407777dab0Sopenharmony_ci * has been garbage-collected. 2417777dab0Sopenharmony_ci * @param finalize_hint Optional contextual hint that is passed to the finalize callback. 2427777dab0Sopenharmony_ci * @return Return the function execution status. 2437777dab0Sopenharmony_ci * @since 12 2447777dab0Sopenharmony_ci */ 2457777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_wrap_sendable(napi_env env, napi_value js_object, void* native_object, 2467777dab0Sopenharmony_ci napi_finalize finalize_cb, void* finalize_hint); 2477777dab0Sopenharmony_ci/** 2487777dab0Sopenharmony_ci * @brief Wraps a native instance in a ArkTS object. 2497777dab0Sopenharmony_ci * 2507777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2517777dab0Sopenharmony_ci * @param js_object The ArkTS object that will be the wrapper for the native object. 2527777dab0Sopenharmony_ci * @param native_object The native instance that will be wrapped in the ArkTS object. 2537777dab0Sopenharmony_ci * @param finalize_lib Optional native callback that can be used to free the native instance when the ArkTS object 2547777dab0Sopenharmony_ci * has been garbage-collected. 2557777dab0Sopenharmony_ci * @param finalize_hint Optional contextual hint that is passed to the finalize callback. 2567777dab0Sopenharmony_ci * @param native_binding_size The size of native binding. 2577777dab0Sopenharmony_ci * @return Return the function execution status. 2587777dab0Sopenharmony_ci * @since 12 2597777dab0Sopenharmony_ci */ 2607777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_wrap_sendable_with_size(napi_env env, napi_value js_object, void* native_object, 2617777dab0Sopenharmony_ci napi_finalize finalize_cb, void* finalize_hint, 2627777dab0Sopenharmony_ci size_t native_binding_size); 2637777dab0Sopenharmony_ci/** 2647777dab0Sopenharmony_ci * @brief Retrieves a native instance that was previously wrapped in a ArkTS object. 2657777dab0Sopenharmony_ci * 2667777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2677777dab0Sopenharmony_ci * @param js_object The object associated with the native instance. 2687777dab0Sopenharmony_ci * @param result Pointer to the wrapped native instance. 2697777dab0Sopenharmony_ci * @return Return the function execution status. 2707777dab0Sopenharmony_ci * @since 12 2717777dab0Sopenharmony_ci */ 2727777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_unwrap_sendable(napi_env env, napi_value js_object, void** result); 2737777dab0Sopenharmony_ci/** 2747777dab0Sopenharmony_ci * @brief Retrieves a native instance that was previously wrapped in a ArkTS object and removes the wrapping. 2757777dab0Sopenharmony_ci * 2767777dab0Sopenharmony_ci * @param env The environment that the API is invoked under. 2777777dab0Sopenharmony_ci * @param js_object The object associated with the native instance. 2787777dab0Sopenharmony_ci * @param result Pointer to the wrapped native instance. 2797777dab0Sopenharmony_ci * @return Return the function execution status. 2807777dab0Sopenharmony_ci * @since 12 2817777dab0Sopenharmony_ci */ 2827777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_remove_wrap_sendable(napi_env env, napi_value js_object, void** result); 2837777dab0Sopenharmony_ci/* 2847777dab0Sopenharmony_ci * @brief Create a sendable array. 2857777dab0Sopenharmony_ci * 2867777dab0Sopenharmony_ci * @param env: The environment that the API is invoked under. 2877777dab0Sopenharmony_ci * @param result: A napi_value representing a sendable array. 2887777dab0Sopenharmony_ci * @return Return the function execution status. 2897777dab0Sopenharmony_ci * @since 12 2907777dab0Sopenharmony_ci */ 2917777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_sendable_array(napi_env env, napi_value* result); 2927777dab0Sopenharmony_ci 2937777dab0Sopenharmony_ci/* 2947777dab0Sopenharmony_ci * @brief Create a sendable array with length. 2957777dab0Sopenharmony_ci * 2967777dab0Sopenharmony_ci * @param env: The environment that the API is invoked under. 2977777dab0Sopenharmony_ci * @param length: The initial length of the sendable array. 2987777dab0Sopenharmony_ci * @param result: A napi_value representing a sendable array. 2997777dab0Sopenharmony_ci * @return Return the function execution status. 3007777dab0Sopenharmony_ci * @since 12 3017777dab0Sopenharmony_ci */ 3027777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_sendable_array_with_length(napi_env env, size_t length, napi_value* result); 3037777dab0Sopenharmony_ci 3047777dab0Sopenharmony_ci/* 3057777dab0Sopenharmony_ci * @brief Create a sendable arraybuffer. 3067777dab0Sopenharmony_ci * 3077777dab0Sopenharmony_ci * @param env: The environment that the API is invoked under. 3087777dab0Sopenharmony_ci * @param byte_length: The length in bytes of the sendable arraybuffer to create. 3097777dab0Sopenharmony_ci * @param data: Pointer to the underlying byte buffer of the sendable arraybuffer. 3107777dab0Sopenharmony_ci * @param result: A napi_value representing a sendable arraybuffer. 3117777dab0Sopenharmony_ci * @return Return the function execution status. 3127777dab0Sopenharmony_ci * @since 12 3137777dab0Sopenharmony_ci */ 3147777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_sendable_arraybuffer(napi_env env, size_t byte_length, 3157777dab0Sopenharmony_ci void** data, napi_value* result); 3167777dab0Sopenharmony_ci 3177777dab0Sopenharmony_ci/* 3187777dab0Sopenharmony_ci * @brief Create a sendable typedarray. 3197777dab0Sopenharmony_ci * 3207777dab0Sopenharmony_ci * @param env: The environment that the API is invoked under. 3217777dab0Sopenharmony_ci * @param type: Scalar datatype of the elements within the sendable typedarray. 3227777dab0Sopenharmony_ci * @param length: Number of elements in the typedarray. 3237777dab0Sopenharmony_ci * @param arraybuffer: Sendable arraybuffer underlying the sendable typedarray. 3247777dab0Sopenharmony_ci * @param byte_offset: The byte offset within the sendable arraybuffer from 3257777dab0Sopenharmony_ci * which to start projecting the sendable typedarray. 3267777dab0Sopenharmony_ci * @param result: A napi_value representing a sendable typedarray. 3277777dab0Sopenharmony_ci * @return Return the function execution status. 3287777dab0Sopenharmony_ci * @since 12 3297777dab0Sopenharmony_ci */ 3307777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_create_sendable_typedarray(napi_env env, 3317777dab0Sopenharmony_ci napi_typedarray_type type, 3327777dab0Sopenharmony_ci size_t length, 3337777dab0Sopenharmony_ci napi_value arraybuffer, 3347777dab0Sopenharmony_ci size_t byte_offset, 3357777dab0Sopenharmony_ci napi_value* result); 3367777dab0Sopenharmony_ci 3377777dab0Sopenharmony_ci/** 3387777dab0Sopenharmony_ci * @brief Run the event loop by the given env and running mode in current thread. 3397777dab0Sopenharmony_ci * 3407777dab0Sopenharmony_ci * Support to run the native event loop in an asynchronous native thread with the specified running mode. 3417777dab0Sopenharmony_ci * 3427777dab0Sopenharmony_ci * @param env Current running virtual machine context. 3437777dab0Sopenharmony_ci * @param mode Indicates the running mode of the native event loop. 3447777dab0Sopenharmony_ci * @return Return the function execution status. 3457777dab0Sopenharmony_ci * @since 12 3467777dab0Sopenharmony_ci */ 3477777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_run_event_loop(napi_env env, napi_event_mode mode); 3487777dab0Sopenharmony_ci 3497777dab0Sopenharmony_ci/** 3507777dab0Sopenharmony_ci * @brief Stop the event loop in current thread. 3517777dab0Sopenharmony_ci * 3527777dab0Sopenharmony_ci * Support to stop the running event loop in current native thread. 3537777dab0Sopenharmony_ci * 3547777dab0Sopenharmony_ci * @param env Current running virtual machine context. 3557777dab0Sopenharmony_ci * @return Return the function execution status. 3567777dab0Sopenharmony_ci * @since 12 3577777dab0Sopenharmony_ci */ 3587777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_stop_event_loop(napi_env env); 3597777dab0Sopenharmony_ci 3607777dab0Sopenharmony_ci/** 3617777dab0Sopenharmony_ci * @brief Serialize a JS object. 3627777dab0Sopenharmony_ci * 3637777dab0Sopenharmony_ci * @param env Current running virtual machine context. 3647777dab0Sopenharmony_ci * @param object The JavaScript value to serialize. 3657777dab0Sopenharmony_ci * @param transfer_list List of data to transfer in transfer mode. 3667777dab0Sopenharmony_ci * @param clone_list List of Sendable data to transfer in clone mode. 3677777dab0Sopenharmony_ci * @param result Serialization result of the JS object. 3687777dab0Sopenharmony_ci * @return Returns the function execution status. 3697777dab0Sopenharmony_ci * @since 12 3707777dab0Sopenharmony_ci*/ 3717777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_serialize(napi_env env, 3727777dab0Sopenharmony_ci napi_value object, 3737777dab0Sopenharmony_ci napi_value transfer_list, 3747777dab0Sopenharmony_ci napi_value clone_list, 3757777dab0Sopenharmony_ci void** result); 3767777dab0Sopenharmony_ci 3777777dab0Sopenharmony_ci/** 3787777dab0Sopenharmony_ci * @brief Restore serialization data to a ArkTS object. 3797777dab0Sopenharmony_ci * 3807777dab0Sopenharmony_ci * @param env Current running virtual machine context. 3817777dab0Sopenharmony_ci * @param buffer Data to deserialize. 3827777dab0Sopenharmony_ci * @param object ArkTS object obtained by deserialization. 3837777dab0Sopenharmony_ci * @return Returns the function execution status. 3847777dab0Sopenharmony_ci * @since 12 3857777dab0Sopenharmony_ci*/ 3867777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_deserialize(napi_env env, void* buffer, napi_value* object); 3877777dab0Sopenharmony_ci 3887777dab0Sopenharmony_ci/** 3897777dab0Sopenharmony_ci * @brief Delete serialization data. 3907777dab0Sopenharmony_ci * 3917777dab0Sopenharmony_ci * @param env Current running virtual machine context. 3927777dab0Sopenharmony_ci * @param buffer Data to delete. 3937777dab0Sopenharmony_ci * @return Returns the function execution status. 3947777dab0Sopenharmony_ci * @since 12 3957777dab0Sopenharmony_ci*/ 3967777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_delete_serialization_data(napi_env env, void* buffer); 3977777dab0Sopenharmony_ci 3987777dab0Sopenharmony_ci/** 3997777dab0Sopenharmony_ci * @brief Dispatch a task with specified priority from a native thread to an ArkTS thread, the task will execute 4007777dab0Sopenharmony_ci * the given thread safe function. 4017777dab0Sopenharmony_ci * 4027777dab0Sopenharmony_ci * @param func Indicates the thread safe function. 4037777dab0Sopenharmony_ci * @param data Indicates the data anticipated to be transferred to the ArkTS thread. 4047777dab0Sopenharmony_ci * @param priority Indicates the priority of the task dispatched. 4057777dab0Sopenharmony_ci * @param isTail Indicates the way of the task dispatched into the native event queue. When "isTail" is true, 4067777dab0Sopenharmony_ci * the task will be dispatched to the tail of the native event queue. Conversely, when "isTail" is false, the 4077777dab0Sopenharmony_ci * tasks will be dispatched to the head of the native event queue. 4087777dab0Sopenharmony_ci * @return Return the function execution status. 4097777dab0Sopenharmony_ci * @since 12 4107777dab0Sopenharmony_ci */ 4117777dab0Sopenharmony_ciNAPI_EXTERN napi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func, 4127777dab0Sopenharmony_ci void *data, 4137777dab0Sopenharmony_ci napi_task_priority priority, 4147777dab0Sopenharmony_ci bool isTail); 4157777dab0Sopenharmony_ci#ifdef __cplusplus 4167777dab0Sopenharmony_ci} 4177777dab0Sopenharmony_ci#endif 4187777dab0Sopenharmony_ci#endif /* FOUNDATION_ACE_NAPI_INTERFACES_KITS_NAPI_NATIVE_API_H */ 419