summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-04-02 07:59:44 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2019-04-15 17:30:52 +0200
commit90e958aa4d225ff1174abea3547da9f7581e0b72 (patch)
tree36ea60ff6b2c4bd2e5e315b0ce91e013607bc421
parent1940114ac323695c758f21a00394b958a68d8428 (diff)
downloadandroid-node-v8-90e958aa4d225ff1174abea3547da9f7581e0b72.tar.gz
android-node-v8-90e958aa4d225ff1174abea3547da9f7581e0b72.tar.bz2
android-node-v8-90e958aa4d225ff1174abea3547da9f7581e0b72.zip
util: only sort weak entries once
This makes sure weak entries are only sorted once, while using the sorted option. PR-URL: https://github.com/nodejs/node/pull/27052 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/internal/util/inspect.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 08f627db88..db54e232aa 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1200,9 +1200,10 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
output[i] = formatValue(ctx, entries[i], recurseTimes);
}
ctx.indentationLvl -= 2;
- if (state === kWeak) {
+ if (state === kWeak && !ctx.sorted) {
// Sort all entries to have a halfway reliable output (if more entries than
- // retrieved ones exist, we can not reliably return the same output).
+ // retrieved ones exist, we can not reliably return the same output) if the
+ // output is not sorted anyway.
output = output.sort();
}
const remaining = entries.length - maxLength;
@@ -1227,9 +1228,11 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
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).
- output = output.sort();
+ // Sort all entries to have a halfway reliable output (if more entries than
+ // retrieved ones exist, we can not reliably return the same output) if the
+ // output is not sorted anyway.
+ if (!ctx.sorted)
+ output = output.sort();
} else {
for (; i < maxLength; i++) {
const pos = i * 2;