Title: [87734] trunk
Revision
87734
Author
[email protected]
Date
2011-05-31 09:22:31 -0700 (Tue, 31 May 2011)

Log Message

2011-05-31  Andreas Kling  <[email protected]>

        Reviewed by Antti Koivisto.

        Canvas/JSC: Auto-generate overloads for drawImage()
        https://bugs.webkit.org/show_bug.cgi?id=61703

        Move CanvasRenderingContext2D.drawImage() to auto-generated JSC bindings.

        There is a subtle difference to the previous behavior: invalid numbers of
        arguments now raise TypeError instead of SyntaxError. This is in accordance
        with Web IDL, and matches the existing V8 bindings.

        Test: fast/canvas/canvas-overloads-drawImage.html

        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
        * html/canvas/CanvasRenderingContext2D.idl:
2011-05-31  Andreas Kling  <[email protected]>

        Reviewed by Antti Koivisto.

        Canvas/JSC: Auto-generate overloads for drawImage()
        https://bugs.webkit.org/show_bug.cgi?id=61703

        Add a test to verify the behavior of drawImage() when called with
        different numbers of arguments.

        * fast/canvas/canvas-overloads-drawImage-expected.txt: Added.
        * fast/canvas/canvas-overloads-drawImage.html: Added.
        * fast/canvas/script-tests/canvas-overloads-drawImage.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (87733 => 87734)


--- trunk/LayoutTests/ChangeLog	2011-05-31 16:20:32 UTC (rev 87733)
+++ trunk/LayoutTests/ChangeLog	2011-05-31 16:22:31 UTC (rev 87734)
@@ -2,6 +2,20 @@
 
         Reviewed by Antti Koivisto.
 
+        Canvas/JSC: Auto-generate overloads for drawImage()
+        https://bugs.webkit.org/show_bug.cgi?id=61703
+
+        Add a test to verify the behavior of drawImage() when called with
+        different numbers of arguments.
+
+        * fast/canvas/canvas-overloads-drawImage-expected.txt: Added.
+        * fast/canvas/canvas-overloads-drawImage.html: Added.
+        * fast/canvas/script-tests/canvas-overloads-drawImage.js: Added.
+
+2011-05-31  Andreas Kling  <[email protected]>
+
+        Reviewed by Antti Koivisto.
+
         Canvas/JSC: Auto-generate overloads for strokeRect()
         https://bugs.webkit.org/show_bug.cgi?id=61641
 

Added: trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt (0 => 87734)


--- trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt	2011-05-31 16:22:31 UTC (rev 87734)
@@ -0,0 +1,32 @@
+Test the behavior of CanvasRenderingContext2D.drawImage() when called with different numbers of arguments.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS ctx.drawImage() threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0) is undefined
+PASS ctx.drawImage(imageElement, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0) is undefined
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0) is undefined
+PASS ctx.drawImage(canvasElement, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0) is undefined
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html (0 => 87734)


--- trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html	2011-05-31 16:22:31 UTC (rev 87734)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-drawImage.js (0 => 87734)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-drawImage.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-drawImage.js	2011-05-31 16:22:31 UTC (rev 87734)
@@ -0,0 +1,34 @@
+description("Test the behavior of CanvasRenderingContext2D.drawImage() when called with different numbers of arguments.");
+
+var ctx = document.createElement('canvas').getContext('2d');
+
+var TypeError = "TypeError: Type error";
+
+var imageElement = document.createElement("img");
+shouldThrow("ctx.drawImage()", "TypeError");
+shouldThrow("ctx.drawImage(imageElement)", "TypeError");
+shouldThrow("ctx.drawImage(imageElement, 0)", "TypeError");
+shouldBe("ctx.drawImage(imageElement, 0, 0)", "undefined");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0)", "TypeError");
+shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0)", "undefined");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+
+var canvasElement = document.createElement("canvas");
+shouldThrow("ctx.drawImage(canvasElement)", "TypeError");
+shouldThrow("ctx.drawImage(canvasElement, 0)", "TypeError");
+shouldBe("ctx.drawImage(canvasElement, 0, 0)", "undefined");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0)", "TypeError");
+shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0)", "undefined");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "'Error: INDEX_SIZE_ERR: DOM Exception 1'");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
+
+var successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (87733 => 87734)


--- trunk/Source/WebCore/ChangeLog	2011-05-31 16:20:32 UTC (rev 87733)
+++ trunk/Source/WebCore/ChangeLog	2011-05-31 16:22:31 UTC (rev 87734)
@@ -2,6 +2,24 @@
 
         Reviewed by Antti Koivisto.
 
+        Canvas/JSC: Auto-generate overloads for drawImage()
+        https://bugs.webkit.org/show_bug.cgi?id=61703
+
+        Move CanvasRenderingContext2D.drawImage() to auto-generated JSC bindings.
+
+        There is a subtle difference to the previous behavior: invalid numbers of
+        arguments now raise TypeError instead of SyntaxError. This is in accordance
+        with Web IDL, and matches the existing V8 bindings.
+
+        Test: fast/canvas/canvas-overloads-drawImage.html
+
+        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
+        * html/canvas/CanvasRenderingContext2D.idl:
+
+2011-05-31  Andreas Kling  <[email protected]>
+
+        Reviewed by Antti Koivisto.
+
         Canvas/JSC: Auto-generate overloads for strokeRect()
         https://bugs.webkit.org/show_bug.cgi?id=61641
 

Modified: trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp (87733 => 87734)


--- trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2011-05-31 16:20:32 UTC (rev 87733)
+++ trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2011-05-31 16:22:31 UTC (rev 87734)
@@ -95,98 +95,6 @@
     context->setFillStyle(toHTMLCanvasStyle(exec, value));
 }
 
-JSValue JSCanvasRenderingContext2D::drawImage(ExecState* exec)
-{ 
-    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
-
-    // DrawImage has three variants:
-    //     drawImage(img, dx, dy)
-    //     drawImage(img, dx, dy, dw, dh)
-    //     drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh)
-    // Composite operation is specified with globalCompositeOperation.
-    // The img parameter can be a <img> or <canvas> element.
-    JSValue value = exec->argument(0);
-    if (value.isNull()) {
-        setDOMException(exec, TYPE_MISMATCH_ERR);
-        return jsUndefined();
-    }
-    if (!value.isObject())
-        return throwTypeError(exec);
-
-    JSObject* o = asObject(value);
-    ExceptionCode ec = 0;
-    if (o->inherits(&JSHTMLImageElement::s_info)) {
-        HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        switch (exec->argumentCount()) {
-            case 3:
-                context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
-                break;
-            case 5:
-                context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                   exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
-                setDOMException(exec, ec);
-                break;
-            case 9:
-                context->drawImage(imgElt, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                   exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
-                                   FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
-                                   exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
-                setDOMException(exec, ec);
-                break;
-            default:
-                return throwSyntaxError(exec);
-        }
-    } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
-        HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        switch (exec->argumentCount()) {
-            case 3:
-                context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
-                setDOMException(exec, ec);
-                break;
-            case 5:
-                context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                   exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
-                setDOMException(exec, ec);
-                break;
-            case 9:
-                context->drawImage(canvas, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                   exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
-                                   FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
-                                   exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
-                setDOMException(exec, ec);
-                break;
-            default:
-                return throwSyntaxError(exec);
-        }
-#if ENABLE(VIDEO)
-    } else if (o->inherits(&JSHTMLVideoElement::s_info)) {
-            HTMLVideoElement* video = static_cast<HTMLVideoElement*>(static_cast<JSHTMLElement*>(o)->impl());
-            switch (exec->argumentCount()) {
-                case 3:
-                    context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
-                    break;
-                case 5:
-                    context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                       exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
-                    setDOMException(exec, ec);
-                    break;
-                case 9:
-                    context->drawImage(video, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
-                                       exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
-                                       FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
-                                       exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
-                    setDOMException(exec, ec);
-                    break;
-                default:
-                    return throwSyntaxError(exec);
-        }
-#endif
-    } else
-        return throwTypeError(exec);
-
-    return jsUndefined();
-}
-
 JSValue JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec)
 { 
     CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (87733 => 87734)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2011-05-31 16:20:32 UTC (rev 87733)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2011-05-31 16:22:31 UTC (rev 87734)
@@ -114,27 +114,28 @@
 
         void strokeRect(in float x, in float y, in float width, in float height, in [Optional] float lineWidth);
 
-#if defined(V8_BINDING) && V8_BINDING
-        void drawImage(in HTMLImageElement image, in float x, in float y)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLImageElement image, in float x, in float y)
             raises (DOMException);
-        void drawImage(in HTMLImageElement image, in float x, in float y, in float width, in float height)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLImageElement image, in float x, in float y, in float width, in float height)
             raises (DOMException);
-        void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
             raises (DOMException);
-        void drawImage(in HTMLCanvasElement canvas, in float x, in float y)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLCanvasElement canvas, in float x, in float y)
             raises (DOMException);
-        void drawImage(in HTMLCanvasElement canvas, in float x, in float y, in float width, in float height)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLCanvasElement canvas, in float x, in float y, in float width, in float height)
             raises (DOMException);
-        void drawImage(in HTMLCanvasElement canvas, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLCanvasElement canvas, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
             raises (DOMException);
 #if defined(ENABLE_VIDEO) && ENABLE_VIDEO
-        void drawImage(in HTMLVideoElement video, in float x, in float y)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLVideoElement video, in float x, in float y)
             raises (DOMException);
-        void drawImage(in HTMLVideoElement video, in float x, in float y, in float width, in float height)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLVideoElement video, in float x, in float y, in float width, in float height)
             raises (DOMException);
-        void drawImage(in HTMLVideoElement video, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
+        [RequiresAllArguments=Raise] void drawImage(in HTMLVideoElement video, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
             raises (DOMException);
 #endif
+
+#if defined(V8_BINDING) && V8_BINDING
         void drawImageFromRect(in HTMLImageElement image,
                                in float sx, in float sy, in float sw, in float sh,
                                in float dx, in float dy, in float dw, in float dh, in DOMString compositeOperation);
@@ -156,7 +157,6 @@
             raises (DOMException);
 #else
         // FIXME: Remove 'else' once JSC supports overloads too.
-        [Custom] void drawImage(/* 3 */);
         [Custom] void drawImageFromRect(/* 10 */);
         [Custom] void setShadow(/* 3 */);
         [Custom] void createPattern(/* 2 */);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to