⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259538 in webkit


Ignore:
Timestamp:
Apr 4, 2020, 3:39:18 PM (6 years ago)
Author:
Doug Kelly
Message:

Additional sanity checks in compareAnimationsByCompositeOrder()
https://bugs.webkit.org/show_bug.cgi?id=209996

Reviewed by Geoffrey Garen.

compareAnimationsByCompositeOrder() is used by std::sort() which requires strict weak ordering.
This adds additional checks to ensure strict weak ordering is maintained, first by ensuring
the transitionProperty string is different before returning that comparison, then by only using
if the animation is a CSSTransition or CSSAnimation if the left hand and right hand sides differ.
This should leave all remaining cases to sort by the global animation list.

No new tests; this should be covered by existing tests and should not change functionality
otherwise.

  • animation/WebAnimationUtilities.cpp:

(WebCore::compareAnimationsByCompositeOrder):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r259534 r259538  
     12020-04-04  Doug Kelly  <dougk@apple.com>
     2
     3        Additional sanity checks in compareAnimationsByCompositeOrder()
     4        https://bugs.webkit.org/show_bug.cgi?id=209996
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        compareAnimationsByCompositeOrder() is used by std::sort() which requires strict weak ordering.
     9        This adds additional checks to ensure strict weak ordering is maintained, first by ensuring
     10        the transitionProperty string is different before returning that comparison, then by only using
     11        if the animation is a CSSTransition or CSSAnimation if the left hand and right hand sides differ.
     12        This should leave all remaining cases to sort by the global animation list.
     13
     14        No new tests; this should be covered by existing tests and should not change functionality
     15        otherwise.
     16
     17        * animation/WebAnimationUtilities.cpp:
     18        (WebCore::compareAnimationsByCompositeOrder):
     19
    1202020-04-04  Wenson Hsieh  <wenson_hsieh@apple.com>
    221
  • trunk/Source/WebCore/animation/WebAnimationUtilities.cpp

    r255076 r259538  
    4545    bool rhsIsCSSTransition = rhsHasOwningElement && is<CSSTransition>(rhsAnimation);
    4646    if (lhsIsCSSTransition || rhsIsCSSTransition) {
    47         if (lhsIsCSSTransition == rhsIsCSSTransition) {
    48             // Sort transitions first by their generation time, and then by transition-property.
    49             // https://drafts.csswg.org/css-transitions-2/#animation-composite-order
    50             auto& lhsCSSTransition = downcast<CSSTransition>(lhsAnimation);
    51             auto& rhsCSSTransition = downcast<CSSTransition>(rhsAnimation);
    52             if (lhsCSSTransition.generationTime() != rhsCSSTransition.generationTime())
    53                 return lhsCSSTransition.generationTime() < rhsCSSTransition.generationTime();
    54             return lhsCSSTransition.transitionProperty().utf8() < rhsCSSTransition.transitionProperty().utf8();
    55         }
    56         return !rhsIsCSSTransition;
     47        if (lhsIsCSSTransition != rhsIsCSSTransition)
     48            return !rhsIsCSSTransition;
     49
     50        // Sort transitions first by their generation time, and then by transition-property.
     51        // https://drafts.csswg.org/css-transitions-2/#animation-composite-order
     52        auto& lhsCSSTransition = downcast<CSSTransition>(lhsAnimation);
     53        auto& rhsCSSTransition = downcast<CSSTransition>(rhsAnimation);
     54        if (lhsCSSTransition.generationTime() != rhsCSSTransition.generationTime())
     55            return lhsCSSTransition.generationTime() < rhsCSSTransition.generationTime();
     56        auto lhsCSSTransitionProperty = lhsCSSTransition.transitionProperty().utf8();
     57        auto rhsCSSTransitionProperty = rhsCSSTransition.transitionProperty().utf8();
     58        if (lhsCSSTransitionProperty != rhsCSSTransitionProperty)
     59            return lhsCSSTransitionProperty < rhsCSSTransitionProperty;
    5760    }
    5861
     
    6164    bool rhsIsCSSAnimation = rhsHasOwningElement && is<CSSAnimation>(rhsAnimation);
    6265    if (lhsIsCSSAnimation || rhsIsCSSAnimation) {
    63         if (lhsIsCSSAnimation == rhsIsCSSAnimation) {
    64             // We must have a list of CSS Animations if we have CSS Animations to sort through.
    65             ASSERT(cssAnimationList);
    66             ASSERT(!cssAnimationList->isEmpty());
     66        if (lhsIsCSSAnimation != rhsIsCSSAnimation)
     67            return !rhsIsCSSAnimation;
    6768
    68             // https://drafts.csswg.org/css-animations-2/#animation-composite-order
    69             // Sort A and B based on their position in the computed value of the animation-name property of the (common) owning element.
    70             auto& lhsBackingAnimation = downcast<CSSAnimation>(lhsAnimation).backingAnimation();
    71             auto& rhsBackingAnimation = downcast<CSSAnimation>(rhsAnimation).backingAnimation();
     69        // We must have a list of CSS Animations if we have CSS Animations to sort through.
     70        ASSERT(cssAnimationList);
     71        ASSERT(!cssAnimationList->isEmpty());
    7272
    73             for (size_t i = 0; i < cssAnimationList->size(); ++i) {
    74                 auto& animation = cssAnimationList->animation(i);
    75                 if (animation == lhsBackingAnimation)
    76                     return true;
    77                 if (animation == rhsBackingAnimation)
    78                     return false;
    79             }
     73        // https://drafts.csswg.org/css-animations-2/#animation-composite-order
     74        // Sort A and B based on their position in the computed value of the animation-name property of the (common) owning element.
     75        auto& lhsBackingAnimation = downcast<CSSAnimation>(lhsAnimation).backingAnimation();
     76        auto& rhsBackingAnimation = downcast<CSSAnimation>(rhsAnimation).backingAnimation();
    8077
    81             // We should have found either of those CSS animations in the CSS animations list.
    82             ASSERT_NOT_REACHED();
     78        for (size_t i = 0; i < cssAnimationList->size(); ++i) {
     79            auto& animation = cssAnimationList->animation(i);
     80            if (animation == lhsBackingAnimation)
     81                return true;
     82            if (animation == rhsBackingAnimation)
     83                return false;
    8384        }
    84         return !rhsIsCSSAnimation;
     85
     86        // We should have found either of those CSS animations in the CSS animations list.
     87        ASSERT_NOT_REACHED();
    8588    }
    8689
Note: See TracChangeset for help on using the changeset viewer.