-
Notifications
You must be signed in to change notification settings - Fork 459
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
Replace napi_is_construct_call with napi_get_new_target #113
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.
LGTM
It might be pretty cheap to just introduce a CallbackInfo::NewTarget()
method and make IsConstructCall()
a small wrapper around it while you’re at it
napi-inl.h
Outdated
napi_status status = napi_is_construct_call(_env, _info, &isConstructCall); | ||
napi_value newTarget; | ||
napi_status status = napi_get_new_target(_env, _info, &newTarget); | ||
bool isConstructCall = (new_target != nullptr); | ||
NAPI_THROW_IF_FAILED(_env, status, false); |
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.
Shouldn’t this line be part of NewTarget()
as well?
By the way, what I had in mind was just replacing IsConstructCall
with
inline bool CallbackInfo::IsConstructCall() const {
return !NewTarget().IsEmpty();
}
2dc38a9
to
0eda0d6
Compare
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 but we need to make sure not to land until the corresponding change goes out in an N-API release.
Landed 458f576 |
For nodejs/node#14698