Skip to content

Commit 90e8f79

Browse files
benglBridgeAR
authored andcommitted
constants: freeze the constants object
Constants ought to be constant. The primary goal of this commit is to make constants exposed in require('constants') immutable, as they were prior to [email protected], and as the constants exposed on fs.constants, crypto.constants, etc. are. Since this is implemented by using Object.freeze, it also has the side effect of making the entire exports of require('constants') immutable, so no new constants can be defined on the object in userland. PR-URL: #19813 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 8444bba commit 90e8f79

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Diff for: lib/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Object.assign(exports,
3232
constants.os.signals,
3333
constants.fs,
3434
constants.crypto);
35+
Object.freeze(exports);

Diff for: test/parallel/test-constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ assert.ok(binding.crypto);
2424
}
2525
});
2626
});
27+
28+
assert.ok(Object.isFrozen(constants));

0 commit comments

Comments
 (0)