Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: add missing exception checking #19362

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2801,11 +2801,15 @@ napi_status napi_make_callback(napi_env env,
isolate, v8recv, v8func, argc,
reinterpret_cast<v8::Local<v8::Value>*>(const_cast<napi_value*>(argv)),
*node_async_context);
CHECK_MAYBE_EMPTY(env, callback_result, napi_generic_failure);

if (result != nullptr) {
*result = v8impl::JsValueFromV8LocalValue(
callback_result.ToLocalChecked());
if (try_catch.HasCaught()) {
return napi_set_last_error(env, napi_pending_exception);
} else {
CHECK_MAYBE_EMPTY(env, callback_result, napi_generic_failure);
if (result != nullptr) {
*result = v8impl::JsValueFromV8LocalValue(
callback_result.ToLocalChecked());
}
}

return GET_RETURN_STATUS(env);
Expand Down
15 changes: 14 additions & 1 deletion test/addons-napi/test_make_callback_recurse/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
napi_value recv = args[0];
napi_value func = args[1];

napi_make_callback(env, nullptr /* async_context */,
napi_status status = napi_make_callback(env, nullptr /* async_context */,
recv, func, 0 /* argc */, nullptr /* argv */, nullptr /* result */);

bool isExceptionPending;
NAPI_CALL(env, napi_is_exception_pending(env, &isExceptionPending));
if (isExceptionPending && !(status == napi_pending_exception)) {
// if there is an exception pending we don't expect any
// other error
napi_value pending_error;
status = napi_get_and_clear_last_exception(env, &pending_error);
NAPI_CALL(env,
napi_throw_error((env),
nullptr,
"error when only pending exception expected"));
}

return recv;
}

Expand Down