diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 89a7e11d1c..b4a782726a 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -4628,13 +4628,9 @@ void Document::for_each_css_style_sheet(Function&& ca callback(*style_sheet); if (m_adopted_style_sheets) { - for (auto& entry : m_adopted_style_sheets->indexed_properties()) { - auto value_and_attributes = m_adopted_style_sheets->indexed_properties().storage()->get(entry.index()); - if (value_and_attributes.has_value()) { - auto& style_sheet = verify_cast(value_and_attributes->value.as_object()); - callback(style_sheet); - } - } + m_adopted_style_sheets->for_each([&](auto& style_sheet) { + callback(style_sheet); + }); } } diff --git a/Userland/Libraries/LibWeb/WebIDL/ObservableArray.h b/Userland/Libraries/LibWeb/WebIDL/ObservableArray.h index 7a1078f0bf..0013007df7 100644 --- a/Userland/Libraries/LibWeb/WebIDL/ObservableArray.h +++ b/Userland/Libraries/LibWeb/WebIDL/ObservableArray.h @@ -28,6 +28,18 @@ public: JS::ThrowCompletionOr append(JS::Value value); void clear(); + template + void for_each(Callback callback) + { + for (auto& entry : indexed_properties()) { + auto value_and_attributes = indexed_properties().storage()->get(entry.index()); + if (value_and_attributes.has_value()) { + auto& style_sheet = verify_cast(value_and_attributes->value.as_object()); + callback(style_sheet); + } + } + } + explicit ObservableArray(Object& prototype); virtual void visit_edges(JS::Cell::Visitor&) override;