diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index d20c7b93c92ceb..4def103f42adeb 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -560,15 +560,6 @@ function formatValue(ctx, value, recurseTimes, typedArray) { return formatRaw(ctx, value, recurseTimes, typedArray); } -function setIteratorBraces(type, tag) { - if (tag !== `${type} Iterator`) { - if (tag !== '') - tag += '] ['; - tag += `${type} Iterator`; - } - return [`[${tag}] {`, '}']; -} - function formatRaw(ctx, value, recurseTimes, typedArray) { let keys; @@ -630,11 +621,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { extrasType = kArrayExtrasType; } else if (isMapIterator(value)) { keys = getKeys(value, ctx.showHidden); - braces = setIteratorBraces('Map', tag); + braces = getIteratorBraces('Map', tag); formatter = formatIterator; } else if (isSetIterator(value)) { keys = getKeys(value, ctx.showHidden); - braces = setIteratorBraces('Set', tag); + braces = getIteratorBraces('Set', tag); formatter = formatIterator; } else { noIterator = true; @@ -754,10 +745,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { } } if (isMapIterator(value)) { - braces = setIteratorBraces('Map', tag); + braces = getIteratorBraces('Map', tag); formatter = formatIterator; } else if (isSetIterator(value)) { - braces = setIteratorBraces('Set', tag); + braces = getIteratorBraces('Set', tag); formatter = formatIterator; // Handle other regular objects again. } else if (keys.length === 0) { @@ -818,6 +809,15 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { return res; } +function getIteratorBraces(type, tag) { + if (tag !== `${type} Iterator`) { + if (tag !== '') + tag += '] ['; + tag += `${type} Iterator`; + } + return [`[${tag}] {`, '}']; +} + function formatError(err, constructor, tag, ctx) { // TODO(BridgeAR): Always show the error code if present. let stack = err.stack || ErrorPrototype.toString(err);