Permalink
Browse files

util: use `[Array]` for deeply nested arrays

Prefer `[Array]` over `[Object]` because the latter is confusing.

PR-URL: #12046
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information...
addaleax authored and jasnell committed Mar 26, 2017
1 parent cd4ddfd commit 4a5a9445b542333ac7cd8e3ea39ac784a16ccd97
Showing with 10 additions and 6 deletions.
  1. +2 −0 lib/util.js
  2. +6 −6 test/parallel/test-util-inspect-proxy.js
  3. +2 −0 test/parallel/test-util-inspect.js
View
@@ -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');
}
@@ -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);
@@ -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 }'

0 comments on commit 4a5a944

Please sign in to comment.