Skip to content

Commit

Permalink
util: improve empty typed array inspection
Browse files Browse the repository at this point in the history
They should be aligned with all other empty objects. Therefore the
whitespace is removed and they got a fast path for that.

PR-URL: #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>
  • Loading branch information
BridgeAR committed Aug 15, 2018
1 parent d164d9d commit db6a246
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}] {`, '}'];
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-empty-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 []'
}
);
3 changes: 2 additions & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit db6a246

Please sign in to comment.