From c2536adc287d4c9af36ed6f4e79a96a24e214fba 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. PR-URL: https://github.com/nodejs/node/pull/60037 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Jordan Harband --- 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 8b318e1fab..d27b7df778 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -2281,11 +2281,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));