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.
  • Loading branch information
JacksonTian committed Aug 26, 2017
1 parent 99c478e commit 5844b92
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 @@ -440,28 +440,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 5844b92

Please sign in to comment.