From aadf3a8941b5761affc5ea670466c46ef22eea51 Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Tue, 20 Mar 2018 10:56:09 -0700 Subject: [PATCH] n-api: `napi_make_callback` error handling Updated error handling to return `napi_pending_exception` when the target of the callback call throws. --- src/node_api_jsrt.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node_api_jsrt.cc b/src/node_api_jsrt.cc index c91be5391ce..beabdcabc33 100644 --- a/src/node_api_jsrt.cc +++ b/src/node_api_jsrt.cc @@ -2159,8 +2159,14 @@ napi_status napi_make_callback(napi_env env, node::MakeCallback(isolate, v8recv, v8func, argc, v8argv, *node_async_context); + bool hasException; + CHECK_JSRT(JsHasException(&hasException)); + if (hasException) { + return napi_set_last_error(napi_pending_exception); + } + if (v8result.IsEmpty()) { - return napi_set_last_error(napi_generic_failure); + return napi_set_last_error(napi_generic_failure); } if (result != nullptr) {