LibWeb: Implement the Streams SetUpReadableStreamBYOBReader AO
Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
This commit is contained in:
parent
aff38ae80f
commit
9ccadf61a2
Notes:
sideshowbarker
2024-07-16 20:12:13 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/9ccadf61a2 Pull-request: https://github.com/SerenityOS/serenity/pull/19740 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/mattco98 ✅
2 changed files with 21 additions and 0 deletions
|
@ -481,6 +481,26 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDe
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#set-up-readable-stream-byob-reader
|
||||
WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader& reader, ReadableStream& stream)
|
||||
{
|
||||
// 1. If ! IsReadableStreamLocked(stream) is true, throw a TypeError exception.
|
||||
if (is_readable_stream_locked(stream))
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot create stream reader for a locked stream"sv };
|
||||
|
||||
// 2. If stream.[[controller]] does not implement ReadableByteStreamController, throw a TypeError exception.
|
||||
if (!stream.controller()->has<JS::NonnullGCPtr<ReadableByteStreamController>>())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "BYOB reader cannot set up reader from non-byte stream"sv };
|
||||
|
||||
// 3. Perform ! ReadableStreamReaderGenericInitialize(reader, stream).
|
||||
readable_stream_reader_generic_initialize(ReadableStreamReader { reader }, stream);
|
||||
|
||||
// 4. Set reader.[[readIntoRequests]] to a new empty list.
|
||||
reader.read_into_requests().clear();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-default-controller-close
|
||||
void readable_stream_default_controller_close(ReadableStreamDefaultController& controller)
|
||||
{
|
||||
|
|
|
@ -49,6 +49,7 @@ void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultRea
|
|||
WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader&);
|
||||
WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&);
|
||||
WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader&, ReadableStream&);
|
||||
void readable_stream_default_controller_close(ReadableStreamDefaultController&);
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_controller_enqueue(ReadableStreamDefaultController&, JS::Value chunk);
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_controller_can_pull_if_needed(ReadableStreamDefaultController&);
|
||||
|
|
Loading…
Add table
Reference in a new issue