Skip to content

Commit db6a246

Browse files
committed
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 d164d9d commit db6a246

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ function formatValue(ctx, value, recurseTimes) {
666666
formatter = formatMap;
667667
} else if (isTypedArray(value)) {
668668
braces = [`${getPrefix(constructor, tag)}[`, ']'];
669+
if (value.length === 0 && keyLength === 0 && !ctx.showHidden)
670+
return `${braces[0]}]`;
669671
formatter = formatTypedArray;
670672
} else if (isMapIterator(value)) {
671673
braces = [`[${tag}] {`, '}'];

test/parallel/test-fs-read-empty-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ assert.throws(
1313
{
1414
code: 'ERR_INVALID_ARG_VALUE',
1515
message: 'The argument \'buffer\' is empty and cannot be written. ' +
16-
'Received Uint8Array [ ]'
16+
'Received Uint8Array []'
1717
}
1818
);

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)