1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:57:44 +00:00

LibWeb: Add ObservableArray::for_each()

This commit is contained in:
Aliaksandr Kalenik 2024-03-08 22:29:36 +01:00 committed by Andreas Kling
parent 54d8e58a68
commit f19c92d78e
2 changed files with 15 additions and 7 deletions

View file

@ -28,6 +28,18 @@ public:
JS::ThrowCompletionOr<void> append(JS::Value value);
void clear();
template<typename T, typename Callback>
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<T>(value_and_attributes->value.as_object());
callback(style_sheet);
}
}
}
explicit ObservableArray(Object& prototype);
virtual void visit_edges(JS::Cell::Visitor&) override;