From f86c3ab148c3cd1f72ad657b207f2b991822e6c8 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 18 Jun 2023 20:26:19 +1200 Subject: [PATCH] LibWeb: Implement ByteLengthQueuingStrategy highWaterMark property --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/Forward.h | 1 + .../Streams/ByteLengthQueuingStrategy.cpp | 38 ++++++++++++++++ .../Streams/ByteLengthQueuingStrategy.h | 43 +++++++++++++++++++ .../Streams/ByteLengthQueuingStrategy.idl | 11 +++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 6 files changed, 95 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp create mode 100644 Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h create mode 100644 Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 69a13ed76d..c908719eb6 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -493,6 +493,7 @@ set(SOURCES SecureContexts/AbstractOperations.cpp SRI/SRI.cpp Streams/AbstractOperations.cpp + Streams/ByteLengthQueuingStrategy.cpp Streams/CountQueuingStrategy.cpp Streams/ReadableByteStreamController.cpp Streams/ReadableStream.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index c3d43ba310..b9cc798a78 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -535,6 +535,7 @@ class Selection; } namespace Web::Streams { +class ByteLengthQueuingStrategy; class CountQueuingStrategy; class ReadableByteStreamController; class ReadableStream; diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp new file mode 100644 index 0000000000..7532e9e876 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Streams { + +// https://streams.spec.whatwg.org/#blqs-constructor +WebIDL::ExceptionOr> ByteLengthQueuingStrategy::construct_impl(JS::Realm& realm, QueuingStrategyInit const& init) +{ + // The new ByteLengthQueuingStrategy(init) constructor steps are: + // 1. Set this.[[highWaterMark]] to init["highWaterMark"]. + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, init.high_water_mark)); +} + +ByteLengthQueuingStrategy::ByteLengthQueuingStrategy(JS::Realm& realm, double high_water_mark) + : PlatformObject(realm) + , m_high_water_mark(high_water_mark) +{ +} + +ByteLengthQueuingStrategy::~ByteLengthQueuingStrategy() = default; + +JS::ThrowCompletionOr ByteLengthQueuingStrategy::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "ByteLengthQueuingStrategy")); + + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h new file mode 100644 index 0000000000..ed2c147a40 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Web::Streams { + +// https://streams.spec.whatwg.org/#bytelengthqueuingstrategy +class ByteLengthQueuingStrategy final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(ByteLengthQueuingStrategy, Bindings::PlatformObject); + +public: + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, QueuingStrategyInit const&); + + virtual ~ByteLengthQueuingStrategy() override; + + // https://streams.spec.whatwg.org/#blqs-high-water-mark + double high_water_mark() const + { + // The highWaterMark getter steps are: + // 1. Return this.[[highWaterMark]]. + return m_high_water_mark; + } + +private: + explicit ByteLengthQueuingStrategy(JS::Realm&, double high_water_mark); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; + + // https://streams.spec.whatwg.org/#bytelengthqueuingstrategy-highwatermark + double m_high_water_mark { 0 }; +}; + +} diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl new file mode 100644 index 0000000000..ed2f14a6df --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl @@ -0,0 +1,11 @@ +#import + +// https://streams.spec.whatwg.org/#blqs-class-definition +[Exposed=*] +interface ByteLengthQueuingStrategy { + constructor(QueuingStrategyInit init); + + readonly attribute unrestricted double highWaterMark; + + // FIXME: readonly attribute Function size; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 9836092e68..d6a58a010f 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -186,6 +186,7 @@ libweb_js_bindings(NavigationTiming/PerformanceTiming) libweb_js_bindings(PerformanceTimeline/PerformanceEntry) libweb_js_bindings(RequestIdleCallback/IdleDeadline) libweb_js_bindings(ResizeObserver/ResizeObserver) +libweb_js_bindings(Streams/ByteLengthQueuingStrategy) libweb_js_bindings(Streams/CountQueuingStrategy) libweb_js_bindings(Streams/ReadableByteStreamController) libweb_js_bindings(Streams/ReadableStream)