From 769e52926272b285b60fe107d72a408ec0617627 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:02:18 +0000 Subject: [PATCH] Update headers from nodejs/node tag v21.4.0 --- def/js_native_api.def | 5 +- def/node_api.def | 6 +- include/js_native_api.h | 19 +++++- include/js_native_api_types.h | 3 +- include/node_api.h | 105 +++++++++++++--------------------- symbols.js | 16 +++++- 6 files changed, 84 insertions(+), 70 deletions(-) diff --git a/def/js_native_api.def b/def/js_native_api.def index ba2b5c0..dc0d9d5 100644 --- a/def/js_native_api.def +++ b/def/js_native_api.def @@ -114,4 +114,7 @@ napi_is_detached_arraybuffer napi_check_object_type_tag napi_object_freeze napi_object_seal -napi_type_tag_object \ No newline at end of file +napi_type_tag_object +node_api_create_syntax_error +node_api_symbol_for +node_api_throw_syntax_error \ No newline at end of file diff --git a/def/node_api.def b/def/node_api.def index 3e3cc23..81c7d35 100644 --- a/def/node_api.def +++ b/def/node_api.def @@ -144,4 +144,8 @@ napi_remove_async_cleanup_hook napi_check_object_type_tag napi_object_freeze napi_object_seal -napi_type_tag_object \ No newline at end of file +napi_type_tag_object +node_api_get_module_file_name +node_api_create_syntax_error +node_api_symbol_for +node_api_throw_syntax_error \ No newline at end of file diff --git a/include/js_native_api.h b/include/js_native_api.h index 14d6bc5..0e11eeb 100644 --- a/include/js_native_api.h +++ b/include/js_native_api.h @@ -24,7 +24,7 @@ #ifndef NAPI_EXTERN #ifdef _WIN32 #define NAPI_EXTERN __declspec(dllexport) -#elif defined(__wasm32__) +#elif defined(__wasm__) #define NAPI_EXTERN \ __attribute__((visibility("default"))) \ __attribute__((__import_module__("napi"))) @@ -91,6 +91,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env, NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env, napi_value description, napi_value* result); +#if NAPI_VERSION >= 9 +NAPI_EXTERN napi_status NAPI_CDECL +node_api_symbol_for(napi_env env, + const char* utf8description, + size_t length, + napi_value* result); +#endif // NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL napi_create_function(napi_env env, const char* utf8name, size_t length, @@ -109,6 +116,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_range_error(napi_env env, napi_value code, napi_value msg, napi_value* result); +#if NAPI_VERSION >= 9 +NAPI_EXTERN napi_status NAPI_CDECL node_api_create_syntax_error( + napi_env env, napi_value code, napi_value msg, napi_value* result); +#endif // NAPI_VERSION >= 9 // Methods to get the native napi_value from Primitive type NAPI_EXTERN napi_status NAPI_CDECL napi_typeof(napi_env env, @@ -363,6 +374,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_throw_type_error(napi_env env, NAPI_EXTERN napi_status NAPI_CDECL napi_throw_range_error(napi_env env, const char* code, const char* msg); +#if NAPI_VERSION >= 9 +NAPI_EXTERN napi_status NAPI_CDECL node_api_throw_syntax_error(napi_env env, + const char* code, + const char* msg); +#endif // NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL napi_is_error(napi_env env, napi_value value, bool* result); @@ -479,6 +495,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env, #endif // NAPI_VERSION >= 5 + #if NAPI_VERSION >= 6 // BigInt diff --git a/include/js_native_api_types.h b/include/js_native_api_types.h index 5176149..005382f 100644 --- a/include/js_native_api_types.h +++ b/include/js_native_api_types.h @@ -99,7 +99,8 @@ typedef enum { napi_arraybuffer_expected, napi_detachable_arraybuffer_expected, napi_would_deadlock, // unused - napi_no_external_buffers_allowed + napi_no_external_buffers_allowed, + napi_cannot_run_js, } napi_status; // Note: when adding a new enum value to `napi_status`, please also update // * `const int last_status` in the definition of `napi_get_last_error_info()' diff --git a/include/node_api.h b/include/node_api.h index a207b69..49a23ae 100644 --- a/include/node_api.h +++ b/include/node_api.h @@ -1,11 +1,11 @@ #ifndef SRC_NODE_API_H_ #define SRC_NODE_API_H_ -#ifdef BUILDING_NODE_EXTENSION +#if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN) #ifdef _WIN32 // Building native addon against node #define NAPI_EXTERN __declspec(dllimport) -#elif defined(__wasm32__) +#elif defined(__wasm__) #define NAPI_EXTERN __attribute__((__import_module__("napi"))) #endif #endif @@ -17,8 +17,13 @@ struct uv_loop_s; // Forward declaration. #ifdef _WIN32 #define NAPI_MODULE_EXPORT __declspec(dllexport) #else +#ifdef __EMSCRIPTEN__ +#define NAPI_MODULE_EXPORT \ + __attribute__((visibility("default"))) __attribute__((used)) +#else #define NAPI_MODULE_EXPORT __attribute__((visibility("default"))) #endif +#endif #if defined(__GNUC__) #define NAPI_NO_RETURN __attribute__((noreturn)) @@ -30,7 +35,9 @@ struct uv_loop_s; // Forward declaration. typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env, napi_value exports); +typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void); +// Used by deprecated registration method napi_module_register. typedef struct napi_module { int nm_version; unsigned int nm_flags; @@ -43,85 +50,51 @@ typedef struct napi_module { #define NAPI_MODULE_VERSION 1 -#if defined(_MSC_VER) -#if defined(__cplusplus) -#define NAPI_C_CTOR(fn) \ - static void NAPI_CDECL fn(void); \ - namespace { \ - struct fn##_ { \ - fn##_() { fn(); } \ - } fn##_v_; \ - } \ - static void NAPI_CDECL fn(void) -#else // !defined(__cplusplus) -#pragma section(".CRT$XCU", read) -// The NAPI_C_CTOR macro defines a function fn that is called during CRT -// initialization. -// C does not support dynamic initialization of static variables and this code -// simulates C++ behavior. Exporting the function pointer prevents it from being -// optimized. See for details: -// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-170 -#define NAPI_C_CTOR(fn) \ - static void NAPI_CDECL fn(void); \ - __declspec(dllexport, allocate(".CRT$XCU")) void(NAPI_CDECL * fn##_)(void) = \ - fn; \ - static void NAPI_CDECL fn(void) -#endif // defined(__cplusplus) -#else -#define NAPI_C_CTOR(fn) \ - static void fn(void) __attribute__((constructor)); \ - static void fn(void) -#endif - -#define NAPI_MODULE_X(modname, regfunc, priv, flags) \ - EXTERN_C_START \ - static napi_module _module = { \ - NAPI_MODULE_VERSION, \ - flags, \ - __FILE__, \ - regfunc, \ - #modname, \ - priv, \ - {0}, \ - }; \ - NAPI_C_CTOR(_register_##modname) { napi_module_register(&_module); } \ - EXTERN_C_END - #define NAPI_MODULE_INITIALIZER_X(base, version) \ NAPI_MODULE_INITIALIZER_X_HELPER(base, version) #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version -#ifdef __wasm32__ -#define NAPI_WASM_INITIALIZER \ - NAPI_MODULE_INITIALIZER_X(napi_register_wasm_v, NAPI_MODULE_VERSION) -#define NAPI_MODULE(modname, regfunc) \ - EXTERN_C_START \ - NAPI_MODULE_EXPORT napi_value NAPI_WASM_INITIALIZER(napi_env env, \ - napi_value exports) { \ - return regfunc(env, exports); \ - } \ - EXTERN_C_END +#ifdef __wasm__ +#define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v #else -#define NAPI_MODULE(modname, regfunc) \ - NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage) +#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v #endif -#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v +#define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v #define NAPI_MODULE_INITIALIZER \ NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION) +#define NODE_API_MODULE_GET_API_VERSION \ + NAPI_MODULE_INITIALIZER_X(NODE_API_MODULE_GET_API_VERSION_BASE, \ + NAPI_MODULE_VERSION) + #define NAPI_MODULE_INIT() \ EXTERN_C_START \ + NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION(void) { \ + return NAPI_VERSION; \ + } \ NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \ napi_value exports); \ EXTERN_C_END \ - NAPI_MODULE(NODE_GYP_MODULE_NAME, NAPI_MODULE_INITIALIZER) \ napi_value NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports) +#define NAPI_MODULE(modname, regfunc) \ + NAPI_MODULE_INIT() { return regfunc(env, exports); } + +// Deprecated. Use NAPI_MODULE. +#define NAPI_MODULE_X(modname, regfunc, priv, flags) \ + NAPI_MODULE(modname, regfunc) + EXTERN_C_START -NAPI_EXTERN void NAPI_CDECL napi_module_register(napi_module* mod); +// Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE +// and NAPI_MODULE_INIT macros. +#if defined(__cplusplus) && __cplusplus >= 201402L +[[deprecated]] +#endif +NAPI_EXTERN void NAPI_CDECL +napi_module_register(napi_module* mod); NAPI_EXTERN NAPI_NO_RETURN void NAPI_CDECL napi_fatal_error(const char* location, @@ -175,7 +148,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env, void** data, size_t* length); -#ifndef __wasm32__ // Methods to manage simple async operations NAPI_EXTERN napi_status NAPI_CDECL napi_create_async_work(napi_env env, @@ -191,7 +163,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env, napi_async_work work); NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env, napi_async_work work); -#endif // __wasm32__ // version management NAPI_EXTERN napi_status NAPI_CDECL @@ -229,7 +200,6 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope); #if NAPI_VERSION >= 4 -#ifndef __wasm32__ // Calling into JS from other threads NAPI_EXTERN napi_status NAPI_CDECL napi_create_threadsafe_function(napi_env env, @@ -263,7 +233,6 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func); NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func); -#endif // __wasm32__ #endif // NAPI_VERSION >= 4 @@ -280,6 +249,12 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle); #endif // NAPI_VERSION >= 8 +#if NAPI_VERSION >= 9 + +NAPI_EXTERN napi_status NAPI_CDECL +node_api_get_module_file_name(napi_env env, const char** result); + +#endif // NAPI_VERSION >= 9 EXTERN_C_END diff --git a/symbols.js b/symbols.js index d8d6af8..855526a 100644 --- a/symbols.js +++ b/symbols.js @@ -215,6 +215,19 @@ const v8 = { ] } +const v9 = { + js_native_api_symbols: [ + ...v8.js_native_api_symbols, + 'node_api_create_syntax_error', + 'node_api_symbol_for', + 'node_api_throw_syntax_error' + ], + node_api_symbols: [ + ...v8.node_api_symbols, + 'node_api_get_module_file_name' + ] +} + module.exports = { v1, v2, @@ -223,5 +236,6 @@ module.exports = { v5, v6, v7, - v8 + v8, + v9 }