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

n-api: use Maybe version of SetPrototype #13513

Closed
wants to merge 1 commit into from

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Jun 7, 2017

Currently the following two warnings are displayed when compiling:

../src/node_api.cc:1966:12: warning: 'SetPrototype' is deprecated
[-Wdeprecated-declarations]
  wrapper->SetPrototype(proto);
           ^

../src/node_api.cc:1967:8: warning: 'SetPrototype' is deprecated
[-Wdeprecated-declarations]
  obj->SetPrototype(wrapper);

This commit changes these calls to use the Maybe version.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

n-api

Currently the following two warnings are displayed when compiling:
../src/node_api.cc:1966:12: warning: 'SetPrototype' is deprecated
[-Wdeprecated-declarations]
  wrapper->SetPrototype(proto);
           ^

../src/node_api.cc:1967:8: warning: 'SetPrototype' is deprecated
[-Wdeprecated-declarations]
  obj->SetPrototype(wrapper);

This commit changes these calls to use the Maybe<bool> version.
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API. labels Jun 7, 2017
@danbev
Copy link
Contributor Author

danbev commented Jun 7, 2017

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM, assuming it's established that SetPrototype cannot ever return an empty value.

@gibfahn
Copy link
Member

gibfahn commented Jun 7, 2017

cc/ @nodejs/n-api

wrapper->SetPrototype(proto);
obj->SetPrototype(wrapper);
wrapper->SetPrototype(context, proto).ToChecked();
obj->SetPrototype(context, wrapper).ToChecked();
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong to me; not your changes, but the logic itself. What happens when proto->IsNull() is true? What happens when obj is a proxy object?

Copy link
Member

Choose a reason for hiding this comment

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

What happens when proto->IsNull() is true?

That should be fine. If it was correct for the original object to have a null prototype, then it is correct for the object inserted in the prototype chain to have a null prototype.

What happens when obj is a proxy object?

Is it not valid to set the prototype of a proxy object? If V8 doesn't allow it, then the SetPrototype() call will presumably return an empty Maybe, and this code should check for that and return an error status in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasongin Thanks for the details. @bnoordhuis Does this seems reasonable to you too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis If you get a chance could you take a look and see if you think I can land this, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

The point about proxy objects still stand. Since they can intercept (and fail) almost any operation, you have to be prepared for exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see. Let me take a look and come up with a suggestion. Thanks

Copy link
Member

Choose a reason for hiding this comment

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

@danbev Any luck? That warning irritates me more by the day. Happy to take over if you don't have time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis Sorry, I've not had time yet so please take over if you do have time. Thanks

@bnoordhuis bnoordhuis mentioned this pull request Jul 3, 2017
@bnoordhuis
Copy link
Member

#14053 landed, I'll close this.

@bnoordhuis bnoordhuis closed this Jul 6, 2017
@danbev danbev deleted the napi-setprototype-warning branch July 7, 2017 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants