Bug 630029 - Throw INDEX_SIZE_ERR instead of SYNTAX_ERR when calling CanvasGradient.addColorStop with non-finite values; r=?sicking
authorMs2ger <ms2ger@gmail.com>
Sat, 02 Apr 2011 20:50:14 +0200
changeset 67714 06be56cbd4f067a48e7f1eb14b5610d5e36e4366
parent 67713 4cadb299e5efac8841181a6547abd4f11cc0e66b
child 67715 6ff088b689a3261ffe4810ff03e98ae7eda4cbb0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs630029
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 630029 - Throw INDEX_SIZE_ERR instead of SYNTAX_ERR when calling CanvasGradient.addColorStop with non-finite values; r=?sicking
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/canvas/test/test_canvas.html
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -215,24 +215,20 @@ public:
     gfxPattern* GetPattern() {
         return mPattern;
     }
 
     /* nsIDOMCanvasGradient */
     NS_IMETHOD AddColorStop (float offset,
                              const nsAString& colorstr)
     {
+        if (!FloatValidate(offset) || offset < 0.0 || offset > 1.0)
+            return NS_ERROR_DOM_INDEX_SIZE_ERR;
+
         nscolor color;
-
-        if (!FloatValidate(offset))
-            return NS_ERROR_DOM_SYNTAX_ERR;
-
-        if (offset < 0.0 || offset > 1.0)
-            return NS_ERROR_DOM_INDEX_SIZE_ERR;
-
         nsCSSParser parser;
         nsresult rv = parser.ParseColorString(nsString(colorstr),
                                               nsnull, 0, &color);
         if (NS_FAILED(rv))
             return NS_ERROR_DOM_SYNTAX_ERR;
 
         mPattern->AddColorStop(offset, gfxRGBA(color));
 
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -6103,23 +6103,23 @@ var g = ctx.createLinearGradient(0, 0, 1
 var _thrown = undefined; try {
   g.addColorStop(-1, '#000');
 } catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
 var _thrown = undefined; try {
   g.addColorStop(2, '#000');
 } catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
 var _thrown = undefined; try {
   g.addColorStop(Infinity, '#000');
-} catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
+} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
 var _thrown = undefined; try {
   g.addColorStop(-Infinity, '#000');
-} catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
+} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
 var _thrown = undefined; try {
   g.addColorStop(NaN, '#000');
-} catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
+} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR");
 
 
 }
 </script>
 
 <!-- [[[ test_2d.gradient.object.return.html ]]] -->
 
 <p>Canvas test: 2d.gradient.object.return</p>