From 5e6940d4f6e59433976dc09979f3c8fb116b4230 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 26 Sep 2018 23:17:26 +0200 Subject: [PATCH] util: set `super_` property to non-enumerable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using `util.inherits()` adds a `super_` property to the constructor and inspecting that constructor is going to show that property even though it's not useful for the user. Therefore the property is now set as non-enumerable and such entries are not visible by default when using `console.log()` or `util.inspect()`. PR-URL: https://github.com/nodejs/node/pull/23107 Reviewed-By: Anna Henningsen Reviewed-By: Jeremiah Senkpiel Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- lib/util.js | 6 +++++- test/parallel/test-util-inherits.js | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index ae2295533df3ef..8eaf62f0abbdd5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -285,7 +285,11 @@ function inherits(ctor, superCtor) { throw new ERR_INVALID_ARG_TYPE('superCtor.prototype', 'Function', superCtor.prototype); } - ctor.super_ = superCtor; + Object.defineProperty(ctor, 'super_', { + value: superCtor, + writable: true, + configurable: true + }); Object.setPrototypeOf(ctor.prototype, superCtor.prototype); } diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index d37cb6bf8b73e4..9bbb4352dc3853 100644 --- a/test/parallel/test-util-inherits.js +++ b/test/parallel/test-util-inherits.js @@ -18,7 +18,15 @@ function B(value) { inherits(B, A); B.prototype.b = function() { return this._b; }; -assert.strictEqual(B.super_, A); +assert.deepStrictEqual( + Object.getOwnPropertyDescriptor(B, 'super_'), + { + value: A, + enumerable: false, + configurable: true, + writable: true + } +); const b = new B('b'); assert.strictEqual(b.a(), 'a');