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 napi_create_ark_runtime_too_many_envs = 22, 97 napi_create_ark_runtime_only_one_env_per_thread = 23, 98 napi_destroy_ark_runtime_env_not_exist = 24 99 } napi_status; 100 // Note: when adding a new enum value to `napi_status`, please also update 101 // * `const int last_status` in the definition of `napi_get_last_error_info()' 102 // in file js_native_api_v8.cc. 103 // * `const char* error_messages[]` in file js_native_api_v8.cc with a brief 104 // message explaining the error. 105 // * the definition of `napi_status` in doc/api/n-api.md to reflect the newly 106 // added value(s). 107 108 typedef napi_value (*napi_callback)(napi_env env, 109 napi_callback_info info); 110 typedef void (*napi_finalize)(napi_env env, 111 void* finalize_data, 112 void* finalize_hint); 113 114 typedef struct { 115 // One of utf8name or name should be NULL. 116 const char* utf8name; 117 napi_value name; 118 119 napi_callback method; 120 napi_callback getter; 121 napi_callback setter; 122 napi_value value; 123 124 napi_property_attributes attributes; 125 void* data; 126 } napi_property_descriptor; 127 128 typedef struct { 129 const char* error_message; 130 void* engine_reserved; 131 uint32_t engine_error_code; 132 napi_status error_code; 133 } napi_extended_error_info; 134 135 #if NAPI_VERSION >= 6 136 typedef enum { 137 napi_key_include_prototypes, 138 napi_key_own_only 139 } napi_key_collection_mode; 140 141 typedef enum { 142 napi_key_all_properties = 0, 143 napi_key_writable = 1, 144 napi_key_enumerable = 1 << 1, 145 napi_key_configurable = 1 << 2, 146 napi_key_skip_strings = 1 << 3, 147 napi_key_skip_symbols = 1 << 4 148 } napi_key_filter; 149 150 typedef enum { 151 napi_key_keep_numbers, 152 napi_key_numbers_to_strings 153 } napi_key_conversion; 154 #endif // NAPI_VERSION >= 6 155 156 #if NAPI_VERSION >= 8 157 typedef struct { 158 uint64_t lower; 159 uint64_t upper; 160 } napi_type_tag; 161 #endif // NAPI_VERSION >= 8 162 163 #endif // SRC_JS_NATIVE_API_TYPES_H_ 164