diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index d2421223191..a88a825681a 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -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>(), process_body_chunk, process_end_of_body, process_body_error); diff --git a/Libraries/LibWeb/FileAPI/Blob.cpp b/Libraries/LibWeb/FileAPI/Blob.cpp index dfa25d08366..4df361dc080 100644 --- a/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Libraries/LibWeb/FileAPI/Blob.cpp @@ -376,7 +376,7 @@ GC::Ref 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 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 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(); diff --git a/Libraries/LibWeb/FileAPI/FileReader.cpp b/Libraries/LibWeb/FileAPI/FileReader.cpp index c6591cf4712..77656e8ee27 100644 --- a/Libraries/LibWeb/FileAPI/FileReader.cpp +++ b/Libraries/LibWeb/FileAPI/FileReader.cpp @@ -134,7 +134,7 @@ WebIDL::ExceptionOr 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; diff --git a/Libraries/LibWeb/Streams/ReadableStream.cpp b/Libraries/LibWeb/Streams/ReadableStream.cpp index 0f02b12be9d..a0283b88579 100644 --- a/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -259,6 +259,13 @@ bool ReadableStream::is_disturbed() const return m_disturbed; } +// https://streams.spec.whatwg.org/#readablestream-get-a-reader +WebIDL::ExceptionOr> 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 ReadableStream::pull_from_bytes(ByteBuffer bytes) { diff --git a/Libraries/LibWeb/Streams/ReadableStream.h b/Libraries/LibWeb/Streams/ReadableStream.h index 54be7a4abb7..3959c82bbe5 100644 --- a/Libraries/LibWeb/Streams/ReadableStream.h +++ b/Libraries/LibWeb/Streams/ReadableStream.h @@ -105,6 +105,7 @@ public: State state() const { return m_state; } void set_state(State value) { m_state = value; } + WebIDL::ExceptionOr> get_a_reader(); WebIDL::ExceptionOr pull_from_bytes(ByteBuffer); WebIDL::ExceptionOr enqueue(JS::Value chunk); void set_up_with_byte_reading_support(GC::Ptr = {}, GC::Ptr = {}, double high_water_mark = 0);