ladybird/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.h
Shannon Booth 637fd51595 LibWeb: Unify WebIDL C++ type generation
Represent WebIDL C++ types with a single CppType model that tracks
nullability, optional presence, and contained storage.

GC-like values now use GC::Ref/GC::Ptr directly, while containers choose
"plain", "Root", or "Conservative" container types depending on what
they contain. For example, sequence<Element> becomes a RootVector of
GC::Ref values, while sequence<SomeDictionary> becomes a
ConservativeVector only when the dictionary contains GC-like values.
This moves the generated bindings away from wrapping GC values in
GC::Root by default.

This has broad fallout as the types passed to interfaces for GC
objects changes almost fully across the board.
2026-05-23 18:26:12 +02:00

66 lines
2.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <AK/SinglyLinkedList.h>
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::Streams {
// https://streams.spec.whatwg.org/#writablestreamdefaultwriter
class WritableStreamDefaultWriter final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(WritableStreamDefaultWriter, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(WritableStreamDefaultWriter);
public:
static WebIDL::ExceptionOr<GC::Ref<WritableStreamDefaultWriter>> construct_impl(JS::Realm&, GC::Ref<WritableStream>);
virtual ~WritableStreamDefaultWriter() override = default;
GC::Ptr<WebIDL::Promise> closed();
WebIDL::ExceptionOr<Optional<double>> desired_size() const;
GC::Ptr<WebIDL::Promise> ready();
GC::Ref<WebIDL::Promise> abort(Optional<JS::Value> reason);
GC::Ref<WebIDL::Promise> close();
void release_lock();
GC::Ref<WebIDL::Promise> write(Optional<JS::Value> chunk);
GC::Ptr<WebIDL::Promise> closed_promise() { return m_closed_promise; }
void set_closed_promise(GC::Ptr<WebIDL::Promise> value) { m_closed_promise = value; }
GC::Ptr<WebIDL::Promise> ready_promise() { return m_ready_promise; }
void set_ready_promise(GC::Ptr<WebIDL::Promise> value) { m_ready_promise = value; }
GC::Ptr<WritableStream const> stream() const { return m_stream; }
GC::Ptr<WritableStream> stream() { return m_stream; }
void set_stream(GC::Ptr<WritableStream> value) { m_stream = value; }
private:
explicit WritableStreamDefaultWriter(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
// https://streams.spec.whatwg.org/#writablestreamdefaultwriter-closedpromise
// A promise returned by the writers closed getter
GC::Ptr<WebIDL::Promise> m_closed_promise;
// https://streams.spec.whatwg.org/#writablestreamdefaultwriter-readypromise
// A promise returned by the writers ready getter
GC::Ptr<WebIDL::Promise> m_ready_promise;
// https://streams.spec.whatwg.org/#writablestreamdefaultwriter-stream
// A WritableStream instance that owns this reader
GC::Ptr<WritableStream> m_stream;
};
}