diff options
author | legendecas <legendecas@gmail.com> | 2019-05-21 13:48:35 +0800 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2019-09-20 10:53:13 +0100 |
commit | f8622762e37f6b6881db1b4ce5d4392b9d233e4a (patch) | |
tree | 7111a77707149bb70c5b6535134b80cd9dfa779b /src | |
parent | 4f41e4f471180e9b86c92e51814b9aa7c5fe00dc (diff) | |
download | node-new-f8622762e37f6b6881db1b4ce5d4392b9d233e4a.tar.gz |
n-api: make func argument of napi_create_threadsafe_function optional
PR-URL: https://github.com/nodejs/node/pull/27791
Backport-PR-URL: https://github.com/nodejs/node/pull/28399
Refs: https://github.com/nodejs/node/issues/27592
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_api.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index e892d1e76b..f04a5bbfb9 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -1089,10 +1089,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); } @@ -4168,7 +4172,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); @@ -4176,7 +4179,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(); |