Bug 1928352: Make SMILCompositor fail earlier when adding an incorrectly configured animation. r=longsonr

If multiple animations of the same element is an error (as asserted in
`SMILCompositor::ComposeAttribute`), then this patch will catch that
when the animation is added.

Differential Revision: https://phabricator.services.mozilla.com/D227737
This commit is contained in:
Brad Werth 2024-11-05 17:44:45 +00:00
parent 7bd39a617f
commit 9cccb8ffb3
3 changed files with 20 additions and 2 deletions

View File

@ -258,7 +258,10 @@ int8_t SMILAnimationFunction::CompareTo(
const SMILAnimationFunction* aOther) const {
NS_ENSURE_TRUE(aOther, 0);
NS_ASSERTION(aOther != this, "Trying to compare to self");
if (aOther == this) {
// std::sort will sometimes compare an element to itself. It's fine.
return 0;
}
// Inactive animations sort first
if (!IsActiveOrFrozen() && aOther->IsActiveOrFrozen()) return -1;
@ -279,7 +282,7 @@ int8_t SMILAnimationFunction::CompareTo(
// Animations that appear later in the document sort after those earlier in
// the document
MOZ_ASSERT(mAnimationElement != aOther->mAnimationElement,
MOZ_ASSERT(!HasSameAnimationElement(aOther),
"Two animations cannot have the same animation content element!");
return (nsContentUtils::PositionIsBefore(mAnimationElement,

View File

@ -46,6 +46,10 @@ class SMILAnimationFunction {
void SetAnimationElement(
mozilla::dom::SVGAnimationElement* aAnimationElement);
bool HasSameAnimationElement(const SMILAnimationFunction* aOther) const {
return aOther && aOther->mAnimationElement == mAnimationElement;
};
/*
* Sets animation-specific attributes (or marks them dirty, in the case
* of from/to/by/values).

View File

@ -40,6 +40,17 @@ void SMILCompositor::Traverse(nsCycleCollectionTraversalCallback* aCallback) {
// Other methods
void SMILCompositor::AddAnimationFunction(SMILAnimationFunction* aFunc) {
if (aFunc) {
#ifdef DEBUG
// Check that we don't already have an animation function that references
// the animation element used by aFunc. This will be an assert when we
// later sort the list. Let's catch the assert now. We use the same
// assert message from the sort.
for (const SMILAnimationFunction* func : mAnimationFunctions) {
MOZ_ASSERT(
!aFunc->HasSameAnimationElement(func),
"Two animations cannot have the same animation content element!");
}
#endif
mAnimationFunctions.AppendElement(aFunc);
}
}