Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/js_native_api_types.h
1 #ifndef SRC_JS_NATIVE_API_TYPES_H_ 2 #define SRC_JS_NATIVE_API_TYPES_H_ 3 4 // Use INT_MAX, this should only be consumed by the pre-processor anyway. 5 #define NAPI_VERSION_EXPERIMENTAL 2147483647 6 #ifndef NAPI_VERSION 7 #ifdef NAPI_EXPERIMENTAL 8 #define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL 9 #else 10 // The baseline version for Node-API. 11 // NAPI_VERSION controls which version is used by default when compiling 12 // a native addon. If the addon developer wants to use functions from a 13 // newer Node-API version not yet available in all LTS versions, they can 14 // set NAPI_VERSION to explicitly depend on that version. 15 #define NAPI_VERSION 8 16 #endif 17 #endif 18 19 // This file needs to be compatible with C compilers. 20 // This is a public include file, and these includes have essentially 21 // become part of its API. 22 #include <stddef.h> // NOLINT(modernize-deprecated-headers) 23 #include <stdint.h> // NOLINT(modernize-deprecated-headers) 24 25 #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900) 26 typedef uint16_t char16_t; 27 #endif 28 29 #ifndef NAPI_CDECL 30 #ifdef _WIN32 31 #define NAPI_CDECL __cdecl 32 #else 33 #define NAPI_CDECL 34 #endif 35 #endif 36 37 // JSVM API types are all opaque pointers for ABI stability 38 // typedef undefined structs instead of void* for compile time type safety 39 typedef struct napi_env__* napi_env; 40 41 // We need to mark APIs which can be called during garbage collection (GC), 42 // meaning that they do not affect the state of the JS engine, and can 43 // therefore be called synchronously from a finalizer that itself runs 44 // synchronously during GC. Such APIs can receive either a `napi_env` or a 45 // `node_api_basic_env` as their first parameter, because we should be able to 46 // also call them during normal, non-garbage-collecting operations, whereas 47 // APIs that affect the state of the JS engine can only receive a `napi_env` as 48 // their first parameter, because we must not call them during GC. In lieu of 49 // inheritance, we use the properties of the const qualifier to accomplish 50 // this, because both a const and a non-const value can be passed to an API 51 // expecting a const value, but only a non-const value can be passed to an API 52 // expecting a non-const value. 53 // 54 // In conjunction with appropriate CFLAGS to warn us if we're passing a const 55 // (basic) environment into an API that expects a non-const environment, and 56 // the definition of basic finalizer function pointer types below, which 57 // receive a basic environment as their first parameter, and can thus only call 58 // basic APIs (unless the user explicitly casts the environment), we achieve 59 // the ability to ensure at compile time that we do not call APIs that affect 60 // the state of the JS engine from a synchronous (basic) finalizer. 61 #if !defined(NAPI_EXPERIMENTAL) || \ 62 (defined(NAPI_EXPERIMENTAL) && \ 63 (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \ 64 defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT))) 65 typedef struct napi_env__* node_api_nogc_env; 66 #else 67 typedef const struct napi_env__* node_api_nogc_env; 68 #endif 69 typedef node_api_nogc_env node_api_basic_env; 70 71 typedef struct napi_value__* napi_value; 72 typedef struct napi_ref__* napi_ref; 73 typedef struct napi_handle_scope__* napi_handle_scope; 74 typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope; 75 typedef struct napi_callback_info__* napi_callback_info; 76 typedef struct napi_deferred__* napi_deferred; 77 78 typedef enum { 79 napi_default = 0, 80 napi_writable = 1 << 0, 81 napi_enumerable = 1 << 1, 82 napi_configurable = 1 << 2, 83 84 // Used with napi_define_class to distinguish static properties 85 // from instance properties. Ignored by napi_define_properties. 86 napi_static = 1 << 10, 87 88 #if NAPI_VERSION >= 8 89 // Default for class methods. 90 napi_default_method = napi_writable | napi_configurable, 91 92 // Default for object properties, like in JS obj[prop]. 93 napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable, 94 #endif // NAPI_VERSION >= 8 95 } napi_property_attributes; 96 97 typedef enum { 98 // ES6 types (corresponds to typeof) 99 napi_undefined, 100 napi_null, 101 napi_boolean, 102 napi_number, 103 napi_string, 104 napi_symbol, 105 napi_object, 106 napi_function, 107 napi_external, 108 napi_bigint, 109 } napi_valuetype; 110 111 typedef enum { 112 napi_int8_array, 113 napi_uint8_array, 114 napi_uint8_clamped_array, 115 napi_int16_array, 116 napi_uint16_array, 117 napi_int32_array, 118 napi_uint32_array, 119 napi_float32_array, 120 napi_float64_array, 121 napi_bigint64_array, 122 napi_biguint64_array, 123 } napi_typedarray_type; 124 125 typedef enum { 126 napi_ok, 127 napi_invalid_arg, 128 napi_object_expected, 129 napi_string_expected, 130 napi_name_expected, 131 napi_function_expected, 132 napi_number_expected, 133 napi_boolean_expected, 134 napi_array_expected, 135 napi_generic_failure, 136 napi_pending_exception, 137 napi_cancelled, 138 napi_escape_called_twice, 139 napi_handle_scope_mismatch, 140 napi_callback_scope_mismatch, 141 napi_queue_full, 142 napi_closing, 143 napi_bigint_expected, 144 napi_date_expected, 145 napi_arraybuffer_expected, 146 napi_detachable_arraybuffer_expected, 147 napi_would_deadlock, // unused 148 napi_no_external_buffers_allowed, 149 napi_cannot_run_js, 150 } napi_status; 151 // Note: when adding a new enum value to `napi_status`, please also update 152 // * `const int last_status` in the definition of `napi_get_last_error_info()' 153 // in file js_native_api_v8.cc. 154 // * `const char* error_messages[]` in file js_native_api_v8.cc with a brief 155 // message explaining the error. 156 // * the definition of `napi_status` in doc/api/n-api.md to reflect the newly 157 // added value(s). 158 159 typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env, 160 napi_callback_info info); 161 typedef void(NAPI_CDECL* napi_finalize)(napi_env env, 162 void* finalize_data, 163 void* finalize_hint); 164 165 #if !defined(NAPI_EXPERIMENTAL) || \ 166 (defined(NAPI_EXPERIMENTAL) && \ 167 (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \ 168 defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT))) 169 typedef napi_finalize node_api_nogc_finalize; 170 #else 171 typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env, 172 void* finalize_data, 173 void* finalize_hint); 174 #endif 175 typedef node_api_nogc_finalize node_api_basic_finalize; 176 177 typedef struct { 178 // One of utf8name or name should be NULL. 179 const char* utf8name; 180 napi_value name; 181 182 napi_callback method; 183 napi_callback getter; 184 napi_callback setter; 185 napi_value value; 186 187 napi_property_attributes attributes; 188 void* data; 189 } napi_property_descriptor; 190 191 typedef struct { 192 const char* error_message; 193 void* engine_reserved; 194 uint32_t engine_error_code; 195 napi_status error_code; 196 } napi_extended_error_info; 197 198 #if NAPI_VERSION >= 6 199 typedef enum { 200 napi_key_include_prototypes, 201 napi_key_own_only 202 } napi_key_collection_mode; 203 204 typedef enum { 205 napi_key_all_properties = 0, 206 napi_key_writable = 1, 207 napi_key_enumerable = 1 << 1, 208 napi_key_configurable = 1 << 2, 209 napi_key_skip_strings = 1 << 3, 210 napi_key_skip_symbols = 1 << 4 211 } napi_key_filter; 212 213 typedef enum { 214 napi_key_keep_numbers, 215 napi_key_numbers_to_strings 216 } napi_key_conversion; 217 #endif // NAPI_VERSION >= 6 218 219 #if NAPI_VERSION >= 8 220 typedef struct { 221 uint64_t lower; 222 uint64_t upper; 223 } napi_type_tag; 224 #endif // NAPI_VERSION >= 8 225 226 #endif // SRC_JS_NATIVE_API_TYPES_H_