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