From 162dde77c29786d8f07dd6d36e2f9c828a320e04 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. --- 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 3336fd8d7fc210..dee46126447e06 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 c11935783f861d..945443d8866a2f 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));