util: fix map entries inspection · nodejs/node@1aa6e99 (original) (raw)

Original file line number Diff line number Diff line change
@@ -1156,27 +1156,28 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1156 1156 const remaining = len - maxArrayLength;
1157 1157 const maxLength = Math.min(maxArrayLength, len);
1158 1158 let output = new Array(maxLength);
1159 -let start = '';
1160 -let end = '';
1161 -let middle = ' => ';
1162 1159 let i = 0;
1163 -if (state === kMapEntries) {
1164 -start = '[ ';
1165 -end = ' ]';
1166 -middle = ', ';
1167 -}
1168 1160 ctx.indentationLvl += 2;
1169 -for (; i < maxLength; i++) {
1170 -const pos = i * 2;
1171 -output[i] = `${start}${formatValue(ctx, entries[pos], recurseTimes)}` +
1172 -`${middle}${formatValue(ctx, entries[pos + 1], recurseTimes)}${end}`;
1173 -}
1174 -ctx.indentationLvl -= 2;
1175 1161 if (state === kWeak) {
1162 +for (; i < maxLength; i++) {
1163 +const pos = i * 2;
1164 +output[i] = `${formatValue(ctx, entries[pos], recurseTimes)}` +
1165 +` => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
1166 +}
1176 1167 // Sort all entries to have a halfway reliable output (if more entries
1177 1168 // than retrieved ones exist, we can not reliably return the same output).
1178 1169 output = output.sort();
1170 +} else {
1171 +for (; i < maxLength; i++) {
1172 +const pos = i * 2;
1173 +const res = [
1174 +formatValue(ctx, entries[pos], recurseTimes),
1175 +formatValue(ctx, entries[pos + 1], recurseTimes)
1176 +];
1177 +output[i] = reduceToSingleString(ctx, res, '', ['[', ']']);
1178 +}
1179 1179 }
1180 +ctx.indentationLvl -= 2;
1180 1181 if (remaining > 0) {
1181 1182 output.push(`... remainingmoreitem{remaining} more itemremainingmoreitem{remaining > 1 ? 's' : ''}`);
1182 1183 }