From 605d625e62667cea845393ed5ee50a2102cabc68 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Fri, 26 May 2017 01:38:29 +0800 Subject: [PATCH] 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 Reviewed-By: Daijiro Wachi Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap_node.js | 21 +++------------------ test/parallel/test-process-versions.js | 6 ++++++ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 1d559a2e34b84b..ad579ab2b549fc 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -395,28 +395,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 }); } } diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index e4da5380217e9a..65634ece6ce8e7 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -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); +}