Skip to content

Commit

Permalink
node-api: rename internal NAPI_VERSION definition
Browse files Browse the repository at this point in the history
PR-URL: #48501
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
legendecas authored and mhdawson committed Jun 28, 2023
1 parent 86ba5be commit 6ffacbf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,7 @@ napi_status NAPI_CDECL napi_get_dataview_info(napi_env env,
napi_status NAPI_CDECL napi_get_version(napi_env env, uint32_t* result) {
CHECK_ENV(env);
CHECK_ARG(env, result);
*result = NAPI_VERSION;
*result = NODE_API_SUPPORTED_VERSION_MAX;
return napi_clear_last_error(env);
}

Expand Down
13 changes: 7 additions & 6 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void ThrowNodeApiVersionError(node::Environment* node_env,
error_message += " requires Node-API version ";
error_message += std::to_string(module_api_version);
error_message += ", but this version of Node.js only supports version ";
error_message += NODE_STRINGIFY(NAPI_VERSION) " add-ons.";
error_message += NODE_STRINGIFY(NODE_API_SUPPORTED_VERSION_MAX) " add-ons.";
node_env->ThrowError(error_message.c_str());
}

Expand All @@ -172,7 +172,7 @@ inline napi_env NewEnv(v8::Local<v8::Context> context,
// Validate module_api_version.
if (module_api_version < NODE_API_DEFAULT_MODULE_API_VERSION) {
module_api_version = NODE_API_DEFAULT_MODULE_API_VERSION;
} else if (module_api_version > NAPI_VERSION &&
} else if (module_api_version > NODE_API_SUPPORTED_VERSION_MAX &&
module_api_version != NAPI_VERSION_EXPERIMENTAL) {
node::Environment* node_env = node::Environment::GetCurrent(context);
CHECK_NOT_NULL(node_env);
Expand Down Expand Up @@ -673,15 +673,16 @@ node::addon_context_register_func get_node_api_context_register_func(
const char* module_name,
int32_t module_api_version) {
static_assert(
NAPI_VERSION == 9,
NODE_API_SUPPORTED_VERSION_MAX == 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<NODE_API_DEFAULT_MODULE_API_VERSION>;
} else if (module_api_version == 9) {
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<NAPI_VERSION_EXPERIMENTAL>;
} else if (module_api_version >= NODE_API_SUPPORTED_VERSION_MIN &&
module_api_version <= NODE_API_DEFAULT_MODULE_API_VERSION) {
return node_api_context_register_func<NODE_API_DEFAULT_MODULE_API_VERSION>;
} else {
v8impl::ThrowNodeApiVersionError(node_env, module_name, module_api_version);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Metadata::Versions::Versions() {
ares = ARES_VERSION_STR;
modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
nghttp2 = NGHTTP2_VERSION;
napi = NODE_STRINGIFY(NAPI_VERSION);
napi = NODE_STRINGIFY(NODE_API_SUPPORTED_VERSION_MAX);
llhttp =
NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
"."
Expand Down
7 changes: 4 additions & 3 deletions src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@
*/
#define NODE_MODULE_VERSION 115

// The NAPI_VERSION provided by this version of the runtime. This is the version
// which the Node binary being built supports.
#define NAPI_VERSION 9
// The NAPI_VERSION supported by the runtime. This is the inclusive range of
// versions which the Node.js binary being built supports.
#define NODE_API_SUPPORTED_VERSION_MAX 9
#define NODE_API_SUPPORTED_VERSION_MIN 1

// Node API modules use NAPI_VERSION 8 by default if it is not explicitly
// specified. It must be always 8.
Expand Down
2 changes: 1 addition & 1 deletion tools/getnapibuildversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_napi_version():

f = open(napi_version_h)

regex = '^#define NAPI_VERSION'
regex = '^#define NODE_API_SUPPORTED_VERSION_MAX'

for line in f:
if re.match(regex, line):
Expand Down

0 comments on commit 6ffacbf

Please sign in to comment.