Skip to content

Commit 5e6940d

Browse files
committed
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: #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>
1 parent 6df2c55 commit 5e6940d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/util.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ function inherits(ctor, superCtor) {
285285
throw new ERR_INVALID_ARG_TYPE('superCtor.prototype',
286286
'Function', superCtor.prototype);
287287
}
288-
ctor.super_ = superCtor;
288+
Object.defineProperty(ctor, 'super_', {
289+
value: superCtor,
290+
writable: true,
291+
configurable: true
292+
});
289293
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
290294
}
291295

test/parallel/test-util-inherits.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ function B(value) {
1818
inherits(B, A);
1919
B.prototype.b = function() { return this._b; };
2020

21-
assert.strictEqual(B.super_, A);
21+
assert.deepStrictEqual(
22+
Object.getOwnPropertyDescriptor(B, 'super_'),
23+
{
24+
value: A,
25+
enumerable: false,
26+
configurable: true,
27+
writable: true
28+
}
29+
);
2230

2331
const b = new B('b');
2432
assert.strictEqual(b.a(), 'a');

0 commit comments

Comments
 (0)