11cb0ef41Sopenharmony_ci#ifndef SRC_JS_NATIVE_API_H_ 21cb0ef41Sopenharmony_ci#define SRC_JS_NATIVE_API_H_ 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This file needs to be compatible with C compilers. 51cb0ef41Sopenharmony_ci#include <stddef.h> // NOLINT(modernize-deprecated-headers) 61cb0ef41Sopenharmony_ci#include <stdbool.h> // NOLINT(modernize-deprecated-headers) 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Use INT_MAX, this should only be consumed by the pre-processor anyway. 91cb0ef41Sopenharmony_ci#define NAPI_VERSION_EXPERIMENTAL 2147483647 101cb0ef41Sopenharmony_ci#ifndef NAPI_VERSION 111cb0ef41Sopenharmony_ci#ifdef NAPI_EXPERIMENTAL 121cb0ef41Sopenharmony_ci#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL 131cb0ef41Sopenharmony_ci#else 141cb0ef41Sopenharmony_ci// The baseline version for N-API. 151cb0ef41Sopenharmony_ci// The NAPI_VERSION controls which version will be used by default when 161cb0ef41Sopenharmony_ci// compilling a native addon. If the addon developer specifically wants to use 171cb0ef41Sopenharmony_ci// functions available in a new version of N-API that is not yet ported in all 181cb0ef41Sopenharmony_ci// LTS versions, they can set NAPI_VERSION knowing that they have specifically 191cb0ef41Sopenharmony_ci// depended on that version. 201cb0ef41Sopenharmony_ci#define NAPI_VERSION 8 211cb0ef41Sopenharmony_ci#endif 221cb0ef41Sopenharmony_ci#endif 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci#include "js_native_api_types.h" 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// If you need __declspec(dllimport), either include <node_api.h> instead, or 271cb0ef41Sopenharmony_ci// define NAPI_EXTERN as __declspec(dllimport) on the compiler's command line. 281cb0ef41Sopenharmony_ci#ifndef NAPI_EXTERN 291cb0ef41Sopenharmony_ci #ifdef _WIN32 301cb0ef41Sopenharmony_ci #define NAPI_EXTERN __declspec(dllexport) 311cb0ef41Sopenharmony_ci #elif defined(__wasm32__) 321cb0ef41Sopenharmony_ci #define NAPI_EXTERN __attribute__((visibility("default"))) \ 331cb0ef41Sopenharmony_ci __attribute__((__import_module__("napi"))) 341cb0ef41Sopenharmony_ci #else 351cb0ef41Sopenharmony_ci #define NAPI_EXTERN __attribute__((visibility("default"))) 361cb0ef41Sopenharmony_ci #endif 371cb0ef41Sopenharmony_ci#endif 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci#define NAPI_AUTO_LENGTH SIZE_MAX 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci#ifdef __cplusplus 421cb0ef41Sopenharmony_ci#define EXTERN_C_START extern "C" { 431cb0ef41Sopenharmony_ci#define EXTERN_C_END } 441cb0ef41Sopenharmony_ci#else 451cb0ef41Sopenharmony_ci#define EXTERN_C_START 461cb0ef41Sopenharmony_ci#define EXTERN_C_END 471cb0ef41Sopenharmony_ci#endif 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciEXTERN_C_START 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 521cb0ef41Sopenharmony_cinapi_get_last_error_info(napi_env env, 531cb0ef41Sopenharmony_ci const napi_extended_error_info** result); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci// Getters for defined singletons 561cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_undefined(napi_env env, napi_value* result); 571cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_null(napi_env env, napi_value* result); 581cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_global(napi_env env, napi_value* result); 591cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_boolean(napi_env env, 601cb0ef41Sopenharmony_ci bool value, 611cb0ef41Sopenharmony_ci napi_value* result); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci// Methods to create Primitive types/Objects 641cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_object(napi_env env, napi_value* result); 651cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_array(napi_env env, napi_value* result); 661cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_array_with_length(napi_env env, 671cb0ef41Sopenharmony_ci size_t length, 681cb0ef41Sopenharmony_ci napi_value* result); 691cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_double(napi_env env, 701cb0ef41Sopenharmony_ci double value, 711cb0ef41Sopenharmony_ci napi_value* result); 721cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_int32(napi_env env, 731cb0ef41Sopenharmony_ci int32_t value, 741cb0ef41Sopenharmony_ci napi_value* result); 751cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_uint32(napi_env env, 761cb0ef41Sopenharmony_ci uint32_t value, 771cb0ef41Sopenharmony_ci napi_value* result); 781cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_int64(napi_env env, 791cb0ef41Sopenharmony_ci int64_t value, 801cb0ef41Sopenharmony_ci napi_value* result); 811cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_string_latin1(napi_env env, 821cb0ef41Sopenharmony_ci const char* str, 831cb0ef41Sopenharmony_ci size_t length, 841cb0ef41Sopenharmony_ci napi_value* result); 851cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_string_utf8(napi_env env, 861cb0ef41Sopenharmony_ci const char* str, 871cb0ef41Sopenharmony_ci size_t length, 881cb0ef41Sopenharmony_ci napi_value* result); 891cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_string_utf16(napi_env env, 901cb0ef41Sopenharmony_ci const char16_t* str, 911cb0ef41Sopenharmony_ci size_t length, 921cb0ef41Sopenharmony_ci napi_value* result); 931cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_symbol(napi_env env, 941cb0ef41Sopenharmony_ci napi_value description, 951cb0ef41Sopenharmony_ci napi_value* result); 961cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_function(napi_env env, 971cb0ef41Sopenharmony_ci const char* utf8name, 981cb0ef41Sopenharmony_ci size_t length, 991cb0ef41Sopenharmony_ci napi_callback cb, 1001cb0ef41Sopenharmony_ci void* data, 1011cb0ef41Sopenharmony_ci napi_value* result); 1021cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_error(napi_env env, 1031cb0ef41Sopenharmony_ci napi_value code, 1041cb0ef41Sopenharmony_ci napi_value msg, 1051cb0ef41Sopenharmony_ci napi_value* result); 1061cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_type_error(napi_env env, 1071cb0ef41Sopenharmony_ci napi_value code, 1081cb0ef41Sopenharmony_ci napi_value msg, 1091cb0ef41Sopenharmony_ci napi_value* result); 1101cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_range_error(napi_env env, 1111cb0ef41Sopenharmony_ci napi_value code, 1121cb0ef41Sopenharmony_ci napi_value msg, 1131cb0ef41Sopenharmony_ci napi_value* result); 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci// Methods to get the native napi_value from Primitive type 1161cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_typeof(napi_env env, 1171cb0ef41Sopenharmony_ci napi_value value, 1181cb0ef41Sopenharmony_ci napi_valuetype* result); 1191cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_double(napi_env env, 1201cb0ef41Sopenharmony_ci napi_value value, 1211cb0ef41Sopenharmony_ci double* result); 1221cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_int32(napi_env env, 1231cb0ef41Sopenharmony_ci napi_value value, 1241cb0ef41Sopenharmony_ci int32_t* result); 1251cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_uint32(napi_env env, 1261cb0ef41Sopenharmony_ci napi_value value, 1271cb0ef41Sopenharmony_ci uint32_t* result); 1281cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_int64(napi_env env, 1291cb0ef41Sopenharmony_ci napi_value value, 1301cb0ef41Sopenharmony_ci int64_t* result); 1311cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_bool(napi_env env, 1321cb0ef41Sopenharmony_ci napi_value value, 1331cb0ef41Sopenharmony_ci bool* result); 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci// Copies LATIN-1 encoded bytes from a string into a buffer. 1361cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_string_latin1(napi_env env, 1371cb0ef41Sopenharmony_ci napi_value value, 1381cb0ef41Sopenharmony_ci char* buf, 1391cb0ef41Sopenharmony_ci size_t bufsize, 1401cb0ef41Sopenharmony_ci size_t* result); 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci// Copies UTF-8 encoded bytes from a string into a buffer. 1431cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_string_utf8(napi_env env, 1441cb0ef41Sopenharmony_ci napi_value value, 1451cb0ef41Sopenharmony_ci char* buf, 1461cb0ef41Sopenharmony_ci size_t bufsize, 1471cb0ef41Sopenharmony_ci size_t* result); 1481cb0ef41Sopenharmony_ci 1491cb0ef41Sopenharmony_ci// Copies UTF-16 encoded bytes from a string into a buffer. 1501cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_string_utf16(napi_env env, 1511cb0ef41Sopenharmony_ci napi_value value, 1521cb0ef41Sopenharmony_ci char16_t* buf, 1531cb0ef41Sopenharmony_ci size_t bufsize, 1541cb0ef41Sopenharmony_ci size_t* result); 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci// Methods to coerce values 1571cb0ef41Sopenharmony_ci// These APIs may execute user scripts 1581cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_coerce_to_bool(napi_env env, 1591cb0ef41Sopenharmony_ci napi_value value, 1601cb0ef41Sopenharmony_ci napi_value* result); 1611cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_coerce_to_number(napi_env env, 1621cb0ef41Sopenharmony_ci napi_value value, 1631cb0ef41Sopenharmony_ci napi_value* result); 1641cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_coerce_to_object(napi_env env, 1651cb0ef41Sopenharmony_ci napi_value value, 1661cb0ef41Sopenharmony_ci napi_value* result); 1671cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_coerce_to_string(napi_env env, 1681cb0ef41Sopenharmony_ci napi_value value, 1691cb0ef41Sopenharmony_ci napi_value* result); 1701cb0ef41Sopenharmony_ci 1711cb0ef41Sopenharmony_ci// Methods to work with Objects 1721cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_prototype(napi_env env, 1731cb0ef41Sopenharmony_ci napi_value object, 1741cb0ef41Sopenharmony_ci napi_value* result); 1751cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_property_names(napi_env env, 1761cb0ef41Sopenharmony_ci napi_value object, 1771cb0ef41Sopenharmony_ci napi_value* result); 1781cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_set_property(napi_env env, 1791cb0ef41Sopenharmony_ci napi_value object, 1801cb0ef41Sopenharmony_ci napi_value key, 1811cb0ef41Sopenharmony_ci napi_value value); 1821cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_has_property(napi_env env, 1831cb0ef41Sopenharmony_ci napi_value object, 1841cb0ef41Sopenharmony_ci napi_value key, 1851cb0ef41Sopenharmony_ci bool* result); 1861cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_property(napi_env env, 1871cb0ef41Sopenharmony_ci napi_value object, 1881cb0ef41Sopenharmony_ci napi_value key, 1891cb0ef41Sopenharmony_ci napi_value* result); 1901cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_delete_property(napi_env env, 1911cb0ef41Sopenharmony_ci napi_value object, 1921cb0ef41Sopenharmony_ci napi_value key, 1931cb0ef41Sopenharmony_ci bool* result); 1941cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_has_own_property(napi_env env, 1951cb0ef41Sopenharmony_ci napi_value object, 1961cb0ef41Sopenharmony_ci napi_value key, 1971cb0ef41Sopenharmony_ci bool* result); 1981cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_set_named_property(napi_env env, 1991cb0ef41Sopenharmony_ci napi_value object, 2001cb0ef41Sopenharmony_ci const char* utf8name, 2011cb0ef41Sopenharmony_ci napi_value value); 2021cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_has_named_property(napi_env env, 2031cb0ef41Sopenharmony_ci napi_value object, 2041cb0ef41Sopenharmony_ci const char* utf8name, 2051cb0ef41Sopenharmony_ci bool* result); 2061cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_named_property(napi_env env, 2071cb0ef41Sopenharmony_ci napi_value object, 2081cb0ef41Sopenharmony_ci const char* utf8name, 2091cb0ef41Sopenharmony_ci napi_value* result); 2101cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_set_element(napi_env env, 2111cb0ef41Sopenharmony_ci napi_value object, 2121cb0ef41Sopenharmony_ci uint32_t index, 2131cb0ef41Sopenharmony_ci napi_value value); 2141cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_has_element(napi_env env, 2151cb0ef41Sopenharmony_ci napi_value object, 2161cb0ef41Sopenharmony_ci uint32_t index, 2171cb0ef41Sopenharmony_ci bool* result); 2181cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_element(napi_env env, 2191cb0ef41Sopenharmony_ci napi_value object, 2201cb0ef41Sopenharmony_ci uint32_t index, 2211cb0ef41Sopenharmony_ci napi_value* result); 2221cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_delete_element(napi_env env, 2231cb0ef41Sopenharmony_ci napi_value object, 2241cb0ef41Sopenharmony_ci uint32_t index, 2251cb0ef41Sopenharmony_ci bool* result); 2261cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 2271cb0ef41Sopenharmony_cinapi_define_properties(napi_env env, 2281cb0ef41Sopenharmony_ci napi_value object, 2291cb0ef41Sopenharmony_ci size_t property_count, 2301cb0ef41Sopenharmony_ci const napi_property_descriptor* properties); 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_ci// Methods to work with Arrays 2331cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_array(napi_env env, 2341cb0ef41Sopenharmony_ci napi_value value, 2351cb0ef41Sopenharmony_ci bool* result); 2361cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_array_length(napi_env env, 2371cb0ef41Sopenharmony_ci napi_value value, 2381cb0ef41Sopenharmony_ci uint32_t* result); 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci// Methods to compare values 2411cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_strict_equals(napi_env env, 2421cb0ef41Sopenharmony_ci napi_value lhs, 2431cb0ef41Sopenharmony_ci napi_value rhs, 2441cb0ef41Sopenharmony_ci bool* result); 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_ci// Methods to work with Functions 2471cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_call_function(napi_env env, 2481cb0ef41Sopenharmony_ci napi_value recv, 2491cb0ef41Sopenharmony_ci napi_value func, 2501cb0ef41Sopenharmony_ci size_t argc, 2511cb0ef41Sopenharmony_ci const napi_value* argv, 2521cb0ef41Sopenharmony_ci napi_value* result); 2531cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_new_instance(napi_env env, 2541cb0ef41Sopenharmony_ci napi_value constructor, 2551cb0ef41Sopenharmony_ci size_t argc, 2561cb0ef41Sopenharmony_ci const napi_value* argv, 2571cb0ef41Sopenharmony_ci napi_value* result); 2581cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_instanceof(napi_env env, 2591cb0ef41Sopenharmony_ci napi_value object, 2601cb0ef41Sopenharmony_ci napi_value constructor, 2611cb0ef41Sopenharmony_ci bool* result); 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ci// Methods to work with napi_callbacks 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci// Gets all callback info in a single call. (Ugly, but faster.) 2661cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_cb_info( 2671cb0ef41Sopenharmony_ci napi_env env, // [in] NAPI environment handle 2681cb0ef41Sopenharmony_ci napi_callback_info cbinfo, // [in] Opaque callback-info handle 2691cb0ef41Sopenharmony_ci size_t* argc, // [in-out] Specifies the size of the provided argv array 2701cb0ef41Sopenharmony_ci // and receives the actual count of args. 2711cb0ef41Sopenharmony_ci napi_value* argv, // [out] Array of values 2721cb0ef41Sopenharmony_ci napi_value* this_arg, // [out] Receives the JS 'this' arg for the call 2731cb0ef41Sopenharmony_ci void** data); // [out] Receives the data pointer for the callback. 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_new_target(napi_env env, 2761cb0ef41Sopenharmony_ci napi_callback_info cbinfo, 2771cb0ef41Sopenharmony_ci napi_value* result); 2781cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 2791cb0ef41Sopenharmony_cinapi_define_class(napi_env env, 2801cb0ef41Sopenharmony_ci const char* utf8name, 2811cb0ef41Sopenharmony_ci size_t length, 2821cb0ef41Sopenharmony_ci napi_callback constructor, 2831cb0ef41Sopenharmony_ci void* data, 2841cb0ef41Sopenharmony_ci size_t property_count, 2851cb0ef41Sopenharmony_ci const napi_property_descriptor* properties, 2861cb0ef41Sopenharmony_ci napi_value* result); 2871cb0ef41Sopenharmony_ci 2881cb0ef41Sopenharmony_ci// Methods to work with external data objects 2891cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_wrap(napi_env env, 2901cb0ef41Sopenharmony_ci napi_value js_object, 2911cb0ef41Sopenharmony_ci void* native_object, 2921cb0ef41Sopenharmony_ci napi_finalize finalize_cb, 2931cb0ef41Sopenharmony_ci void* finalize_hint, 2941cb0ef41Sopenharmony_ci napi_ref* result); 2951cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_unwrap(napi_env env, 2961cb0ef41Sopenharmony_ci napi_value js_object, 2971cb0ef41Sopenharmony_ci void** result); 2981cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_remove_wrap(napi_env env, 2991cb0ef41Sopenharmony_ci napi_value js_object, 3001cb0ef41Sopenharmony_ci void** result); 3011cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_external(napi_env env, 3021cb0ef41Sopenharmony_ci void* data, 3031cb0ef41Sopenharmony_ci napi_finalize finalize_cb, 3041cb0ef41Sopenharmony_ci void* finalize_hint, 3051cb0ef41Sopenharmony_ci napi_value* result); 3061cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_external(napi_env env, 3071cb0ef41Sopenharmony_ci napi_value value, 3081cb0ef41Sopenharmony_ci void** result); 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci// Methods to control object lifespan 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ci// Set initial_refcount to 0 for a weak reference, >0 for a strong reference. 3131cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_reference(napi_env env, 3141cb0ef41Sopenharmony_ci napi_value value, 3151cb0ef41Sopenharmony_ci uint32_t initial_refcount, 3161cb0ef41Sopenharmony_ci napi_ref* result); 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci// Deletes a reference. The referenced value is released, and may 3191cb0ef41Sopenharmony_ci// be GC'd unless there are other references to it. 3201cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref); 3211cb0ef41Sopenharmony_ci 3221cb0ef41Sopenharmony_ci// Increments the reference count, optionally returning the resulting count. 3231cb0ef41Sopenharmony_ci// After this call the reference will be a strong reference because its 3241cb0ef41Sopenharmony_ci// refcount is >0, and the referenced object is effectively "pinned". 3251cb0ef41Sopenharmony_ci// Calling this when the refcount is 0 and the object is unavailable 3261cb0ef41Sopenharmony_ci// results in an error. 3271cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_reference_ref(napi_env env, 3281cb0ef41Sopenharmony_ci napi_ref ref, 3291cb0ef41Sopenharmony_ci uint32_t* result); 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ci// Decrements the reference count, optionally returning the resulting count. 3321cb0ef41Sopenharmony_ci// If the result is 0 the reference is now weak and the object may be GC'd 3331cb0ef41Sopenharmony_ci// at any time if there are no other references. Calling this when the 3341cb0ef41Sopenharmony_ci// refcount is already 0 results in an error. 3351cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_reference_unref(napi_env env, 3361cb0ef41Sopenharmony_ci napi_ref ref, 3371cb0ef41Sopenharmony_ci uint32_t* result); 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ci// Attempts to get a referenced value. If the reference is weak, 3401cb0ef41Sopenharmony_ci// the value might no longer be available, in that case the call 3411cb0ef41Sopenharmony_ci// is still successful but the result is NULL. 3421cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_reference_value(napi_env env, 3431cb0ef41Sopenharmony_ci napi_ref ref, 3441cb0ef41Sopenharmony_ci napi_value* result); 3451cb0ef41Sopenharmony_ci 3461cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_open_handle_scope(napi_env env, 3471cb0ef41Sopenharmony_ci napi_handle_scope* result); 3481cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_close_handle_scope(napi_env env, 3491cb0ef41Sopenharmony_ci napi_handle_scope scope); 3501cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 3511cb0ef41Sopenharmony_cinapi_open_escapable_handle_scope(napi_env env, 3521cb0ef41Sopenharmony_ci napi_escapable_handle_scope* result); 3531cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 3541cb0ef41Sopenharmony_cinapi_close_escapable_handle_scope(napi_env env, 3551cb0ef41Sopenharmony_ci napi_escapable_handle_scope scope); 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_escape_handle(napi_env env, 3581cb0ef41Sopenharmony_ci napi_escapable_handle_scope scope, 3591cb0ef41Sopenharmony_ci napi_value escapee, 3601cb0ef41Sopenharmony_ci napi_value* result); 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ci// Methods to support error handling 3631cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error); 3641cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_throw_error(napi_env env, 3651cb0ef41Sopenharmony_ci const char* code, 3661cb0ef41Sopenharmony_ci const char* msg); 3671cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_throw_type_error(napi_env env, 3681cb0ef41Sopenharmony_ci const char* code, 3691cb0ef41Sopenharmony_ci const char* msg); 3701cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_throw_range_error(napi_env env, 3711cb0ef41Sopenharmony_ci const char* code, 3721cb0ef41Sopenharmony_ci const char* msg); 3731cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_error(napi_env env, 3741cb0ef41Sopenharmony_ci napi_value value, 3751cb0ef41Sopenharmony_ci bool* result); 3761cb0ef41Sopenharmony_ci 3771cb0ef41Sopenharmony_ci// Methods to support catching exceptions 3781cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_exception_pending(napi_env env, bool* result); 3791cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_and_clear_last_exception(napi_env env, 3801cb0ef41Sopenharmony_ci napi_value* result); 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ci// Methods to work with array buffers and typed arrays 3831cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_arraybuffer(napi_env env, 3841cb0ef41Sopenharmony_ci napi_value value, 3851cb0ef41Sopenharmony_ci bool* result); 3861cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_arraybuffer(napi_env env, 3871cb0ef41Sopenharmony_ci size_t byte_length, 3881cb0ef41Sopenharmony_ci void** data, 3891cb0ef41Sopenharmony_ci napi_value* result); 3901cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 3911cb0ef41Sopenharmony_cinapi_create_external_arraybuffer(napi_env env, 3921cb0ef41Sopenharmony_ci void* external_data, 3931cb0ef41Sopenharmony_ci size_t byte_length, 3941cb0ef41Sopenharmony_ci napi_finalize finalize_cb, 3951cb0ef41Sopenharmony_ci void* finalize_hint, 3961cb0ef41Sopenharmony_ci napi_value* result); 3971cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_arraybuffer_info(napi_env env, 3981cb0ef41Sopenharmony_ci napi_value arraybuffer, 3991cb0ef41Sopenharmony_ci void** data, 4001cb0ef41Sopenharmony_ci size_t* byte_length); 4011cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_typedarray(napi_env env, 4021cb0ef41Sopenharmony_ci napi_value value, 4031cb0ef41Sopenharmony_ci bool* result); 4041cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_typedarray(napi_env env, 4051cb0ef41Sopenharmony_ci napi_typedarray_type type, 4061cb0ef41Sopenharmony_ci size_t length, 4071cb0ef41Sopenharmony_ci napi_value arraybuffer, 4081cb0ef41Sopenharmony_ci size_t byte_offset, 4091cb0ef41Sopenharmony_ci napi_value* result); 4101cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_typedarray_info(napi_env env, 4111cb0ef41Sopenharmony_ci napi_value typedarray, 4121cb0ef41Sopenharmony_ci napi_typedarray_type* type, 4131cb0ef41Sopenharmony_ci size_t* length, 4141cb0ef41Sopenharmony_ci void** data, 4151cb0ef41Sopenharmony_ci napi_value* arraybuffer, 4161cb0ef41Sopenharmony_ci size_t* byte_offset); 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_dataview(napi_env env, 4191cb0ef41Sopenharmony_ci size_t length, 4201cb0ef41Sopenharmony_ci napi_value arraybuffer, 4211cb0ef41Sopenharmony_ci size_t byte_offset, 4221cb0ef41Sopenharmony_ci napi_value* result); 4231cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_dataview(napi_env env, 4241cb0ef41Sopenharmony_ci napi_value value, 4251cb0ef41Sopenharmony_ci bool* result); 4261cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_dataview_info(napi_env env, 4271cb0ef41Sopenharmony_ci napi_value dataview, 4281cb0ef41Sopenharmony_ci size_t* bytelength, 4291cb0ef41Sopenharmony_ci void** data, 4301cb0ef41Sopenharmony_ci napi_value* arraybuffer, 4311cb0ef41Sopenharmony_ci size_t* byte_offset); 4321cb0ef41Sopenharmony_ci 4331cb0ef41Sopenharmony_ci// version management 4341cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_version(napi_env env, uint32_t* result); 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_ci// Promises 4371cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_promise(napi_env env, 4381cb0ef41Sopenharmony_ci napi_deferred* deferred, 4391cb0ef41Sopenharmony_ci napi_value* promise); 4401cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_resolve_deferred(napi_env env, 4411cb0ef41Sopenharmony_ci napi_deferred deferred, 4421cb0ef41Sopenharmony_ci napi_value resolution); 4431cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_reject_deferred(napi_env env, 4441cb0ef41Sopenharmony_ci napi_deferred deferred, 4451cb0ef41Sopenharmony_ci napi_value rejection); 4461cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_promise(napi_env env, 4471cb0ef41Sopenharmony_ci napi_value value, 4481cb0ef41Sopenharmony_ci bool* is_promise); 4491cb0ef41Sopenharmony_ci 4501cb0ef41Sopenharmony_ci// Running a script 4511cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_run_script(napi_env env, 4521cb0ef41Sopenharmony_ci napi_value script, 4531cb0ef41Sopenharmony_ci napi_value* result); 4541cb0ef41Sopenharmony_ci 4551cb0ef41Sopenharmony_ci// Memory management 4561cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env, 4571cb0ef41Sopenharmony_ci int64_t change_in_bytes, 4581cb0ef41Sopenharmony_ci int64_t* adjusted_value); 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci#if NAPI_VERSION >= 5 4611cb0ef41Sopenharmony_ci 4621cb0ef41Sopenharmony_ci// Dates 4631cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_date(napi_env env, 4641cb0ef41Sopenharmony_ci double time, 4651cb0ef41Sopenharmony_ci napi_value* result); 4661cb0ef41Sopenharmony_ci 4671cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_date(napi_env env, 4681cb0ef41Sopenharmony_ci napi_value value, 4691cb0ef41Sopenharmony_ci bool* is_date); 4701cb0ef41Sopenharmony_ci 4711cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_date_value(napi_env env, 4721cb0ef41Sopenharmony_ci napi_value value, 4731cb0ef41Sopenharmony_ci double* result); 4741cb0ef41Sopenharmony_ci 4751cb0ef41Sopenharmony_ci// Add finalizer for pointer 4761cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_add_finalizer(napi_env env, 4771cb0ef41Sopenharmony_ci napi_value js_object, 4781cb0ef41Sopenharmony_ci void* native_object, 4791cb0ef41Sopenharmony_ci napi_finalize finalize_cb, 4801cb0ef41Sopenharmony_ci void* finalize_hint, 4811cb0ef41Sopenharmony_ci napi_ref* result); 4821cb0ef41Sopenharmony_ci 4831cb0ef41Sopenharmony_ci#endif // NAPI_VERSION >= 5 4841cb0ef41Sopenharmony_ci 4851cb0ef41Sopenharmony_ci#if NAPI_VERSION >= 6 4861cb0ef41Sopenharmony_ci 4871cb0ef41Sopenharmony_ci// BigInt 4881cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_bigint_int64(napi_env env, 4891cb0ef41Sopenharmony_ci int64_t value, 4901cb0ef41Sopenharmony_ci napi_value* result); 4911cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_bigint_uint64(napi_env env, 4921cb0ef41Sopenharmony_ci uint64_t value, 4931cb0ef41Sopenharmony_ci napi_value* result); 4941cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_create_bigint_words(napi_env env, 4951cb0ef41Sopenharmony_ci int sign_bit, 4961cb0ef41Sopenharmony_ci size_t word_count, 4971cb0ef41Sopenharmony_ci const uint64_t* words, 4981cb0ef41Sopenharmony_ci napi_value* result); 4991cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_bigint_int64(napi_env env, 5001cb0ef41Sopenharmony_ci napi_value value, 5011cb0ef41Sopenharmony_ci int64_t* result, 5021cb0ef41Sopenharmony_ci bool* lossless); 5031cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_bigint_uint64(napi_env env, 5041cb0ef41Sopenharmony_ci napi_value value, 5051cb0ef41Sopenharmony_ci uint64_t* result, 5061cb0ef41Sopenharmony_ci bool* lossless); 5071cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_value_bigint_words(napi_env env, 5081cb0ef41Sopenharmony_ci napi_value value, 5091cb0ef41Sopenharmony_ci int* sign_bit, 5101cb0ef41Sopenharmony_ci size_t* word_count, 5111cb0ef41Sopenharmony_ci uint64_t* words); 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_ci// Object 5141cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 5151cb0ef41Sopenharmony_cinapi_get_all_property_names(napi_env env, 5161cb0ef41Sopenharmony_ci napi_value object, 5171cb0ef41Sopenharmony_ci napi_key_collection_mode key_mode, 5181cb0ef41Sopenharmony_ci napi_key_filter key_filter, 5191cb0ef41Sopenharmony_ci napi_key_conversion key_conversion, 5201cb0ef41Sopenharmony_ci napi_value* result); 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci// Instance data 5231cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_set_instance_data(napi_env env, 5241cb0ef41Sopenharmony_ci void* data, 5251cb0ef41Sopenharmony_ci napi_finalize finalize_cb, 5261cb0ef41Sopenharmony_ci void* finalize_hint); 5271cb0ef41Sopenharmony_ci 5281cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_get_instance_data(napi_env env, 5291cb0ef41Sopenharmony_ci void** data); 5301cb0ef41Sopenharmony_ci#endif // NAPI_VERSION >= 6 5311cb0ef41Sopenharmony_ci 5321cb0ef41Sopenharmony_ci#if NAPI_VERSION >= 7 5331cb0ef41Sopenharmony_ci// ArrayBuffer detaching 5341cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_detach_arraybuffer(napi_env env, 5351cb0ef41Sopenharmony_ci napi_value arraybuffer); 5361cb0ef41Sopenharmony_ci 5371cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_is_detached_arraybuffer(napi_env env, 5381cb0ef41Sopenharmony_ci napi_value value, 5391cb0ef41Sopenharmony_ci bool* result); 5401cb0ef41Sopenharmony_ci#endif // NAPI_VERSION >= 7 5411cb0ef41Sopenharmony_ci 5421cb0ef41Sopenharmony_ci#if NAPI_VERSION >= 8 5431cb0ef41Sopenharmony_ci// Type tagging 5441cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_type_tag_object(napi_env env, 5451cb0ef41Sopenharmony_ci napi_value value, 5461cb0ef41Sopenharmony_ci const napi_type_tag* type_tag); 5471cb0ef41Sopenharmony_ci 5481cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status 5491cb0ef41Sopenharmony_cinapi_check_object_type_tag(napi_env env, 5501cb0ef41Sopenharmony_ci napi_value value, 5511cb0ef41Sopenharmony_ci const napi_type_tag* type_tag, 5521cb0ef41Sopenharmony_ci bool* result); 5531cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_object_freeze(napi_env env, 5541cb0ef41Sopenharmony_ci napi_value object); 5551cb0ef41Sopenharmony_ciNAPI_EXTERN napi_status napi_object_seal(napi_env env, 5561cb0ef41Sopenharmony_ci napi_value object); 5571cb0ef41Sopenharmony_ci#endif // NAPI_VERSION >= 8 5581cb0ef41Sopenharmony_ci 5591cb0ef41Sopenharmony_ciEXTERN_C_END 5601cb0ef41Sopenharmony_ci 5611cb0ef41Sopenharmony_ci#endif // SRC_JS_NATIVE_API_H_ 562