-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib,src: make constants not inherit from Object #10458
lib,src: make constants not inherit from Object #10458
Conversation
lib/fs.js
Outdated
@@ -1004,7 +1004,7 @@ fs.fchmodSync = function(fd, mode) { | |||
return binding.fchmod(fd, modeNum(mode)); | |||
}; | |||
|
|||
if (constants.hasOwnProperty('O_SYMLINK')) { | |||
if ('O_SYMLINK' in constants) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these have a small performance impact, maybe Object.prototype.hasOwnProperty.call
is better for all of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As constants
inherit from null
, will the performance implication still be applicable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance of the in
operator has recently been optimized in V8 (in 5.2).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@targos It's still quite slow though in master (V8 5.4). I recently swapped usage of in
with a simpler undefined
check and saw a ~50% improvement.
@thefourtheye I would just do an undefined
check (constants.O_SYMLINK !== undefined
) instead of in
. It should still work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I changed them to !== undefined
.
What do we gain from this change? |
11a0b88
to
8638f31
Compare
Object.keys(constants.os).sort(), ['UV_UDP_REUSEADDR', 'errno', 'signals'] | ||
); | ||
|
||
// make sure all the constants objects don't inherit from Object.prototype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you capitalize "make" please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
); | ||
|
||
// make sure all the constants objects don't inherit from Object.prototype | ||
const INHERITED_PROPERTIES = Object.getOwnPropertyNames(Object.prototype); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you name this with camelCase please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
8638f31
to
aaf7165
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for a major (if it works, ci)
LGTM |
I'm wondering if a similar semver-major change should not be made to the docs-only deprecated |
@jasnell Do you mean the object returned by |
aaf7165
to
002ce78
Compare
Make sure `constants` object and all the nested objects don't inherit from `Object.prototype` but from `null`.
002ce78
to
3a75d7c
Compare
@thefourtheye ... yes, that's what I'm thinking. We could choose to leave it untouched but for consistency it may make sense |
@jasnell I just tried that and it affects graceful-fs, https://github.com/isaacs/node-graceful-fs/blob/v4.1.11/polyfills.js#L31 :'( |
Boo. Ok, I'd leave it as is then. |
cc @nodejs/ctc as this is a major change. |
Yet another CI Run to BUMP https://ci.nodejs.org/job/node-test-pull-request/6372/ |
@thefourtheye ... this should be good to go! |
@jasnell Thanks :-) I would be comfortable if I get a green CITGM as well, as this is a major change. I'll try to spend sometime this week to fix it. |
CITGM and CI both were good. Landing. |
Make sure `constants` object and all the nested objects don't inherit from `Object.prototype` but from `null`. PR-URL: #10458 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Landed in caf9ae7 |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
lib src test
Description of change
Make sure
constants
object and all the nested objects don't inheritfrom
Object.prototype
but fromnull
.