Skip to content

Commit

Permalink
constants: freeze the constants object
Browse files Browse the repository at this point in the history
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: nodejs#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]>
  • Loading branch information
bengl authored and BridgeAR committed May 7, 2018
1 parent 8444bba commit 90e8f79
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Object.assign(exports,
constants.os.signals,
constants.fs,
constants.crypto);
Object.freeze(exports);
2 changes: 2 additions & 0 deletions test/parallel/test-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ assert.ok(binding.crypto);
}
});
});

assert.ok(Object.isFrozen(constants));

0 comments on commit 90e8f79

Please sign in to comment.