1 #ifndef SRC_JS_NATIVE_API_TYPES_H_ 2 #define SRC_JS_NATIVE_API_TYPES_H_ 3 4 // This file needs to be compatible with C compilers. 5 // This is a public include file, and these includes have essentially 6 // became part of it's API. 7 #include <stddef.h> // NOLINT(modernize-deprecated-headers) 8 #include <stdint.h> // NOLINT(modernize-deprecated-headers) 9 10 #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900) 11 typedef uint16_t char16_t; 12 #endif 13 14 // JSVM API types are all opaque pointers for ABI stability 15 // typedef undefined structs instead of void* for compile time type safety 16 typedef struct napi_env__* napi_env; 17 typedef struct napi_value__* napi_value; 18 typedef struct napi_ref__* napi_ref; 19 typedef struct napi_handle_scope__* napi_handle_scope; 20 typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope; 21 typedef struct napi_callback_info__* napi_callback_info; 22 typedef struct napi_deferred__* napi_deferred; 23 24 typedef enum { 25 napi_default = 0, 26 napi_writable = 1 << 0, 27 napi_enumerable = 1 << 1, 28 napi_configurable = 1 << 2, 29 30 // Used with napi_define_class to distinguish static properties 31 // from instance properties. Ignored by napi_define_properties. 32 napi_static = 1 << 10, 33 34 #if NAPI_VERSION >= 8 35 // Default for class methods. 36 napi_default_method = napi_writable | napi_configurable, 37 38 // Default for object properties, like in JS obj[prop]. 39 napi_default_jsproperty = napi_writable | 40 napi_enumerable | 41 napi_configurable, 42 #endif // NAPI_VERSION >= 8 43 } napi_property_attributes; 44 45 typedef enum { 46 // ES6 types (corresponds to typeof) 47 napi_undefined, 48 napi_null, 49 napi_boolean, 50 napi_number, 51 napi_string, 52 napi_symbol, 53 napi_object, 54 napi_function, 55 napi_external, 56 napi_bigint, 57 } napi_valuetype; 58 59 typedef enum { 60 napi_int8_array, 61 napi_uint8_array, 62 napi_uint8_clamped_array, 63 napi_int16_array, 64 napi_uint16_array, 65 napi_int32_array, 66 napi_uint32_array, 67 napi_float32_array, 68 napi_float64_array, 69 napi_bigint64_array, 70 napi_biguint64_array, 71 } napi_typedarray_type; 72 73 typedef enum { 74 napi_ok, 75 napi_invalid_arg, 76 napi_object_expected, 77 napi_string_expected, 78 napi_name_expected, 79 napi_function_expected, 80 napi_number_expected, 81 napi_boolean_expected, 82 napi_array_expected, 83 napi_generic_failure, 84 napi_pending_exception, 85 napi_cancelled, 86 napi_escape_called_twice, 87 napi_handle_scope_mismatch, 88 napi_callback_scope_mismatch, 89 napi_queue_full, 90 napi_closing, 91 napi_bigint_expected, 92 napi_date_expected, 93 napi_arraybuffer_expected, 94 napi_detachable_arraybuffer_expected, 95 napi_would_deadlock, // unused 96 // Created too many ark runtime environment, up to 16. 97 napi_create_ark_runtime_too_many_envs = 22, 98 // Only one ark runtime environment can be created per thread. 99 napi_create_ark_runtime_only_one_env_per_thread = 23, 100 // The ark runtime environment to be destroyed does not exist. 101 napi_destroy_ark_runtime_env_not_exist = 24 102 } napi_status; 103 // Note: when adding a new enum value to `napi_status`, please also update 104 // * `const int last_status` in the definition of `napi_get_last_error_info()' 105 // in file js_native_api_v8.cc. 106 // * `const char* error_messages[]` in file js_native_api_v8.cc with a brief 107 // message explaining the error. 108 // * the definition of `napi_status` in doc/api/n-api.md to reflect the newly 109 // added value(s). 110 111 typedef napi_value (*napi_callback)(napi_env env, 112 napi_callback_info info); 113 typedef void (*napi_finalize)(napi_env env, 114 void* finalize_data, 115 void* finalize_hint); 116 117 typedef struct { 118 // One of utf8name or name should be NULL. 119 const char* utf8name; 120 napi_value name; 121 122 napi_callback method; 123 napi_callback getter; 124 napi_callback setter; 125 napi_value value; 126 127 napi_property_attributes attributes; 128 void* data; 129 } napi_property_descriptor; 130 131 typedef struct { 132 const char* error_message; 133 void* engine_reserved; 134 uint32_t engine_error_code; 135 napi_status error_code; 136 } napi_extended_error_info; 137 138 #if NAPI_VERSION >= 6 139 typedef enum { 140 napi_key_include_prototypes, 141 napi_key_own_only 142 } napi_key_collection_mode; 143 144 typedef enum { 145 napi_key_all_properties = 0, 146 napi_key_writable = 1, 147 napi_key_enumerable = 1 << 1, 148 napi_key_configurable = 1 << 2, 149 napi_key_skip_strings = 1 << 3, 150 napi_key_skip_symbols = 1 << 4 151 } napi_key_filter; 152 153 typedef enum { 154 napi_key_keep_numbers, 155 napi_key_numbers_to_strings 156 } napi_key_conversion; 157 #endif // NAPI_VERSION >= 6 158 159 #if NAPI_VERSION >= 8 160 typedef struct { 161 uint64_t lower; 162 uint64_t upper; 163 } napi_type_tag; 164 #endif // NAPI_VERSION >= 8 165 166 #endif // SRC_JS_NATIVE_API_TYPES_H_ 167