diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 451962d287..7339d8e09f 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -110,6 +110,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(plugin_object);
for (auto& mime_type_object : m_pdf_viewer_mime_type_objects)
visitor.visit(mime_type_object);
+ visitor.visit(m_count_queuing_strategy_size_function);
}
Window::~Window() = default;
@@ -757,6 +758,28 @@ Vector> Window::pdf_viewer_mime_type_objects()
return m_pdf_viewer_mime_type_objects;
}
+// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
+WebIDL::ExceptionOr> Window::count_queuing_strategy_size_function()
+{
+ auto& realm = this->realm();
+
+ if (!m_count_queuing_strategy_size_function) {
+ // 1. Let steps be the following steps:
+ auto steps = [](auto const&) {
+ // 1. Return 1.
+ return 1.0;
+ };
+
+ // 2. Let F be ! CreateBuiltinFunction(steps, 0, "size", « », globalObject’s relevant Realm).
+ auto function = JS::NativeFunction::create(realm, move(steps), 0, "size", &realm);
+
+ // 3. Set globalObject’s count queuing strategy size function to a Function that represents a reference to F, with callback context equal to globalObject’s relevant settings object.
+ m_count_queuing_strategy_size_function = MUST_OR_THROW_OOM(heap().allocate(realm, *function, relevant_settings_object(*this)));
+ }
+
+ return JS::NonnullGCPtr { *m_count_queuing_strategy_size_function };
+}
+
WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge)
{
auto& realm = this->realm();
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index 659ee7de91..a3ac489be7 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -122,6 +122,8 @@ public:
CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; }
CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
+ WebIDL::ExceptionOr> count_queuing_strategy_size_function();
+
// JS API functions
JS::NonnullGCPtr window() const;
JS::NonnullGCPtr self() const;
@@ -241,6 +243,9 @@ private:
// https://html.spec.whatwg.org/multipage/interaction.html#user-activation-data-model
HighResolutionTime::DOMHighResTimeStamp m_last_activation_timestamp { NumericLimits::max() };
+
+ // https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
+ JS::GCPtr m_count_queuing_strategy_size_function;
};
void run_animation_frame_callbacks(DOM::Document&, double now);
diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp
index 368abdf016..d62baeec6e 100644
--- a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp
+++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp
@@ -1,11 +1,13 @@
/*
* Copyright (c) 2023, Shannon Booth
+ * Copyright (c) 2023, Matthew Olsson
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include
#include
+#include
#include
#include
@@ -27,6 +29,13 @@ CountQueuingStrategy::CountQueuingStrategy(JS::Realm& realm, double high_water_m
CountQueuingStrategy::~CountQueuingStrategy() = default;
+// https://streams.spec.whatwg.org/#cqs-size
+WebIDL::ExceptionOr> CountQueuingStrategy::size()
+{
+ // 1. Return this's relevant global object's count queuing strategy size function.
+ return global_object().count_queuing_strategy_size_function();
+}
+
JS::ThrowCompletionOr CountQueuingStrategy::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h
index 39d7e6a9ac..e244b7985d 100644
--- a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h
+++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.h
@@ -31,6 +31,8 @@ public:
return m_high_water_mark;
}
+ WebIDL::ExceptionOr> size();
+
private:
explicit CountQueuingStrategy(JS::Realm&, double high_water_mark);
diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl
index 10abe6bfdd..da94810894 100644
--- a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl
+++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.idl
@@ -1,3 +1,4 @@
+#import
#import
// https://streams.spec.whatwg.org/#cqs-class-definition
@@ -7,5 +8,5 @@ interface CountQueuingStrategy {
readonly attribute unrestricted double highWaterMark;
- // FIXME: readonly attribute Function size;
+ readonly attribute Function size;
};