Bug 1474213 - Add assertions checking that PendingAnimationTracker is used for animations whose target element belongs to the same document of the PenginAnimationTracker. r?birtles
MozReview-Commit-ID: DQ1rNwg0lgC
--- a/dom/animation/Animation.h
+++ b/dom/animation/Animation.h
@@ -385,16 +385,21 @@ public:
* where the Animation may have been cancelled.
*
* We need to do this synchronously because after a CSS animation/transition
* is canceled, it will be released by its owning element and may not still
* exist when we would normally go to queue events on the next tick.
*/
virtual void MaybeQueueCancelEvent(const StickyTimeDuration& aActiveTime) {};
+ /**
+ * Returns the document associated with the animation target element.
+ */
+ nsIDocument* GetRenderedDocument() const;
+
protected:
void SilentlySetCurrentTime(const TimeDuration& aNewCurrentTime);
void CancelNoUpdate();
void PlayNoUpdate(ErrorResult& aRv, LimitBehavior aLimitBehavior);
void ResumeAt(const TimeDuration& aReadyTime);
void PauseAt(const TimeDuration& aReadyTime);
void FinishPendingAt(const TimeDuration& aReadyTime)
{
@@ -517,17 +522,16 @@ protected:
static constexpr StickyTimeDuration zeroDuration = StickyTimeDuration();
return std::max(
std::min((EffectEnd() - mEffect->SpecifiedTiming().Delay()),
aActiveDuration),
zeroDuration);
}
- nsIDocument* GetRenderedDocument() const;
nsIDocument* GetTimelineDocument() const;
RefPtr<AnimationTimeline> mTimeline;
RefPtr<AnimationEffect> mEffect;
// The beginning of the delay period.
Nullable<TimeDuration> mStartTime; // Timeline timescale
Nullable<TimeDuration> mHoldTime; // Animation timescale
Nullable<TimeDuration> mPendingReadyTime; // Timeline timescale
--- a/dom/animation/PendingAnimationTracker.cpp
+++ b/dom/animation/PendingAnimationTracker.cpp
@@ -22,28 +22,36 @@ NS_IMPL_CYCLE_COLLECTION(PendingAnimatio
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingAnimationTracker, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingAnimationTracker, Release)
void
PendingAnimationTracker::AddPending(dom::Animation& aAnimation,
AnimationSet& aSet)
{
+ MOZ_ASSERT(aAnimation.GetRenderedDocument() &&
+ aAnimation.GetRenderedDocument() == mDocument,
+ "Should be used for animations that the target element belongs to "
+ "the same document");
aSet.PutEntry(&aAnimation);
// Schedule a paint. Otherwise animations that don't trigger a paint by
// themselves (e.g. CSS animations with an empty keyframes rule) won't
// start until something else paints.
EnsurePaintIsScheduled();
}
void
PendingAnimationTracker::RemovePending(dom::Animation& aAnimation,
AnimationSet& aSet)
{
+ MOZ_ASSERT(aAnimation.GetRenderedDocument() &&
+ aAnimation.GetRenderedDocument() == mDocument,
+ "Should be used for animations that the target element belongs to "
+ "the same document");
aSet.RemoveEntry(&aAnimation);
}
bool
PendingAnimationTracker::IsWaiting(const dom::Animation& aAnimation,
const AnimationSet& aSet) const
{
return aSet.Contains(const_cast<dom::Animation*>(&aAnimation));