From 96c3373dbef9ced780eb9aa29f0763fb3663d2b7 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Tue, 16 Aug 2022 03:46:13 +0900 Subject: [PATCH] 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 daeyeon.dev@gmail.com PR-URL: https://github.com/nodejs/node/pull/44155 Refs: https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-with-new-view Reviewed-By: Luigi Pinca --- lib/internal/webstreams/readablestream.js | 9 +++++++++ test/wpt/status/streams.json | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 5c5c8da724ace9..eed7b668c0d709 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -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, diff --git a/test/wpt/status/streams.json b/test/wpt/status/streams.json index e6fd391a620885..b45fb191f2fcf8 100644 --- a/test/wpt/status/streams.json +++ b/test/wpt/status/streams.json @@ -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)" - ] - } } }