util: use constructor name
When reaching the depth limit util.inspect always prints [Array] or [Object] no matter if it is a subclass or not. This fixes it by showing the actual constructor name instead. PR-URL: https://github.com/nodejs/node/pull/14886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
4bcb1c3f75
commit
b1c8f15c5f
@ -594,11 +594,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
|
||||
return ctx.stylize('[Circular]', 'special');
|
||||
|
||||
if (recurseTimes != null) {
|
||||
if (recurseTimes < 0) {
|
||||
if (Array.isArray(value))
|
||||
return ctx.stylize('[Array]', 'special');
|
||||
return ctx.stylize('[Object]', 'special');
|
||||
}
|
||||
if (recurseTimes < 0)
|
||||
return ctx.stylize(`[${constructor ? constructor.name : 'Object'}]`,
|
||||
'special');
|
||||
recurseTimes -= 1;
|
||||
}
|
||||
|
||||
|
@ -994,6 +994,10 @@ if (typeof Symbol !== 'undefined') {
|
||||
'MapSubclass { \'foo\' => 42 }');
|
||||
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
|
||||
'PromiseSubclass { <pending> }');
|
||||
assert.strictEqual(
|
||||
util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }),
|
||||
'{ a: { b: [ArraySubclass] } }'
|
||||
);
|
||||
}
|
||||
|
||||
// Empty and circular before depth
|
||||
|
Loading…
x
Reference in New Issue
Block a user