util: fix map entries inspection
This makes sure the arrays returned by Map#entries() are handled as any other array instead of just visualizing the entries as array. Therefore options should have an impact on the arrays. PR-URL: https://github.com/nodejs/node/pull/26918 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
f9da55cca2
commit
520b3e63ea
@ -1180,27 +1180,28 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
|
|||||||
const remaining = len - maxArrayLength;
|
const remaining = len - maxArrayLength;
|
||||||
const maxLength = Math.min(maxArrayLength, len);
|
const maxLength = Math.min(maxArrayLength, len);
|
||||||
let output = new Array(maxLength);
|
let output = new Array(maxLength);
|
||||||
let start = '';
|
|
||||||
let end = '';
|
|
||||||
let middle = ' => ';
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
if (state === kMapEntries) {
|
|
||||||
start = '[ ';
|
|
||||||
end = ' ]';
|
|
||||||
middle = ', ';
|
|
||||||
}
|
|
||||||
ctx.indentationLvl += 2;
|
ctx.indentationLvl += 2;
|
||||||
for (; i < maxLength; i++) {
|
|
||||||
const pos = i * 2;
|
|
||||||
output[i] = `${start}${formatValue(ctx, entries[pos], recurseTimes)}` +
|
|
||||||
`${middle}${formatValue(ctx, entries[pos + 1], recurseTimes)}${end}`;
|
|
||||||
}
|
|
||||||
ctx.indentationLvl -= 2;
|
|
||||||
if (state === kWeak) {
|
if (state === kWeak) {
|
||||||
|
for (; i < maxLength; i++) {
|
||||||
|
const pos = i * 2;
|
||||||
|
output[i] = `${formatValue(ctx, entries[pos], recurseTimes)}` +
|
||||||
|
` => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
|
||||||
|
}
|
||||||
// Sort all entries to have a halfway reliable output (if more entries
|
// Sort all entries to have a halfway reliable output (if more entries
|
||||||
// than retrieved ones exist, we can not reliably return the same output).
|
// than retrieved ones exist, we can not reliably return the same output).
|
||||||
output = output.sort();
|
output = output.sort();
|
||||||
|
} else {
|
||||||
|
for (; i < maxLength; i++) {
|
||||||
|
const pos = i * 2;
|
||||||
|
const res = [
|
||||||
|
formatValue(ctx, entries[pos], recurseTimes),
|
||||||
|
formatValue(ctx, entries[pos + 1], recurseTimes)
|
||||||
|
];
|
||||||
|
output[i] = reduceToSingleString(ctx, res, '', ['[', ']']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ctx.indentationLvl -= 2;
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`);
|
output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`);
|
||||||
}
|
}
|
||||||
|
@ -1017,7 +1017,10 @@ if (typeof Symbol !== 'undefined') {
|
|||||||
|
|
||||||
// Test Set iterators.
|
// Test Set iterators.
|
||||||
{
|
{
|
||||||
const aSet = new Set([1, 3]);
|
const aSet = new Set([1]);
|
||||||
|
assert.strictEqual(util.inspect(aSet.entries(), { compact: false }),
|
||||||
|
'[Set Entries] {\n [\n 1,\n 1\n ]\n}');
|
||||||
|
aSet.add(3);
|
||||||
assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }');
|
assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }');
|
||||||
assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }');
|
assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }');
|
||||||
const setEntries = aSet.entries();
|
const setEntries = aSet.entries();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user