Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make create_pattern() return None for incomplete images
  • Loading branch information
pylbrecht committed Feb 10, 2020
1 parent 423b86e commit 481ef46
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 35 deletions.
14 changes: 8 additions & 6 deletions components/script/canvas_state.rs
Expand Up @@ -895,12 +895,14 @@ impl CanvasState {
global: &GlobalScope,
image: CanvasImageSource,
mut repetition: DOMString,
) -> Fallible<DomRoot<CanvasPattern>> {
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
let (image_data, image_size) = match image {
CanvasImageSource::HTMLImageElement(ref image) => {
// 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
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !image.is_usable()? {
return Ok(None);
}

image
.get_url()
.and_then(|url| {
Expand Down Expand Up @@ -933,13 +935,13 @@ impl CanvasState {
}

if let Ok(rep) = RepetitionStyle::from_str(&repetition) {
Ok(CanvasPattern::new(
Ok(Some(CanvasPattern::new(
global,
image_data,
image_size,
rep,
self.is_origin_clean(image),
))
)))
} else {
Err(Error::Syntax)
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -566,7 +566,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
&self,
image: CanvasImageSource,
repetition: DOMString,
) -> Fallible<DomRoot<CanvasPattern>> {
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
self.canvas_state
.borrow()
.create_pattern(&self.global(), image, repetition)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/offscreencanvasrenderingcontext2d.rs
Expand Up @@ -210,7 +210,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
&self,
image: CanvasImageSource,
repetition: DOMString,
) -> Fallible<DomRoot<CanvasPattern>> {
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
self.canvas_state
.borrow()
.create_pattern(&self.global(), image, repetition)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/paintrenderingcontext2d.rs
Expand Up @@ -340,7 +340,7 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
&self,
image: CanvasImageSource,
repetition: DOMString,
) -> Fallible<DomRoot<CanvasPattern>> {
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
self.context.CreatePattern(image, repetition)
}

Expand Down
Expand Up @@ -93,7 +93,7 @@ interface mixin CanvasFillStrokeStyles {
[Throws]
CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
[Throws]
CanvasPattern createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);
CanvasPattern? createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);
};

[Exposed=(PaintWorklet, Window, Worker)]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 481ef46

Please sign in to comment.