Title: [270126] trunk
Revision
270126
Author
[email protected]
Date
2020-11-20 11:58:40 -0800 (Fri, 20 Nov 2020)

Log Message

canvas: drawImage should not raise IndexSizeError on empty sources
https://bugs.webkit.org/show_bug.cgi?id=219068

Reviewed by Noam Rosenthal.

Source/WebCore:

Per 4.12.5.1.14 Drawing images[1] point 5, if the src rect has one of the dimensions zero, return silently.

[1] https://html.spec.whatwg.org/multipage/canvas.html#drawing-images

Covered by existing tests and fixes WPT offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource flakiness

* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::drawImage): Return early instead of raising an exception if the rect is empty.

LayoutTests:

Update baselines and tests with new drawImage behavior of not raising IndexSizeError on empty src rects.

* http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap-expected.txt: Updated with new drawImage behavior
* http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap.html:  Updated with new drawImage behavior
* platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt: Renamed from LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt.
* platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (270125 => 270126)


--- trunk/LayoutTests/ChangeLog	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/LayoutTests/ChangeLog	2020-11-20 19:58:40 UTC (rev 270126)
@@ -1,3 +1,17 @@
+2020-11-20  Lauro Moura  <[email protected]>
+
+        canvas: drawImage should not raise IndexSizeError on empty sources
+        https://bugs.webkit.org/show_bug.cgi?id=219068
+
+        Reviewed by Noam Rosenthal.
+
+        Update baselines and tests with new drawImage behavior of not raising IndexSizeError on empty src rects.
+
+        * http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap-expected.txt: Updated with new drawImage behavior
+        * http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap.html:  Updated with new drawImage behavior
+        * platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt: Renamed from LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt.
+        * platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt: Removed.
+
 2020-11-20  Truitt Savell  <[email protected]>
 
         http/tests/security/contentSecurityPolicy/1.1/plugintypes-affects-child.html is flaky failing

Modified: trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap-expected.txt (270125 => 270126)


--- trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap-expected.txt	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap-expected.txt	2020-11-20 19:58:40 UTC (rev 270126)
@@ -5,5 +5,5 @@
 PASS drawImage of ImageBitmap from HTMLImageElement with cropping and different origin
 PASS drawImage of ImageBitmap from HTMLImageElement with cropping and different non-zero origin
 PASS drawImage throws with InvalidStateError if the ImageBitmap is closed
-PASS drawImage throws with IndexSizeError if the source rectangle of the ImageBitmap is empty
+PASS drawImage does not draw if the source rectangle of the ImageBitmap is empty
 

Modified: trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap.html (270125 => 270126)


--- trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap.html	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/LayoutTests/http/wpt/2dcontext/imagebitmap/drawImage-ImageBitmap.html	2020-11-20 19:58:40 UTC (rev 270126)
@@ -134,11 +134,12 @@
             return createImageBitmap(img);
         }).then(function(imageBitmap) {
             let [canvas, ctx] = create9x9CanvasWith2dContext();
-            assert_throws_dom("IndexSizeError", function () {
-                ctx.drawImage(imageBitmap, 0, 0, 0, 0, 0, 0, 9, 9);
-            }, "drawImage with an empty source rectangle should fail.");
+            ctx.drawImage(imageBitmap, 0, 0, 0, 0, 0, 0, 9, 9);
+            _assertPixel(canvas, 0,0, 0,0,0,0, "8,8", "0,0,0,0");
+            _assertPixel(canvas, 4,4, 0,0,0,0, "8,8", "0,0,0,0");
+            _assertPixel(canvas, 8,8, 0,0,0,0, "8,8", "0,0,0,0");
         });
-    }, "drawImage throws with IndexSizeError if the source rectangle of the ImageBitmap is empty");
+    }, "drawImage does not draw if the source rectangle of the ImageBitmap is empty");
 })();
 </script>
 </body>

Copied: trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt (from rev 270125, trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt) (0 => 270126)


--- trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	2020-11-20 19:58:40 UTC (rev 270126)
@@ -0,0 +1,7 @@
+2d.drawImage.zerosource
+
+drawImage with zero-sized source rectangle draws nothing without exception
+
+
+PASS drawImage with zero-sized source rectangle draws nothing without exception
+

Deleted: trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt (270125 => 270126)


--- trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	2020-11-20 19:58:40 UTC (rev 270126)
@@ -1,8 +0,0 @@
-CONSOLE MESSAGE: Unhandled Promise Rejection: IndexSizeError: The index is not in the allowed range.
-2d.drawImage.zerosource
-
-drawImage with zero-sized source rectangle draws nothing without exception
-
-
-PASS drawImage with zero-sized source rectangle draws nothing without exception
-

Deleted: trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt (270125 => 270126)


--- trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt	2020-11-20 19:58:40 UTC (rev 270126)
@@ -1,7 +0,0 @@
-2d.drawImage.zerosource
-
-drawImage with zero-sized source rectangle draws nothing without exception
-
-
-PASS drawImage with zero-sized source rectangle draws nothing without exception
-

Modified: trunk/Source/WebCore/ChangeLog (270125 => 270126)


--- trunk/Source/WebCore/ChangeLog	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/Source/WebCore/ChangeLog	2020-11-20 19:58:40 UTC (rev 270126)
@@ -1,3 +1,19 @@
+2020-11-20  Lauro Moura  <[email protected]>
+
+        canvas: drawImage should not raise IndexSizeError on empty sources
+        https://bugs.webkit.org/show_bug.cgi?id=219068
+
+        Reviewed by Noam Rosenthal.
+
+        Per 4.12.5.1.14 Drawing images[1] point 5, if the src rect has one of the dimensions zero, return silently.
+
+        [1] https://html.spec.whatwg.org/multipage/canvas.html#drawing-images
+
+        Covered by existing tests and fixes WPT offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource flakiness
+
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::drawImage): Return early instead of raising an exception if the rect is empty.
+
 2020-11-20  Simon Fraser  <[email protected]>
 
         Rename some wheel-event handling functions for clarity

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (270125 => 270126)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2020-11-20 19:37:33 UTC (rev 270125)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2020-11-20 19:58:40 UTC (rev 270126)
@@ -1665,8 +1665,8 @@
     if (!imageBitmap.width() || !imageBitmap.height())
         return Exception { InvalidStateError };
 
-    if (!srcRect.width() || !srcRect.height())
-        return Exception { IndexSizeError };
+    if (srcRect.isEmpty())
+        return { };
 
     FloatRect srcBitmapRect = FloatRect(FloatPoint(), FloatSize(imageBitmap.width(), imageBitmap.height()));
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to