Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-09 08:49:24

0001 #ifndef SRC_JS_NATIVE_API_TYPES_H_
0002 #define SRC_JS_NATIVE_API_TYPES_H_
0003 
0004 // Use INT_MAX, this should only be consumed by the pre-processor anyway.
0005 #define NAPI_VERSION_EXPERIMENTAL 2147483647
0006 #ifndef NAPI_VERSION
0007 #ifdef NAPI_EXPERIMENTAL
0008 #define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
0009 #else
0010 // The baseline version for N-API.
0011 // The NAPI_VERSION controls which version will be used by default when
0012 // compilling a native addon. If the addon developer specifically wants to use
0013 // functions available in a new version of N-API that is not yet ported in all
0014 // LTS versions, they can set NAPI_VERSION knowing that they have specifically
0015 // depended on that version.
0016 #define NAPI_VERSION 8
0017 #endif
0018 #endif
0019 
0020 // This file needs to be compatible with C compilers.
0021 // This is a public include file, and these includes have essentially
0022 // became part of it's API.
0023 #include <stddef.h>  // NOLINT(modernize-deprecated-headers)
0024 #include <stdint.h>  // NOLINT(modernize-deprecated-headers)
0025 
0026 #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
0027 typedef uint16_t char16_t;
0028 #endif
0029 
0030 #ifndef NAPI_CDECL
0031 #ifdef _WIN32
0032 #define NAPI_CDECL __cdecl
0033 #else
0034 #define NAPI_CDECL
0035 #endif
0036 #endif
0037 
0038 // JSVM API types are all opaque pointers for ABI stability
0039 // typedef undefined structs instead of void* for compile time type safety
0040 typedef struct napi_env__* napi_env;
0041 
0042 // We need to mark APIs which can be called during garbage collection (GC),
0043 // meaning that they do not affect the state of the JS engine, and can
0044 // therefore be called synchronously from a finalizer that itself runs
0045 // synchronously during GC. Such APIs can receive either a `napi_env` or a
0046 // `node_api_basic_env` as their first parameter, because we should be able to
0047 // also call them during normal, non-garbage-collecting operations, whereas
0048 // APIs that affect the state of the JS engine can only receive a `napi_env` as
0049 // their first parameter, because we must not call them during GC. In lieu of
0050 // inheritance, we use the properties of the const qualifier to accomplish
0051 // this, because both a const and a non-const value can be passed to an API
0052 // expecting a const value, but only a non-const value can be passed to an API
0053 // expecting a non-const value.
0054 //
0055 // In conjunction with appropriate CFLAGS to warn us if we're passing a const
0056 // (basic) environment into an API that expects a non-const environment, and
0057 // the definition of basic finalizer function pointer types below, which
0058 // receive a basic environment as their first parameter, and can thus only call
0059 // basic APIs (unless the user explicitly casts the environment), we achieve
0060 // the ability to ensure at compile time that we do not call APIs that affect
0061 // the state of the JS engine from a synchronous (basic) finalizer.
0062 #if !defined(NAPI_EXPERIMENTAL) ||                                             \
0063     (defined(NAPI_EXPERIMENTAL) &&                                             \
0064      (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) ||                       \
0065       defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
0066 typedef struct napi_env__* node_api_nogc_env;
0067 #else
0068 typedef const struct napi_env__* node_api_nogc_env;
0069 #endif
0070 typedef node_api_nogc_env node_api_basic_env;
0071 
0072 typedef struct napi_value__* napi_value;
0073 typedef struct napi_ref__* napi_ref;
0074 typedef struct napi_handle_scope__* napi_handle_scope;
0075 typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
0076 typedef struct napi_callback_info__* napi_callback_info;
0077 typedef struct napi_deferred__* napi_deferred;
0078 
0079 typedef enum {
0080   napi_default = 0,
0081   napi_writable = 1 << 0,
0082   napi_enumerable = 1 << 1,
0083   napi_configurable = 1 << 2,
0084 
0085   // Used with napi_define_class to distinguish static properties
0086   // from instance properties. Ignored by napi_define_properties.
0087   napi_static = 1 << 10,
0088 
0089 #if NAPI_VERSION >= 8
0090   // Default for class methods.
0091   napi_default_method = napi_writable | napi_configurable,
0092 
0093   // Default for object properties, like in JS obj[prop].
0094   napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
0095 #endif  // NAPI_VERSION >= 8
0096 } napi_property_attributes;
0097 
0098 typedef enum {
0099   // ES6 types (corresponds to typeof)
0100   napi_undefined,
0101   napi_null,
0102   napi_boolean,
0103   napi_number,
0104   napi_string,
0105   napi_symbol,
0106   napi_object,
0107   napi_function,
0108   napi_external,
0109   napi_bigint,
0110 } napi_valuetype;
0111 
0112 typedef enum {
0113   napi_int8_array,
0114   napi_uint8_array,
0115   napi_uint8_clamped_array,
0116   napi_int16_array,
0117   napi_uint16_array,
0118   napi_int32_array,
0119   napi_uint32_array,
0120   napi_float32_array,
0121   napi_float64_array,
0122   napi_bigint64_array,
0123   napi_biguint64_array,
0124 } napi_typedarray_type;
0125 
0126 typedef enum {
0127   napi_ok,
0128   napi_invalid_arg,
0129   napi_object_expected,
0130   napi_string_expected,
0131   napi_name_expected,
0132   napi_function_expected,
0133   napi_number_expected,
0134   napi_boolean_expected,
0135   napi_array_expected,
0136   napi_generic_failure,
0137   napi_pending_exception,
0138   napi_cancelled,
0139   napi_escape_called_twice,
0140   napi_handle_scope_mismatch,
0141   napi_callback_scope_mismatch,
0142   napi_queue_full,
0143   napi_closing,
0144   napi_bigint_expected,
0145   napi_date_expected,
0146   napi_arraybuffer_expected,
0147   napi_detachable_arraybuffer_expected,
0148   napi_would_deadlock,  // unused
0149   napi_no_external_buffers_allowed,
0150   napi_cannot_run_js,
0151 } napi_status;
0152 // Note: when adding a new enum value to `napi_status`, please also update
0153 //   * `const int last_status` in the definition of `napi_get_last_error_info()'
0154 //     in file js_native_api_v8.cc.
0155 //   * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
0156 //     message explaining the error.
0157 //   * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
0158 //     added value(s).
0159 
0160 typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
0161                                               napi_callback_info info);
0162 typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
0163                                         void* finalize_data,
0164                                         void* finalize_hint);
0165 
0166 #if !defined(NAPI_EXPERIMENTAL) ||                                             \
0167     (defined(NAPI_EXPERIMENTAL) &&                                             \
0168      (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) ||                       \
0169       defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
0170 typedef napi_finalize node_api_nogc_finalize;
0171 #else
0172 typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
0173                                                  void* finalize_data,
0174                                                  void* finalize_hint);
0175 #endif
0176 typedef node_api_nogc_finalize node_api_basic_finalize;
0177 
0178 typedef struct {
0179   // One of utf8name or name should be NULL.
0180   const char* utf8name;
0181   napi_value name;
0182 
0183   napi_callback method;
0184   napi_callback getter;
0185   napi_callback setter;
0186   napi_value value;
0187 
0188   napi_property_attributes attributes;
0189   void* data;
0190 } napi_property_descriptor;
0191 
0192 typedef struct {
0193   const char* error_message;
0194   void* engine_reserved;
0195   uint32_t engine_error_code;
0196   napi_status error_code;
0197 } napi_extended_error_info;
0198 
0199 #if NAPI_VERSION >= 6
0200 typedef enum {
0201   napi_key_include_prototypes,
0202   napi_key_own_only
0203 } napi_key_collection_mode;
0204 
0205 typedef enum {
0206   napi_key_all_properties = 0,
0207   napi_key_writable = 1,
0208   napi_key_enumerable = 1 << 1,
0209   napi_key_configurable = 1 << 2,
0210   napi_key_skip_strings = 1 << 3,
0211   napi_key_skip_symbols = 1 << 4
0212 } napi_key_filter;
0213 
0214 typedef enum {
0215   napi_key_keep_numbers,
0216   napi_key_numbers_to_strings
0217 } napi_key_conversion;
0218 #endif  // NAPI_VERSION >= 6
0219 
0220 #if NAPI_VERSION >= 8
0221 typedef struct {
0222   uint64_t lower;
0223   uint64_t upper;
0224 } napi_type_tag;
0225 #endif  // NAPI_VERSION >= 8
0226 
0227 #endif  // SRC_JS_NATIVE_API_TYPES_H_