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 <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
BridgeAR authored and targos committed Aug 19, 2018
1 parent a1c580f commit 9bfe4c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,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
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 9bfe4c7

Please sign in to comment.