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.

PR-URL: #44827
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Flarna authored Oct 3, 2022
1 parent f4815fc commit ecd5de0
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 ecd5de0

Please sign in to comment.