lib: simplify the readonly properties of icu
Call Object.defineProperty() twice to set readonly property is unnecessary. PR-URL: https://github.com/nodejs/node/pull/13221 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
c7dda4925d
commit
83a5eef6f2
21
lib/internal/bootstrap_node.js
vendored
21
lib/internal/bootstrap_node.js
vendored
@ -431,28 +431,13 @@
|
||||
// of possible types.
|
||||
const versionTypes = icu.getVersion().split(',');
|
||||
|
||||
function makeGetter(name) {
|
||||
return () => {
|
||||
// With an argument, getVersion(type) returns
|
||||
// the actual version string.
|
||||
const version = icu.getVersion(name);
|
||||
// Replace the current getter with a new property.
|
||||
delete process.versions[name];
|
||||
Object.defineProperty(process.versions, name, {
|
||||
value: version,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
});
|
||||
return version;
|
||||
};
|
||||
}
|
||||
|
||||
for (var n = 0; n < versionTypes.length; n++) {
|
||||
var name = versionTypes[n];
|
||||
const version = icu.getVersion(name);
|
||||
Object.defineProperty(process.versions, name, {
|
||||
configurable: true,
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
get: makeGetter(name)
|
||||
value: version
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -32,3 +32,9 @@ assert(commonTemplate.test(process.versions.zlib));
|
||||
assert(/^\d+\.\d+\.\d+(?:\.\d+)?(?: \(candidate\))?$/
|
||||
.test(process.versions.v8));
|
||||
assert(/^\d+$/.test(process.versions.modules));
|
||||
|
||||
for (let i = 0; i < expected_keys.length; i++) {
|
||||
const key = expected_keys[i];
|
||||
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
|
||||
assert.strictEqual(descriptor.writable, false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user