Re: [whatwg/streams] Various fixes for readable byte streams (#1123)

Hmm, `enqueue()` also invalidates the BYOB request but doesn't always detach the previous request's buffer either.
```javascript
reader.read(new Uint32Array(1));

const byobRequest1 = controller.byobRequest;
const view1 = byobRequest1.view;
controller.enqueue(new Uint8Array([0x01]));
view1[0] === 0x01;
```
Maybe this was intentional? Should the underlying byte stream be able to continue using the old view as long as we haven't committed the pull-into descriptor? 🤔

---

One thing that we definitely *should* fix, is actually transferring the request's buffer when we commit the pull-into descriptor. Right now, we aren't actually doing that when using `enqueue()`... oops! 😅
```javascript
let byobView;
const rs = new ReadableStream({
  type: 'bytes',
  pull(controller) {
    byobView = controller.byobRequest.view;
    controller.enqueue(new Uint8Array([0x01]));
  }
})

const reader = rs.getReader({ mode: 'byob' });
const { done, value } = await reader.read(new Uint8Array(1));
value[0] === 0x01;
byobView.buffer === value.buffer; // true... oops, forgot to transfer!
```

-- 
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/1123#issuecomment-824383678

Received on Wednesday, 21 April 2021 21:55:06 UTC