You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider "new.target" for constructor callbacks #200
In mixed JS/native inheritance scenarios, it can be necessary to get the "new target" for the constructor, via v8::FunctionCallbackInfo<T>::NewTarget(). In N-API this would be exposed as napi_get_cb_new_target() or something similar.
Should this be added as an optional out parameter to napi_get_cb_info? If we remove the other methods in this family since one method could handle all of their use cases, it seems to make sense. Would make sense to do that together with #196.
@boingoing I don't think it should be added to napi_get_cb_info() because it would be very rarely needed, only by some constructors. Maybe it could be combined with napi_is_construct_call() into a napi_get_cb_construct_info() or something like that.
Actually a callback is a constructor call if and only if a new target is defined. So I think we can just change napi_is_construct_call() to napi_get_new_target().
Activity
[-]Consider "new target" for constructor callbacks[/-][+]Consider "new.target" for constructor callbacks[/+]boingoing commentedon Mar 27, 2017
Should this be added as an optional out parameter to
napi_get_cb_info? If we remove the other methods in this family since one method could handle all of their use cases, it seems to make sense. Would make sense to do that together with #196.jasongin commentedon Mar 27, 2017
@boingoing I don't think it should be added to
napi_get_cb_info()because it would be very rarely needed, only by some constructors. Maybe it could be combined withnapi_is_construct_call()into anapi_get_cb_construct_info()or something like that.boingoing commentedon Mar 28, 2017
This sounds like a good plan to me. Only constructors would be interested in this flag or new.target generally.
jasongin commentedon Aug 1, 2017
Actually a callback is a constructor call if and only if a new target is defined. So I think we can just change
napi_is_construct_call()tonapi_get_new_target().mhdawson commentedon Aug 3, 2017
That makes sense to me.
sampsongao commentedon Aug 8, 2017
nodejs/node#14698
mhdawson commentedon Nov 15, 2021
Looks like related PR landed, closing.