Diff
Modified: trunk/LayoutTests/ChangeLog (291747 => 291748)
--- trunk/LayoutTests/ChangeLog 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/ChangeLog 2022-03-23 17:05:16 UTC (rev 291748)
@@ -1,3 +1,15 @@
+2022-03-23 Kimmo Kinnunen <[email protected]>
+
+ 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
+
+ Reviewed by Simon Fraser.
+
+ * 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:
+
2022-03-23 Tyler Wilcock <[email protected]>
AccessibilityRenderObject::nextSibling should allow parent differences in the presence of display: contents
Modified: trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt (291747 => 291748)
--- trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt 2022-03-23 17:05:16 UTC (rev 291748)
@@ -9,6 +9,7 @@
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, 700, 677) 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.
@@ -23,9 +24,9 @@
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 IndexSizeError: The index is not in the allowed range..
-PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception IndexSizeError: The index is not in the allowed range..
-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..
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
+PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html (291747 => 291748)
--- trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage.html 2022-03-23 17:05:16 UTC (rev 291748)
@@ -19,6 +19,7 @@
shouldBe("ctx.drawImage(imageElement, 0, 0)", "undefined");
shouldThrow("ctx.drawImage(imageElement, 0, 0, 0)", "TypeError");
shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0)", "undefined");
+shouldBe("ctx.drawImage(imageElement, 0, 0, 700, 677)", "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");
@@ -35,9 +36,9 @@
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");
-shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
-shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
-shouldThrowErrorName("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "IndexSizeError");
+shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
+shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
+shouldBe("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
</script>
<script src=""
</body>
Modified: trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args-expected.txt (291747 => 291748)
--- trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args-expected.txt 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args-expected.txt 2022-03-23 17:05:16 UTC (rev 291748)
@@ -8,9 +8,9 @@
PASS: image argument plus 8 numbers
PASS: image argument plus zero size
PASS: image argument plus 8 numbers, zero size
-PASS: image argument plus 8 numbers, negative size of source, zero size, got exception as expected
-PASS: image argument plus 8 numbers, negative size of destination, zero size, got exception as expected
-PASS: image argument plus 8 numbers, negative size of source and destination, zero size, got exception as expected
+PASS: image argument plus 8 numbers, negative size of source, zero size
+PASS: image argument plus 8 numbers, negative size of destination, zero size
+PASS: image argument plus 8 numbers, negative size of source and destination, zero size
PASS: null image, got exception as expected
PASS: null image, got exception as expected
PASS: null image, got exception as expected
Modified: trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args.html (291747 => 291748)
--- trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args.html 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/fast/canvas/drawImage-with-invalid-args.html 2022-03-23 17:05:16 UTC (rev 291748)
@@ -72,21 +72,21 @@
}
try{
ctx.drawImage(myImage, 20, 20, -20, 0, 0, 0, 20, 20);
+ print("PASS: image argument plus 8 numbers, negative size of source, zero size");
+ } catch (e) {
print("FAIL");
- } catch (e) {
- print("PASS: image argument plus 8 numbers, negative size of source, zero size, got exception as expected");
}
try{
ctx.drawImage(myImage, 0, 0, 20, 0, 20, 20, -20, -20);
+ print("PASS: image argument plus 8 numbers, negative size of destination, zero size");
+ } catch (e) {
print("FAIL");
- } catch (e) {
- print("PASS: image argument plus 8 numbers, negative size of destination, zero size, got exception as expected");
}
try{
ctx.drawImage(myImage, 20, 20, -20, 0, 20, 20, -20, -20);
+ print("PASS: image argument plus 8 numbers, negative size of source and destination, zero size");
+ } catch (e) {
print("FAIL");
- } catch (e) {
- print("PASS: image argument plus 8 numbers, negative size of source and destination, zero size, got exception as expected");
}
try{
ctx.drawImage(null);
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt (291747 => 291748)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.zerosource-expected.txt 2022-03-23 17:05:16 UTC (rev 291748)
@@ -4,5 +4,5 @@
Expected output:
-FAIL drawImage with zero-sized source rectangle draws nothing without exception The index is not in the allowed range.
+PASS drawImage with zero-sized source rectangle draws nothing without exception
Modified: trunk/Source/WebCore/ChangeLog (291747 => 291748)
--- trunk/Source/WebCore/ChangeLog 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/Source/WebCore/ChangeLog 2022-03-23 17:05:16 UTC (rev 291748)
@@ -1,3 +1,24 @@
+2022-03-23 Kimmo Kinnunen <[email protected]>
+
+ 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
+
+ Reviewed by Simon Fraser.
+
+ 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):
+
2022-03-23 Tyler Wilcock <[email protected]>
AccessibilityRenderObject::nextSibling should allow parent differences in the presence of display: contents
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (291747 => 291748)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-03-23 17:00:33 UTC (rev 291747)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-03-23 17:05:16 UTC (rev 291748)
@@ -1500,6 +1500,9 @@
|| !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::isfinite(srcRect.width()) || !std::isfinite(srcRect.height()))
return { };
+ if (!srcRect.width() || !srcRect.height())
+ return { };
+
if (!dstRect.width() || !dstRect.height())
return { };
@@ -1506,9 +1509,6 @@
FloatRect normalizedSrcRect = normalizeRect(srcRect);
FloatRect normalizedDstRect = normalizeRect(dstRect);
- if (!srcRect.width() || !srcRect.height())
- return Exception { IndexSizeError };
-
// When the source rectangle is outside the source image, the source rectangle must be clipped
// to the source image and the destination rectangle must be clipped in the same proportion.
FloatRect originalNormalizedSrcRect = normalizedSrcRect;
@@ -1582,7 +1582,7 @@
return Exception { InvalidStateError };
if (!srcRect.width() || !srcRect.height())
- return Exception { IndexSizeError };
+ return { };
if (!srcCanvasRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
return { };
@@ -1638,7 +1638,7 @@
FloatRect videoRect = FloatRect(FloatPoint(), size(video));
if (!srcRect.width() || !srcRect.height())
- return Exception { IndexSizeError };
+ return { };
if (!videoRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
return { };