Bug 1474213 - Add assertions checking that PendingAnimationTracker is used for animations whose target element belongs to the same document of the PenginAnimationTracker. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 09 Jul 2018 07:16:37 +0900
changeset 815505 89cec7d9edfd14f67778537fad3028e9436c563c
parent 815500 b0111088608390a0ab4baa3727e5e6fb06cd9f31
child 815506 c66b824525e0d38d7f213cc09a3b445eaec2a119
push id115520
push userbmo:hikezoe@mozilla.com
push dateSun, 08 Jul 2018 22:24:35 +0000
reviewersbirtles
bugs1474213
milestone63.0a1
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
dom/animation/Animation.h
dom/animation/PendingAnimationTracker.cpp
--- 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));