Skip to content

Commit c90d878

Browse files
committed
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
1 parent d7ea02d commit c90d878

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,8 +2545,11 @@ function formatPromise(ctx, value, recurseTimes) {
25452545
}
25462546

25472547
function formatExtraProperties(ctx, value, recurseTimes, key, typedArray) {
2548+
// Read the value before indenting: the getter throws for a detached
2549+
// DataView, and formatRaw() then retries with a fallback value.
2550+
const extraValue = value[key];
25482551
ctx.indentationLvl += 2;
2549-
const str = formatValue(ctx, value[key], recurseTimes, typedArray);
2552+
const str = formatValue(ctx, extraValue, recurseTimes, typedArray);
25502553
ctx.indentationLvl -= 2;
25512554

25522555
// These entries are mainly getters. Should they be formatted like getters?

‎test/parallel/test-util-inspect.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ assert.doesNotMatch(
217217
assert.strictEqual(
218218
util.inspect(dv),
219219
'DataView {\n' +
220-
' [byteLength]: 0,\n' +
221-
' [byteOffset]: undefined,\n' +
222-
' [buffer]: ArrayBuffer { (detached), [byteLength]: 0 }\n' +
223-
' }',
220+
' [byteLength]: 0,\n' +
221+
' [byteOffset]: undefined,\n' +
222+
' [buffer]: ArrayBuffer { (detached), [byteLength]: 0 }\n' +
223+
'}',
224224
);
225225
}
226226

0 commit comments

Comments
 (0)