Skip to content

Commit 88e8b7c

Browse files
Octavian SoldeaMylesBorins
Octavian Soldea
authored andcommitted
n-api: correct bug in napi_get_last_error
napi_get_last_error returns incorrect napi_status. Backport-PR-URL: #30532 PR-URL: #28702 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 3e0709c commit 88e8b7c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/node_api.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -1407,14 +1407,16 @@ napi_status napi_get_last_error_info(napi_env env,
14071407
CHECK_ENV(env);
14081408
CHECK_ARG(env, result);
14091409

1410-
// you must update this assert to reference the last message
1411-
// in the napi_status enum each time a new error message is added.
1410+
// The value of the constant below must be updated to reference the last
1411+
// message in the `napi_status` enum each time a new error message is added.
14121412
// We don't have a napi_status_last as this would result in an ABI
14131413
// change each time a message was added.
1414+
const int last_status = napi_date_expected;
1415+
14141416
static_assert(
1415-
node::arraysize(error_messages) == napi_date_expected + 1,
1417+
node::arraysize(error_messages) == last_status + 1,
14161418
"Count of error messages must match count of error values");
1417-
CHECK_LE(env->last_error.error_code, napi_callback_scope_mismatch);
1419+
CHECK_LE(env->last_error.error_code, last_status);
14181420

14191421
// Wait until someone requests the last error information to fetch the error
14201422
// message string

src/node_api_types.h

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ typedef enum {
8484
napi_bigint_expected,
8585
napi_date_expected,
8686
} napi_status;
87+
// Note: when adding a new enum value to `napi_status`, please also update
88+
// `const int last_status` in `napi_get_last_error_info()' definition,
89+
// in file js_native_api_v8.cc. Please also update the definition of
90+
// `napi_status` in doc/api/n-api.md to reflect the newly added value(s).
8791

8892
#if NAPI_VERSION >= 4
8993
typedef enum {

0 commit comments

Comments
 (0)