Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:02:40

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