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

@MattiasBuelens commented on this pull request.



> -    1.  Let |length| be 0.
-    1.  If |jsBufferSource| has a \[[ViewedArrayBuffer]] [=/internal slot=], then:
-        1.  Set |jsArrayBuffer| to |jsBufferSource|.\[[ViewedArrayBuffer]].
-        1.  Set |offset| to |jsBufferSource|.\[[ByteOffset]].
-        1.  Set |length| to |jsBufferSource|.\[[ByteLength]].
-    1.  Otherwise:
-        1.  Assert: |jsBufferSource| is an {{ArrayBuffer}} or
-            {{SharedArrayBuffer}} object.
-        1.  Set |length| to |jsBufferSource|.\[[ArrayBufferByteLength]].
+    1.  Let |length| be |bufferSource|'s [=BufferSource/byte length=].
+    1.  If |bufferSource| is a [=buffer view type=] instance:
+        1.  Set |arrayBuffer| to |bufferSource|'s [=underlying buffer=].
+        1.  Set |offset| to |bufferSource|'s [=ArrayBufferView/byte offset=].
+    1.  [=/Assert=]: |arrayBuffer| is an {{ArrayBuffer}} or {{SharedArrayBuffer}} object.
+    1.  Let |jsArrayBuffer| be the result of [=converted to a JavaScript value|converting=]
+        |arrayBuffer| to a JavaScript value.
     1.  If [$IsDetachedBuffer$](|jsArrayBuffer|) is true, then return the empty

I've moved the detached check all the way to the top. I also check if *length* is zero, so reading byte offset later on won't throw.

Funnily enough, reading *bufferSource's byte length* itself can still throw for an out-of-bounds `DataView` [(as you already reported)](https://github.com/whatwg/webidl/pull/1529#discussion_r2663169745)... Do we want "get a copy of the bytes held" to propagate that error? Or should we return an empty byte sequence in that case? 🤔

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

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

Received on Friday, 9 January 2026 13:33:47 UTC