LibWeb: Implement ReadableStream transfer

This commit is contained in:
Timothy Flynn 2025-05-20 17:20:22 -04:00 committed by Tim Flynn
commit 312db85a84
Notes: github-actions[bot] 2025-05-21 10:56:01 +00:00
9 changed files with 511 additions and 28 deletions

View file

@ -11,6 +11,7 @@
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/ReadableStreamPrototype.h>
#include <LibWeb/Bindings/Transferable.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Streams/Algorithms.h>
#include <LibWeb/Streams/QueuingStrategy.h>
@ -58,7 +59,9 @@ struct ReadableStreamPair {
};
// https://streams.spec.whatwg.org/#readablestream
class ReadableStream final : public Bindings::PlatformObject {
class ReadableStream final
: public Bindings::PlatformObject
, public Bindings::Transferable {
WEB_PLATFORM_OBJECT(ReadableStream, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(ReadableStream);
@ -113,6 +116,11 @@ public:
GC::Ptr<WebIDL::ArrayBufferView> current_byob_request_view();
// ^Transferable
virtual WebIDL::ExceptionOr<void> transfer_steps(HTML::TransferDataHolder&) override;
virtual WebIDL::ExceptionOr<void> transfer_receiving_steps(HTML::TransferDataHolder&) override;
virtual HTML::TransferType primary_interface() const override { return HTML::TransferType::ReadableStream; }
private:
explicit ReadableStream(JS::Realm&);
@ -123,10 +131,6 @@ private:
// A ReadableStreamDefaultController or ReadableByteStreamController created with the ability to control the state and queue of this stream
Optional<ReadableStreamController> m_controller;
// https://streams.spec.whatwg.org/#readablestream-detached
// A boolean flag set to true when the stream is transferred
bool m_detached { false };
// https://streams.spec.whatwg.org/#readablestream-disturbed
// A boolean flag set to true when the stream has been read from or canceled
bool m_disturbed { false };