diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2019-07-08 23:36:06 -0700 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2019-07-11 00:21:17 -0700 |
commit | f5b40b2ffaac2932f941bda1e456b62ec61eabd1 (patch) | |
tree | 933f1989f540af9ddd78e7c5cff324c8a59503a3 /src/node_api.cc | |
parent | e800f9d68a3d949cd2bcea741638cfa8e42f3461 (diff) | |
download | node-new-f5b40b2ffaac2932f941bda1e456b62ec61eabd1.tar.gz |
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.
PR-URL: https://github.com/nodejs/node/pull/28606
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r-- | src/node_api.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index a10664d3e3..a9f26e551d 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -325,10 +325,9 @@ class ThreadSafeFunction : public node::AsyncResource { v8::Local<v8::Function>::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(); } |