mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Throw error when calling drawImage() with a broken image
This commit is contained in:
parent
96b34ea744
commit
c4e56cc845
Notes:
github-actions[bot]
2025-10-22 08:46:24 +00:00
Author: https://github.com/tcl3
Commit: c4e56cc845
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6541
Reviewed-by: https://github.com/gmta ✅
8 changed files with 109 additions and 1 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||||
#include <LibWeb/HTML/ImageBitmap.h>
|
#include <LibWeb/HTML/ImageBitmap.h>
|
||||||
#include <LibWeb/HTML/ImageData.h>
|
#include <LibWeb/HTML/ImageData.h>
|
||||||
|
#include <LibWeb/HTML/ImageRequest.h>
|
||||||
#include <LibWeb/HTML/Path2D.h>
|
#include <LibWeb/HTML/Path2D.h>
|
||||||
#include <LibWeb/HTML/TextMetrics.h>
|
#include <LibWeb/HTML/TextMetrics.h>
|
||||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||||
|
|
@ -802,7 +803,9 @@ WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasI
|
||||||
auto usability = TRY(image.visit(
|
auto usability = TRY(image.visit(
|
||||||
// HTMLOrSVGImageElement
|
// HTMLOrSVGImageElement
|
||||||
[](GC::Root<HTMLImageElement> const& image_element) -> WebIDL::ExceptionOr<Optional<CanvasImageSourceUsability>> {
|
[](GC::Root<HTMLImageElement> const& image_element) -> WebIDL::ExceptionOr<Optional<CanvasImageSourceUsability>> {
|
||||||
// FIXME: If image's current request's state is broken, then throw an "InvalidStateError" DOMException.
|
// If image's current request's state is broken, then throw an "InvalidStateError" DOMException.
|
||||||
|
if (image_element->current_request().state() == HTML::ImageRequest::State::Broken)
|
||||||
|
return WebIDL::InvalidStateError::create(image_element->realm(), "Image element state is broken"_utf16);
|
||||||
|
|
||||||
// If image is not fully decodable, then return bad.
|
// If image is not fully decodable, then return bad.
|
||||||
if (!image_element->immutable_bitmap())
|
if (!image_element->immutable_bitmap())
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Canvas test: 2d.drawImage.nonexistent
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Canvas test: 2d.pattern.image.broken
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Canvas test: 2d.pattern.image.nonexistent
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Canvas test: 2d.drawImage.nonexistent</title>
|
||||||
|
<script src="../../../../resources/testharness.js"></script>
|
||||||
|
<script src="../../../../resources/testharnessreport.js"></script>
|
||||||
|
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
|
||||||
|
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
|
||||||
|
<body class="show_output">
|
||||||
|
|
||||||
|
<h1>2d.drawImage.nonexistent</h1>
|
||||||
|
<p class="desc"></p>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="output">Actual output:</p>
|
||||||
|
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||||
|
|
||||||
|
<ul id="d"></ul>
|
||||||
|
<script>
|
||||||
|
var t = async_test("");
|
||||||
|
_addTest(function(canvas, ctx) {
|
||||||
|
|
||||||
|
var img = document.getElementById('not-found-at-all.png');
|
||||||
|
assert_throws_dom("INVALID_STATE_ERR", function() { ctx.drawImage(img, 0, 0); });
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<img src="../../../../images/not-found-at-all.png" id="not-found-at-all.png" class="resource">
|
||||||
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Canvas test: 2d.pattern.image.broken</title>
|
||||||
|
<script src="../../../../resources/testharness.js"></script>
|
||||||
|
<script src="../../../../resources/testharnessreport.js"></script>
|
||||||
|
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
|
||||||
|
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
|
||||||
|
<body class="show_output">
|
||||||
|
|
||||||
|
<h1>2d.pattern.image.broken</h1>
|
||||||
|
<p class="desc"></p>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="output">Actual output:</p>
|
||||||
|
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||||
|
|
||||||
|
<ul id="d"></ul>
|
||||||
|
<script>
|
||||||
|
var t = async_test("");
|
||||||
|
_addTest(function(canvas, ctx) {
|
||||||
|
|
||||||
|
var img = document.getElementById('broken.png');
|
||||||
|
assert_throws_dom("INVALID_STATE_ERR", function() { ctx.createPattern(img, 'repeat'); });
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<img src="../../../../images/broken.png" id="broken.png" class="resource">
|
||||||
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Canvas test: 2d.pattern.image.nonexistent</title>
|
||||||
|
<script src="../../../../resources/testharness.js"></script>
|
||||||
|
<script src="../../../../resources/testharnessreport.js"></script>
|
||||||
|
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
|
||||||
|
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
|
||||||
|
<body class="show_output">
|
||||||
|
|
||||||
|
<h1>2d.pattern.image.nonexistent</h1>
|
||||||
|
<p class="desc"></p>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="output">Actual output:</p>
|
||||||
|
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||||
|
|
||||||
|
<ul id="d"></ul>
|
||||||
|
<script>
|
||||||
|
var t = async_test("");
|
||||||
|
_addTest(function(canvas, ctx) {
|
||||||
|
|
||||||
|
var img = document.getElementById('no-such-image-really.png');
|
||||||
|
assert_throws_dom("INVALID_STATE_ERR", function() { ctx.createPattern(img, 'repeat'); });
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<img src="../../../../images/no-such-image-really.png" id="no-such-image-really.png" class="resource">
|
||||||
|
|
||||||
BIN
Tests/LibWeb/Text/input/wpt-import/images/broken.png
Normal file
BIN
Tests/LibWeb/Text/input/wpt-import/images/broken.png
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue