Skip to content

Commit

Permalink
n-api: make thread-safe-function calls properly
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
Gabriel Schulhof authored and targos committed Jul 20, 2019
1 parent 5b9c227 commit 44de431
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 44de431

Please sign in to comment.