Changeset 201664 in webkit


Ignore:
Timestamp:
Jun 3, 2016 3:26:50 PM (8 years ago)
Author:
Chris Dumez
Message:

CanvasRenderingContext2D.createPattern() / putImageData() throw wrong exception type
https://bugs.webkit.org/show_bug.cgi?id=158322

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline test now that it is passing.

  • canvas/2d.pattern.image.undefined-expected.txt:

Source/WebCore:

CanvasRenderingContext2D.createPattern() / putImageData() were throwing the wrong
exception type when the first parameter was null. It should throw a TypeError
but it was throwing a legacy TYPE_MISMATCH_ERR:

This patch aligns our behavior with the specification.

No new tests, covered by existing tests.

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::createPattern):
(WebCore::CanvasRenderingContext2D::putImageData):
(WebCore::CanvasRenderingContext2D::webkitPutImageDataHD):
(WebCore::CanvasRenderingContext2D::didDraw): Deleted.
(WebCore::CanvasRenderingContext2D::drawFocusIfNeeded): Deleted.
(WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal): Deleted.
(WebCore::CanvasRenderingContext2D::font): Deleted.

  • html/canvas/CanvasRenderingContext2D.h:
  • html/canvas/CanvasRenderingContext2D.idl:

LayoutTests:

