util: set super_ property to non-enumerable

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 <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-09-26 23:17:26 +02:00
parent 6df2c556bd
commit 5e6940d4f6
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 14 additions and 2 deletions

View File

@ -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);
}

View File

@ -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');