- From: Joshua Bell <notifications@github.com>
- Date: Wed, 17 Jul 2024 10:55:10 -0700
- To: whatwg/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/webidl/pull/1419/review/2183622855@github.com>
@inexorabletash 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.
Hopefully I'm not misunderstanding your question. The use case is over at https://webmachinelearning.github.io/webnn/#mlnamedarraybufferviews-transfer
Shorter version for explanatory purposes:
1. For each _buffer_ of _buffers_:
1. If _buffer_ is not **detachable**, then throw a TypeError.
1. For each _buffer_ of _buffers_:
1. Let _xfer_ be the result of [transferring](https://webidl.spec.whatwg.org/#arraybuffer-transfer) _buffer_'s underlying buffer.
The "IsDetachedBuffer" check is to ensure that [transferring](https://webidl.spec.whatwg.org/#arraybuffer-transfer) wouldn't assert ("_Assert: IsDetachedBuffer(jsArrayBuffer) is false"_).
This could alternately be done by the caller, e.g.:
1. For each _buffer_ of _buffers_:
1. If _buffer_ has a [[ViewedArrayBuffer]] internal slot, then set _buffer_ to _buffer_.[[ViewedArrayBuffer]].
1. If [IsDetachedBuffer](https://tc39.es/ecma262/multipage/structured-data.html#sec-isdetachedbuffer)(_buffer_) is true, then throw a TypeError.
1. If _buffer_ is not **detachable**, then throw a TypeError.
1. For each _buffer_ of _buffers_:
1. Let _xfer_ be the result of [transferring](https://webidl.spec.whatwg.org/#arraybuffer-transfer) _buffer_'s underlying buffer.
... but it seems we'd want to keep this logic together in WebIDL. Would it be clearer if we named the new algorithm **transferable** instead?
(But maybe I'm answering the wrong question?)
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1419#discussion_r1681471321
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/webidl/pull/1419/review/2183622855@github.com>
Received on Wednesday, 17 July 2024 17:55:14 UTC