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 <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
This commit is contained in:
Ruben Bridgewater 2018-08-12 23:35:27 +02:00
parent d164d9d606
commit db6a24699a
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 5 additions and 2 deletions

View File

@ -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}] {`, '}'];

View File

@ -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 []'
}
);

View File

@ -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(