Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: attach data with napi_add_finalizer #577

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ static inline napi_status AttachData(napi_env env,
FreeType* data,
napi_finalize finalizer = nullptr,
void* hint = nullptr) {
napi_status status;
if (finalizer == nullptr) {
finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
delete static_cast<FreeType*>(data);
};
}
#if (NAPI_VERSION < 5)
napi_value symbol, external;
napi_status status = napi_create_symbol(env, nullptr, &symbol);
status = napi_create_symbol(env, nullptr, &symbol);
if (status == napi_ok) {
if (finalizer == nullptr) {
finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
delete static_cast<FreeType*>(data);
};
}
status = napi_create_external(env,
data,
finalizer,
Expand All @@ -54,6 +56,9 @@ static inline napi_status AttachData(napi_env env,
status = napi_define_properties(env, obj, 1, &desc);
}
}
#else // NAPI_VERSION >= 5
status = napi_add_finalizer(env, obj, data, finalizer, hint, nullptr);
#endif
return status;
}

Expand Down