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

@annevk commented on this pull request.



> -        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.  If [$IsDetachedBuffer$](|jsArrayBuffer|) is true, then return the empty
-        [=byte sequence=].
+    1.  If |bufferSource| is a [=buffer view type=] instance:
+        1.  Set |arrayBuffer| to |bufferSource|'s [=BufferSource/underlying buffer=].
+        1.  Set |offset| to |bufferSource|'s [=ArrayBufferView/byte offset=].
+    1.  If |length| is 0, then return the empty [=byte sequence=].
+
+        <p class="note">This step is not strictly necessary, since [=the range=] below is empty
+        when |length| is 0. It is spelled out as a fast path for implementations.

This is necessary because of the second assert below.

Also, when _length_ is 0 you would get _offset_ + 0 &minus; 1 below, right? That also seems like a problem. This might be an existing problem in this document though.

> @@ -9380,17 +9440,15 @@ a reference to the same object that the IDL value represents.
     {{ArrayBufferView}} |view|, optionally given a
     <dfn export for="ArrayBufferView/write">|startingOffset|</dfn> (default 0):
 
-    1.  Let |jsView| be the result of [=converted to a JavaScript value|converting=] |view| to
-        a JavaScript value.
-    1.  Assert: |bytes|'s [=byte sequence/length=] ≤ |jsView|.\[[ByteLength]] &minus;
-        |startingOffset|.
+    1.  Assert: |view| is not [=ArrayBufferView/out of bounds=].
+        <p class="note">This implies that |view| is not [=BufferSource/detached=].

We should add a newline before this note.

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

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

Received on Saturday, 29 August 2026 13:55:39 UTC