Skip to content

Commit 44de431

Browse files
Gabriel Schulhoftargos
authored andcommitted
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: #28606 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 5b9c227 commit 44de431

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/node_api.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,9 @@ class ThreadSafeFunction : public node::AsyncResource {
325325
v8::Local<v8::Function>::New(env->isolate, ref);
326326
js_callback = v8impl::JsValueFromV8LocalValue(js_cb);
327327
}
328-
call_js_cb(env,
329-
js_callback,
330-
context,
331-
data);
328+
NapiCallIntoModuleThrow(env, [&]() {
329+
call_js_cb(env, js_callback, context, data);
330+
});
332331
}
333332
}
334333
}
@@ -347,7 +346,9 @@ class ThreadSafeFunction : public node::AsyncResource {
347346
v8::HandleScope scope(env->isolate);
348347
if (finalize_cb) {
349348
CallbackScope cb_scope(this);
350-
finalize_cb(env, finalize_data, context);
349+
NapiCallIntoModuleThrow(env, [&]() {
350+
finalize_cb(env, finalize_data, context);
351+
});
351352
}
352353
EmptyQueueAndDelete();
353354
}

0 commit comments

Comments
 (0)