From 98f4a1caf1eaab233a13b30cefd5df912bd28c21 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 27 Sep 2025 21:57:35 +0200 Subject: [PATCH] console,util: improve array inspection performance There is no need to do the own property check, since the descriptor is needed right afterwards anyway. --- lib/internal/util/inspect.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 0cd2bcdfab0028..b95ad2088f5a8a 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -2271,11 +2271,12 @@ function formatArray(ctx, value, recurseTimes) { const remaining = valLen - len; const output = []; for (let i = 0; i < len; i++) { - // Special handle sparse arrays. - if (!ObjectPrototypeHasOwnProperty(value, i)) { + const desc = ObjectGetOwnPropertyDescriptor(value, i); + if (desc === undefined) { + // Special handle sparse arrays. return formatSpecialArray(ctx, value, recurseTimes, len, output, i); } - ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType)); + ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType, desc)); } if (remaining > 0) { ArrayPrototypePush(output, remainingText(remaining));