From 7f55e00cde50945b54e11251d73154417c26cd4f Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 20 Jul 2021 21:41:58 -0400 Subject: [PATCH] doc: handle pending exception in callback wrapper fixes: https://github.com/nodejs/node-addon-api/issues/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 --- src/js_native_api_v8.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index fe3d8fbc977c2e..5d18980fc76a7b 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -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 value) { + exceptionOccurred = true; + env->isolate->ThrowException(value); }); - if (result != nullptr) { + if (!exceptionOccurred && (result != nullptr)) { this->SetReturnValue(result); } }