mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Add a 'get a reader' helper method on ReadableStream
This commit is contained in:
parent
da408cb09a
commit
9ce0c5914b
Notes:
github-actions[bot]
2024-12-25 11:03:14 +00:00
Author: https://github.com/shannonbooth
Commit: 9ce0c5914b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3029
Reviewed-by: https://github.com/kennethmyhra ✅
5 changed files with 14 additions and 6 deletions
|
@ -90,7 +90,7 @@ void Body::fully_read(JS::Realm& realm, Web::Fetch::Infrastructure::Body::Proces
|
|||
|
||||
// 4. Let reader be the result of getting a reader for body’s stream. If that threw an exception, then run errorSteps
|
||||
// with that exception and return.
|
||||
auto reader = Streams::acquire_readable_stream_default_reader(m_stream);
|
||||
auto reader = m_stream->get_a_reader();
|
||||
|
||||
if (reader.is_exception()) {
|
||||
auto throw_completion = Bindings::exception_to_throw_completion(realm.vm(), reader.release_error());
|
||||
|
@ -113,7 +113,7 @@ void Body::incrementally_read(ProcessBodyChunkCallback process_body_chunk, Proce
|
|||
|
||||
// 2. Let reader be the result of getting a reader for body’s stream.
|
||||
// NOTE: This operation will not throw an exception.
|
||||
auto reader = MUST(Streams::acquire_readable_stream_default_reader(m_stream));
|
||||
auto reader = MUST(m_stream->get_a_reader());
|
||||
|
||||
// 3. Perform the incrementally-read loop given reader, taskDestination, processBodyChunk, processEndOfBody, and processBodyError.
|
||||
incrementally_read_loop(reader, task_destination.get<GC::Ref<JS::Object>>(), process_body_chunk, process_end_of_body, process_body_error);
|
||||
|
|
|
@ -376,7 +376,7 @@ GC::Ref<WebIDL::Promise> Blob::text()
|
|||
auto stream = get_stream();
|
||||
|
||||
// 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception.
|
||||
auto reader_or_exception = acquire_readable_stream_default_reader(*stream);
|
||||
auto reader_or_exception = stream->get_a_reader();
|
||||
if (reader_or_exception.is_exception())
|
||||
return WebIDL::create_rejected_promise_from_exception(realm, reader_or_exception.release_error());
|
||||
auto reader = reader_or_exception.release_value();
|
||||
|
@ -405,7 +405,7 @@ GC::Ref<WebIDL::Promise> Blob::array_buffer()
|
|||
auto stream = get_stream();
|
||||
|
||||
// 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception.
|
||||
auto reader_or_exception = acquire_readable_stream_default_reader(*stream);
|
||||
auto reader_or_exception = stream->get_a_reader();
|
||||
if (reader_or_exception.is_exception())
|
||||
return WebIDL::create_rejected_promise_from_exception(realm, reader_or_exception.release_error());
|
||||
auto reader = reader_or_exception.release_value();
|
||||
|
@ -432,7 +432,7 @@ GC::Ref<WebIDL::Promise> Blob::bytes()
|
|||
auto stream = get_stream();
|
||||
|
||||
// 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception.
|
||||
auto reader_or_exception = acquire_readable_stream_default_reader(*stream);
|
||||
auto reader_or_exception = stream->get_a_reader();
|
||||
if (reader_or_exception.is_exception())
|
||||
return WebIDL::create_rejected_promise_from_exception(realm, reader_or_exception.release_error());
|
||||
auto reader = reader_or_exception.release_value();
|
||||
|
|
|
@ -134,7 +134,7 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
|
|||
auto stream = blob.get_stream();
|
||||
|
||||
// 6. Let reader be the result of getting a reader from stream.
|
||||
auto reader = TRY(acquire_readable_stream_default_reader(*stream));
|
||||
auto reader = TRY(stream->get_a_reader());
|
||||
|
||||
// 7. Let bytes be an empty byte sequence.
|
||||
ByteBuffer bytes;
|
||||
|
|
|
@ -259,6 +259,13 @@ bool ReadableStream::is_disturbed() const
|
|||
return m_disturbed;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-get-a-reader
|
||||
WebIDL::ExceptionOr<GC::Ref<ReadableStreamDefaultReader>> ReadableStream::get_a_reader()
|
||||
{
|
||||
// To get a reader for a ReadableStream stream, return ? AcquireReadableStreamDefaultReader(stream). The result will be a ReadableStreamDefaultReader.
|
||||
return TRY(acquire_readable_stream_default_reader(*this));
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-pull-from-bytes
|
||||
WebIDL::ExceptionOr<void> ReadableStream::pull_from_bytes(ByteBuffer bytes)
|
||||
{
|
||||
|
|
|
@ -105,6 +105,7 @@ public:
|
|||
State state() const { return m_state; }
|
||||
void set_state(State value) { m_state = value; }
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<ReadableStreamDefaultReader>> get_a_reader();
|
||||
WebIDL::ExceptionOr<void> pull_from_bytes(ByteBuffer);
|
||||
WebIDL::ExceptionOr<void> enqueue(JS::Value chunk);
|
||||
void set_up_with_byte_reading_support(GC::Ptr<PullAlgorithm> = {}, GC::Ptr<CancelAlgorithm> = {}, double high_water_mark = 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue