1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibWeb: Implement Streams AO ReadableStreamAddReadIntoRequest

This is effectively identical to ReadableStreamAddReadRequest besides
from the fact that it takes a ReadIntoRequest instead of a ReadRequest,
and is instead intended to be used for BYOB readers.
This commit is contained in:
Shannon Booth 2023-11-19 11:47:11 +13:00 committed by Andreas Kling
parent f27e76b0b7
commit 446a78f30e
2 changed files with 14 additions and 0 deletions

View file

@ -358,6 +358,19 @@ void readable_stream_add_read_request(ReadableStream& stream, JS::NonnullGCPtr<R
stream.reader()->get<JS::NonnullGCPtr<ReadableStreamDefaultReader>>()->read_requests().append(read_request);
}
// https://streams.spec.whatwg.org/#readable-stream-add-read-into-request
void readable_stream_add_read_into_request(ReadableStream& stream, JS::NonnullGCPtr<ReadIntoRequest> read_into_request)
{
// 1. Assert: stream.[[reader]] implements ReadableStreamBYOBReader.
VERIFY(stream.reader().has_value() && stream.reader()->has<JS::NonnullGCPtr<ReadableStreamBYOBReader>>());
// 2. Assert: stream.[[state]] is "readable" or "closed".
VERIFY(stream.is_readable() || stream.is_closed());
// 3. Append readRequest to stream.[[reader]].[[readIntoRequests]].
stream.reader()->get<JS::NonnullGCPtr<ReadableStreamBYOBReader>>()->read_into_requests().append(read_into_request);
}
// https://streams.spec.whatwg.org/#readable-stream-reader-generic-cancel
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin& reader, JS::Value reason)
{