Skip to content

fix(ext/web): mark special properties when inspecting buffers and DataView - #36929

Open
Kjubikstronk wants to merge 1 commit into
denoland:mainfrom
Kjubikstronk:fix-node-util-inspect-special-props
Open

Kjubikstronk wants to merge 1 commit into
denoland:mainfrom
Kjubikstronk:fix-node-util-inspect-special-props

Conversation

@Kjubikstronk

Copy link
Copy Markdown

Node marks the byteLength, byteOffset and buffer entries of ArrayBuffers, SharedArrayBuffers and DataViews with brackets, since they are not own properties (nodejs/node#60131 and nodejs/node#60479). Deno still prints them like regular properties:

import util from "node:util";

console.log(util.inspect(new DataView(new ArrayBuffer(4), 1, 2)));

Node:

DataView {
  [byteLength]: 2,
  [byteOffset]: 1,
  [buffer]: ArrayBuffer { [Uint8Contents]: <00 00 00 00>, [byteLength]: 4 }
}

Deno:

DataView {
  byteLength: 2,
  byteOffset: 1,
  buffer: ArrayBuffer { [Uint8Contents]: <00 00 00 00>, byteLength: 4 }
}

This ports that change to ext/web/console/inspect.rs. The keys are printed as extra entries after the formatter output instead of being added to the property list, and the typed array showHidden entries, which already had brackets, go through the same path now.

It also fixes inspecting a DataView whose buffer was detached. That currently prints [Internal Formatting Error] TypeError: Cannot perform get DataView.prototype.byteLength on a detached or out-of-bounds ArrayBuffer and a stack trace. Like Node, the key is now read from the buffer instead when the getter throws.

Since this is the shared formatter, console.log and Deno.inspect change too. I updated the three affected expectations in tests/unit/console_test.ts and added a test for DataViews, typed arrays with showHidden and the detached case.

One intentional difference: for a detached DataView, Node's formatExtraProperties raises ctx.indentationLvl before the getter throws and never lowers it, so that DataView and everything after it in the same inspect call ends up indented 4 spaces too far. Deno indents it normally. test-util-inspect.js asserts Node's output there (line 217), so if you would rather match it exactly, I can change that.

I compared Deno and Node 24.19 for 23 inputs (ArrayBuffers, SharedArrayBuffers, detached buffers, DataViews with and without own properties, typed arrays with showHidden, colors, depth, maxArrayLength, breakLength and compact). 21 differed before this change. Now only the detached DataView differs, as described above.

With this, #36927 and #36928 applied together, test-util-format.js passes (cargo test --test node_compat -- test-util-format), so it can go into config.jsonc once all three have landed. This PR and #36927 both change one line (the short { [byteLength]: n } form); I will resolve that on whichever lands second.

AI disclosure: this change and this description were written with Claude Code (Anthropic). The Node comparison and the tests mentioned above were run locally.

@CLAassistant

CLAassistant commented Sep 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

NetOpWibby pushed a commit to theende/ende that referenced this pull request Nov 8, 2026
…aView

The byteLength of an ArrayBuffer or SharedArrayBuffer and the
byteLength, byteOffset and buffer of a DataView are prototype getters,
not own properties, but the inspector printed them like own properties.
Print them in brackets, like the typed array entries shown with
showHidden and like Node.js, after the formatter output.

This also fixes inspecting a DataView whose buffer was detached or
shrunk, which printed "[Internal Formatting Error] TypeError: Cannot
perform get DataView.prototype.byteLength on a detached or out-of-bounds
ArrayBuffer": when a getter throws, the key is read from the buffer
instead.

(cherry picked from commit fffc0380d00942d0e87283e34f5be950e5d7028d)

Upstream: denoland/deno#36929

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants