Bug 1253470 - Part 3: Produce console warnings for invalid iterations. r=birtles
authorDaisuke Akatsuka <daisuke@mozilla-japan.org>
Fri, 18 Mar 2016 10:14:49 +0900
changeset 314915 b798c62e43652ecc167d39c020f430f302716a2e
parent 314914 ad28fd60184e2719acd520164860d0e7322e3f58
child 314916 a0c0ea60eaefc2f2907527e77fd71fe8b84bb7eb
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-esr52@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1253470
milestone48.0a1
Bug 1253470 - Part 3: Produce console warnings for invalid iterations. r=birtles
dom/animation/TimingParams.cpp
dom/animation/TimingParams.h
testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
testing/web-platform/tests/web-animations/keyframe-effect/getComputedTiming.html
--- a/dom/animation/TimingParams.cpp
+++ b/dom/animation/TimingParams.cpp
@@ -55,16 +55,20 @@ TimingParamsFromOptionsUnion(const Optio
       TimingParams::ParseDuration(timing.mDuration, aRv);
     if (aRv.Failed()) {
       return result;
     }
     TimingParams::ValidateIterationStart(timing.mIterationStart, aRv);
     if (aRv.Failed()) {
       return result;
     }
+    TimingParams::ValidateIterations(timing.mIterations, aRv);
+    if (aRv.Failed()) {
+      return result;
+    }
 
     result.mDuration = duration;
     result.mDelay = TimeDuration::FromMilliseconds(timing.mDelay);
     result.mEndDelay = TimeDuration::FromMilliseconds(timing.mEndDelay);
     result.mIterations = timing.mIterations;
     result.mIterationStart = timing.mIterationStart;
     result.mDirection = timing.mDirection;
     result.mFill = timing.mFill;
--- a/dom/animation/TimingParams.h
+++ b/dom/animation/TimingParams.h
@@ -67,16 +67,24 @@ struct TimingParams
                                      ErrorResult& aRv)
   {
     if (aIterationStart < 0) {
       aRv.ThrowTypeError<dom::MSG_ENFORCE_RANGE_OUT_OF_RANGE>(
         NS_LITERAL_STRING("iterationStart"));
     }
   }
 
+  static void ValidateIterations(double aIterations, ErrorResult& aRv)
+  {
+    if (IsNaN(aIterations) || aIterations < 0) {
+      aRv.ThrowTypeError<dom::MSG_ENFORCE_RANGE_OUT_OF_RANGE>(
+        NS_LITERAL_STRING("iterations"));
+    }
+  }
+
   // mDuration.isNothing() represents the "auto" value
   Maybe<StickyTimeDuration> mDuration;
   TimeDuration mDelay;      // Initializes to zero
   TimeDuration mEndDelay;
   double mIterations = 1.0; // Can be NaN, negative, +/-Infinity
   double mIterationStart = 0.0;
   dom::PlaybackDirection mDirection = dom::PlaybackDirection::Normal;
   dom::FillMode mFill = dom::FillMode::Auto;
--- a/testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
+++ b/testing/web-platform/tests/web-animations/keyframe-effect/constructor.html
@@ -497,25 +497,16 @@ var gKeyframeEffectOptionTests = [
     input:    { duration: Infinity },
     expected: { duration: Infinity } },
   { desc:     "an auto duration",
     input:    { duration: "auto" },
     expected: { duration: "auto" } },
   { desc:     "an Infinity iterations",
     input:    { iterations: Infinity },
     expected: { iterations: Infinity } },
-  { desc:     "a negative Infinity iterations",
-    input:    { iterations: -Infinity },
-    expected: { iterations: -Infinity } },
-  { desc:     "a NaN iterations",
-    input:    { iterations: NaN },
-    expected: { iterations: NaN } },
-  { desc:     "a negative iterations",
-    input:    { iterations: -1 },
-    expected: { iterations: -1 } },
   { desc:     "an auto fill",
     input:    { fill: "auto" },
     expected: { fill: "auto" } },
   { desc:     "a forwards fill",
     input:    { fill: "forwards" },
     expected: { fill: "forwards" } }
 ];
 
@@ -562,16 +553,25 @@ var gInvalidKeyframeEffectOptionTests = 
   { desc:     "a NaN duration",
     input:    { duration: NaN },
     expected: { name: "TypeError" } },
   { desc:     "a negative duration",
     input:    { duration: -1 },
     expected: { name: "TypeError" } },
   { desc:     "a string duration",
     input:    { duration: "merrychristmas" },
+    expected: { name: "TypeError" } },
+  { desc:     "a negative Infinity iterations",
+    input:    { iterations: -Infinity},
+    expected: { name: "TypeError" } },
+  { desc:     "a NaN iterations",
+    input:    { iterations: NaN },
+    expected: { name: "TypeError" } },
+  { desc:     "a negative iterations",
+    input:    { iterations: -1 },
     expected: { name: "TypeError" } }
 ];
 
 gInvalidKeyframeEffectOptionTests.forEach(function(stest) {
   test(function(t) {
     assert_throws(stest.expected, function() {
       new KeyframeEffectReadOnly(target,
                                  {left: ["10px", "20px"]},
--- a/testing/web-platform/tests/web-animations/keyframe-effect/getComputedTiming.html
+++ b/testing/web-platform/tests/web-animations/keyframe-effect/getComputedTiming.html
@@ -58,25 +58,16 @@ var gGetComputedTimingTests = [
     input:    { duration: Infinity },
     expected: { duration: Infinity } },
   { desc:     "an auto duration",
     input:    { duration: "auto" },
     expected: { duration: 0 } },
   { desc:     "an Infinity iterations",
     input:    { iterations: Infinity },
     expected: { iterations: Infinity } },
-  { desc:     "a negative Infinity iterations",
-    input:    { iterations: -Infinity},
-    expected: { iterations: 1 } },
-  { desc:     "a NaN iterations",
-    input:    { iterations: NaN },
-    expected: { iterations: 1 } },
-  { desc:     "a negative iterations",
-    input:    { iterations: -1 },
-    expected: { iterations: 1 } },
   { desc:     "an auto fill",
     input:    { fill: "auto" },
     expected: { fill: "none" } },
   { desc:     "a forwards fill",
     input:    { fill: "forwards" },
     expected: { fill: "forwards" } }
 ];
 
@@ -148,20 +139,17 @@ var gActiveDurationTests = [
   { desc:     "an infinite duration and fractional iteration count",
     input:    { duration: Infinity, iterations: 2.5 },
     expected: Infinity },
   { desc:     "an infinite duration and infinite iteration count",
     input:    { duration: Infinity, iterations: Infinity },
     expected: Infinity },
   { desc:     "an infinite duration and zero iteration count",
     input:    { duration: Infinity, iterations: 0 },
-    expected: 0 },
-  { desc:     "a non-zero duration and invalid iteration count",
-    input:    { duration: 1000, iterations: "cabbage" },
-    expected: 1000 }
+    expected: 0 }
 ];
 
 gActiveDurationTests.forEach(function(stest) {
   test(function(t) {
     var effect = new KeyframeEffectReadOnly(target,
                                             { left: ["10px", "20px"] },
                                             stest.input);