LibWeb: Use DefaultReader request in read_all_chunks instead of ReadLoop

ReadLoop requests require the chunks to be Uint8Array objects, however,
TextEncoderStream requires a String (Convertible) value. This is fixed
by implementing read_all_chunks as a loop of DefaultReader requests
instead, which is an identity transformation. This should be okay to
do, as stream chunk steps expect a JS::Value, and convert it to the
type they want.
This commit is contained in:
Luke Wilde 2025-02-06 16:28:40 +00:00 committed by Tim Flynn
commit c14d5f27f9
Notes: github-actions[bot] 2025-02-07 16:06:06 +00:00
3 changed files with 43 additions and 16 deletions

View file

@ -75,13 +75,23 @@ class ReadableStreamDefaultReader final
public:
static WebIDL::ExceptionOr<GC::Ref<ReadableStreamDefaultReader>> construct_impl(JS::Realm&, GC::Ref<ReadableStream>);
// AD-HOC: Callback functions for read_all_chunks
// successSteps, which is an algorithm accepting a JavaScript value
using ReadAllOnSuccessSteps = GC::Function<void()>;
// failureSteps, which is an algorithm accepting a JavaScript value
using ReadAllOnFailureSteps = GC::Function<void(JS::Value error)>;
// AD-HOC: callback triggered on every chunk received from the stream.
using ReadAllOnChunkSteps = GC::Function<void(JS::Value chunk)>;
virtual ~ReadableStreamDefaultReader() override = default;
GC::Ref<WebIDL::Promise> read();
void read_a_chunk(Fetch::Infrastructure::IncrementalReadLoopReadRequest& read_request);
void read_all_bytes(GC::Ref<ReadLoopReadRequest::SuccessSteps>, GC::Ref<ReadLoopReadRequest::FailureSteps>);
void read_all_chunks(GC::Ref<ReadLoopReadRequest::ChunkSteps>, GC::Ref<ReadLoopReadRequest::SuccessSteps>, GC::Ref<ReadLoopReadRequest::FailureSteps>);
void read_all_chunks(GC::Ref<ReadAllOnChunkSteps>, GC::Ref<ReadAllOnSuccessSteps>, GC::Ref<ReadAllOnFailureSteps>);
GC::Ref<WebIDL::Promise> read_all_bytes_deprecated();
void release_lock();