From c90d878cf56eeaa324719674490326f6a1a75f2d Mon Sep 17 00:00:00 2001 From: Miodrag Obradovic Date: Wed, 30 Sep 2026 20:59:50 +0200 Subject: [PATCH] util: fix inspect indentation of detached DataView formatExtraProperties() raised ctx.indentationLvl before reading the property. The getters of a detached DataView throw, so the level was never lowered again, and the DataView and everything inspected after it in the same call ended up indented too far. Read the value first. Signed-off-by: Miodrag Obradovic Assisted-by: a closed-source coding agent --- lib/internal/util/inspect.js | 5 ++++- test/parallel/test-util-inspect.js | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index cf0a8892f8f4..622dab4eae8a 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -2545,8 +2545,11 @@ function formatPromise(ctx, value, recurseTimes) { } function formatExtraProperties(ctx, value, recurseTimes, key, typedArray) { + // Read the value before indenting: the getter throws for a detached + // DataView, and formatRaw() then retries with a fallback value. + const extraValue = value[key]; ctx.indentationLvl += 2; - const str = formatValue(ctx, value[key], recurseTimes, typedArray); + const str = formatValue(ctx, extraValue, recurseTimes, typedArray); ctx.indentationLvl -= 2; // These entries are mainly getters. Should they be formatted like getters? diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 3fc17bc6ae91..4e26661a4b49 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -217,10 +217,10 @@ assert.doesNotMatch( assert.strictEqual( util.inspect(dv), 'DataView {\n' + - ' [byteLength]: 0,\n' + - ' [byteOffset]: undefined,\n' + - ' [buffer]: ArrayBuffer { (detached), [byteLength]: 0 }\n' + - ' }', + ' [byteLength]: 0,\n' + + ' [byteOffset]: undefined,\n' + + ' [buffer]: ArrayBuffer { (detached), [byteLength]: 0 }\n' + + '}', ); }