LibWeb: Implement WritableStream transfer

This commit is contained in:
Timothy Flynn 2025-05-20 17:27:51 -04:00 committed by Tim Flynn
commit cca08ad833
Notes: github-actions[bot] 2025-05-21 10:55:54 +00:00
6 changed files with 260 additions and 26 deletions

View file

@ -10,6 +10,7 @@
#include <AK/SinglyLinkedList.h>
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/Transferable.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Streams/QueuingStrategy.h>
#include <LibWeb/WebIDL/Promise.h>
@ -32,7 +33,9 @@ struct PendingAbortRequest {
};
// https://streams.spec.whatwg.org/#writablestream
class WritableStream final : public Bindings::PlatformObject {
class WritableStream final
: public Bindings::PlatformObject
, public Bindings::Transferable {
WEB_PLATFORM_OBJECT(WritableStream, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(WritableStream);
@ -85,6 +88,11 @@ public:
SinglyLinkedList<GC::Ref<WebIDL::Promise>>& write_requests() { return m_write_requests; }
// ^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::WritableStream; }
private:
explicit WritableStream(JS::Realm&);
@ -104,10 +112,6 @@ private:
// A WritableStreamDefaultController created with the ability to control the state and queue of this stream
GC::Ptr<WritableStreamDefaultController> m_controller;
// https://streams.spec.whatwg.org/#writablestream-detached
// A boolean flag set to true when the stream is transferred
bool m_detached { false };
// https://streams.spec.whatwg.org/#writablestream-inflightwriterequest
// A slot set to the promise for the current in-flight write operation while the underlying sink's write algorithm is executing and has not yet fulfilled, used to prevent reentrant calls
GC::Ptr<WebIDL::Promise> m_in_flight_write_request;