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

fix(napi): Make napi_wrap work on regular objects #15622

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

190n
Copy link
Contributor

@190n 190n commented Dec 6, 2024

What does this PR do?

Currently, napi_wrap only works on instances of Node-API classes. This PR will make it work on any JavaScript object.

Fixes #15383, which is occurring in @napi-rs/canvas and eventually in more projects because of napi-rs/napi-rs#2348

How did you verify your code works?

Added tests and passes the existing ones.

@robobun
Copy link

robobun commented Dec 6, 2024

@190n, your commit 96e45b4 has some failures in #7911

@190n 190n changed the title Make napi_wrap work on regular objects fix(napi): Make napi_wrap work on regular objects Dec 7, 2024

if (!refPtr) {
return napi_object_expected;
if (!hasNapiWrap(vm, globalObject, jsc_object)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calls getDirect twice. We only need to call it once. Let's call it once.

} else if (auto* val = jsDynamicCast<NapiClass*>(value)) {
ref = val->napiRef;

if (!hasNapiWrap(vm, globalObject, jsc_object)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also calls getDirect twice

} else {
ASSERT(false);
JSValue contents_value = jsc_object->getDirect(vm, propertyName);
RETURN_IF_EXCEPTION(scope, napi_pending_exception);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check for exceptions when using getDirect

@190n 190n marked this pull request as ready for review December 10, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrap finalizer for PromiseRaw failed (@napi-rs/canvas)
3 participants