mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibWeb: Add TransformStreamDefaultController scaffolding
This adds the scaffolding of TransformStreamDefaultController so we can start implementing the necessary abstract operations for it.
This commit is contained in:
parent
f1d69d789b
commit
0091a60448
6 changed files with 106 additions and 0 deletions
|
@ -515,6 +515,7 @@ set(SOURCES
|
||||||
Streams/ReadableStreamGenericReader.cpp
|
Streams/ReadableStreamGenericReader.cpp
|
||||||
Streams/Transformer.cpp
|
Streams/Transformer.cpp
|
||||||
Streams/TransformStream.cpp
|
Streams/TransformStream.cpp
|
||||||
|
Streams/TransformStreamDefaultController.cpp
|
||||||
Streams/UnderlyingSink.cpp
|
Streams/UnderlyingSink.cpp
|
||||||
Streams/UnderlyingSource.cpp
|
Streams/UnderlyingSource.cpp
|
||||||
Streams/WritableStream.cpp
|
Streams/WritableStream.cpp
|
||||||
|
|
|
@ -24,6 +24,8 @@ using StartAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::Value>()>;
|
||||||
using AbortAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
|
using AbortAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
|
||||||
using CloseAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>;
|
using CloseAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>;
|
||||||
using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
|
using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
|
||||||
|
using FlushAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>;
|
||||||
|
using TransformAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamBYOBReader>> acquire_readable_stream_byob_reader(ReadableStream&);
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamBYOBReader>> acquire_readable_stream_byob_reader(ReadableStream&);
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/Streams/TransformStream.h>
|
||||||
|
#include <LibWeb/Streams/TransformStreamDefaultController.h>
|
||||||
|
|
||||||
|
namespace Web::Streams {
|
||||||
|
|
||||||
|
TransformStreamDefaultController::TransformStreamDefaultController(JS::Realm& realm)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformStreamDefaultController::~TransformStreamDefaultController() = default;
|
||||||
|
|
||||||
|
JS::ThrowCompletionOr<void> TransformStreamDefaultController::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||||
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::TransformStreamDefaultControllerPrototype>(realm, "TransformStreamDefaultController"));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransformStreamDefaultController::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#ts-default-controller-desired-size
|
||||||
|
Optional<double> TransformStreamDefaultController::desired_size()
|
||||||
|
{
|
||||||
|
VERIFY(stream()->readable()->controller().has_value() && stream()->readable()->controller()->has<JS::NonnullGCPtr<ReadableStreamDefaultController>>());
|
||||||
|
|
||||||
|
// 1. Let readableController be this.[[stream]].[[readable]].[[controller]].
|
||||||
|
auto readable_controller = stream()->readable()->controller()->get<JS::NonnullGCPtr<ReadableStreamDefaultController>>();
|
||||||
|
|
||||||
|
// 2. Return ! ReadableStreamDefaultControllerGetDesiredSize(readableController).
|
||||||
|
return readable_stream_default_controller_get_desired_size(*readable_controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/Streams/AbstractOperations.h>
|
||||||
|
|
||||||
|
namespace Web::Streams {
|
||||||
|
|
||||||
|
class TransformStreamDefaultController : public Bindings::PlatformObject {
|
||||||
|
WEB_PLATFORM_OBJECT(TransformStreamDefaultController, Bindings::PlatformObject);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TransformStreamDefaultController(JS::Realm&);
|
||||||
|
virtual ~TransformStreamDefaultController() override;
|
||||||
|
|
||||||
|
Optional<double> desired_size();
|
||||||
|
|
||||||
|
auto& flush_algorithm() { return m_flush_algorithm; }
|
||||||
|
void set_flush_algorithm(Optional<FlushAlgorithm>&& value) { m_flush_algorithm = move(value); }
|
||||||
|
|
||||||
|
auto& transform_algorithm() { return m_transform_algorithm; }
|
||||||
|
void set_transform_algorithm(Optional<TransformAlgorithm>&& value) { m_transform_algorithm = move(value); }
|
||||||
|
|
||||||
|
JS::GCPtr<TransformStream> stream() { return m_stream; }
|
||||||
|
void set_stream(JS::GCPtr<TransformStream> stream) { m_stream = stream; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#transformstreamdefaultcontroller-flushalgorithm
|
||||||
|
Optional<FlushAlgorithm> m_flush_algorithm;
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#transformstreamdefaultcontroller-transformalgorithm
|
||||||
|
Optional<TransformAlgorithm> m_transform_algorithm;
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#transformstreamdefaultcontroller-stream
|
||||||
|
JS::GCPtr<TransformStream> m_stream;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
// https://streams.spec.whatwg.org/#transformstreamdefaultcontroller
|
||||||
|
[Exposed=*]
|
||||||
|
interface TransformStreamDefaultController {
|
||||||
|
readonly attribute unrestricted double? desiredSize;
|
||||||
|
|
||||||
|
// FIXME: undefined enqueue(optional any chunk);
|
||||||
|
// FIXME: undefined error(optional any reason);
|
||||||
|
// FIXME: undefined terminate();
|
||||||
|
};
|
|
@ -197,6 +197,7 @@ libweb_js_bindings(Streams/ReadableStreamBYOBRequest)
|
||||||
libweb_js_bindings(Streams/ReadableStreamDefaultController)
|
libweb_js_bindings(Streams/ReadableStreamDefaultController)
|
||||||
libweb_js_bindings(Streams/ReadableStreamDefaultReader)
|
libweb_js_bindings(Streams/ReadableStreamDefaultReader)
|
||||||
libweb_js_bindings(Streams/TransformStream)
|
libweb_js_bindings(Streams/TransformStream)
|
||||||
|
libweb_js_bindings(Streams/TransformStreamDefaultController)
|
||||||
libweb_js_bindings(Streams/WritableStream)
|
libweb_js_bindings(Streams/WritableStream)
|
||||||
libweb_js_bindings(Streams/WritableStreamDefaultWriter)
|
libweb_js_bindings(Streams/WritableStreamDefaultWriter)
|
||||||
libweb_js_bindings(SVG/SVGAnimatedLength)
|
libweb_js_bindings(SVG/SVGAnimatedLength)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue