LibWeb: Throw error when calling drawImage() with a broken image

This commit is contained in:
Tim Ledbetter 2025-10-22 00:40:32 +01:00 committed by Jelle Raaijmakers
parent 96b34ea744
commit c4e56cc845
Notes: github-actions[bot] 2025-10-22 08:46:24 +00:00
8 changed files with 109 additions and 1 deletions

View file

@ -23,6 +23,7 @@
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/ImageBitmap.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/ImageRequest.h>
#include <LibWeb/HTML/Path2D.h>
#include <LibWeb/HTML/TextMetrics.h>
#include <LibWeb/HTML/TraversableNavigable.h>
@ -802,7 +803,9 @@ WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasI
auto usability = TRY(image.visit(
// HTMLOrSVGImageElement
[](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_element->immutable_bitmap())