Bug 1249564 - Part 2: Cycle collect AnimationEffectTimingReadOnly. r?birtles
Add KeyframeEffectReadOnly::mTiming into the list of cycle collection to
avoid any possible memory leak.
MozReview-Commit-ID: C5mFQ7TsqC7
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -57,17 +57,18 @@ GetComputedTimingDictionary(const Comput
}
}
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(KeyframeEffectReadOnly,
AnimationEffectReadOnly,
mTarget,
- mAnimation)
+ mAnimation,
+ mTiming)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(KeyframeEffectReadOnly,
AnimationEffectReadOnly)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(KeyframeEffectReadOnly)
NS_INTERFACE_MAP_END_INHERITING(AnimationEffectReadOnly)
@@ -87,17 +88,17 @@ KeyframeEffectReadOnly::KeyframeEffectRe
KeyframeEffectReadOnly::KeyframeEffectReadOnly(
nsIDocument* aDocument,
Element* aTarget,
CSSPseudoElementType aPseudoType,
AnimationEffectTimingReadOnly* aTiming)
: AnimationEffectReadOnly(aDocument)
, mTarget(aTarget)
- , mTiming(*aTiming)
+ , mTiming(aTiming)
, mPseudoType(aPseudoType)
, mInEffectOnLastAnimationTimingUpdate(false)
{
MOZ_ASSERT(aTiming);
MOZ_ASSERT(aTarget, "null animation target is not yet supported");
}
JSObject*
@@ -1398,13 +1399,17 @@ void KeyframeEffect::NotifySpecifiedTimi
EffectCompositor::RestyleType::Layer,
mAnimation->CascadeLevel());
}
}
}
KeyframeEffect::~KeyframeEffect()
{
- mTiming->Unlink();
+ // mTiming is cycle collected, so we have to do null check first even though
+ // mTiming shouldn't be null during the lifetime of KeyframeEffect.
+ if (mTiming) {
+ mTiming->Unlink();
+ }
}
} // namespace dom
} // namespace mozilla
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -367,17 +367,17 @@ protected:
// As a result, we need to make sure this gets called whenever anything
// changes with regards to this effects's timing including changes to the
// owning Animation's timing.
void UpdateTargetRegistration();
nsCOMPtr<Element> mTarget;
RefPtr<Animation> mAnimation;
- OwningNonNull<AnimationEffectTimingReadOnly> mTiming;
+ RefPtr<AnimationEffectTimingReadOnly> mTiming;
CSSPseudoElementType mPseudoType;
// The specified keyframes.
nsTArray<Keyframe> mFrames;
// A set of per-property value arrays, derived from |mFrames|.
nsTArray<AnimationProperty> mProperties;