summaryrefslogtreecommitdiff
path: root/src/node_api.cc
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2019-05-21 13:48:35 +0800
committerRich Trott <rtrott@gmail.com>2019-06-21 20:23:22 -0600
commit5705d7bf6089bb8f8a8887658f7c60de6779491c (patch)
tree89d29082462d4bd9daa1134ca474fb89e615389e /src/node_api.cc
parentab3174ca08dcc4a435d61f4ce43e5bfd8cf23115 (diff)
downloadandroid-node-v8-5705d7bf6089bb8f8a8887658f7c60de6779491c.tar.gz
android-node-v8-5705d7bf6089bb8f8a8887658f7c60de6779491c.tar.bz2
android-node-v8-5705d7bf6089bb8f8a8887658f7c60de6779491c.zip
n-api: make func argument of napi_create_threadsafe_function optional
PR-URL: https://github.com/nodejs/node/pull/27791 Refs: https://github.com/nodejs/node/issues/27592 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r--src/node_api.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index 3aab7a2257..a10664d3e3 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -319,10 +319,14 @@ class ThreadSafeFunction : public node::AsyncResource {
"ERR_NAPI_TSFN_STOP_IDLE_LOOP",
"Failed to stop the idle loop") == napi_ok);
} else {
- v8::Local<v8::Function> js_cb =
+ napi_value js_callback = nullptr;
+ if (!ref.IsEmpty()) {
+ v8::Local<v8::Function> js_cb =
v8::Local<v8::Function>::New(env->isolate, ref);
+ js_callback = v8impl::JsValueFromV8LocalValue(js_cb);
+ }
call_js_cb(env,
- v8impl::JsValueFromV8LocalValue(js_cb),
+ js_callback,
context,
data);
}
@@ -1014,7 +1018,6 @@ napi_create_threadsafe_function(napi_env env,
napi_threadsafe_function_call_js call_js_cb,
napi_threadsafe_function* result) {
CHECK_ENV(env);
- CHECK_ARG(env, func);
CHECK_ARG(env, async_resource_name);
RETURN_STATUS_IF_FALSE(env, initial_thread_count > 0, napi_invalid_arg);
CHECK_ARG(env, result);
@@ -1022,7 +1025,11 @@ napi_create_threadsafe_function(napi_env env,
napi_status status = napi_ok;
v8::Local<v8::Function> v8_func;
- CHECK_TO_FUNCTION(env, v8_func, func);
+ if (func == nullptr) {
+ CHECK_ARG(env, call_js_cb);
+ } else {
+ CHECK_TO_FUNCTION(env, v8_func, func);
+ }
v8::Local<v8::Context> v8_context = env->context();