From 25051e540236edf81bbf304f4b99f7b9ec1de422 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 24 May 2023 18:04:49 +0800 Subject: [PATCH] node-api: define version 9 --- doc/api/n-api.md | 12 ++++-------- src/js_native_api.h | 12 ++++++------ src/node_api.cc | 4 +++- src/node_api.h | 4 ++-- src/node_version.h | 2 +- test/js-native-api/test_error/test_error.c | 2 +- test/js-native-api/test_general/test.js | 2 +- test/js-native-api/test_properties/test_properties.c | 2 +- test/js-native-api/test_reference/test_reference.c | 2 +- test/node-api/test_general/test_general.c | 2 +- 10 files changed, 21 insertions(+), 23 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index ec8df553562be7..a96b1be67c5889 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1220,10 +1220,9 @@ This API throws a JavaScript `RangeError` with the text provided. added: - v17.2.0 - v16.14.0 +napiVersion: 9 --> -> Stability: 1 - Experimental - ```c NAPI_EXTERN napi_status node_api_throw_syntax_error(napi_env env, const char* code, @@ -1341,10 +1340,9 @@ This API returns a JavaScript `RangeError` with the text provided. added: - v17.2.0 - v16.14.0 +napiVersion: 9 --> -> Stability: 1 - Experimental - ```c NAPI_EXTERN napi_status node_api_create_syntax_error(napi_env env, napi_value code, @@ -2592,10 +2590,9 @@ of the ECMAScript Language Specification. added: - v17.5.0 - v16.15.0 +napiVersion: 9 --> -> Stability: 1 - Experimental - ```c napi_status node_api_symbol_for(napi_env env, const char* utf8description, @@ -6348,10 +6345,9 @@ added: - v15.9.0 - v14.18.0 - v12.22.0 +napiVersion: 9 --> -> Stability: 1 - Experimental - ```c NAPI_EXTERN napi_status node_api_get_module_file_name(napi_env env, const char** result); diff --git a/src/js_native_api.h b/src/js_native_api.h index b72f5980dc0785..8fe93ecb1d1815 100644 --- a/src/js_native_api.h +++ b/src/js_native_api.h @@ -95,13 +95,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); -#ifdef NAPI_EXPERIMENTAL +#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_EXPERIMENTAL +#endif // NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL napi_create_function(napi_env env, const char* utf8name, size_t length, @@ -120,10 +120,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_range_error(napi_env env, napi_value code, napi_value msg, napi_value* result); -#ifdef NAPI_EXPERIMENTAL +#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_EXPERIMENTAL +#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, @@ -378,11 +378,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); -#ifdef NAPI_EXPERIMENTAL +#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_EXPERIMENTAL +#endif // NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL napi_is_error(napi_env env, napi_value value, bool* result); diff --git a/src/node_api.cc b/src/node_api.cc index efe1d09ed8ed0c..7537dc20b2bd82 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -673,11 +673,13 @@ node::addon_context_register_func get_node_api_context_register_func( const char* module_name, int32_t module_api_version) { static_assert( - NAPI_VERSION == 8, + NAPI_VERSION == 9, "New version of Node-API requires adding another else-if statement below " "for the new version and updating this assert condition."); if (module_api_version <= NODE_API_DEFAULT_MODULE_API_VERSION) { return node_api_context_register_func; + } else if (module_api_version == 9) { + return node_api_context_register_func<9>; } else if (module_api_version == NAPI_VERSION_EXPERIMENTAL) { return node_api_context_register_func; } else { diff --git a/src/node_api.h b/src/node_api.h index 4c0356eaccb2fc..03454683c401d4 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -248,12 +248,12 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle); #endif // NAPI_VERSION >= 8 -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL node_api_get_module_file_name(napi_env env, const char** result); -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION >= 9 EXTERN_C_END diff --git a/src/node_version.h b/src/node_version.h index abd90885d054e2..d477f632fd6cf9 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -93,7 +93,7 @@ // The NAPI_VERSION provided by this version of the runtime. This is the version // which the Node binary being built supports. -#define NAPI_VERSION 8 +#define NAPI_VERSION 9 // Node API modules use NAPI_VERSION 8 by default if it is not explicitly // specified. It must be always 8. diff --git a/test/js-native-api/test_error/test_error.c b/test/js-native-api/test_error/test_error.c index 0dea66a51cc3a6..43e98921efadb0 100644 --- a/test/js-native-api/test_error/test_error.c +++ b/test/js-native-api/test_error/test_error.c @@ -1,4 +1,4 @@ -#define NAPI_EXPERIMENTAL +#define NAPI_VERSION 9 #include #include "../common.h" diff --git a/test/js-native-api/test_general/test.js b/test/js-native-api/test_general/test.js index ec5c4fe0ddc86f..9072e734468964 100644 --- a/test/js-native-api/test_general/test.js +++ b/test/js-native-api/test_general/test.js @@ -33,7 +33,7 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject), test_general.testGetPrototype(extendedObject)); // Test version management functions -assert.strictEqual(test_general.testGetVersion(), 8); +assert.strictEqual(test_general.testGetVersion(), 9); [ 123, diff --git a/test/js-native-api/test_properties/test_properties.c b/test/js-native-api/test_properties/test_properties.c index 2c1a513449d214..d822d3628d87fa 100644 --- a/test/js-native-api/test_properties/test_properties.c +++ b/test/js-native-api/test_properties/test_properties.c @@ -1,4 +1,4 @@ -#define NAPI_EXPERIMENTAL +#define NAPI_VERSION 9 #include #include "../common.h" diff --git a/test/js-native-api/test_reference/test_reference.c b/test/js-native-api/test_reference/test_reference.c index e9f3ec7a919542..c17f27021b4215 100644 --- a/test/js-native-api/test_reference/test_reference.c +++ b/test/js-native-api/test_reference/test_reference.c @@ -1,4 +1,4 @@ -#define NAPI_EXPERIMENTAL +#define NAPI_VERSION 9 #include #include #include diff --git a/test/node-api/test_general/test_general.c b/test/node-api/test_general/test_general.c index b8d837d5e45650..ece1f2703b4aec 100644 --- a/test/node-api/test_general/test_general.c +++ b/test/node-api/test_general/test_general.c @@ -1,4 +1,4 @@ -#define NAPI_EXPERIMENTAL +#define NAPI_VERSION 9 // we define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED here to validate that it can // be used as a form of test itself. It is // not related to any of the other tests