Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <mck097@gmail.com>
Assisted-by: a closed-source coding agent
  • Loading branch information
Kjubikstronk committed Sep 30, 2026
commit c90d878cf56eeaa324719674490326f6a1a75f2d
5 changes: 4 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
'}',
);
}

Expand Down
Loading