Bug 1275067: Flip logic in nsStyleCoord::ToLength, for safer general-case behavior. r?heycam draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 23 May 2016 12:02:04 -0700
changeset 369817 b8eaa95b8aac1e414e7a1e18ed9e8465283157d3
parent 369317 16663eb3dcfa759f25b5e27b101bc79270c156f2
child 521625 4e68ecfd0a0cb86e734eeab63bba1673cb264cbf
push id18923
push userdholbert@mozilla.com
push dateMon, 23 May 2016 19:02:53 +0000
reviewersheycam
bugs1275067
milestone49.0a1
Bug 1275067: Flip logic in nsStyleCoord::ToLength, for safer general-case behavior. r?heycam MozReview-Commit-ID: 7KYn5hv2Kmd
layout/style/nsStyleCoord.h
--- a/layout/style/nsStyleCoord.h
+++ b/layout/style/nsStyleCoord.h
@@ -181,21 +181,21 @@ public:
   }
 
   bool ConvertsToLength() const {
     return ConvertsToLength(mUnit, mValue);
   }
 
   static nscoord ToLength(nsStyleUnit aUnit, nsStyleUnion aValue) {
     MOZ_ASSERT(ConvertsToLength(aUnit, aValue));
-    if (aUnit == eStyleUnit_Coord) {
-      return aValue.mInt;
+    if (IsCalcUnit(aUnit)) {
+      return AsCalcValue(aValue)->ToLength(); // Note: This asserts !mHasPercent
     }
-    MOZ_ASSERT(IsCalcUnit(aUnit) && !AsCalcValue(aValue)->mHasPercent);
-    return AsCalcValue(aValue)->ToLength();
+    MOZ_ASSERT(aUnit == eStyleUnit_Coord);
+    return aValue.mInt;
   }
 
   nscoord ToLength() const {
     return ToLength(GetUnit(), mValue);
   }
 
   // Callers must verify IsCalcUnit before calling this function.
   static Calc* AsCalcValue(nsStyleUnion aValue) {