From c9941ba95bd1471b2ca32d52e9543d45ffd829eb Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 18 Jun 2023 19:43:56 +1200 Subject: [PATCH] LibWeb: Implement CountQueuingStrategy highWaterMark property --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/Forward.h | 1 + .../LibWeb/Streams/CountQueuingStrategy.cpp | 38 ++++++++++++++++ .../LibWeb/Streams/CountQueuingStrategy.h | 43 +++++++++++++++++++ .../LibWeb/Streams/CountQueuingStrategy.idl | 11 +++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 6 files changed, 95 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp create mode 100644 Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h create mode 100644 Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 2bfbc29134..69a13ed76d 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/CountQueuingStrategy.cpp Streams/ReadableByteStreamController.cpp Streams/ReadableStream.cpp Streams/ReadableStreamBYOBReader.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 5a6246d934..c3d43ba310 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -535,6 +535,7 @@ class Selection; } namespace Web::Streams { +class CountQueuingStrategy; class ReadableByteStreamController; class ReadableStream; class ReadableStreamBYOBReader; diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp new file mode 100644 index 0000000000..368abdf016 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.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> CountQueuingStrategy::construct_impl(JS::Realm& realm, QueuingStrategyInit const& init) +{ + // The new CountQueuingStrategy(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)); +} + +CountQueuingStrategy::CountQueuingStrategy(JS::Realm& realm, double high_water_mark) + : PlatformObject(realm) + , m_high_water_mark(high_water_mark) +{ +} + +CountQueuingStrategy::~CountQueuingStrategy() = default; + +JS::ThrowCompletionOr CountQueuingStrategy::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "CountQueuingStrategy")); + + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h new file mode 100644 index 0000000000..39d7e6a9ac --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.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/#countqueuingstrategy +class CountQueuingStrategy final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(CountQueuingStrategy, Bindings::PlatformObject); + +public: + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, QueuingStrategyInit const&); + + virtual ~CountQueuingStrategy() override; + + // https://streams.spec.whatwg.org/#cqs-high-water-mark + double high_water_mark() const + { + // The highWaterMark getter steps are: + // 1. Return this.[[highWaterMark]]. + return m_high_water_mark; + } + +private: + explicit CountQueuingStrategy(JS::Realm&, double high_water_mark); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; + + // https://streams.spec.whatwg.org/#countqueuingstrategy-highwatermark + double m_high_water_mark { 0 }; +}; + +} diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl new file mode 100644 index 0000000000..10abe6bfdd --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl @@ -0,0 +1,11 @@ +#import + +// https://streams.spec.whatwg.org/#cqs-class-definition +[Exposed=*] +interface CountQueuingStrategy { + 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 7af1b14a99..9836092e68 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/CountQueuingStrategy) libweb_js_bindings(Streams/ReadableByteStreamController) libweb_js_bindings(Streams/ReadableStream) libweb_js_bindings(Streams/ReadableStreamBYOBReader)