Changeset 291748 in webkit


Ignore:
Timestamp:
Mar 23, 2022 10:05:16 AM (4 months ago)
Author:
commit-queue@webkit.org
Message:

Context2D drawImage(img, x, y, w, h) should not throw IndexSizeError when width == 0 or height == 0
https://bugs.webkit.org/show_bug.cgi?id=238195

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2022-03-23
Reviewed by Simon Fraser.

Source/WebCore:

When drawing HTMLImageElement with width == 0 or height==0, do nothing as per spec.

When drawing HTMLCanvasElement with source rectangle width == 0 or height == 0,
do nothing as per spec.

Previously these would throw IndexSizeError. The CanvasDrawImage methods do not throw these.

Spec:
HTML Living Standard — Last Updated 17 March 2022
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage

  • html/canvas/CanvasRenderingContext2DBase.cpp:

(WebCore::CanvasRenderingContext2DBase::drawImage):

LayoutTests:

  • fast/canvas/canvas-overloads-drawImage-expected.txt:
  • fast/canvas/canvas-overloads-drawImage.html:
  • fast/canvas/drawImage-with-invalid-args-expected.txt:
  • fast/canvas/drawImage-with-invalid-args.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r291747 r291748  
     12022-03-23  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        Context2D drawImage(img, x, y, w, h) should not throw IndexSizeError when width == 0 or height == 0
     4        https://bugs.webkit.org/show_bug.cgi?id=238195
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/canvas/canvas-overloads-drawImage-expected.txt:
     9        * fast/canvas/canvas-overloads-drawImage.html:
     10        * fast/canvas/drawImage-with-invalid-args-expected.txt:
     11        * fast/canvas/drawImage-with-invalid-args.html:
     12
    1132022-03-23  Tyler Wilcock  <tyler_w@apple.com>
    214
  • trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt

    r219663 r291748  
    1010PASS ctx.drawImage(imageElement, 0, 0, 0) threw exception TypeError: Type error.
    1111PASS ctx.drawImage(imageElement, 0, 0, 0, 0) is undefined
     12PASS ctx.drawImage(imageElement, 0, 0, 700, 677) is undefined
    1213PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    1314PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     
    2425PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    2526PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    26 PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0) threw exception IndexSizeError: The index is not in the allowed range..
    27 PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception IndexSizeError: The index is not in the allowed range..
    28 PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception IndexSizeError: The index is not in the allowed range..
     27PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
     28PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
     29PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
    2930PASS successfullyParsed is true
    3031
  • trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html

    r219663 r291748  
    2020shouldThrow("ctx.drawImage(imageElement, 0, 0, 0)", "TypeError");
    2121shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0)", "undefined");
     22shouldBe("ctx.drawImage(imageElement, 0, 0, 700, 677)", "undefined");
    2223shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0)", "TypeError");
    2324shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0)", "TypeError");
     
    3637shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0)", "TypeError");
    3738shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
    38 shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
    39 shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
    40 shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
     39shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
     40shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
     41shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
    4142</script>
    4243<script src="../../resources/js-test-post.js"></script>
  • trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args-expected.txt

    r95899 r291748  
    99PASS: image argument plus zero size
    1010PASS: image argument plus 8 numbers, zero size
    11 PASS: image argument plus 8 numbers, negative size of source, zero size, got exception as expected
    12 PASS: image argument plus 8 numbers, negative size of destination, zero size, got exception as expected
    13 PASS: image argument plus 8 numbers, negative size of source and destination, zero size, got exception as expected
     11PASS: image argument plus 8 numbers, negative size of source, zero size
     12PASS: image argument plus 8 numbers, negative size of destination, zero size
     13PASS: image argument plus 8 numbers, negative size of source and destination, zero size
    1414PASS: null image, got exception as expected
    1515PASS: null image, got exception as expected
  • trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args.html

    r120683 r291748  
    7373        try{
    7474            ctx.drawImage(myImage, 20, 20, -20, 0, 0, 0, 20, 20);
     75            print("PASS: image argument plus 8 numbers, negative size of source, zero size");
     76        } catch (e) {
    7577            print("FAIL");
    76         } catch (e) {
    77             print("PASS: image argument plus 8 numbers, negative size of source, zero size, got exception as expected");
    7878        }
    7979        try{
    8080            ctx.drawImage(myImage, 0, 0, 20, 0, 20, 20, -20, -20);
     81            print("PASS: image argument plus 8 numbers, negative size of destination, zero size");
     82        } catch (e) {
    8183            print("FAIL");
    82         } catch (e) {
    83             print("PASS: image argument plus 8 numbers, negative size of destination, zero size, got exception as expected");
    8484        }
    8585        try{
    8686            ctx.drawImage(myImage, 20, 20, -20, 0, 20, 20, -20, -20);
     87            print("PASS: image argument plus 8 numbers, negative size of source and destination, zero size");
     88        } catch (e) {
    8789            print("FAIL");
    88         } catch (e) {
    89             print("PASS: image argument plus 8 numbers, negative size of source and destination, zero size, got exception as expected");
    9090        }
    9191        try{
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt

    r262539 r291748  
    55
    66
    7 FAIL drawImage with zero-sized source rectangle draws nothing without exception The index is not in the allowed range.
     7PASS drawImage with zero-sized source rectangle draws nothing without exception
    88
  • trunk/Source/WebCore/ChangeLog

    r291747 r291748  
     12022-03-23  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        Context2D drawImage(img, x, y, w, h) should not throw IndexSizeError when width == 0 or height == 0
     4        https://bugs.webkit.org/show_bug.cgi?id=238195
     5
     6        Reviewed by Simon Fraser.
     7
     8        When drawing HTMLImageElement with width == 0 or height==0, do nothing as per spec.
     9
     10        When drawing HTMLCanvasElement with source rectangle width == 0 or height == 0,
     11        do nothing as per spec.
     12
     13        Previously these would throw IndexSizeError. The CanvasDrawImage methods do not throw these.
     14
     15        Spec:
     16        HTML Living Standard — Last Updated 17 March 2022
     17        https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage
     18
     19        * html/canvas/CanvasRenderingContext2DBase.cpp:
     20        (WebCore::CanvasRenderingContext2DBase::drawImage):
     21
    1222022-03-23  Tyler Wilcock  <tyler_w@apple.com>
    223
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp

    r290839 r291748  
    15011501        return { };
    15021502
     1503    if (!srcRect.width() || !srcRect.height())
     1504        return { };
     1505
    15031506    if (!dstRect.width() || !dstRect.height())
    15041507        return { };
     
    15061509    FloatRect normalizedSrcRect = normalizeRect(srcRect);
    15071510    FloatRect normalizedDstRect = normalizeRect(dstRect);
    1508 
    1509     if (!srcRect.width() || !srcRect.height())
    1510         return Exception { IndexSizeError };
    15111511
    15121512    // When the source rectangle is outside the source image, the source rectangle must be clipped
     
    15831583
    15841584    if (!srcRect.width() || !srcRect.height())
    1585         return Exception { IndexSizeError };
     1585        return { };
    15861586
    15871587    if (!srcCanvasRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
     
    16391639    FloatRect videoRect = FloatRect(FloatPoint(), size(video));
    16401640    if (!srcRect.width() || !srcRect.height())
    1641         return Exception { IndexSizeError };
     1641        return { };
    16421642
    16431643    if (!videoRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
Note: See TracChangeset for help on using the changeset viewer.