From 0bf022d4c0f9e8f45442aaec3166d594a676e8de 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 3cc551a2839..f2d8c0ee383 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -2029,11 +2029,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));