diff --git a/Libraries/LibWeb/HTML/HTMLOrSVGElement.idl b/Libraries/LibWeb/HTML/HTMLOrSVGElement.idl index 88c4b22c5ad..3f7641e4c65 100644 --- a/Libraries/LibWeb/HTML/HTMLOrSVGElement.idl +++ b/Libraries/LibWeb/HTML/HTMLOrSVGElement.idl @@ -1,3 +1,5 @@ +#import + // https://html.spec.whatwg.org/#htmlorsvgelement interface mixin HTMLOrSVGElement { [SameObject] readonly attribute DOMStringMap dataset; diff --git a/Libraries/LibWeb/HTML/ImageBitmap.h b/Libraries/LibWeb/HTML/ImageBitmap.h index c1ede98b76e..4e1ad6641bd 100644 --- a/Libraries/LibWeb/HTML/ImageBitmap.h +++ b/Libraries/LibWeb/HTML/ImageBitmap.h @@ -16,7 +16,7 @@ namespace Web::HTML { -using ImageBitmapSource = Variant, GC::Root>; +using ImageBitmapSource = FlattenVariant, GC::Root>>; // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapoptions struct ImageBitmapOptions { diff --git a/Libraries/LibWeb/HTML/ImageBitmap.idl b/Libraries/LibWeb/HTML/ImageBitmap.idl index d2ec371ab18..644655485fd 100644 --- a/Libraries/LibWeb/HTML/ImageBitmap.idl +++ b/Libraries/LibWeb/HTML/ImageBitmap.idl @@ -1,5 +1,7 @@ #import #import +#import +#import // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#images-2 [Exposed=(Window,Worker), Serializable, Transferable] @@ -9,8 +11,10 @@ interface ImageBitmap { undefined close(); }; -// FIXME: This should also includes CanvasImageSource -typedef (Blob or + +// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapsource +typedef (CanvasImageSource or + Blob or ImageData) ImageBitmapSource; enum ImageOrientation { "from-image", "flipY" }; diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp index 4d93c84cc5d..04f19d618fa 100644 --- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp +++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp @@ -133,12 +133,25 @@ GC::Ref WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp (void)options; // 3. Check the usability of the image argument. If this throws an exception or returns bad, then return a promise rejected with an "InvalidStateError" DOMException. - // FIXME: "Check the usability of the image argument" is only defined for CanvasImageSource, let's skip it for other types - if (image.has()) { - if (auto usability = check_usability_of_image(image.get()); usability.is_error() or usability.value() == CanvasImageSourceUsability::Bad) { - auto error = WebIDL::InvalidStateError::create(this_impl().realm(), "image argument is not usable"_string); - return WebIDL::create_rejected_promise_from_exception(realm, error); - } + auto error_promise = image.visit( + [](GC::Root&) -> Optional> { + return {}; + }, + [](GC::Root&) -> Optional> { + return {}; + }, + [&](auto& canvas_image_source) -> Optional> { + // Note: "Check the usability of the image argument" is only defined for CanvasImageSource + if (auto usability = check_usability_of_image(canvas_image_source); usability.is_error() or usability.value() == CanvasImageSourceUsability::Bad) { + auto error = WebIDL::InvalidStateError::create(this_impl().realm(), "image argument is not usable"_string); + return WebIDL::create_rejected_promise_from_exception(realm, error); + } + + return {}; + }); + + if (error_promise.has_value()) { + return error_promise.release_value(); } // 4. Let p be a new promise. diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.idl b/Libraries/LibWeb/HTML/WorkerGlobalScope.idl index 07c1901deb4..c801754609f 100644 --- a/Libraries/LibWeb/HTML/WorkerGlobalScope.idl +++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.idl @@ -3,6 +3,7 @@ #import #import #import +#import #import #import #import diff --git a/Libraries/LibWeb/SVG/SVGElement.idl b/Libraries/LibWeb/SVG/SVGElement.idl index d132fa57892..383667be6ed 100644 --- a/Libraries/LibWeb/SVG/SVGElement.idl +++ b/Libraries/LibWeb/SVG/SVGElement.idl @@ -1,6 +1,7 @@ #import #import -#import +#import +#import #import #import #import diff --git a/Tests/LibWeb/Text/expected/HTML/image-bitmap-from-invalid-types-no-crash.txt b/Tests/LibWeb/Text/expected/HTML/image-bitmap-from-invalid-types-no-crash.txt index 43be68f8969..e9d593bdc3f 100644 --- a/Tests/LibWeb/Text/expected/HTML/image-bitmap-from-invalid-types-no-crash.txt +++ b/Tests/LibWeb/Text/expected/HTML/image-bitmap-from-invalid-types-no-crash.txt @@ -1,7 +1,7 @@ Blob [Success]: [object ImageBitmap] ImageData [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types -HTMLImageElement [ Error ]: TypeError: No union types matched -SVGImageElement [ Error ]: TypeError: No union types matched -HTMLCanvasElement [ Error ]: TypeError: No union types matched +HTMLImageElement [ Error ]: InvalidStateError: image argument is not usable +SVGImageElement [ Error ]: InvalidStateError: image argument is not usable +HTMLCanvasElement [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types ImageBitmap [ Error ]: TypeError: No union types matched -HTMLVideoElement [ Error ]: TypeError: No union types matched +HTMLVideoElement [ Error ]: InvalidStateError: image argument is not usable diff --git a/Tests/LibWeb/Text/input/HTML/image-bitmap-from-invalid-types-no-crash.html b/Tests/LibWeb/Text/input/HTML/image-bitmap-from-invalid-types-no-crash.html index 4d9bb8a276d..7c5ba4d8418 100644 --- a/Tests/LibWeb/Text/input/HTML/image-bitmap-from-invalid-types-no-crash.html +++ b/Tests/LibWeb/Text/input/HTML/image-bitmap-from-invalid-types-no-crash.html @@ -22,7 +22,7 @@ 255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0, ]), ]); - let imageBitmap = createImageBitmap(file, 0, 0, 0, 0); + let imageBitmap = createImageBitmap(file, 0, 0, 20, 20); const types = [ [file, "Blob"],