From 4a5a9445b542333ac7cd8e3ea39ac784a16ccd97 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 26 Mar 2017 01:28:23 +0100 Subject: [PATCH] util: use `[Array]` for deeply nested arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer `[Array]` over `[Object]` because the latter is confusing. PR-URL: https://github.com/nodejs/node/pull/12046 Reviewed-By: Evan Lucas Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- lib/util.js | 2 ++ test/parallel/test-util-inspect-proxy.js | 12 ++++++------ test/parallel/test-util-inspect.js | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/util.js b/lib/util.js index 80195c26722a1f..fa750d363be0a7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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'); } diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index a6afc9f9bf9bad..ae6da3a34f8727 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -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); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 45999abcb00644..32e36135efd260 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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 }'