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 <[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]>
1 parent acfb724 commit 3dc3a31

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/util.js

+2
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

+2-1
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)