-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
src: add process.binding('config') #6266
Conversation
Uh, that is not ok. We aren't just going to expose an alias on |
Doesn't really seem like an issue to me but very well. Made it internal. PTAL |
@jasnell Should this also contain a change changing our internals to use this? It's not very useful to land something that no-one uses. :) |
Currently in master we only use If/when this lands, I intend to backport it to resolve the existing regressions that have occurred in v5 and v4. |
@@ -60,7 +60,7 @@ function setupConfig(_source) { | |||
.replace(/"/g, '\\"') | |||
.replace(/'/g, '"'); | |||
|
|||
process.config = JSON.parse(config, function(key, value) { | |||
process.config = exports.config = JSON.parse(config, (key, value) => { |
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.
This line doesn't make a copy, process.config
and exports.config
point to the same object.
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.
Yep. Modification is still possible. The problem we're having in userland is with code that does stuff like process.config = {}
, essentially overwriting everything. The userland code that extends the object hasn't been a problem that I can determine. This is an attempt at doing the simplest thing first. If we need to lock it down more, then let's do so.
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.
If we want to be robust against users clobbering the runtime environment, then we shouldn't take half measures; either we guard against it or we don't.
The other obvious option here is to set a rule that we simply should not be depending on this in core code at all. If some bit of code needs to know if a config flag was set on compile time, then some other mechanism should be used to expose (perhaps an |
That's sounds fine. As long as the net effect is the same. |
Would it be considered a breaking change to make or read only? Native modules use |
There are a number of userland modules that either replace |
Ok, so looking it over I can see a couple of possible routes. Here's one that I just stepped through the implementation on:
Thoughts? Other solutions? |
There's never been any stability guarantee for |
@bnoordhuis, @srl295, @trevnorris, @Fishrock123 ... PTAL. Reworked this completely to use the proposed |
@jasnell why underscore? Binding is already private |
To ahem underscore the point? ;) Honestly it's just what I chose in the moment. You're right that it's redundant. |
6f62762
to
b9afcf3
Compare
@vkurchatkin ... updated to remove the underscore! |
@@ -132,6 +132,7 @@ | |||
'src/node_buffer.cc', | |||
'src/node_constants.cc', | |||
'src/node_contextify.cc', | |||
'src/node_config.cc', |
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.
nit: this should go between buffer and constants
Can we put the place we are actually going to use this into this PR? This is kinda pointless without being coupled to it. :) |
@Fishrock123 ... that's a separate issue (#4253 (comment)) that makes much more sense keeping separated. Also, I'd prefer to keep this separate as I intend to backport it to v5 and v4 to address bugs there. |
@@ -60,7 +60,7 @@ function setupConfig(_source) { | |||
.replace(/"/g, '\\"') | |||
.replace(/'/g, '"'); | |||
|
|||
process.config = JSON.parse(config, function(key, value) { | |||
process.config = JSON.parse(config, (key, value) => { |
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.
Unrelated change now.
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.
ah, right +1
PR-URL: nodejs#6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: nodejs#6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: nodejs#6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
@jasnell do we still want to backport this to v4.x? |
Oh right! I'll do that.
|
PR-URL: nodejs#6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: nodejs#6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. PR-URL: #6266 Reviewed-By: Ben Noordhuis <[email protected]>
Checklist
Affected core subsystem(s)
process
Description of change
It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal reference. It's still not read-only but that should be ok.process.config
can and likely will be overwrittenprocess.binding('config')
/cc @Fishrock123 @srl295