diff options
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/util.js b/lib/util.js index afd3cae724..5413cc0a33 100644 --- a/lib/util.js +++ b/lib/util.js @@ -981,7 +981,7 @@ function formatMap(ctx, value, recurseTimes, keys) { function formatWeakSet(ctx, value, recurseTimes, keys) { const maxArrayLength = Math.max(ctx.maxArrayLength, 0); - const entries = previewEntries(value).slice(0, maxArrayLength + 1); + const [ entries ] = previewEntries(value).slice(0, maxArrayLength + 1); const maxLength = Math.min(maxArrayLength, entries.length); let output = new Array(maxLength); for (var i = 0; i < maxLength; ++i) @@ -998,14 +998,16 @@ function formatWeakSet(ctx, value, recurseTimes, keys) { function formatWeakMap(ctx, value, recurseTimes, keys) { const maxArrayLength = Math.max(ctx.maxArrayLength, 0); - const entries = previewEntries(value).slice(0, maxArrayLength + 1); - const remainder = entries.length > maxArrayLength; - const len = entries.length - (remainder ? 1 : 0); + const [ entries ] = previewEntries(value).slice(0, (maxArrayLength + 1) * 2); + // Entries exist as [key1, val1, key2, val2, ...] + const remainder = entries.length / 2 > maxArrayLength; + const len = entries.length / 2 - (remainder ? 1 : 0); const maxLength = Math.min(maxArrayLength, len); let output = new Array(maxLength); - for (var i = 0; i < len; i++) { - output[i] = `${formatValue(ctx, entries[i][0], recurseTimes)} => ` + - formatValue(ctx, entries[i][1], recurseTimes); + for (var i = 0; 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 than // retrieved ones exist, we can not reliably return the same output). @@ -1017,9 +1019,19 @@ function formatWeakMap(ctx, value, recurseTimes, keys) { return output; } +function zip2(list) { + const ret = Array(list.length / 2); + for (var i = 0; i < ret.length; ++i) + ret[i] = [list[2 * i], list[2 * i + 1]]; + return ret; +} + function formatCollectionIterator(ctx, value, recurseTimes, keys) { const output = []; - for (const entry of previewEntries(value)) { + var [ entries, isKeyValue ] = previewEntries(value); + if (isKeyValue) + entries = zip2(entries); + for (const entry of entries) { if (ctx.maxArrayLength === output.length) { output.push('... more items'); break; |