From 24a96bc6e6d576caba1f1c8603338038099b03b9 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Mon, 8 Jul 2019 23:36:06 -0700 Subject: [PATCH] n-api: make thread-safe-function calls properly Use `NapiCallIntoModuleThrow()` to execute the call into JavaScript and the finalizer for consistency with the rest of the calls into the N-API addon. --- src/node_api.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node_api.cc b/src/node_api.cc index a10664d3e344fe..a9f26e551db03d 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -325,10 +325,9 @@ class ThreadSafeFunction : public node::AsyncResource { v8::Local::New(env->isolate, ref); js_callback = v8impl::JsValueFromV8LocalValue(js_cb); } - call_js_cb(env, - js_callback, - context, - data); + NapiCallIntoModuleThrow(env, [&]() { + call_js_cb(env, js_callback, context, data); + }); } } } @@ -347,7 +346,9 @@ class ThreadSafeFunction : public node::AsyncResource { v8::HandleScope scope(env->isolate); if (finalize_cb) { CallbackScope cb_scope(this); - finalize_cb(env, finalize_data, context); + NapiCallIntoModuleThrow(env, [&]() { + finalize_cb(env, finalize_data, context); + }); } EmptyQueueAndDelete(); }