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

napi: Remove napi_is_construct_call and introduce napi_get_new_target #14698

Closed
wants to merge 12 commits into from

Conversation

sampsongao
Copy link

@sampsongao sampsongao commented Aug 8, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

@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 Aug 8, 2017
Copy link
Member

@addaleax addaleax left a 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);
Copy link
Member

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.

Copy link
Author

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;
Copy link
Member

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; }


Copy link
Member

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,
Copy link
Member

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.

Copy link
Member

@jasongin jasongin left a 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 );
Copy link
Contributor

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
Copy link
Member

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.)

Copy link
Contributor

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
Copy link
Contributor

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()) {
Copy link
Contributor

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.

Copy link
Author

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`.
Copy link
Member

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."

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mhdawson
Copy link
Member

@mhdawson
Copy link
Member

AIX is known unrelated issue
ARM was problem in building and unrelated.

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.

@sampsongao
Copy link
Author

For node-sass: sampsongao/node-sass@9338267

@BridgeAR
Copy link
Member

@mhdawson are you going to check for the required changes? If so, would you mind assigning yourself to the PR?

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2017

Ping @mhdawson

@mhdawson
Copy link
Member

Assigned to myself, will land along with other breaking changes.

@mhdawson
Copy link
Member

New CI run since its been a while: https://ci.nodejs.org/job/node-test-pull-request/10080/

@mhdawson
Copy link
Member

#14697 landed, going to check ci results and land if ok.

@mhdawson
Copy link
Member

Linux failure looks unrelated, opened #15416

@mhdawson
Copy link
Member

mhdawson commented Sep 14, 2017

ARM failure said this

ccache: error: x_calloc: Could not allocate 40 bytes

so believe its unrelated as well, opened nodejs/build#884

@mhdawson
Copy link
Member

Landed as 973c12f

@mhdawson mhdawson closed this Sep 14, 2017
mhdawson pushed a commit that referenced this pull request Sep 14, 2017
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>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 17, 2017
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>
jasnell pushed a commit that referenced this pull request Sep 20, 2017
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>
Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
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>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 16, 2018
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>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
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>
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
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

10 participants