Skip to content

Commit 3dc3a31

Browse files
BridgeARtargos
authored andcommitted
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: #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>
1 parent acfb724 commit 3dc3a31

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ function formatValue(ctx, value, recurseTimes) {
625625
formatter = formatMap;
626626
} else if (isTypedArray(value)) {
627627
braces = [`${getPrefix(constructor, tag)}[`, ']'];
628+
if (value.length === 0 && keyLength === 0 && !ctx.showHidden)
629+
return `${braces[0]}]`;
628630
formatter = formatTypedArray;
629631
} else if (isMapIterator(value)) {
630632
braces = [`[${tag}] {`, '}'];

test/parallel/test-util-inspect.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': 2 } } }, false, 1),
7979
'{ a: { b: [Object] } }');
8080
assert.strictEqual(util.inspect({ 'a': { 'b': ['c'] } }, false, 1),
8181
'{ a: { b: [Array] } }');
82-
assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array [ ]');
82+
assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array []');
83+
assert(inspect(new Uint8Array(0), { showHidden: true }).includes('[buffer]'));
8384
assert.strictEqual(
8485
util.inspect(
8586
Object.create(

0 commit comments

Comments
 (0)