From 2fcfe2a01f0800b577a49fe84fbade1ee9d6604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Mar 2025 11:44:36 +0000 Subject: [PATCH] Bug 1947516 - Always provide a consistent EventContext, not just depending on the event type. r=boris Otherwise you get into situations where a transitions X and Y compare differently depending on whether you're a cancel event or not, which trips the weak ordering guarantees. Differential Revision: https://phabricator.services.mozilla.com/D242817 --- dom/animation/AnimationEventDispatcher.h | 16 ++++------------ dom/animation/CSSTransition.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/dom/animation/AnimationEventDispatcher.h b/dom/animation/AnimationEventDispatcher.h index 652e750026c7..b454a6ec3890 100644 --- a/dom/animation/AnimationEventDispatcher.h +++ b/dom/animation/AnimationEventDispatcher.h @@ -78,22 +78,14 @@ struct AnimationEventInfo { Maybe GetEventContext() const { if (mData.is()) { const auto& data = mData.as(); - return data.mMessage == eAnimationCancel - ? Some(dom::Animation::EventContext{ - NonOwningAnimationTarget(data.mTarget), - data.mAnimationIndex}) - : Nothing(); + return Some(dom::Animation::EventContext{ + NonOwningAnimationTarget(data.mTarget), data.mAnimationIndex}); } - if (mData.is()) { const auto& data = mData.as(); - return data.mMessage == eTransitionCancel - ? Some(dom::Animation::EventContext{ - NonOwningAnimationTarget(data.mTarget), - data.mAnimationIndex}) - : Nothing(); + return Some(dom::Animation::EventContext{ + NonOwningAnimationTarget(data.mTarget), data.mAnimationIndex}); } - return Nothing(); } diff --git a/dom/animation/CSSTransition.cpp b/dom/animation/CSSTransition.cpp index 861ce724bebd..bb2460e016f8 100644 --- a/dom/animation/CSSTransition.cpp +++ b/dom/animation/CSSTransition.cpp @@ -242,18 +242,18 @@ int32_t CSSTransition::CompareCompositeOrder( // 1. Sort by document order const OwningElementRef& owningElement1 = - aContext ? OwningElementRef(aContext->mTarget) : mOwningElement; + IsTiedToMarkup() ? mOwningElement : OwningElementRef(aContext->mTarget); const OwningElementRef& owningElement2 = - aOtherContext ? OwningElementRef(aOtherContext->mTarget) - : aOther.mOwningElement; + aOther.IsTiedToMarkup() ? aOther.mOwningElement + : OwningElementRef(aOtherContext->mTarget); if (!owningElement1.Equals(owningElement2)) { return owningElement1.Compare(owningElement2, aCache); } // 2. (Same element and pseudo): Sort by transition generation - const uint64_t& index1 = aContext ? aContext->mIndex : mAnimationIndex; - const uint64_t& index2 = - aOtherContext ? aOtherContext->mIndex : aOther.mAnimationIndex; + const uint64_t index1 = IsTiedToMarkup() ? mAnimationIndex : aContext->mIndex; + const uint64_t index2 = + aOther.IsTiedToMarkup() ? aOther.mAnimationIndex : aOtherContext->mIndex; if (index1 != index2) { return index1 < index2 ? -1 : 1; }