Skip to content

Commit 7f55e00

Browse files
committed
doc: handle pending exception in callback wrapper
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 <[email protected]>
1 parent ad5dc4c commit 7f55e00

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/js_native_api_v8.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,16 @@ class CallbackWrapperBase : public CallbackWrapper {
306306
napi_env env = _bundle->env;
307307
napi_callback cb = _bundle->cb;
308308

309-
napi_value result;
309+
napi_value result = nullptr;
310+
bool exceptionOccurred = false;
310311
env->CallIntoModule([&](napi_env env) {
311312
result = cb(env, cbinfo_wrapper);
313+
}, [&](napi_env env, v8::Local<v8::Value> value) {
314+
exceptionOccurred = true;
315+
env->isolate->ThrowException(value);
312316
});
313317

314-
if (result != nullptr) {
318+
if (!exceptionOccurred && (result != nullptr)) {
315319
this->SetReturnValue(result);
316320
}
317321
}

0 commit comments

Comments
 (0)