LibWeb: Implement ReadableStreamPipeTo according to spec

Our existing implementation of stream piping was extremely ad-hoc. It
did nothing to handle closed/errored streams, and did not read from or
write to streams in a way required by the spec.

This new implementation uses a custom JS::Cell to drive the read/write
loop.
This commit is contained in:
Timothy Flynn 2025-04-09 12:01:51 -04:00 committed by Tim Flynn
commit eb0a51faf0
Notes: github-actions[bot] 2025-04-11 16:11:49 +00:00
33 changed files with 3926 additions and 85 deletions

View file

@ -20,6 +20,8 @@ struct ReadableStreamReadResult {
bool done;
};
class ReadableStreamPipeTo;
class ReadRequest : public JS::Cell {
GC_CELL(ReadRequest, JS::Cell);
@ -91,13 +93,14 @@ public:
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<ReadAllOnChunkSteps>, GC::Ref<ReadAllOnSuccessSteps>, GC::Ref<ReadAllOnFailureSteps>);
GC::Ref<WebIDL::Promise> read_all_bytes_deprecated();
void release_lock();
SinglyLinkedList<GC::Ref<ReadRequest>>& read_requests() { return m_read_requests; }
void set_readable_stream_pipe_to_operation(Badge<ReadableStreamPipeTo>, GC::Ptr<JS::Cell> readable_stream_pipe_to_operation) { m_readable_stream_pipe_to_operation = readable_stream_pipe_to_operation; }
private:
explicit ReadableStreamDefaultReader(JS::Realm&);
@ -106,6 +109,8 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
SinglyLinkedList<GC::Ref<ReadRequest>> m_read_requests;
GC::Ptr<JS::Cell> m_readable_stream_pipe_to_operation;
};
}