Skip to content

Commit

Permalink
node-api: create reference only when needed
Browse files Browse the repository at this point in the history
Optimize napi_create_external() to create the reference for calling
finalizer only if user actually provides a finalizer callback.
  • Loading branch information
Flarna committed Sep 30, 2022
1 parent d6c2316 commit 41662d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2387,10 +2387,12 @@ napi_status NAPI_CDECL napi_create_external(napi_env env,

v8::Local<v8::Value> external_value = v8::External::New(isolate, data);

// The Reference object will delete itself after invoking the finalizer
// callback.
v8impl::Reference::New(
env, external_value, 0, true, finalize_cb, data, finalize_hint);
if (finalize_cb) {
// The Reference object will delete itself after invoking the finalizer
// callback.
v8impl::Reference::New(
env, external_value, 0, true, finalize_cb, data, finalize_hint);
}

*result = v8impl::JsValueFromV8LocalValue(external_value);

Expand Down

0 comments on commit 41662d5

Please sign in to comment.