-
Notifications
You must be signed in to change notification settings - Fork 30k
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
napi: Remove napi_is_construct_call and introduce napi_get_new_target #14698
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Can you also change the documentation?
Also, it would be great if you could try to fit the commit message into 50 characters (starting with n-api:
), otherwise somebody can do that while landing.
src/node_api.cc
Outdated
CHECK_ENV(env); | ||
CHECK_ARG(env, cbinfo); | ||
CHECK_ARG(env, result); | ||
|
||
v8impl::CallbackWrapper* info = | ||
reinterpret_cast<v8impl::CallbackWrapper*>(cbinfo); | ||
reinterpret_cast<v8impl::CallbackWrapper*>(cbinfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This is a bit pedantic but we do use 4-space indentation for statement continuations, this can stay as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typo, will fix it
src/node_api.cc
Outdated
@@ -439,11 +439,13 @@ class CallbackWrapper { | |||
: _this(this_arg), _args_length(args_length), _data(data) {} | |||
|
|||
virtual bool IsConstructCall() = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the IsConstructCall()
methods be deleted?
src/node_api.cc
Outdated
virtual void Args(napi_value* buffer, size_t bufferlength) = 0; | ||
virtual void SetReturnValue(napi_value value) = 0; | ||
|
||
napi_value This() { return _this; } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra blank line. I think the linter will complain anyway.
NAPI_EXTERN napi_status napi_is_construct_call(napi_env env, | ||
napi_callback_info cbinfo, | ||
bool* result); | ||
NAPI_EXTERN napi_status napi_get_new_target(napi_env env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to also update doc\api\n-api.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. Mainly the doc needs updating.
NAPI_CALL(env, napi_is_construct_call(env, info, &is_constructor)); | ||
napi_value new_target; | ||
NAPI_CALL(env, napi_get_new_target(env, info, &new_target)); | ||
bool is_constructor = ( new_target != NULL ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Since this is C++ code use nullptr
doc/api/n-api.md
Outdated
<!-- YAML | ||
added: v8.0.0 | ||
added: v9.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use REPLACEME
instead of a specific version. Whoever does a release will then update it to the correct version. (This will be in some later 8.x release.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's worth it since n-api is still unofficial, but we could also make a function level changelog entry stating that it was renamed.
doc/api/n-api.md
Outdated
<!-- YAML | ||
added: v8.0.0 | ||
added: v9.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's worth it since n-api is still unofficial, but we could also make a function level changelog entry stating that it was renamed.
src/node_api.cc
Outdated
napi_value NewTarget() override { | ||
return v8impl::JsValueFromV8LocalValue(_cbinfo.NewTarget()); | ||
if (_cbinfo.IsConstructCall()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the curly braces on the if-else
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is better to be consistent with the rest of the file.
doc/api/n-api.md
Outdated
This API checks if the the current callback was due to a | ||
consructor call. | ||
This API return the `new.target` of the construct call. If the current | ||
callback is not a constructor call, the result equals to `nulltpr`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace "construct" with "constructor" here and above.
Fix grammar: "This API returns the new.target
" ... "the result is nullptr
."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
AIX is known unrelated issue We are good to land, but I want to make sure we are ready with required changes in wrapper and ported modules before we land. |
For node-sass: sampsongao/node-sass@9338267 |
@mhdawson are you going to check for the required changes? If so, would you mind assigning yourself to the PR? |
Ping @mhdawson |
Assigned to myself, will land along with other breaking changes. |
New CI run since its been a while: https://ci.nodejs.org/job/node-test-pull-request/10080/ |
#14697 landed, going to check ci results and land if ok. |
Linux failure looks unrelated, opened #15416 |
ARM failure said this
so believe its unrelated as well, opened nodejs/build#884 |
Landed as 973c12f |
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: #14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: nodejs/node#14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: #14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: nodejs/node#14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: nodejs#14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Remove napi_is_construct_call and introduce napi_get_new_target. Backport-PR-URL: #19447 PR-URL: #14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)