ladybird/Libraries/LibWeb/Streams/WritableStreamDefaultController.cpp
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

76 lines
2.3 KiB
C++

/*
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/WritableStreamDefaultController.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/Streams/WritableStream.h>
#include <LibWeb/Streams/WritableStreamDefaultController.h>
#include <LibWeb/Streams/WritableStreamOperations.h>
namespace Web::Streams {
GC_DEFINE_ALLOCATOR(WritableStreamDefaultController);
void WritableStreamDefaultController::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_signal);
for (auto& value : m_queue)
visitor.visit(value.value);
visitor.visit(m_stream);
visitor.visit(m_abort_algorithm);
visitor.visit(m_close_algorithm);
visitor.visit(m_strategy_size_algorithm);
visitor.visit(m_write_algorithm);
}
void WritableStreamDefaultController::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(WritableStreamDefaultController);
Base::initialize(realm);
}
// https://streams.spec.whatwg.org/#ws-default-controller-error
void WritableStreamDefaultController::error(Optional<JS::Value> error)
{
// 1. Let state be this.[[stream]].[[state]].
auto state = m_stream->state();
// 2. If state is not "writable", return.
if (state != WritableStream::State::Writable)
return;
// 3. Perform ! WritableStreamDefaultControllerError(this, e).
writable_stream_default_controller_error(*this, error.value_or(JS::js_undefined()));
}
// https://streams.spec.whatwg.org/#ws-default-controller-private-abort
GC::Ref<WebIDL::Promise> WritableStreamDefaultController::abort_steps(JS::Value reason)
{
// 1. Let result be the result of performing this.[[abortAlgorithm]], passing reason.
auto result = m_abort_algorithm->function()(reason);
// 2. Perform ! WritableStreamDefaultControllerClearAlgorithms(this).
writable_stream_default_controller_clear_algorithms(*this);
// 3. Return result.
return result;
}
// https://streams.spec.whatwg.org/#ws-default-controller-private-error
void WritableStreamDefaultController::error_steps()
{
// 1. Perform ! ResetQueue(this).
reset_queue(*this);
}
WritableStreamDefaultController::WritableStreamDefaultController(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
}