LibWeb: Implement the Streams AcquireReadableStreamBYOBReader AO

Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
This commit is contained in:
Shannon Booth 2023-06-29 20:51:14 +12:00 committed by Linus Groh
parent 9ccadf61a2
commit 729f4838c2
2 changed files with 16 additions and 0 deletions

View file

@ -46,6 +46,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_reada
return reader;
}
// https://streams.spec.whatwg.org/#acquire-readable-stream-byob-reader
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamBYOBReader>> acquire_readable_stream_byob_reader(ReadableStream& stream)
{
auto& realm = stream.realm();
// 1. Let reader be a new ReadableStreamBYOBReader.
auto reader = TRY(realm.heap().allocate<ReadableStreamBYOBReader>(realm, realm));
// 2. Perform ? SetUpReadableStreamBYOBReader(reader, stream).
TRY(set_up_readable_stream_byob_reader(reader, stream));
// 3. Return reader.
return reader;
}
// https://streams.spec.whatwg.org/#is-readable-stream-locked
bool is_readable_stream_locked(ReadableStream const& stream)
{

View file

@ -26,6 +26,7 @@ using CloseAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<Web
using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamBYOBReader>> acquire_readable_stream_byob_reader(ReadableStream&);
bool is_readable_stream_locked(ReadableStream const&);
SizeAlgorithm extract_size_algorithm(QueuingStrategy const&);