Skip to content

Commit

Permalink
lib: simplify the readonly properties of icu
Browse files Browse the repository at this point in the history
Call Object.defineProperty() twice to set readonly property is
unnecessary.

PR-URL: #13221
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
JacksonTian authored and MylesBorins committed Sep 12, 2017
1 parent 87e44d8 commit 605d625
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 3 additions & 18 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 605d625

Please sign in to comment.