Skip to content

Consider "new.target" for constructor callbacks #200

Closed

Description

@jasongin

Reference nodejs/node#11975 (comment), nodejs/node#9293, nodejs/node#10915

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.

Activity

  1. changed the title [-]Consider "new target" for constructor callbacks[/-] [+]Consider "new.target" for constructor callbacks[/+] on Mar 27, 2017
  2. boingoing commented on Mar 27, 2017

    @boingoing

    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.

  3. jasongin commented on Mar 27, 2017

    @jasongin
    MemberAuthor

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

  4. boingoing commented on Mar 28, 2017

    @boingoing

    Maybe it could be combined with napi_is_construct_call() into a napi_get_cb_construct_info() or something like that.

    This sounds like a good plan to me. Only constructors would be interested in this flag or new.target generally.

  5. jasongin commented on Aug 1, 2017

    @jasongin
    MemberAuthor

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

  6. mhdawson commented on Aug 3, 2017

    @mhdawson
    Member

    That makes sense to me.

  7. sampsongao commented on Aug 8, 2017

    @sampsongao
    Collaborator
  8. mhdawson commented on Nov 15, 2021

    @mhdawson
    Member

    Looks like related PR landed, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions