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:
Jackson Tian 2017-05-26 01:38:29 +08:00 committed by Ruben Bridgewater
parent c7dda4925d
commit 83a5eef6f2
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 9 additions and 18 deletions

View File

@ -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
});
}
}

View File

@ -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);
}