Skip to content

Truly independent web browser

LibWeb: Root the animations returned by getAnimations()

Shannon Booth863a261fe577
diff --git a/Libraries/LibWeb/Animations/Animatable.cpp b/Libraries/LibWeb/Animations/Animatable.cpp
index 3c409599962..c0e9907b4e9 100644
--- a/Libraries/LibWeb/Animations/Animatable.cpp
+++ b/Libraries/LibWeb/Animations/Animatable.cpp
@@ -118,19 +118,19 @@ WebIDL::ExceptionOr<GC::Ref<Animation>> Animatable::animate(JS::Realm& realm, GC
}
// https://drafts.csswg.org/web-animations-1/#dom-animatable-getanimations
-WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations(GetAnimationsOptions const& options)
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> Animatable::get_animations(GetAnimationsOptions const& options)
{
as<DOM::Element>(*this).document().update_style();
return get_animations_internal(GetAnimationsSorted::Yes, options);
}
-WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations(Bindings::GetAnimationsOptions const& options)
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> Animatable::get_animations(Bindings::GetAnimationsOptions const& options)
{
return get_animations(TRY(get_animations_options_from_bindings(options)));
}
-WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_internal(GetAnimationsSorted sorted, GetAnimationsOptions const& options)
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> Animatable::get_animations_internal(GetAnimationsSorted sorted, GetAnimationsOptions const& options)
{
// 1. Let object be the object on which this method was called.
@@ -142,7 +142,7 @@ WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_inter
// 4. If options is passed with subtree set to true, then return the set of relevant animations for a subtree of target.
// Otherwise, return the set of relevant animations for target.
- Vector<GC::Ref<Animation>> relevant_animations;
+ GC::RootVector<GC::Ref<Animation>> relevant_animations;
if (m_impl) {
auto& associated_animations = m_impl->associated_animations;
for (auto const& animation : associated_animations) {
diff --git a/Libraries/LibWeb/Animations/Animatable.h b/Libraries/LibWeb/Animations/Animatable.h
index d8d6f17c5b3..56fb34948ff 100644
--- a/Libraries/LibWeb/Animations/Animatable.h
+++ b/Libraries/LibWeb/Animations/Animatable.h
@@ -11,6 +11,7 @@
#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <AK/Utf16FlyString.h>
+#include <LibGC/RootVector.h>
#include <LibWeb/Animations/KeyframeEffect.h>
#include <LibWeb/Bindings/Animatable.h>
#include <LibWeb/Export.h>
@@ -45,9 +46,9 @@ public:
WebIDL::ExceptionOr<GC::Ref<Animation>> animate(Vector<BaseKeyframe> keyframes, Variant<double, KeyframeAnimationOptions> const& options);
WebIDL::ExceptionOr<GC::Ref<Animation>> animate(JS::Realm&, GC::Ptr<JS::Object> keyframes, Variant<double, Bindings::KeyframeAnimationOptions> const& options);
- WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations(GetAnimationsOptions const& options);
- WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations(Bindings::GetAnimationsOptions const& options);
- WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations_internal(GetAnimationsSorted sorted, GetAnimationsOptions const& options);
+ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> get_animations(GetAnimationsOptions const& options);
+ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> get_animations(Bindings::GetAnimationsOptions const& options);
+ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animation>>> get_animations_internal(GetAnimationsSorted sorted, GetAnimationsOptions const& options);
ReadonlySpan<GC::Ref<Animation>> associated_animations_in_composite_order();
ReadonlySpan<GC::Ref<Animation>> associated_animations_unordered() const { return m_impl ? m_impl->associated_animations.span() : ReadonlySpan<GC::Ref<Animation>> {}; }
void invalidate_associated_animation_composite_order();
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index d67466c553a..f51371e9f03 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -9314,7 +9314,7 @@ void Document::remove_replaced_animations()
}
}
-WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> Document::get_animations()
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animations::Animation>>> Document::get_animations()
{
update_style();
return calculate_get_animations(*this);
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 8fe55bfff72..af950e681f2 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1226,7 +1226,7 @@ public:
void dispatch_events_for_animation_if_necessary(GC::Ref<Animations::Animation>);
void remove_replaced_animations();
- WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> get_animations();
+ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animations::Animation>>> get_animations();
HashTable<GC::Ref<Animations::AnimationTimeline>> const& associated_animation_timelines() const { return m_associated_animation_timelines; }
void begin_smil_time_container_once_loaded(SVG::SMILTimeContainer&);
void schedule_svg_referenced_motion_path_update(SVG::SVGAnimateMotionElement&);
diff --git a/Libraries/LibWeb/DOM/DocumentOrShadowRoot.h b/Libraries/LibWeb/DOM/DocumentOrShadowRoot.h
index adccc5367cd..4534f779081 100644
--- a/Libraries/LibWeb/DOM/DocumentOrShadowRoot.h
+++ b/Libraries/LibWeb/DOM/DocumentOrShadowRoot.h
@@ -60,11 +60,11 @@ GC::Ptr<Element> calculate_active_element(T& self)
// https://drafts.csswg.org/web-animations-1/#dom-documentorshadowroot-getanimations
template<DocumentOrShadowRoot T>
-WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> calculate_get_animations(T& self)
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animations::Animation>>> calculate_get_animations(T& self)
{
// Returns the set of relevant animations for a subtree for the document or shadow root on which this
// method is called.
- Vector<GC::Ref<Animations::Animation>> relevant_animations;
+ GC::RootVector<GC::Ref<Animations::Animation>> relevant_animations;
TRY(self.template for_each_child_of_type_fallible<Element>([&](auto& child) -> WebIDL::ExceptionOr<IterationDecision> {
relevant_animations.extend(TRY(child.get_animations_internal(
Animations::Animatable::GetAnimationsSorted::No,
diff --git a/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Libraries/LibWeb/DOM/ShadowRoot.cpp
index f86d5f002a2..f289c2f6adf 100644
--- a/Libraries/LibWeb/DOM/ShadowRoot.cpp
+++ b/Libraries/LibWeb/DOM/ShadowRoot.cpp
@@ -284,7 +284,7 @@ void ShadowRoot::for_each_active_css_style_sheet(Function<void(CSS::StyleSheetSt
}
}
-WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> ShadowRoot::get_animations()
+WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animations::Animation>>> ShadowRoot::get_animations()
{
document().update_style();
return calculate_get_animations(*this);
diff --git a/Libraries/LibWeb/DOM/ShadowRoot.h b/Libraries/LibWeb/DOM/ShadowRoot.h
index 5ca3ab73c68..1071a4fcd55 100644
--- a/Libraries/LibWeb/DOM/ShadowRoot.h
+++ b/Libraries/LibWeb/DOM/ShadowRoot.h
@@ -77,7 +77,7 @@ public:
void for_each_css_style_sheet(Function<void(CSS::StyleSheetState&)>&& callback) const;
void for_each_active_css_style_sheet(Function<void(CSS::StyleSheetState&)> const& callback) const;
- WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> get_animations();
+ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<Animations::Animation>>> get_animations();
ElementByIdMap& element_by_id() const;