From db6a24699abce1eba6760c2c3e31b390ab684410 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 12 Aug 2018 23:35:27 +0200 Subject: [PATCH] util: improve empty typed array inspection They should be aligned with all other empty objects. Therefore the whitespace is removed and they got a fast path for that. PR-URL: https://github.com/nodejs/node/pull/22284 Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Trivikram Kamat Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung --- lib/util.js | 2 ++ test/parallel/test-fs-read-empty-buffer.js | 2 +- test/parallel/test-util-inspect.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 793aa3ca167db2..88a753409c085f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -666,6 +666,8 @@ function formatValue(ctx, value, recurseTimes) { formatter = formatMap; } else if (isTypedArray(value)) { braces = [`${getPrefix(constructor, tag)}[`, ']']; + if (value.length === 0 && keyLength === 0 && !ctx.showHidden) + return `${braces[0]}]`; formatter = formatTypedArray; } else if (isMapIterator(value)) { braces = [`[${tag}] {`, '}']; diff --git a/test/parallel/test-fs-read-empty-buffer.js b/test/parallel/test-fs-read-empty-buffer.js index 281d2675e72730..840e52d60c7a97 100644 --- a/test/parallel/test-fs-read-empty-buffer.js +++ b/test/parallel/test-fs-read-empty-buffer.js @@ -13,6 +13,6 @@ assert.throws( { code: 'ERR_INVALID_ARG_VALUE', message: 'The argument \'buffer\' is empty and cannot be written. ' + - 'Received Uint8Array [ ]' + 'Received Uint8Array []' } ); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index a66beb063af711..3f08e5e6e7100c 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -79,7 +79,8 @@ 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(new Uint8Array(0)), 'Uint8Array [ ]'); +assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array []'); +assert(inspect(new Uint8Array(0), { showHidden: true }).includes('[buffer]')); assert.strictEqual( util.inspect( Object.create(