diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index a351edc023c562..485c242dce23eb 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -267,7 +267,7 @@ class RefBase : protected Finalizer, RefTracker { protected: inline void Finalize(bool is_env_teardown = false) override { if (_finalize_callback != nullptr) { - _env->CallIntoModuleThrow([&](napi_env env) { + _env->CallIntoModule([&](napi_env env) { _finalize_callback( env, _finalize_data, @@ -508,7 +508,7 @@ class CallbackWrapperBase : public CallbackWrapper { napi_callback cb = _bundle->*FunctionField; napi_value result; - env->CallIntoModuleThrow([&](napi_env env) { + env->CallIntoModule([&](napi_env env) { result = cb(env, cbinfo_wrapper); }); diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 32fc16f155a7fe..9c737f3c9cc9fc 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -82,8 +82,13 @@ struct napi_env__ { return v8::Just(true); } - template - void CallIntoModule(T&& call, U&& handle_exception) { + static inline void + HandleThrow(napi_env env, v8::Local value) { + env->isolate->ThrowException(value); + } + + template + inline void CallIntoModule(T&& call, U&& handle_exception = HandleThrow) { int open_handle_scopes_before = open_handle_scopes; int open_callback_scopes_before = open_callback_scopes; napi_clear_last_error(this); @@ -96,13 +101,6 @@ struct napi_env__ { } } - template - void CallIntoModuleThrow(T&& call) { - CallIntoModule(call, [&](napi_env env, v8::Local value) { - env->isolate->ThrowException(value); - }); - } - v8impl::Persistent last_exception; // We store references in two different lists, depending on whether they have diff --git a/src/node_api.cc b/src/node_api.cc index b87690752b3d9a..fe24eca1b8e2d8 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -57,7 +57,7 @@ class BufferFinalizer : private Finalizer { v8::HandleScope handle_scope(finalizer->_env->isolate); v8::Context::Scope context_scope(finalizer->_env->context()); - finalizer->_env->CallIntoModuleThrow([&](napi_env env) { + finalizer->_env->CallIntoModule([&](napi_env env) { finalizer->_finalize_callback( env, finalizer->_finalize_data, @@ -308,7 +308,7 @@ class ThreadSafeFunction : public node::AsyncResource { v8::Local::New(env->isolate, ref); js_callback = v8impl::JsValueFromV8LocalValue(js_cb); } - env->CallIntoModuleThrow([&](napi_env env) { + env->CallIntoModule([&](napi_env env) { call_js_cb(env, js_callback, context, data); }); } @@ -318,7 +318,7 @@ class ThreadSafeFunction : public node::AsyncResource { v8::HandleScope scope(env->isolate); if (finalize_cb) { CallbackScope cb_scope(this); - env->CallIntoModuleThrow([&](napi_env env) { + env->CallIntoModule([&](napi_env env) { finalize_cb(env, finalize_data, context); }); } @@ -455,7 +455,7 @@ void napi_module_register_by_symbol(v8::Local exports, napi_env env = v8impl::NewEnv(context); napi_value _exports; - env->CallIntoModuleThrow([&](napi_env env) { + env->CallIntoModule([&](napi_env env) { _exports = init(env, v8impl::JsValueFromV8LocalValue(exports)); });