Bug 1265611 - Make TransitionProperty() and ToValue() safe when mProperties is not set draft
authorBrian Birtles <birtles@gmail.com>
Thu, 21 Apr 2016 08:31:36 +0900
changeset 354491 fc5203cea908add676e482a86b1dcd105d4989b0
parent 354481 4feb4dd910a5a2d3061dbdd376a80975206819c6
child 354492 efe6b7005d4f055ee909a804b5c6b2cb10074926
push id16093
push userbbirtles@mozilla.com
push dateThu, 21 Apr 2016 00:32:40 +0000
bugs1265611
milestone48.0a1
Bug 1265611 - Make TransitionProperty() and ToValue() safe when mProperties is not set MozReview-Commit-ID: KIzE5jdvPfT
layout/style/nsTransitionManager.h
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -48,29 +48,38 @@ struct ElementPropertyTransition : publi
 
   ElementPropertyTransition* AsTransition() override { return this; }
   const ElementPropertyTransition* AsTransition() const override
   {
     return this;
   }
 
   nsCSSProperty TransitionProperty() const {
-    MOZ_ASSERT(mProperties.Length() == 1,
-               "Transitions should have exactly one animation property. "
+    MOZ_ASSERT(mFrames.Length() == 2,
+               "Transitions should have exactly two animation frames. "
                "Perhaps we are using an un-initialized transition?");
-    return mProperties[0].mProperty;
+    MOZ_ASSERT(mFrames[0].mPropertyValues.Length() == 1,
+               "Transitions should have exactly one property in their first "
+               "frame");
+    return mFrames[0].mPropertyValues[0].mProperty;
   }
 
   StyleAnimationValue ToValue() const {
-    MOZ_ASSERT(mProperties.Length() == 1,
-               "Transitions should have exactly one animation property");
-    MOZ_ASSERT(mProperties[0].mSegments.Length() == 1,
-               "Transitions should have one animation property segment ");
+    // If we failed to generate properties from the transition frames,
+    // return a null value but also show a warning since we should be
+    // detecting that kind of situation in advance and not generating a
+    // transition in the first place.
+    if (mProperties.Length() < 1 ||
+        mProperties[0].mSegments.Length() < 1) {
+      NS_WARNING("Failed to generate transition property values");
+      return StyleAnimationValue();
+    }
     return mProperties[0].mSegments[0].mToValue;
   }
+
   // This is the start value to be used for a check for whether a
   // transition is being reversed.  Normally the same as
   // mProperties[0].mSegments[0].mFromValue, except when this transition
   // started as the reversal of another in-progress transition.
   // Needed so we can handle two reverses in a row.
   StyleAnimationValue mStartForReversingTest;
   // Likewise, the portion (in value space) of the "full" reversed
   // transition that we're actually covering.  For example, if a :hover