Skip to content

Commit

Permalink
node-api: rename internal NAPI_VERSION definition
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jun 20, 2023
1 parent 51ca71c commit e122d27
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 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_MODULE_API_VERSION;
return napi_clear_last_error(env);
}

Expand Down
6 changes: 3 additions & 3 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_MODULE_API_VERSION) " 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_MODULE_API_VERSION &&
module_api_version != NAPI_VERSION_EXPERIMENTAL) {
node::Environment* node_env = node::Environment::GetCurrent(context);
CHECK_NOT_NULL(node_env);
Expand Down Expand Up @@ -673,7 +673,7 @@ 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_MODULE_API_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) {
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_MODULE_API_VERSION);
llhttp =
NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
"."
Expand Down
5 changes: 4 additions & 1 deletion src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@

// 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
// Distinguished from NAPI_VERSION intentionally to avoid re-defining
// NAPI_VERSION unexpectedly when both node_version.h and js_native_api.h are
// included.
#define NODE_API_MODULE_API_VERSION 9

// 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_MODULE_API_VERSION'

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

0 comments on commit e122d27

Please sign in to comment.