diff --git a/src/node_api.cc b/src/node_api.cc index 63d755e614..7eae848180 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -637,7 +637,8 @@ void napi_clear_last_error() { static_last_error.engine_reserved = nullptr; } -const napi_extended_error_info* napi_get_last_error_info() { +const napi_extended_error_info* napi_get_last_error_info(napi_env env) { + (void)env; static_assert(node::arraysize(error_messages) == napi_status_last, "Count of error messages must match count of error values"); assert(static_last_error.error_code < napi_status_last); diff --git a/src/node_api.h b/src/node_api.h index 61372322a9..1e9b7f21f6 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -100,7 +100,8 @@ EXTERN_C_START NAPI_EXTERN void napi_module_register(napi_module* mod); -NAPI_EXTERN const napi_extended_error_info* napi_get_last_error_info(); +NAPI_EXTERN const napi_extended_error_info* napi_get_last_error_info( + napi_env env); // Getters for defined singletons NAPI_EXTERN napi_status napi_get_undefined(napi_env env, napi_value* result); diff --git a/test/addons-napi/3_callbacks/binding.c b/test/addons-napi/3_callbacks/binding.c index 7e2750a2a9..77da3e343b 100644 --- a/test/addons-napi/3_callbacks/binding.c +++ b/test/addons-napi/3_callbacks/binding.c @@ -1,36 +1,36 @@ #include -#define NAPI_CALL(theCall) \ - if (theCall != napi_ok) { \ - const char* errorMessage = napi_get_last_error_info()->error_message; \ - errorMessage = errorMessage ? errorMessage : "empty error message"; \ - napi_throw_error((env), errorMessage); \ - return; \ +#define NAPI_CALL(env, theCall) \ + if (theCall != napi_ok) { \ + const char* errorMessage = napi_get_last_error_info((env))->error_message; \ + errorMessage = errorMessage ? errorMessage : "empty error message"; \ + napi_throw_error((env), errorMessage); \ + return; \ } void RunCallback(napi_env env, napi_callback_info info) { napi_value args[1]; - NAPI_CALL(napi_get_cb_args(env, info, args, 1)); + NAPI_CALL(env, napi_get_cb_args(env, info, args, 1)); napi_value cb = args[0]; napi_value argv[1]; - NAPI_CALL(napi_create_string_utf8(env, "hello world", -1, argv)); + NAPI_CALL(env, napi_create_string_utf8(env, "hello world", -1, argv)); napi_value global; - NAPI_CALL(napi_get_global(env, &global)); + NAPI_CALL(env, napi_get_global(env, &global)); - NAPI_CALL(napi_call_function(env, global, cb, 1, argv, NULL)); + NAPI_CALL(env, napi_call_function(env, global, cb, 1, argv, NULL)); } void RunCallbackWithRecv(napi_env env, napi_callback_info info) { napi_value args[2]; - NAPI_CALL(napi_get_cb_args(env, info, args, 2)); + NAPI_CALL(env, napi_get_cb_args(env, info, args, 2)); napi_value cb = args[0]; napi_value recv = args[1]; - NAPI_CALL(napi_call_function(env, recv, cb, 0, NULL, NULL)); + NAPI_CALL(env, napi_call_function(env, recv, cb, 0, NULL, NULL)); } #define DECLARE_NAPI_METHOD(name, func) \ diff --git a/test/addons-napi/test_buffer/test_buffer.c b/test/addons-napi/test_buffer/test_buffer.c index d99ab45c42..76a57b2f3a 100644 --- a/test/addons-napi/test_buffer/test_buffer.c +++ b/test/addons-napi/test_buffer/test_buffer.c @@ -10,12 +10,12 @@ return; \ } -#define NAPI_CALL(env, theCall) \ - if (theCall != napi_ok) { \ - const char* errorMessage = napi_get_last_error_info()->error_message; \ - errorMessage = errorMessage ? errorMessage : "empty error message"; \ - napi_throw_error((env), errorMessage); \ - return; \ +#define NAPI_CALL(env, theCall) \ + if (theCall != napi_ok) { \ + const char* errorMessage = napi_get_last_error_info((env))->error_message; \ + errorMessage = errorMessage ? errorMessage : "empty error message"; \ + napi_throw_error((env), errorMessage); \ + return; \ } static const char theText[] = diff --git a/test/addons-napi/test_conversions/test_conversions.c b/test/addons-napi/test_conversions/test_conversions.c index 4902752761..d39ded0531 100644 --- a/test/addons-napi/test_conversions/test_conversions.c +++ b/test/addons-napi/test_conversions/test_conversions.c @@ -1,7 +1,7 @@ #include void ThrowLastError(napi_env env) { - const napi_extended_error_info* error_info = napi_get_last_error_info(); + const napi_extended_error_info* error_info = napi_get_last_error_info(env); if (error_info->error_code != napi_ok) { napi_throw_error(env, error_info->error_message); }