From 4bfc06f6b5aa9278f4ed4b84d462448750c840c4 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 26 Mar 2019 09:15:10 +0100 Subject: [PATCH] util: improve proxy inspection This makes sure the brace is actually handled as any other brace. It was handled differently so far than any other brace and that had an impact on how the output would be formatted. PR-URL: https://github.com/nodejs/node/pull/26919 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- lib/internal/util/inspect.js | 3 +-- test/parallel/test-util-inspect-proxy.js | 18 +++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index dc0a1dcb279ff7..06578cb56ef6a1 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -423,8 +423,7 @@ function formatProxy(ctx, proxy, recurseTimes) { formatValue(ctx, proxy[1], recurseTimes) ]; ctx.indentationLvl -= 2; - const str = reduceToSingleString(ctx, res, '', ['[', ']']); - return `Proxy ${str}`; + return reduceToSingleString(ctx, res, '', ['Proxy [', ']']); } function findTypedConstructor(value) { diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index 9aaa8fb13eeb71..97d2006408acdc 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -49,7 +49,8 @@ assert.strictEqual(handler, details[1]); assert.strictEqual( util.inspect(proxyObj, opts), - 'Proxy [ [ 1, 2, 3 ],\n' + + 'Proxy [\n' + + ' [ 1, 2, 3 ],\n' + ' { getPrototypeOf: [Function: getPrototypeOf],\n' + ' setPrototypeOf: [Function: setPrototypeOf],\n' + ' isExtensible: [Function: isExtensible],\n' + @@ -86,12 +87,15 @@ 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 [Array], {} ],' + - ' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' + - ', 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' + +const expected5 = 'Proxy [\n ' + + 'Proxy [ Proxy [ Proxy [Array], {} ], Proxy [ {}, {} ] ],\n' + + ' Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [Array], {} ] ] ]'; +const expected6 = 'Proxy [\n' + + ' Proxy [\n' + + ' Proxy [ Proxy [Array], Proxy [Array] ],\n' + + ' Proxy [ Proxy [Array], Proxy [Array] ] ],\n' + + ' Proxy [\n' + + ' Proxy [ Proxy [Array], Proxy [Array] ],\n' + ' Proxy [ Proxy [Array], Proxy [Array] ] ] ]'; assert.strictEqual( util.inspect(proxy1, { showProxy: true, depth: null }),