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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Ruben Bridgewater authored and Michaël Zasso committed 2025-10-06 16:19:22 +02:00
1 parent d949222043
commit 0bf022d4c0
1 file changed
+4 -3
+4 -3
View File
@@ -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));