Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
n-api: rename to node-api
  • Loading branch information
Gabriel Schulhof
Gabriel Schulhof committed Jan 24, 2021
commit 7dbc94b49bdad6ffe72ded19005e5f572cfa0a3d
9 changes: 6 additions & 3 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

// Use INT_MAX, this should only be consumed by the pre-processor anyway.
#define NAPI_VERSION_EXPERIMENTAL 2147483647
#ifndef NAPI_VERSION
#ifdef NAPI_EXPERIMENTAL
#define NODE_API_VERSION_EXPERIMENTAL NAPI_VERSION_EXPERIMENTAL
#if !(defined(NAPI_VERSION) || defined(NODE_API_VERSION))
#if defined(NAPI_EXPERIMENTAL) || defined(NODE_API_EXPERIMENTAL)
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
#define NODE_API_VERSION NODE_API_VERSION_EXPERIMENTAL
#else
// The baseline version for N-API.
// The NAPI_VERSION controls which version will be used by default when
Expand All @@ -18,6 +20,7 @@
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
// depended on that version.
#define NAPI_VERSION 7
#define NODE_API_VERSION NAPI_VERSION
#endif
#endif

Expand Down Expand Up @@ -48,7 +51,7 @@

EXTERN_C_START

NAPI_EXTERN napi_status
NODE_API_EXTERN node_api_status
napi_get_last_error_info(napi_env env,
const napi_extended_error_info** result);

Expand Down
103 changes: 93 additions & 10 deletions src/js_native_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ typedef struct napi_handle_scope__* napi_handle_scope;
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
typedef struct napi_callback_info__* napi_callback_info;
typedef struct napi_deferred__* napi_deferred;
#define node_api_env napi_env
#define node_api_value napi_value
#define node_api_ref napi_ref
#define node_api_handle_scope napi_handle_scope
#define node_api_escapable_handle_scope napi_escapable_handle_scope
#define node_api_callback_info napi_callback_info
#define node_api_deferred napi_deferred

