- From: Kevin Gibbons <notifications@github.com>
- Date: Mon, 05 Jan 2026 16:36:59 -0800
- To: whatwg/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/webidl/pull/1529/review/3628866730@github.com>
@bakkot commented on this pull request.
> + 1. If |jsBufferSource| has a \[[ViewedArrayBuffer]] [=/internal slot=]:
+ 1. If |jsBufferSource| has a \[[TypedArrayName]] [=/internal slot=]:
+ 1. [=/Assert=]: |jsBufferSource| is a [=typed array type=] instance.
+ 1. Let |taRecord| be [$MakeTypedArrayWithBufferWitnessRecord$](|jsBufferSource|,
+ Seq-Cst).
+ 1. If [$IsTypedArrayOutOfBounds$](|taRecord|) is true, then return 0.
+ 1. Return [$TypedArrayByteLength$](|taRecord|).
+ 1. Otherwise:
+ 1. [=/Assert=]: |jsBufferSource| is a {{DataView}}.
+ 1. Let |viewRecord| be [$MakeDataViewWithBufferWitnessRecord$](|jsBufferSource|,
+ Seq-Cst).
+ 1. If [$IsViewOutOfBounds$](|viewRecord|) is true, then return 0.
+ 1. Return [$GetViewByteLength$](|viewRecord|).
+ 1. Otherwise:
+ 1. [=/Assert=]: |jsBufferSource| is an {{ArrayBuffer}} or a {{SharedArrayBuffer}}.
+ 1. Return [$ArrayBufferByteLength$](|jsBufferSource|, Seq-Cst).
There is an invariant in JS that [ArrayBufferByteLength](https://tc39.es/ecma262/multipage/structured-data.html#sec-arraybufferbytelength) can only be called on ArrayBuffers which are not detached. Callers of the "byte length" operation in other specs may not be respecting that invariant. (Is there any way to know what those callers are? I checked a couple likely specs and the only one I found which is passing an ArrayBuffer is [WebNN](https://www.w3.org/TR/webnn/#validate-buffer-with-descriptor), which is indeed not guarding against detached buffers.)
It would be good to either handle that here (by throwing or returning 0) or at the very least to note that invariant for callers.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1529#pullrequestreview-3628866730
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/webidl/pull/1529/review/3628866730@github.com>
Received on Tuesday, 6 January 2026 00:37:03 UTC