diff --git a/lib/util.js b/lib/util.js index 793aa3ca167..88a753409c0 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 281d2675e72..840e52d60c7 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 a66beb063af..3f08e5e6e71 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(