Skip to content

Normative: make DataView.prototype.{byteLength,byteOffset} not throw when backed by detached buffer - #3972

Open
bakkot wants to merge 1 commit into
tc39:mainfrom
bakkot:dataview-throwyness
Open

bakkot wants to merge 1 commit into
tc39:mainfrom
bakkot:dataview-throwyness

Conversation

@bakkot

@bakkot bakkot commented Sep 9, 2026

Copy link
Copy Markdown
Member

Fixes #2635. This makes these getters on DataViews behave like the corresponding getters on TypedArrays.

Note that these getters will still throw when .call'd on incompatible receivers; this is just about what happens when a real DataView's .byteLength or .byteOffset is invoked after the buffer backing said view has been detached or become out of bounds.

This came up in the context of Web IDL, which has badly needed to rationalize its TypedArray handling for a long time; @MattiasBuelens has been working on that in whatwg/webidl#1529 but encountered this inconsistency, which was surprising and also complicates that side of things (since webIDL normally treats DataViews and TypedArrays very similarly).

@bakkot
bakkot marked this pull request as ready for review September 9, 2026 21:35
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/3972 and as multiple pages at https://tc39.es/ecma262/pr/3972/multipage .

@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text needs consensus This needs committee consensus before it can be eligible to be merged. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Sep 9, 2026
@MattiasBuelens

Copy link
Copy Markdown

Tests are in tc39/test262#5137. These cover the cases of a detached buffer, and of a resizable buffer that is shrunk such that the view becomes out of bounds.

@linusg linusg added has test262 tests and removed needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Sep 18, 2026

@linusg linusg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserves a mention in Annex F.

@bakkot

bakkot commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

This got consensus at the October plenary.

@ljharb ljharb added has consensus This has committee consensus. and removed needs consensus This needs committee consensus before it can be eligible to be merged. labels Oct 9, 2026
@nicolo-ribaudo

Copy link
Copy Markdown
Member

I think this deserves a mention in Annex F.

Does it? It's only turning an error case into a non-error.

@linusg

linusg commented Oct 16, 2026

Copy link
Copy Markdown
Member

Does it? It's only turning an error case into a non-error.

That's the usual guideline for what committee considers web compatible, it still is an incompatibility with a prior edition of ES. Falls under the same category as these:

20.1.2.16: In ECMAScript 2015, if the argument to Object.isExtensible is not an object it is treated as if it was a non-extensible ordinary object with no own properties. In the previous edition, a non-object argument always causes a TypeError to be thrown.

20.1.2.17: In ECMAScript 2015, if the argument to Object.isFrozen is not an object it is treated as if it was a non-extensible ordinary object with no own properties. In the previous edition, a non-object argument always causes a TypeError to be thrown.

20.1.2.18: In ECMAScript 2015, if the argument to Object.isSealed is not an object it is treated as if it was a non-extensible ordinary object with no own properties. In the previous edition, a non-object argument always causes a TypeError to be thrown.

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

has consensus This has committee consensus. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataView byteLength/byteOffset still specified to throw when buffer detached

6 participants