Update several outdated layout tests.

  • canvas/philip/tests/2d.imageData.put.null.html:
  • canvas/philip/tests/2d.pattern.image.null.html:
  • canvas/philip/tests/2d.pattern.image.undefined.html:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201662 r201664  
     12016-06-03  Chris Dumez  <cdumez@apple.com>
     2
     3        CanvasRenderingContext2D.createPattern() / putImageData() throw wrong exception type
     4        https://bugs.webkit.org/show_bug.cgi?id=158322
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Update several outdated layout tests.
     9
     10        * canvas/philip/tests/2d.imageData.put.null.html:
     11        * canvas/philip/tests/2d.pattern.image.null.html:
     12        * canvas/philip/tests/2d.pattern.image.undefined.html:
     13
    1142016-06-03  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/canvas/philip/tests/2d.imageData.put.null.html

    r134440 r201664  
    1515try { var _thrown = false;
    1616  ctx.putImageData(null, 0, 0);
    17 } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) _fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TYPE_MISMATCH_ERR: ctx.putImageData(null, 0, 0)"); }
     17} catch (e) { if (e.name != "TypeError") _fail("Failed assertion: expected exception of type TypeError, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TypeError: ctx.putImageData(null, 0, 0)"); }
    1818
    1919
  • trunk/LayoutTests/canvas/philip/tests/2d.pattern.image.null.html

    r134440 r201664  
    1515try { var _thrown = false;
    1616  ctx.createPattern(null, 'repeat');
    17 } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) _fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TYPE_MISMATCH_ERR: ctx.createPattern(null, 'repeat')"); }
     17} catch (e) { if (e.name != "TypeError") _fail("Failed assertion: expected exception of type TypeError, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TypeError: ctx.createPattern(null, 'repeat')"); }
    1818
    1919
  • trunk/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined.html

    r71481 r201664  
    1515try { var _thrown = false;
    1616  ctx.createPattern(undefined, 'repeat');
    17 } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) _fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TYPE_MISMATCH_ERR: ctx.createPattern(undefined, 'repeat')"); }
     17} catch (e) { if (e.name != "TypeError") _fail("Failed assertion: expected exception of type TypeError, got: "+e.message); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TypeError: ctx.createPattern(undefined, 'repeat')"); }
    1818
    1919
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r201627 r201664  
     12016-06-03  Chris Dumez  <cdumez@apple.com>
     2
     3        CanvasRenderingContext2D.createPattern() / putImageData() throw wrong exception type
     4        https://bugs.webkit.org/show_bug.cgi?id=158322
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Rebaseline test now that it is passing.
     9
     10        * canvas/2d.pattern.image.undefined-expected.txt:
     11
    1122016-06-02  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/canvas/2d.pattern.image.undefined-expected.txt

    r201627 r201664  
    33Defined in "Web IDL" (draft)
    44Actual output:
    5 Failed assertion: expected exception of type TypeError, got: Error: TypeMismatchError: DOM Exception 17
     5Passed
  • trunk/Source/WebCore/ChangeLog

    r201663 r201664  
     12016-06-03  Chris Dumez  <cdumez@apple.com>
     2
     3        CanvasRenderingContext2D.createPattern() / putImageData() throw wrong exception type
     4        https://bugs.webkit.org/show_bug.cgi?id=158322
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        CanvasRenderingContext2D.createPattern() / putImageData() were throwing the wrong
     9        exception type when the first parameter was null. It should throw a TypeError
     10        but it was throwing a legacy TYPE_MISMATCH_ERR:
     11        - http://www.w3.org/TR/2dcontext/#canvasrenderingcontext2d
     12        - http://www.w3.org/TR/2dcontext/#canvasimagesource
     13
     14        This patch aligns our behavior with the specification.
     15
     16        No new tests, covered by existing tests.
     17
     18        * html/canvas/CanvasRenderingContext2D.cpp:
     19        (WebCore::CanvasRenderingContext2D::createPattern):
     20        (WebCore::CanvasRenderingContext2D::putImageData):
     21        (WebCore::CanvasRenderingContext2D::webkitPutImageDataHD):
     22        (WebCore::CanvasRenderingContext2D::didDraw): Deleted.
     23        (WebCore::CanvasRenderingContext2D::drawFocusIfNeeded): Deleted.
     24        (WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal): Deleted.
     25        (WebCore::CanvasRenderingContext2D::font): Deleted.
     26        * html/canvas/CanvasRenderingContext2D.h:
     27        * html/canvas/CanvasRenderingContext2D.idl:
     28
    1292016-06-03  Anders Carlsson  <andersca@apple.com>
    230
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r201629 r201664  
    17451745}
    17461746
    1747 RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement* imageElement,
     1747RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement& imageElement,
    17481748    const String& repetitionType, ExceptionCode& ec)
    17491749{
    1750     if (!imageElement) {
    1751         ec = TYPE_MISMATCH_ERR;
    1752         return nullptr;
    1753     }
    17541750    bool repeatX, repeatY;
    17551751    ec = 0;
     
    17581754        return nullptr;
    17591755
    1760     CachedImage* cachedImage = imageElement->cachedImage();
     1756    CachedImage* cachedImage = imageElement.cachedImage();
    17611757    // If the image loading hasn't started or the image is not complete, it is not fully decodable.
    1762     if (!cachedImage || !imageElement->complete())
     1758    if (!cachedImage || !imageElement.complete())
    17631759        return nullptr;
    17641760
     
    17681764    }
    17691765
    1770     if (!imageElement->cachedImage()->imageForRenderer(imageElement->renderer()))
     1766    if (!imageElement.cachedImage()->imageForRenderer(imageElement.renderer()))
    17711767        return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true);
    17721768
     
    17821778        originClean = false;
    17831779
    1784     return CanvasPattern::create(cachedImage->imageForRenderer(imageElement->renderer()), repeatX, repeatY, originClean);
    1785 }
    1786 
    1787 RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElement* canvas,
     1780    return CanvasPattern::create(cachedImage->imageForRenderer(imageElement.renderer()), repeatX, repeatY, originClean);
     1781}
     1782
     1783RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElement& canvas,
    17881784    const String& repetitionType, ExceptionCode& ec)
    17891785{
    1790     if (!canvas) {
    1791         ec = TYPE_MISMATCH_ERR;
    1792         return nullptr;
    1793     }
    1794     if (!canvas->width() || !canvas->height() || !canvas->buffer()) {
     1786    if (!canvas.width() || !canvas.height() || !canvas.buffer()) {
    17951787        ec = INVALID_STATE_ERR;
    17961788        return nullptr;
     
    18021794    if (ec)
    18031795        return nullptr;
    1804     return CanvasPattern::create(canvas->copiedImage(), repeatX, repeatY, canvas->originClean());
     1796    return CanvasPattern::create(canvas.copiedImage(), repeatX, repeatY, canvas.originClean());
    18051797}
    18061798
     
    20172009}
    20182010
    2019 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, ExceptionCode& ec)
    2020 {
    2021     if (!data) {
    2022         ec = TYPE_MISMATCH_ERR;
    2023         return;
    2024     }
    2025     putImageData(data, dx, dy, 0, 0, data->width(), data->height(), ec);
    2026 }
    2027 
    2028 void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData* data, float dx, float dy, ExceptionCode& ec)
    2029 {
    2030     if (!data) {
    2031         ec = TYPE_MISMATCH_ERR;
    2032         return;
    2033     }
    2034     webkitPutImageDataHD(data, dx, dy, 0, 0, data->width(), data->height(), ec);
    2035 }
    2036 
    2037 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, float dirtyX, float dirtyY,
     2011void CanvasRenderingContext2D::putImageData(ImageData& data, float dx, float dy, ExceptionCode& ec)
     2012{
     2013    putImageData(data, dx, dy, 0, 0, data.width(), data.height(), ec);
     2014}
     2015
     2016void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData& data, float dx, float dy, ExceptionCode& ec)
     2017{
     2018    webkitPutImageDataHD(data, dx, dy, 0, 0, data.width(), data.height(), ec);
     2019}
     2020
     2021void CanvasRenderingContext2D::putImageData(ImageData& data, float dx, float dy, float dirtyX, float dirtyY,
    20382022                                            float dirtyWidth, float dirtyHeight, ExceptionCode& ec)
    20392023{
     
    20412025}
    20422026
    2043 void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData* data, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode& ec)
     2027void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData& data, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode& ec)
    20442028{
    20452029    putImageData(data, ImageBuffer::BackingStoreCoordinateSystem, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, ec);
     
    20672051}
    20682052
    2069 void CanvasRenderingContext2D::putImageData(ImageData* data, ImageBuffer::CoordinateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY,
     2053void CanvasRenderingContext2D::putImageData(ImageData& data, ImageBuffer::CoordinateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY,
    20702054                                            float dirtyWidth, float dirtyHeight, ExceptionCode& ec)
    20712055{
    2072     if (!data) {
    2073         ec = TYPE_MISMATCH_ERR;
    2074         return;
    2075     }
    20762056    if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dirtyX) || !std::isfinite(dirtyY) || !std::isfinite(dirtyWidth) || !std::isfinite(dirtyHeight)) {
    20772057        ec = NOT_SUPPORTED_ERR;
     
    20942074
    20952075    FloatRect clipRect(dirtyX, dirtyY, dirtyWidth, dirtyHeight);
    2096     clipRect.intersect(IntRect(0, 0, data->width(), data->height()));
     2076    clipRect.intersect(IntRect(0, 0, data.width(), data.height()));
    20972077    IntSize destOffset(static_cast<int>(dx), static_cast<int>(dy));
    20982078    IntRect destRect = enclosingIntRect(clipRect);
     
    21042084    sourceRect.move(-destOffset);
    21052085
    2106     buffer->putByteArray(Unmultiplied, data->data(), IntSize(data->width(), data->height()), sourceRect, IntPoint(destOffset), coordinateSystem);
     2086    buffer->putByteArray(Unmultiplied, data.data(), IntSize(data.width(), data.height()), sourceRect, IntPoint(destOffset), coordinateSystem);
    21072087
    21082088    didDraw(destRect, CanvasDidDrawApplyNone); // ignore transform, shadow and clip
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r200361 r201664  
    181181    RefPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1, ExceptionCode&);
    182182    RefPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode&);
    183     RefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&);
    184     RefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&);
     183    RefPtr<CanvasPattern> createPattern(HTMLImageElement&, const String& repetitionType, ExceptionCode&);
     184    RefPtr<CanvasPattern> createPattern(HTMLCanvasElement&, const String& repetitionType, ExceptionCode&);
    185185
    186186    RefPtr<ImageData> createImageData(RefPtr<ImageData>&&, ExceptionCode&) const;
     
    188188    RefPtr<ImageData> getImageData(float sx, float sy, float sw, float sh, ExceptionCode&) const;
    189189    RefPtr<ImageData> webkitGetImageDataHD(float sx, float sy, float sw, float sh, ExceptionCode&) const;
    190     void putImageData(ImageData*, float dx, float dy, ExceptionCode&);
    191     void putImageData(ImageData*, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
    192     void webkitPutImageDataHD(ImageData*, float dx, float dy, ExceptionCode&);
    193     void webkitPutImageDataHD(ImageData*, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
     190    void putImageData(ImageData&, float dx, float dy, ExceptionCode&);
     191    void putImageData(ImageData&, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
     192    void webkitPutImageDataHD(ImageData&, float dx, float dy, ExceptionCode&);
     193    void webkitPutImageDataHD(ImageData&, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
    194194
    195195    void drawFocusIfNeeded(Element*);
     
    371371
    372372    RefPtr<ImageData> getImageData(ImageBuffer::CoordinateSystem, float sx, float sy, float sw, float sh, ExceptionCode&) const;
    373     void putImageData(ImageData*, ImageBuffer::CoordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
     373    void putImageData(ImageData&, ImageBuffer::CoordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
    374374
    375375    bool is2d() const override { return true; }
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r200058 r201664  
    170170        unrestricted float y, unrestricted float k, unrestricted float a);
    171171
    172     [RaisesException] void putImageData(ImageData? imagedata, float dx, float dy);
    173     [RaisesException] void putImageData(ImageData? imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
    174 
    175     [RaisesException] void webkitPutImageDataHD(ImageData? imagedata, float dx, float dy);
    176     [RaisesException] void webkitPutImageDataHD(ImageData? imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
    177 
    178     [RaisesException] CanvasPattern createPattern(HTMLCanvasElement? canvas, [TreatNullAs=EmptyString] DOMString repetitionType);
    179     [RaisesException] CanvasPattern createPattern(HTMLImageElement? image, [TreatNullAs=EmptyString] DOMString repetitionType);
     172    [RaisesException] void putImageData(ImageData imagedata, float dx, float dy);
     173    [RaisesException] void putImageData(ImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
     174
     175    [RaisesException] void webkitPutImageDataHD(ImageData imagedata, float dx, float dy);
     176    [RaisesException] void webkitPutImageDataHD(ImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
     177
     178    [RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, [TreatNullAs=EmptyString] DOMString repetitionType);
     179    [RaisesException] CanvasPattern createPattern(HTMLImageElement image, [TreatNullAs=EmptyString] DOMString repetitionType);
    180180    [RaisesException] ImageData createImageData(ImageData? imagedata);
    181181    [RaisesException] ImageData createImageData(float sw, float sh);
Note: See TracChangeset for help on using the changeset viewer.