Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:05:22

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_nogc_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 // (nogc) environment into an API that expects a non-const environment, and the
0041 // definition of nogc finalizer function pointer types below, which receive a
0042 // nogc environment as their first parameter, and can thus only call nogc APIs
0043 // (unless the user explicitly casts the environment), we achieve the ability
0044 // to ensure at compile time that we do not call APIs that affect the state of
0045 // the JS engine from a synchronous (nogc) finalizer.
0046 #if !defined(NAPI_EXPERIMENTAL) ||                                             \
0047     (defined(NAPI_EXPERIMENTAL) &&                                             \
0048      defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
0049 typedef struct napi_env__* node_api_nogc_env;
0050 #else
0051 typedef const struct napi_env__* node_api_nogc_env;
0052 #endif
0053 
0054 typedef struct napi_value__* napi_value;
0055 typedef struct napi_ref__* napi_ref;
0056 typedef struct napi_handle_scope__* napi_handle_scope;
0057 typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
0058 typedef struct napi_callback_info__* napi_callback_info;
0059 typedef struct napi_deferred__* napi_deferred;
0060 
0061 typedef enum {
0062   napi_default = 0,
0063   napi_writable = 1 << 0,
0064   napi_enumerable = 1 << 1,
0065   napi_configurable = 1 << 2,
0066 
0067   // Used with napi_define_class to distinguish static properties
0068   // from instance properties. Ignored by napi_define_properties.
0069   napi_static = 1 << 10,
0070 
0071 #if NAPI_VERSION >= 8
0072   // Default for class methods.
0073   napi_default_method = napi_writable | napi_configurable,
0074 
0075   // Default for object properties, like in JS obj[prop].
0076   napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
0077 #endif  // NAPI_VERSION >= 8
0078 } napi_property_attributes;
0079 
0080 typedef enum {
0081   // ES6 types (corresponds to typeof)
0082   napi_undefined,
0083   napi_null,
0084   napi_boolean,
0085   napi_number,
0086   napi_string,
0087   napi_symbol,
0088   napi_object,
0089   napi_function,
0090   napi_external,
0091   napi_bigint,
0092 } napi_valuetype;
0093 
0094 typedef enum {
0095   napi_int8_array,
0096   napi_uint8_array,
0097   napi_uint8_clamped_array,
0098   napi_int16_array,
0099   napi_uint16_array,
0100   napi_int32_array,
0101   napi_uint32_array,
0102   napi_float32_array,
0103   napi_float64_array,
0104   napi_bigint64_array,
0105   napi_biguint64_array,
0106 } napi_typedarray_type;
0107 
0108 typedef enum {
0109   napi_ok,
0110   napi_invalid_arg,
0111   napi_object_expected,
0112   napi_string_expected,
0113   napi_name_expected,
0114   napi_function_expected,
0115   napi_number_expected,
0116   napi_boolean_expected,
0117   napi_array_expected,
0118   napi_generic_failure,
0119   napi_pending_exception,
0120   napi_cancelled,
0121   napi_escape_called_twice,
0122   napi_handle_scope_mismatch,
0123   napi_callback_scope_mismatch,
0124   napi_queue_full,
0125   napi_closing,
0126   napi_bigint_expected,
0127   napi_date_expected,
0128   napi_arraybuffer_expected,
0129   napi_detachable_arraybuffer_expected,
0130   napi_would_deadlock,  // unused
0131   napi_no_external_buffers_allowed,
0132   napi_cannot_run_js,
0133 } napi_status;
0134 // Note: when adding a new enum value to `napi_status`, please also update
0135 //   * `const int last_status` in the definition of `napi_get_last_error_info()'
0136 //     in file js_native_api_v8.cc.
0137 //   * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
0138 //     message explaining the error.
0139 //   * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
0140 //     added value(s).
0141 
0142 typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
0143                                               napi_callback_info info);
0144 typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
0145                                         void* finalize_data,
0146                                         void* finalize_hint);
0147 
0148 #if !defined(NAPI_EXPERIMENTAL) ||                                             \
0149     (defined(NAPI_EXPERIMENTAL) &&                                             \
0150      defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
0151 typedef napi_finalize node_api_nogc_finalize;
0152 #else
0153 typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
0154                                                  void* finalize_data,
0155                                                  void* finalize_hint);
0156 #endif
0157 
0158 typedef struct {
0159   // One of utf8name or name should be NULL.
0160   const char* utf8name;
0161   napi_value name;
0162 
0163   napi_callback method;
0164   napi_callback getter;
0165   napi_callback setter;
0166   napi_value value;
0167 
0168   napi_property_attributes attributes;
0169   void* data;
0170 } napi_property_descriptor;
0171 
0172 typedef struct {
0173   const char* error_message;
0174   void* engine_reserved;
0175   uint32_t engine_error_code;
0176   napi_status error_code;
0177 } napi_extended_error_info;
0178 
0179 #if NAPI_VERSION >= 6
0180 typedef enum {
0181   napi_key_include_prototypes,
0182   napi_key_own_only
0183 } napi_key_collection_mode;
0184 
0185 typedef enum {
0186   napi_key_all_properties = 0,
0187   napi_key_writable = 1,
0188   napi_key_enumerable = 1 << 1,
0189   napi_key_configurable = 1 << 2,
0190   napi_key_skip_strings = 1 << 3,
0191   napi_key_skip_symbols = 1 << 4
0192 } napi_key_filter;
0193 
0194 typedef enum {
0195   napi_key_keep_numbers,
0196   napi_key_numbers_to_strings
0197 } napi_key_conversion;
0198 #endif  // NAPI_VERSION >= 6
0199 
0200 #if NAPI_VERSION >= 8
0201 typedef struct {
0202   uint64_t lower;
0203   uint64_t upper;
0204 } napi_type_tag;
0205 #endif  // NAPI_VERSION >= 8
0206 
0207 #endif  // SRC_JS_NATIVE_API_TYPES_H_