GeezerVison is showing github.com — process: make process.config read only · nodejs/node@e0ab8dd
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/deprecations.md +4-1Lines changed: 4 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2889,12 +2889,15 @@ Prefer [`message.socket`][] over [`message.connection`][]. | 2889 | 2889 |
| 2890 | 2890 | <!-- YAML | 2891 | 2891 | changes: | | 2892 | + - version: REPLACEME | | 2893 | + pr-url: https://github.com/nodejs/node/pull/43627 | | 2894 | + description: End-of-Life. | 2892 | 2895 | - version: v16.0.0 | 2893 | 2896 | pr-url: https://github.com/nodejs/node/pull/36902 | 2894 | 2897 | description: Runtime deprecation. | 2895 | 2898 | --> | 2896 | 2899 |
| 2897 | | -Type: Runtime | | 2900 | +Type: End-of-Life | 2898 | 2901 |
| 2899 | 2902 | The `process.config` property provides access to Node.js compile-time settings. | 2900 | 2903 | However, the property is mutable and therefore subject to tampering. The ability | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/process.md +7-12Lines changed: 7 additions & 12 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1041,17 +1041,20 @@ This feature is not available in [`Worker`][] threads. | 1041 | 1041 | <!-- YAML | 1042 | 1042 | added: v0.7.7 | 1043 | 1043 | changes: | | 1044 | + - version: REPLACEME | | 1045 | + pr-url: https://github.com/nodejs/node/pull/43627 | | 1046 | + description: The `process.config` object is now frozen. | 1044 | 1047 | - version: v16.0.0 | 1045 | 1048 | pr-url: https://github.com/nodejs/node/pull/36902 | 1046 | 1049 | description: Modifying process.config has been deprecated. | 1047 | 1050 | --> | 1048 | 1051 |
| 1049 | 1052 | * {Object} | 1050 | 1053 |
| 1051 | | -The `process.config` property returns an `Object` containing the JavaScript | 1052 | | -representation of the configure options used to compile the current Node.js | 1053 | | -executable. This is the same as the `config.gypi` file that was produced when | 1054 | | -running the `./configure` script. | | 1054 | +The `process.config` property returns a frozen `Object` containing the | | 1055 | +JavaScript representation of the configure options used to compile the current | | 1056 | +Node.js executable. This is the same as the `config.gypi` file that was produced | | 1057 | +when running the `./configure` script. | 1055 | 1058 |
| 1056 | 1059 | An example of the possible output looks like: | 1057 | 1060 |
| @@ -1084,14 +1087,6 @@ An example of the possible output looks like: | 1084 | 1087 | } | 1085 | 1088 | ``` | 1086 | 1089 |
| 1087 | | -The `process.config` property is **not** read-only and there are existing | 1088 | | -modules in the ecosystem that are known to extend, modify, or entirely replace | 1089 | | -the value of `process.config`. | 1090 | | - | 1091 | | -Modifying the `process.config` property, or any child-property of the | 1092 | | -`process.config` object has been deprecated. The `process.config` will be made | 1093 | | -read-only in a future release. | 1094 | | - | 1095 | 1090 | ## `process.connected` | 1096 | 1091 |
| 1097 | 1092 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +8-67Lines changed: 8 additions & 67 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,10 +46,8 @@ const { | 46 | 46 | JSONParse, | 47 | 47 | ObjectDefineProperty, | 48 | 48 | ObjectGetPrototypeOf, | 49 | | - ObjectPreventExtensions, | 50 | 49 | ObjectSetPrototypeOf, | 51 | | - ReflectGet, | 52 | | - ReflectSet, | | 50 | + ObjectFreeze, | 53 | 51 | SymbolToStringTag, | 54 | 52 | globalThis, | 55 | 53 | } = primordials; | @@ -91,75 +89,18 @@ process._exiting = false; | 91 | 89 | // process.config is serialized config.gypi | 92 | 90 | const nativeModule = internalBinding('builtins'); | 93 | 91 |
| 94 | | -// TODO(@jasnell): Once this has gone through one full major | 95 | | -// release cycle, remove the Proxy and setter and update the | 96 | | -// getter to either return a read-only object or always return | 97 | | -// a freshly parsed version of nativeModule.config. | 98 | | - | 99 | | -const deprecationHandler = { | 100 | | - warned: false, | 101 | | - message: 'Setting process.config is deprecated. ' + | 102 | | - 'In the future the property will be read-only.', | 103 | | - code: 'DEP0150', | 104 | | - maybeWarn() { | 105 | | - if (!this.warned) { | 106 | | - process.emitWarning(this.message, { | 107 | | - type: 'DeprecationWarning', | 108 | | - code: this.code | 109 | | - }); | 110 | | - this.warned = true; | 111 | | - } | 112 | | - }, | 113 | | - | 114 | | - defineProperty(target, key, descriptor) { | 115 | | - this.maybeWarn(); | 116 | | - return ObjectDefineProperty(target, key, descriptor); | 117 | | - }, | 118 | | - | 119 | | - deleteProperty(target, key) { | 120 | | - this.maybeWarn(); | 121 | | - delete target[key]; | 122 | | - }, | 123 | | - | 124 | | - preventExtensions(target) { | 125 | | - this.maybeWarn(); | 126 | | - return ObjectPreventExtensions(target); | 127 | | - }, | 128 | | - | 129 | | - set(target, key, value) { | 130 | | - this.maybeWarn(); | 131 | | - return ReflectSet(target, key, value); | 132 | | - }, | 133 | | - | 134 | | - get(target, key, receiver) { | 135 | | - const val = ReflectGet(target, key, receiver); | 136 | | - if (val != null && typeof val === 'object') { | 137 | | - // eslint-disable-next-line node-core/prefer-primordials | 138 | | - return new Proxy(val, deprecationHandler); | 139 | | - } | 140 | | - return val; | 141 | | - }, | 142 | | - | 143 | | - setPrototypeOf(target, proto) { | 144 | | - this.maybeWarn(); | 145 | | - return ObjectSetPrototypeOf(target, proto); | 146 | | - } | 147 | | -}; | 148 | | - | 149 | | -// eslint-disable-next-line node-core/prefer-primordials | 150 | | -let processConfig = new Proxy( | 151 | | - JSONParse(nativeModule.config), | 152 | | - deprecationHandler); | | 92 | +const processConfig = JSONParse(nativeModule.config, (_key, value) => { | | 93 | + // The `reviver` argument of the JSONParse method will visit all the values of | | 94 | + // the parsed config, including the "root" object, so there is no need to | | 95 | + // explicitly freeze the config outside of this method | | 96 | + return ObjectFreeze(value); | | 97 | +}); | 153 | 98 |
| 154 | 99 | ObjectDefineProperty(process, 'config', { | 155 | 100 | __proto__: null, | 156 | 101 | enumerable: true, | 157 | 102 | configurable: true, | 158 | | - get() { return processConfig; }, | 159 | | - set(value) { | 160 | | - deprecationHandler.maybeWarn(); | 161 | | - processConfig = value; | 162 | | - } | | 103 | + value: processConfig, | 163 | 104 | }); | 164 | 105 |
| 165 | 106 | require('internal/worker/js_transferable').setup(); | |
Collapse file Copy file name to clipboardExpand all lines: test/abort/test-abort-fatal-error.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,7 @@ const assert = require('assert'); | 28 | 28 | const exec = require('child_process').exec; | 29 | 29 |
| 30 | 30 | let cmdline = `ulimit -c 0; ${process.execPath}`; | 31 | | -cmdline += ' --max-old-space-size=4 --max-semi-space-size=1'; | | 31 | +cmdline += ' --max-old-space-size=16 --max-semi-space-size=4'; | 32 | 32 | cmdline += ' -e "a = []; for (i = 0; i < 1e9; i++) { a.push({}) }"'; | 33 | 33 |
| 34 | 34 | exec(cmdline, function(err, stdout, stderr) { | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/overwrite-config-preload-module.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const common = require('../common'); | 3 | 3 | common.skipIfInspectorDisabled(); | 4 | 4 |
| | 5 | +delete process.config; | 5 | 6 | process.config = {}; |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-process-config.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,6 +36,9 @@ assert(Object.hasOwn(process, 'config')); | 36 | 36 | // Ensure that `process.config` is an Object. | 37 | 37 | assert.strictEqual(Object(process.config), process.config); | 38 | 38 |
| | 39 | +// Ensure that you can't change config values | | 40 | +assert.throws(() => { process.config.variables = 42; }, TypeError); | | 41 | + | 39 | 42 | const configPath = path.resolve(__dirname, '..', '..', 'config.gypi'); | 40 | 43 |
| 41 | 44 | if (!fs.existsSync(configPath)) { | |
|