Skip to content

Commit 605d625

Browse files
JacksonTianMylesBorins
authored andcommitted
lib: simplify the readonly properties of icu
Call Object.defineProperty() twice to set readonly property is unnecessary. PR-URL: #13221 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 87e44d8 commit 605d625

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

lib/internal/bootstrap_node.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -395,28 +395,13 @@
395395
// of possible types.
396396
const versionTypes = icu.getVersion().split(',');
397397

398-
function makeGetter(name) {
399-
return () => {
400-
// With an argument, getVersion(type) returns
401-
// the actual version string.
402-
const version = icu.getVersion(name);
403-
// Replace the current getter with a new property.
404-
delete process.versions[name];
405-
Object.defineProperty(process.versions, name, {
406-
value: version,
407-
writable: false,
408-
enumerable: true
409-
});
410-
return version;
411-
};
412-
}
413-
414398
for (var n = 0; n < versionTypes.length; n++) {
415399
var name = versionTypes[n];
400+
const version = icu.getVersion(name);
416401
Object.defineProperty(process.versions, name, {
417-
configurable: true,
402+
writable: false,
418403
enumerable: true,
419-
get: makeGetter(name)
404+
value: version
420405
});
421406
}
422407
}

test/parallel/test-process-versions.js

+6
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ assert(commonTemplate.test(process.versions.zlib));
3232
assert(/^\d+\.\d+\.\d+(?:\.\d+)?(?: \(candidate\))?$/
3333
.test(process.versions.v8));
3434
assert(/^\d+$/.test(process.versions.modules));
35+
36+
for (let i = 0; i < expected_keys.length; i++) {
37+
const key = expected_keys[i];
38+
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
39+
assert.strictEqual(descriptor.writable, false);
40+
}

0 commit comments

Comments
 (0)