Re: [whatwg/streams] Support teeing readable byte streams (#1114)

@MattiasBuelens commented on this pull request.



> @@ -3205,7 +3442,7 @@ The following abstract operations support the implementation of the
  1. Let |firstDescriptor| be |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=][0].
  1. If |firstDescriptor|'s [=pull-into descriptor/byte offset=] + |firstDescriptor|' [=pull-into
     descriptor/bytes filled=] is not |view|.\[[ByteOffset]], throw a {{RangeError}} exception.
- 1. If |firstDescriptor|'s [=pull-into descriptor/byte length=] is not |view|.\[[ByteLength]], throw
+ 1. If |firstDescriptor|'s [=pull-into descriptor/byte length=] < |view|.\[[ByteLength]], throw

I agree. `byobRequest.respondWithNewView(newView)` should not allow passing a view whose buffer is *smaller* than the original buffer of the original BYOB request.

I would go even further: I'd say `byobRequest.respondWithNewView(newView)` must only be called with a view on the **same buffer** that was originally passed as `byobRequest.view.buffer`, after it has been **transferred** zero or more times. All of the data that was originally inside `byobRequest.view.buffer` should also be in `newView.buffer` (except for the part spanned by `newView`'s start and end, since that will contain the read data).

Ideally, I would make `.respondWithNewView()` enforce this: if `newView.buffer` is not the "transferred version" of `byobRequest.view.buffer`, then it should throw an error. Unfortunately, I don't think the ECMAScript specification provides any way to check this... 😞

We could approximate it by storing the original `byobRequest.view.buffer.byteLength` as part of the pull-into descriptor, and then checking whether `newView.buffer.byteLength` equals that original length. However, that doesn't prevent someone from creating a new `ArrayBuffer` with the same size and using that for `newView`... 😕

---

Either way, you **must** be able to pass a smaller view onto that buffer. Otherwise, it's impossible to satisfy the assert in step 3.1 of [ReadableByteStreamControllerRespondInternal](https://streams.spec.whatwg.org/commit-snapshots/dd76a17a3738d78708a8dfd8f0508e717d6a1988/#readable-byte-stream-controller-respond-internal) when called from `.respondWithNewView()`. And [we definitely need this](https://github.com/whatwg/streams/pull/1114#discussion_r601890120)! 😁 

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

Received on Thursday, 25 March 2021 23:23:11 UTC