diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 2f5a4bf83cd9f1..6ff49c65b4f87d 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -684,14 +684,16 @@ napi_status napi_get_last_error_info(napi_env env, CHECK_ENV(env); CHECK_ARG(env, result); - // you must update this assert to reference the last message - // in the napi_status enum each time a new error message is added. + // The value of the constant below must be updated to reference the last + // message in the napi_status enum each time a new error message is added. // We don't have a napi_status_last as this would result in an ABI // change each time a message was added. + const int last_status = napi_date_expected; + static_assert( - NAPI_ARRAYSIZE(error_messages) == napi_date_expected + 1, + NAPI_ARRAYSIZE(error_messages) == last_status + 1, "Count of error messages must match count of error values"); - CHECK_LE(env->last_error.error_code, napi_callback_scope_mismatch); + CHECK_LE(env->last_error.error_code, last_status); // Wait until someone requests the last error information to fetch the error // message string diff --git a/test/js-native-api/test_constructor/test.js b/test/js-native-api/test_constructor/test.js index 21c08f459b0a01..3e4ac1168c6083 100644 --- a/test/js-native-api/test_constructor/test.js +++ b/test/js-native-api/test_constructor/test.js @@ -53,7 +53,7 @@ assert.strictEqual(test_object.staticReadonlyAccessor1, undefined); // Verify that passing NULL to napi_define_class() results in the correct // error. assert.deepStrictEqual(TestConstructor.TestDefineClass(), { - envIsNull: 'napi_ok', + envIsNull: 'napi_env_null_is_ok', nameIsNull: 'Invalid argument', cbIsNull: 'Invalid argument', cbDataIsNull: 'napi_ok', diff --git a/test/js-native-api/test_constructor/test_constructor.c b/test/js-native-api/test_constructor/test_constructor.c index 838918b615954a..2428ac5d14c686 100644 --- a/test/js-native-api/test_constructor/test_constructor.c +++ b/test/js-native-api/test_constructor/test_constructor.c @@ -8,22 +8,25 @@ static void add_named_property(napi_env env, const char* key, napi_value return_ const napi_extended_error_info* p_last_error; NAPI_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error)); - NAPI_CALL(env, napi_create_string_utf8(env, - (p_last_error->error_message == NULL ? - "napi_ok" : - p_last_error->error_message), - NAPI_AUTO_LENGTH, - &prop_value)); - NAPI_CALL(env, napi_set_named_property(env, - return_value, - key, - prop_value)); + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8(env, + (p_last_error->error_message == NULL ? + "napi_ok" : + p_last_error->error_message), + NAPI_AUTO_LENGTH, + &prop_value)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, + return_value, + key, + prop_value)); } static napi_value TestDefineClass(napi_env env, napi_callback_info info) { + napi_value prop_value; napi_value result, return_value; + napi_status status; napi_property_descriptor property_descriptor = { "TestDefineClass", @@ -37,18 +40,26 @@ static napi_value TestDefineClass(napi_env env, NAPI_CALL(env, napi_create_object(env, &return_value)); - napi_define_class(NULL, - "TrackedFunction", - NAPI_AUTO_LENGTH, - TestDefineClass, - NULL, - 1, - &property_descriptor, - &result); - - add_named_property(env, "envIsNull", return_value); - - napi_define_class(env, + status = napi_define_class(NULL, + "TrackedFunction", + NAPI_AUTO_LENGTH, + TestDefineClass, + NULL, + 1, + &property_descriptor, + &result); + + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8(env, + "napi_env_null_is_ok", + NAPI_AUTO_LENGTH, + &prop_value)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, + return_value, + "envIsNull", + prop_value)); + + napi_define_class(env, NULL, NAPI_AUTO_LENGTH, TestDefineClass,