Skip to content

Commit

Permalink
util: use [Array] for deeply nested arrays
Browse files Browse the repository at this point in the history
Prefer `[Array]` over `[Object]` because the latter is confusing.

PR-URL: #12046
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
addaleax authored and jasnell committed Mar 28, 2017
1 parent cd4ddfd commit 4a5a944
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ function formatValue(ctx, value, recurseTimes) {
if (recurseTimes < 0) {
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
} else if (Array.isArray(value)) {
return ctx.stylize('[Array]', 'special');
} else {
return ctx.stylize('[Object]', 'special');
}
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const expected1 = 'Proxy [ {}, {} ]';
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], {} ],' +
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' +
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' +
', Proxy [ Proxy [Object], {} ] ] ]';
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], Proxy [Object]' +
' ],\n Proxy [ Proxy [Object], Proxy [Object] ] ],\n' +
' Proxy [ Proxy [ Proxy [Object], Proxy [Object] ],\n' +
' Proxy [ Proxy [Object], Proxy [Object] ] ] ]';
', Proxy [ Proxy [Array], {} ] ] ]';
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' +
' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
assert.strictEqual(util.inspect(proxy1, opts), expected1);
assert.strictEqual(util.inspect(proxy2, opts), expected2);
assert.strictEqual(util.inspect(proxy3, opts), expected3);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ assert.strictEqual(util.inspect({'a': {'b': { 'c': 2}}}, false, 0),
'{ a: [Object] }');
assert.strictEqual(util.inspect({'a': {'b': { 'c': 2}}}, false, 1),
'{ a: { b: [Object] } }');
assert.strictEqual(util.inspect({'a': {'b': ['c']}}, false, 1),
'{ a: { b: [Array] } }');
assert.strictEqual(util.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
'{ visible: 1 }'
Expand Down

0 comments on commit 4a5a944

Please sign in to comment.