diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 7339d8e09f..d9ffdcba02 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -111,6 +111,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
for (auto& mime_type_object : m_pdf_viewer_mime_type_objects)
visitor.visit(mime_type_object);
visitor.visit(m_count_queuing_strategy_size_function);
+ visitor.visit(m_byte_length_queuing_strategy_size_function);
}
Window::~Window() = default;
@@ -780,6 +781,30 @@ WebIDL::ExceptionOr> Window::count_queuin
return JS::NonnullGCPtr { *m_count_queuing_strategy_size_function };
}
+// https://streams.spec.whatwg.org/#byte-length-queuing-strategy-size-function
+WebIDL::ExceptionOr> Window::byte_length_queuing_strategy_size_function()
+{
+ auto& realm = this->realm();
+
+ if (!m_byte_length_queuing_strategy_size_function) {
+ // 1. Let steps be the following steps, given chunk:
+ auto steps = [](JS::VM& vm) {
+ auto chunk = vm.argument(0);
+
+ // 1. Return ? GetV(chunk, "byteLength").
+ return chunk.get(vm, vm.names.byteLength);
+ };
+
+ // 2. Let F be ! CreateBuiltinFunction(steps, 1, "size", « », globalObject’s relevant Realm).
+ auto function = JS::NativeFunction::create(realm, move(steps), 1, "size", &realm);
+
+ // 3. Set globalObject’s byte length queuing strategy size function to a Function that represents a reference to F, with callback context equal to globalObject’s relevant settings object.
+ m_byte_length_queuing_strategy_size_function = MUST_OR_THROW_OOM(heap().allocate(realm, *function, relevant_settings_object(*this)));
+ }
+
+ return JS::NonnullGCPtr { *m_byte_length_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 a3ac489be7..b4a6aeb47c 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -123,6 +123,7 @@ public:
CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
WebIDL::ExceptionOr> count_queuing_strategy_size_function();
+ WebIDL::ExceptionOr> byte_length_queuing_strategy_size_function();
// JS API functions
JS::NonnullGCPtr window() const;
@@ -246,6 +247,9 @@ private:
// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
JS::GCPtr m_count_queuing_strategy_size_function;
+
+ // https://streams.spec.whatwg.org/#byte-length-queuing-strategy-size-function
+ JS::GCPtr m_byte_length_queuing_strategy_size_function;
};
void run_animation_frame_callbacks(DOM::Document&, double now);
diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp
index 7532e9e876..5475af3c0e 100644
--- a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp
+++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.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 @@ ByteLengthQueuingStrategy::ByteLengthQueuingStrategy(JS::Realm& realm, double hi
ByteLengthQueuingStrategy::~ByteLengthQueuingStrategy() = default;
+// https://streams.spec.whatwg.org/#blqs-size
+WebIDL::ExceptionOr> ByteLengthQueuingStrategy::size()
+{
+ // 1. Return this's relevant global object's byte length queuing strategy size function.
+ return global_object().byte_length_queuing_strategy_size_function();
+}
+
JS::ThrowCompletionOr ByteLengthQueuingStrategy::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h
index ed2c147a40..bbae612177 100644
--- a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h
+++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.h
@@ -31,6 +31,8 @@ public:
return m_high_water_mark;
}
+ WebIDL::ExceptionOr> size();
+
private:
explicit ByteLengthQueuingStrategy(JS::Realm&, double high_water_mark);
diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl
index ed2f14a6df..24864e6fc9 100644
--- a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl
+++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.idl
@@ -1,3 +1,4 @@
+#import
#import
// https://streams.spec.whatwg.org/#blqs-class-definition
@@ -7,5 +8,5 @@ interface ByteLengthQueuingStrategy {
readonly attribute unrestricted double highWaterMark;
- // FIXME: readonly attribute Function size;
+ readonly attribute Function size;
};