Re: [whatwg/webidl] Introduce a "detachable" algorithm for BufferSource (PR #1419)

@domenic commented on this pull request.



> @@ -9054,6 +9054,21 @@ a reference to the same object that the IDL value represents.
     1.  Return [$IsDetachedBuffer$](|jsArrayBuffer|).
 </div>
 
+<div algorithm>
+    A [=buffer source type=] instance |bufferSource| is
+    <dfn for="BufferSource" export>detachable</dfn> if the following steps return true:
+
+    1.  Let |jsArrayBuffer| be the result of [=converted to a JavaScript value|converting=]
+        |bufferSource| to a JavaScript value.
+    1.  If |jsArrayBuffer| has a \[[ViewedArrayBuffer]] internal slot, then set |jsArrayBuffer| to
+        |jsArrayBuffer|.\[[ViewedArrayBuffer]].
+    1.  If [$IsSharedArrayBuffer$](|jsArrayBuffer|) is true, then return false.
+    1.  If [$IsDetachedBuffer$](|jsArrayBuffer|) is true, then return false.

Right, sorry for being brief.

What I mean is that even if IsDetachedBuffer() returns true, DetachArrayBuffer() will still work. (It will just be a no-op.) So it's a bit surprising to include this step, since if it was missing, the algorithm would still give a correct answer to "is this detachable?"

And yeah, I think changing it to "transferable", while keeping the check, would be perfect. That reflects the actual use case.

(Also, it's strange that we assert instead of throw for detached array buffers in "transfer". I just checked all usages and it seems like it'd be safe, and perhaps an improvement, to update the algorithm to throw instead. But we can do that separately.)

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

Message ID: <whatwg/webidl/pull/1419/review/2184379244@github.com>

Received on Thursday, 18 July 2024 01:14:57 UTC