From 90e8f79f652b02a8fdf6f72e273cc81429a9376a Mon Sep 17 00:00:00 2001 From: Bryan English Date: Wed, 4 Apr 2018 14:47:08 -0700 Subject: [PATCH] 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 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Rich Trott Reviewed-By: Gus Caplan Reviewed-By: Ruben Bridgewater Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Matteo Collina --- lib/constants.js | 1 + test/parallel/test-constants.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/constants.js b/lib/constants.js index 3336fd8d7fc..dee46126447 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -32,3 +32,4 @@ Object.assign(exports, constants.os.signals, constants.fs, constants.crypto); +Object.freeze(exports); diff --git a/test/parallel/test-constants.js b/test/parallel/test-constants.js index c11935783f8..945443d8866 100644 --- a/test/parallel/test-constants.js +++ b/test/parallel/test-constants.js @@ -24,3 +24,5 @@ assert.ok(binding.crypto); } }); }); + +assert.ok(Object.isFrozen(constants));