镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Unused prototype objects from V8 FunctionTemplate initialization #17668

Closed

Description

@TimothyGu
  • Version: all
  • Platform: all
  • Subsystem: src
> typeof process.binding('udp_wrap').UDP.prototype.bind6.prototype
'object'

We don't need these prototypes, and we can get rid of them either through v8::FunctionTemplate::RemovePrototype() or indirectly, by specifying v8::ConstructorBehavior::kThrow when creating the v8::FunctionTemplate.

Activity

  1. added
    c++Issues and PRs that require attention from people who are familiar with C++.
    on Dec 14, 2017
  2. added
    discussIssues opened for discussion and feedback.
    on Dec 25, 2017
  3. removed
    discussIssues opened for discussion and feedback.
    on Mar 11, 2018
  4. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Apr 12, 2018
  5. brandontruggles commented on Apr 12, 2018

    @brandontruggles

    Hello, I'd like to work on this! Any tips on where I should look?

  6. addaleax commented on Apr 14, 2018

    @addaleax
    Member

    @brandonrninefive I think Environment::SetMethod, Environment::SetProtoMethod and Environment::SetTemplateMethod in env-inl.h are the relevant places where this would apply.

  7. brandontruggles commented on Apr 19, 2018

    @brandontruggles

    @addaleax Great! Thank you. I think I've figured out how this works. The udp_wrap binding and its associated prototypes/functions are defined within udp_wrap.cc. From there, I can use RemovePrototype() on FunctionTemplate objects to remove their prototype objects. Furthermore, I can use the Environment methods that you listed above to define methods outside or within prototype objects.

    For clarification regarding this exact issue, am I just getting rid of the last prototype object listed in
    > typeof process.binding('udp_wrap').UDP.prototype.bind6.prototype ?

    Or am getting rid of that prototype and also the prototype object after UDP, and replacing its prototype methods with regular methods defined either by Environment::SetMethod or Environment::SetTemplateMethod?

    I appreciate the help, and please let me know if any of my above conclusions are incorrect.

  8. TimothyGu commented on Apr 20, 2018

    @TimothyGu
    MemberAuthor

    @brandonrninefive My recommendation is that you do not use RemovePrototype(), instead using v8::ConstructorBehavior::kThrow when creating such methods in Environment::SetProtoMethod. (You will need to tweak Environment::NewFunctionTemplate() (decl, impl) to accept a third optional parameter of type v8::ConstructorBehavior, to allow passing this information to V8.) There are several reasons for this:

    • This way, not only udp_wrap's classes are fixed but also other bindings. In the original issue, I only used udp_wrap as an example. The same issue applies to all other bindings.
    • As a bonus, this would make new (process.binding('udp_wrap').UDP.prototype.bind6)() throw. One should never do something like that in the first place, and since process.binding is considered internal API this makes the code more robust.

    With regards to your last question, you are only getting rid of the last prototype. If you look at built-in methods like Number.prototype.toString, you will notice that they don't have a prototype property. That's what we are trying to accomplish here as well.

  9. brandontruggles commented on Apr 25, 2018

    @brandontruggles

    @TimothyGu Thank you for all the tips! I'm working on implementing this now, and I should have a PR ready over the next few days.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Issues and PRs that require attention from people who are familiar with C++.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions