Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support empty strings as the repeat argument (CreatePattern)
According to the third step in the specification [1], createPattern
should let the repetition argument be "repeat" when it is the empty
string.

The code in CanvasRenderingContext2D::CreatePattern did not implement
this step and instead threw a SyntaxError exception when an empty
string was supplied as the repetition argument.

Fixes #9079.

[1] https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern
  • Loading branch information
nerith committed Dec 31, 2015
1 parent 0f5c614 commit 1ccab32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
6 changes: 5 additions & 1 deletion components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -1147,7 +1147,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern // https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern
fn CreatePattern(&self, fn CreatePattern(&self,
image: HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D, image: HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D,
repetition: DOMString) mut repetition: DOMString)
-> Fallible<Root<CanvasPattern>> { -> Fallible<Root<CanvasPattern>> {
let (image_data, image_size) = match image { let (image_data, image_size) = match image {
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::eHTMLImageElement(ref image) => { HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::eHTMLImageElement(ref image) => {
Expand All @@ -1169,6 +1169,10 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
} }
}; };


if repetition.is_empty() {
repetition.push_str("repeat");
}

if let Ok(rep) = RepetitionStyle::from_str(&repetition) { if let Ok(rep) = RepetitionStyle::from_str(&repetition) {
Ok(CanvasPattern::new(self.global.root().r(), Ok(CanvasPattern::new(self.global.root().r(),
image_data, image_data,
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 1ccab32

Please sign in to comment.