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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
d164d9d606
commit
db6a24699a
@ -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}] {`, '}'];
|
||||
|
@ -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 []'
|
||||
}
|
||||
);
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user