Skip to content

Commit

Permalink
stream: improve views validation on BYOBRequest
Browse files Browse the repository at this point in the history
- This throws if the view is zero-length when there is an active reader
when using `ReadableStreamBYOBRequest.respondWithNewView()`.

- By doing that, we can get all tests passed in
`readable-byte-streams/bad-buffers-and-views.any.js`.

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
PR-URL: #44155
Refs: https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-with-new-view
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
daeyeon authored and ruyadorno committed Aug 22, 2022
1 parent 8c1fe86 commit c079abe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 9 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,15 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);

if (stream[kState].state === 'closed') {
if (viewByteLength !== 0)
throw new ERR_INVALID_STATE.TypeError('View is not zero-length');
} else {
assert(stream[kState].state === 'readable');
if (viewByteLength === 0)
throw new ERR_INVALID_STATE.TypeError('View is zero-length');
}

const {
byteOffset,
byteLength,
Expand Down
8 changes: 0 additions & 8 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@
},
"transferable/deserialize-error.window.js": {
"skip": "Browser-specific test"
},
"readable-byte-streams/bad-buffers-and-views.any.js": {
"fail": {
"note": "TODO: implement detached ArrayBuffer support",
"expected": [
"ReadableStream with byte source: respondWithNewView() throws if the supplied view's buffer is zero-length (in the readable state)"
]
}
}
}

0 comments on commit c079abe

Please sign in to comment.