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 node@7.0.0, 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: https://github.com/nodejs/node/pull/19813
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
pull/20519/merge
Bryan English 2018-04-04 14:47:08 -07:00 committed by Ruben Bridgewater
parent 8444bba0af
commit 90e8f79f65
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 3 additions and 0 deletions

View File

@ -32,3 +32,4 @@ Object.assign(exports,
constants.os.signals,
constants.fs,
constants.crypto);
Object.freeze(exports);

View File

@ -24,3 +24,5 @@ assert.ok(binding.crypto);
}
});
});
assert.ok(Object.isFrozen(constants));