Skip to content

Commit 96c3373

Browse files
daeyeondanielleadams
authored andcommitted
stream: improve views validation on BYOBRequest
- 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] PR-URL: #44155 Refs: https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-with-new-view Reviewed-By: Luigi Pinca <[email protected]>
1 parent 741402d commit 96c3373

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/internal/webstreams/readablestream.js

+9
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,15 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
25162516
const viewBuffer = ArrayBufferViewGetBuffer(view);
25172517
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);
25182518

2519+
if (stream[kState].state === 'closed') {
2520+
if (viewByteLength !== 0)
2521+
throw new ERR_INVALID_STATE.TypeError('View is not zero-length');
2522+
} else {
2523+
assert(stream[kState].state === 'readable');
2524+
if (viewByteLength === 0)
2525+
throw new ERR_INVALID_STATE.TypeError('View is zero-length');
2526+
}
2527+
25192528
const {
25202529
byteOffset,
25212530
byteLength,

test/wpt/status/streams.json

-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,5 @@
44
},
55
"transferable/deserialize-error.window.js": {
66
"skip": "Browser-specific test"
7-
},
8-
"readable-byte-streams/bad-buffers-and-views.any.js": {
9-
"fail": {
10-
"note": "TODO: implement detached ArrayBuffer support",
11-
"expected": [
12-
"ReadableStream with byte source: respondWithNewView() throws if the supplied view's buffer is zero-length (in the readable state)"
13-
]
14-
}
157
}
168
}

0 commit comments

Comments
 (0)