Skip to content
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

refactor defineProperty usage #28967

Closed
ronag opened this issue Aug 5, 2019 · 6 comments
Closed

refactor defineProperty usage #28967

ronag opened this issue Aug 5, 2019 · 6 comments

Comments

@ronag
Copy link
Member

ronag commented Aug 5, 2019

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

@ronag
Copy link
Member Author

ronag commented Aug 5, 2019

#28934 (comment)

@ronag ronag changed the title refactor defineProperty refactor defineProperty usage Aug 5, 2019
@bnoordhuis
Copy link
Member

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

@ronag
Copy link
Member Author

ronag commented Aug 6, 2019

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

Sorry, I don't understand?

@bnoordhuis
Copy link
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.

@ronag
Copy link
Member Author

ronag commented Aug 8, 2019

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

@bnoordhuis
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants