Changeset 87734 in webkit


Ignore:
Timestamp:
May 31, 2011 9:22:31 AM (13 years ago)
Author:
andreas.kling@nokia.com
Message:

2011-05-31 Andreas Kling <kling@webkit.org>

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 <kling@webkit.org>

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.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r87733 r87734  
     12011-05-31  Andreas Kling  <kling@webkit.org>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        Canvas/JSC: Auto-generate overloads for drawImage()
     6        https://bugs.webkit.org/show_bug.cgi?id=61703
     7
     8        Add a test to verify the behavior of drawImage() when called with
     9        different numbers of arguments.
     10
     11        * fast/canvas/canvas-overloads-drawImage-expected.txt: Added.
     12        * fast/canvas/canvas-overloads-drawImage.html: Added.
     13        * fast/canvas/script-tests/canvas-overloads-drawImage.js: Added.
     14
    1152011-05-31  Andreas Kling  <kling@webkit.org>
    216
  • trunk/Source/WebCore/ChangeLog

    r87733 r87734  
     12011-05-31  Andreas Kling  <kling@webkit.org>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        Canvas/JSC: Auto-generate overloads for drawImage()
     6        https://bugs.webkit.org/show_bug.cgi?id=61703
     7
     8        Move CanvasRenderingContext2D.drawImage() to auto-generated JSC bindings.
     9
     10        There is a subtle difference to the previous behavior: invalid numbers of
     11        arguments now raise TypeError instead of SyntaxError. This is in accordance
     12        with Web IDL, and matches the existing V8 bindings.
     13
     14        Test: fast/canvas/canvas-overloads-drawImage.html
     15
     16        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
     17        * html/canvas/CanvasRenderingContext2D.idl:
     18
    1192011-05-31  Andreas Kling  <kling@webkit.org>
    220
  • trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp

    r87733 r87734  
    9696}
    9797
    98 JSValue JSCanvasRenderingContext2D::drawImage(ExecState* exec)
    99 {
    100     CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
    101 
    102     // DrawImage has three variants:
    103     //     drawImage(img, dx, dy)
    104     //     drawImage(img, dx, dy, dw, dh)
    105     //     drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh)
    106     // Composite operation is specified with globalCompositeOperation.
    107     // The img parameter can be a <img> or <canvas> element.
    108     JSValue value = exec->argument(0);
    109     if (value.isNull()) {
    110         setDOMException(exec, TYPE_MISMATCH_ERR);
    111         return jsUndefined();
    112     }
    113     if (!value.isObject())
    114         return throwTypeError(exec);
    115 
    116     JSObject* o = asObject(value);
    117     ExceptionCode ec = 0;
    118     if (o->inherits(&JSHTMLImageElement::s_info)) {
    119         HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl());
    120         switch (exec->argumentCount()) {
    121             case 3:
    122                 context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
    123                 break;
    124             case 5:
    125                 context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    126                                    exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
    127                 setDOMException(exec, ec);
    128                 break;
    129             case 9:
    130                 context->drawImage(imgElt, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    131                                    exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
    132                                    FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
    133                                    exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
    134                 setDOMException(exec, ec);
    135                 break;
    136             default:
    137                 return throwSyntaxError(exec);
    138         }
    139     } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
    140         HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl());
    141         switch (exec->argumentCount()) {
    142             case 3:
    143                 context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
    144                 setDOMException(exec, ec);
    145                 break;
    146             case 5:
    147                 context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    148                                    exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
    149                 setDOMException(exec, ec);
    150                 break;
    151             case 9:
    152                 context->drawImage(canvas, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    153                                    exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
    154                                    FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
    155                                    exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
    156                 setDOMException(exec, ec);
    157                 break;
    158             default:
    159                 return throwSyntaxError(exec);
    160         }
    161 #if ENABLE(VIDEO)
    162     } else if (o->inherits(&JSHTMLVideoElement::s_info)) {
    163             HTMLVideoElement* video = static_cast<HTMLVideoElement*>(static_cast<JSHTMLElement*>(o)->impl());
    164             switch (exec->argumentCount()) {
    165                 case 3:
    166                     context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
    167                     break;
    168                 case 5:
    169                     context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    170                                        exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec);
    171                     setDOMException(exec, ec);
    172                     break;
    173                 case 9:
    174                     context->drawImage(video, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    175                                        exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)),
    176                                        FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec),
    177                                        exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec);
    178                     setDOMException(exec, ec);
    179                     break;
    180                 default:
    181                     return throwSyntaxError(exec);
    182         }
    183 #endif
    184     } else
    185         return throwTypeError(exec);
    186 
    187     return jsUndefined();
    188 }
    189 
    19098JSValue JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec)
    19199{
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r87733 r87734  
    115115        void strokeRect(in float x, in float y, in float width, in float height, in [Optional] float lineWidth);
    116116
    117 #if defined(V8_BINDING) && V8_BINDING
    118         void drawImage(in HTMLImageElement image, in float x, in float y)
     117        [RequiresAllArguments=Raise] void drawImage(in HTMLImageElement image, in float x, in float y)
    119118            raises (DOMException);
    120         void drawImage(in HTMLImageElement image, in float x, in float y, in float width, in float height)
     119        [RequiresAllArguments=Raise] void drawImage(in HTMLImageElement image, in float x, in float y, in float width, in float height)
    121120            raises (DOMException);
    122         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)
     121        [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)
    123122            raises (DOMException);
    124         void drawImage(in HTMLCanvasElement canvas, in float x, in float y)
     123        [RequiresAllArguments=Raise] void drawImage(in HTMLCanvasElement canvas, in float x, in float y)
    125124            raises (DOMException);
    126         void drawImage(in HTMLCanvasElement canvas, in float x, in float y, in float width, in float height)
     125        [RequiresAllArguments=Raise] void drawImage(in HTMLCanvasElement canvas, in float x, in float y, in float width, in float height)
    127126            raises (DOMException);
    128         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)
     127        [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)
    129128            raises (DOMException);
    130129#if defined(ENABLE_VIDEO) && ENABLE_VIDEO
    131         void drawImage(in HTMLVideoElement video, in float x, in float y)
     130        [RequiresAllArguments=Raise] void drawImage(in HTMLVideoElement video, in float x, in float y)
    132131            raises (DOMException);
    133         void drawImage(in HTMLVideoElement video, in float x, in float y, in float width, in float height)
     132        [RequiresAllArguments=Raise] void drawImage(in HTMLVideoElement video, in float x, in float y, in float width, in float height)
    134133            raises (DOMException);
    135         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)
     134        [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)
    136135            raises (DOMException);
    137136#endif
     137
     138#if defined(V8_BINDING) && V8_BINDING
    138139        void drawImageFromRect(in HTMLImageElement image,
    139140                               in float sx, in float sy, in float sw, in float sh,
     
    157158#else
    158159        // FIXME: Remove 'else' once JSC supports overloads too.
    159         [Custom] void drawImage(/* 3 */);
    160160        [Custom] void drawImageFromRect(/* 10 */);
    161161        [Custom] void setShadow(/* 3 */);
Note: See TracChangeset for help on using the changeset viewer.