Re: [whatwg/webidl] Fix `BufferSource` algorithms for shared and resizable buffers (PR #1529)

@bakkot commented on this pull request.



>  <div algorithm>
     The <dfn export for="BufferSource">byte length</dfn> of a [=buffer source type=] instance
     |bufferSource| is the value returned by the following steps:
 
     1.  Let |jsBufferSource| be the result of [=converted to a JavaScript value|converting=]
         |bufferSource| to a JavaScript value.
-    1.  If |jsBufferSource| has a \[[ViewedArrayBuffer]] internal slot, then return
-        |jsBufferSource|.\[[ByteLength]].
-    1.  Return |jsBufferSource|.\[[ArrayBufferByteLength]].
+    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.

Horrifyingly, in JavaScript the analogous `.byteLength` operation throws - [only for DataViews](https://tc39.es/ecma262/multipage/structured-data.html#sec-get-dataview.prototype.bytelength), not [TypedArrays](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-get-%typedarray%.prototype.bytelength) or [ArrayBuffers](https://tc39.es/ecma262/multipage/structured-data.html#sec-get-arraybuffer.prototype.bytelength).

Up to you if you want to match that behavior.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1529#pullrequestreview-3628840171
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/pull/1529/review/3628840171@github.com>

Received on Tuesday, 6 January 2026 00:22:54 UTC