Add image usability checks to drawImage()

This commit is contained in:
pylbrecht 2020-02-02 19:24:39 +01:00
parent 5f55cd5d71
commit ed0973fb1c
9 changed files with 29 additions and 34 deletions

View file

@ -388,6 +388,14 @@ impl CanvasState {
self.draw_offscreen_canvas(&canvas, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh)
},
CanvasImageSource::HTMLImageElement(ref image) => {
// https://html.spec.whatwg.org/multipage/#drawing-images
// 2. Let usability be the result of checking the usability of image.
// 3. If usability is bad, then return (without drawing anything).
if !image.is_usable()? {
return Ok(());
}
// TODO(pylbrecht): is it possible for image.get_url() to return None after the usability check?
// https://html.spec.whatwg.org/multipage/#img-error
// If the image argument is an HTMLImageElement object that is in the broken state,
// then throw an InvalidStateError exception