Skip to content

refactor defineProperty usage #28967

Closed
Closed

Description

@ronag

I've noticed that there is a lot of strange usage of `defineProperty" through the code base with slightly inconsistent options/configurations.

I don't mind helping out with this but I would need some help understanding the rules/thoughts behind some of these.

Furthermore if any of them need special configuration we should probably add tests for those...

Activity

  1. ronag commented on Aug 5, 2019

    @ronag
    MemberAuthor
  2. changed the title [-]refactor defineProperty[/-] [+]refactor defineProperty usage[/+] on Aug 5, 2019
  3. bnoordhuis commented on Aug 6, 2019

    @bnoordhuis
    Member

    Happy to provide input but can you phrase it as closed questions? ^^

  4. ronag commented on Aug 6, 2019

    @ronag
    MemberAuthor

    Happy to provide input but can you phrase it as closed questions? ^^

    Sorry, I don't understand?

  5. bnoordhuis commented on Aug 6, 2019

    @bnoordhuis
    Member

    Can you point to examples and explain what's unclear? The way your OP is phrased makes it kind of hard now to know where to start.

  6. ronag commented on Aug 8, 2019

    @ronag
    MemberAuthor

    https://github.com/nodejs/node/search?q=defineProperty%28+-path%3Adeps+-path%3Atest&unscoped_q=defineProperty%28+-path%3Adeps+-path%3Atest

    In particular the configuration of enumerable and configurable is unclear.

    http seems to like to set enumerable: true and configurable: true with no defined reasoning: https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L552

    Likewise buffer seems to have some extra configuration that seems unclear: https://github.com/nodejs/node/blob/master/lib/buffer.js

  7. bnoordhuis commented on Aug 9, 2019

    @bnoordhuis
    Member

    I think most of those can be explained by the words "backwards compatibility."

    E.g. buffer.parent used to be an enumerable data property, now it's a getter. It makes no sense to redefine it (it'd be unsafe), hence it's non-configurable.

    I don't know why outgoing.headersSent is configurable but it's probably for compatibility. It's enumerable because it was enumerable when it was still a simple data property.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions