Skip to content

Commit

Permalink
node-api: handle pending exception in cb wrapper
Browse files Browse the repository at this point in the history
fixes: nodejs/node-addon-api#1025

The functionreference test from the node-api tests
was reporting a failed v8 check when Node.js was compiled
as debug. The failure was because an exception was
pending but the C++ wrappers were returning
a return value that was invalid.

Signed-off-by: Michael Dawson <mdawson@devrus.com>
  • Loading branch information
mhdawson committed Jul 21, 2021
1 parent ad5dc4c commit 77018ed
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,16 @@ class CallbackWrapperBase : public CallbackWrapper {
napi_env env = _bundle->env;
napi_callback cb = _bundle->cb;

napi_value result;
napi_value result = nullptr;
bool exceptionOccurred = false;
env->CallIntoModule([&](napi_env env) {
result = cb(env, cbinfo_wrapper);
}, [&](napi_env env, v8::Local<v8::Value> value) {
exceptionOccurred = true;
env->isolate->ThrowException(value);
});

if (result != nullptr) {
if (!exceptionOccurred && (result != nullptr)) {
this->SetReturnValue(result);
}
}
Expand Down

0 comments on commit 77018ed

Please sign in to comment.