Re: [whatwg/streams] Add ReadableStreamBYOBReader.read(view, { min }) (#1145)

@MattiasBuelens commented on this pull request.



>   method steps are:
 
  1. If |view|.\[[ByteLength]] is 0, return [=a promise rejected with=] a {{TypeError}} exception.
  1. If |view|.\[[ViewedArrayBuffer]].\[[ArrayBufferByteLength]] is 0, return [=a promise rejected
     with=] a {{TypeError}} exception.
  1. If ! [$IsDetachedBuffer$](|view|.\[[ViewedArrayBuffer]]) is true, return
     [=a promise rejected with=] a {{TypeError}} exception.
+ 1. Let |minimumFill| be undefined.
+ 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] was given,
+  1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] is 0, return [=a promise
+     rejected with=] a {{TypeError}} exception.
+  1. If |view| has a \[[TypedArrayName]] internal slot,
+   1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ArrayLength]],
+      return [=a promise rejected with=] a {{RangeError}} exception.
+   1. Let |elementSize| be the element size specified in [=the typed array constructors table=] for
+      |view|.\[[TypedArrayName]].
+   1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] *
+      |elementSize|.
+  1. Otherwise (i.e., it is a {{DataView}}),
+   1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ByteLength]],
+      return [=a promise rejected with=] a {{RangeError}} exception.
+   1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"].

I added a default value for `min`.

However, I ended up *not* making the `minimumFill` argument required, because [`ReadableByteStreamTee`](https://streams.spec.whatwg.org/commit-snapshots/14b47076896e155898c1ef698fb08a508837b2d0/#abstract-opdef-readablebytestreamtee) still uses `ReadableStreamBYOBReaderRead` without that argument. Moving the computation out of `ReadableStreamBYOBReaderRead` would make `ReadableByteStreamTee` less readable in my opinion, and it would be harder to use `ReadableStreamBYOBReaderRead` in other parts of the spec in the future.

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

Message ID: <whatwg/streams/pull/1145/review/1629943788@github.com>

Received on Saturday, 16 September 2023 10:09:42 UTC