Skip to content

Commit 9c6791e

Browse files
Octavian Soldeatargos
Octavian Soldea
authored andcommitted
n-api: correct bug in napi_get_last_error
napi_get_last_error returns incorrect napi_status. PR-URL: #28702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent d630cc0 commit 9c6791e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/js_native_api_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ typedef enum {
8181
napi_bigint_expected,
8282
napi_date_expected,
8383
} napi_status;
84+
// Note: when adding a new enum value to `napi_status`, please also update
85+
// `const int last_status` in `napi_get_last_error_info()' definition,
86+
// in file js_native_api_v8.cc. Please also update the definition of
87+
// `napi_status` in doc/api/n-api.md to reflect the newly added value(s).
8488

8589
typedef napi_value (*napi_callback)(napi_env env,
8690
napi_callback_info info);

src/js_native_api_v8.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,16 @@ napi_status napi_get_last_error_info(napi_env env,
684684
CHECK_ENV(env);
685685
CHECK_ARG(env, result);
686686

687-
// you must update this assert to reference the last message
688-
// in the napi_status enum each time a new error message is added.
687+
// The value of the constant below must be updated to reference the last
688+
// message in the `napi_status` enum each time a new error message is added.
689689
// We don't have a napi_status_last as this would result in an ABI
690690
// change each time a message was added.
691+
const int last_status = napi_date_expected;
692+
691693
static_assert(
692-
NAPI_ARRAYSIZE(error_messages) == napi_date_expected + 1,
694+
NAPI_ARRAYSIZE(error_messages) == last_status + 1,
693695
"Count of error messages must match count of error values");
694-
CHECK_LE(env->last_error.error_code, napi_callback_scope_mismatch);
696+
CHECK_LE(env->last_error.error_code, last_status);
695697

696698
// Wait until someone requests the last error information to fetch the error
697699
// message string

0 commit comments

Comments
 (0)