typedef enum {
napi_default = 0,
Expand All @@ -41,6 +48,16 @@ typedef enum {
napi_configurable,
#endif // NAPI_EXPERIMENTAL
} napi_property_attributes;
#define node_api_default napi_default
#define node_api_writable napi_writable
#define node_api_enumerable napi_enumerable
#define node_api_configurable napi_configurable
#define node_api_static napi_static
#ifdef NAPI_EXPERIMENTAL
#define node_api_default_method napi_default_method
#define node_api_default_jsproperty napi_default_jsproperty
#endif // NAPI_EXPERIMENTAL
#define node_api_property_attributes napi_property_attributes

typedef enum {
// ES6 types (corresponds to typeof)
Expand All @@ -55,6 +72,17 @@ typedef enum {
napi_external,
napi_bigint,
} napi_valuetype;
#define node_api_undefined napi_undefined
#define node_api_null napi_null
#define node_api_boolean napi_boolean
#define node_api_number napi_number
#define node_api_string napi_string
#define node_api_symbol napi_symbol
#define node_api_object napi_object
#define node_api_function napi_function
#define napi_external,
#define napi_bigint,
#define napi_valuetype;

typedef enum {
napi_int8_array,
Expand All @@ -69,6 +97,18 @@ typedef enum {
napi_bigint64_array,
napi_biguint64_array,
} napi_typedarray_type;
#define node_api_int8_array napi_int8_array
#define node_api_uint8_array napi_uint8_array
#define node_api_uint8_clamped_array napi_uint8_clamped_array
#define node_api_int16_array napi_int16_array
#define node_api_uint16_array napi_uint16_array
#define node_api_int32_array napi_int32_array
#define node_api_uint32_array napi_uint32_array
#define node_api_float32_array napi_float32_array
#define node_api_float64_array napi_float64_array
#define node_api_bigint64_array napi_bigint64_array
#define node_api_biguint64_array napi_biguint64_array
#define node_api_typedarray_type napi_typedarray_type

typedef enum {
napi_ok,
Expand Down Expand Up @@ -102,38 +142,70 @@ typedef enum {
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
// added value(s).

typedef napi_value (*napi_callback)(napi_env env,
napi_callback_info info);
typedef void (*napi_finalize)(napi_env env,
#define node_api_ok napi_ok
#define node_api_invalid_arg napi_invalid_arg
#define node_api_object_expected napi_object_expected
#define node_api_string_expected napi_string_expected
#define node_api_name_expected napi_name_expected
#define node_api_function_expected napi_function_expected
#define node_api_number_expected napi_number_expected
#define node_api_boolean_expected napi_boolean_expected
#define node_api_array_expected napi_array_expected
#define node_api_generic_failure napi_generic_failure
#define node_api_pending_exception napi_pending_exception
#define node_api_cancelled napi_cancelled
#define node_api_escape_called_twice napi_escape_called_twice
#define node_api_handle_scope_mismatch napi_handle_scope_mismatch
#define node_api_callback_scope_mismatch napi_callback_scope_mismatch
#define node_api_queue_full napi_queue_full
#define node_api_closing napi_closing
#define node_api_bigint_expected napi_bigint_expected
#define node_api_date_expected napi_date_expected
#define node_api_arraybuffer_expected napi_arraybuffer_expected
#define node_api_detachable_arraybuffer_expected \
napi_detachable_arraybuffer_expected
#define node_api_would_deadlock napi_would_deadlock
#define node_api_status napi_status

typedef node_api_value (*napi_callback)(node_api_env env,
node_api_callback_info info);
#define node_api_callback napi_callback
typedef void (*napi_finalize)(node_api_env env,
void* finalize_data,
void* finalize_hint);
#define node_api_finalize napi_finalize

typedef struct {
// One of utf8name or name should be NULL.
const char* utf8name;
napi_value name;
node_api_value name;

napi_callback method;
napi_callback getter;
napi_callback setter;
napi_value value;
node_api_callback method;
node_api_callback getter;
node_api_callback setter;
node_api_value value;

napi_property_attributes attributes;
node_api_property_attributes attributes;
void* data;
} napi_property_descriptor;
#define node_api_property_descriptor napi_property_descriptor

typedef struct {
const char* error_message;
void* engine_reserved;
uint32_t engine_error_code;
napi_status error_code;
node_api_status error_code;
} napi_extended_error_info;
#define node_api_extended_error_info napi_extended_error_info

#if NAPI_VERSION >= 6
typedef enum {
napi_key_include_prototypes,
napi_key_own_only
} napi_key_collection_mode;
#define node_api_key_include_prototypes napi_key_include_prototypes
#define node_api_key_own_only napi_key_own_only
#define node_api_key_collection_mode napi_key_collection_mode

typedef enum {
napi_key_all_properties = 0,
Expand All @@ -143,18 +215,29 @@ typedef enum {
napi_key_skip_strings = 1 << 3,
napi_key_skip_symbols = 1 << 4
} napi_key_filter;
#define node_api_key_all_properties napi_key_all_properties
#define node_api_key_writable napi_key_writable
#define node_api_key_enumerable napi_key_enumerable
#define node_api_key_configurable napi_key_configurable
#define node_api_key_skip_strings napi_key_skip_strings
#define node_api_key_skip_symbols napi_key_skip_symbols
#define node_api_key_filter napi_key_filter

typedef enum {
napi_key_keep_numbers,
napi_key_numbers_to_strings
} napi_key_conversion;
#define node_api_key_keep_numbers napi_key_keep_numbers
#define node_api_key_numbers_to_strings napi_key_numbers_to_strings
#define node_api_key_conversion napi_key_conversion
#endif // NAPI_VERSION >= 6

#ifdef NAPI_EXPERIMENTAL
typedef struct {
uint64_t lower;
uint64_t upper;
} napi_type_tag;
#define node_api_type_tag napi_type_tag
#endif // NAPI_EXPERIMENTAL

#endif // SRC_JS_NATIVE_API_TYPES_H_
Loading