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 [email protected]
  • Loading branch information
daeyeon committed Aug 6, 2022
1 parent 0a2c910 commit d2b1fd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 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
3 changes: 0 additions & 3 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
},
"transferable/deserialize-error.window.js": {
"skip": "Browser-specific test"
},
"readable-byte-streams/bad-buffers-and-views.any.js": {
"fail": "TODO: implement detached ArrayBuffer support"
}
}

0 comments on commit d2b1fd7

Please sign in to comment.