diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index c1e61a12c26..349d434114c 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::CanvasGradientBinding; use dom::bindings::codegen::Bindings::CanvasGradientBinding::CanvasGradientMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::canvasrenderingcontext2d::parse_color; @@ -41,7 +42,7 @@ impl CanvasGradient { } impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> { - fn AddColorStop(self, offset: f32, color: String) { + fn AddColorStop(self, offset: Finite, color: String) { let default_black = RGBA { red: 0.0, green: 0.0, @@ -50,7 +51,7 @@ impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> { }; self.stops.borrow_mut().push(CanvasGradientStop { - offset: offset as f64, + offset: (*offset) as f64, color: parse_color(color.as_slice()).unwrap_or(default_black), }); } diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 58f3b51ab05..621bb629df0 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -12,6 +12,7 @@ use dom::bindings::error::Error::{IndexSize, TypeError}; use dom::bindings::error::Fallible; use dom::bindings::global::{GlobalRef, GlobalField}; use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary}; +use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle}; use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers}; @@ -383,7 +384,13 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> Point2D(x as f32, y as f32))).unwrap(); } - fn Arc(self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) { + fn Arc(self, x: Finite, y: Finite, r: Finite, start: Finite, end: Finite, ccw: bool) { + let x = *x; + let y = *y; + let r = *r; + let start = *start; + let end = *end; + self.renderer.send(CanvasMsg::Arc(Point2D(x as f32, y as f32), r as f32, start as f32, end as f32, ccw)).unwrap(); } @@ -467,7 +474,10 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> Ok(ImageData::new(self.global.root().r(), imagedata.Width(), imagedata.Height(), None)) } - fn GetImageData(self, sx: f64, sy: f64, sw: f64, sh: f64) -> Fallible> { + fn GetImageData(self, sx: Finite, sy: Finite, sw: Finite, sh: Finite) -> Fallible> { + let sw = *sw; + let sh = *sh; + if sw == 0.0 || sh == 0.0 { return Err(IndexSize) } @@ -480,15 +490,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data))) } - fn PutImageData(self, imagedata: JSRef, dx: f64, dy: f64) { + fn PutImageData(self, imagedata: JSRef, dx: Finite, dy: Finite) { let data = imagedata.get_data_array(&self.global.root().r()); let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()), imagedata.get_size()); let dirty_rect = None; self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect)).unwrap() } - fn PutImageData_(self, imagedata: JSRef, dx: f64, dy: f64, - dirtyX: f64, dirtyY: f64, dirtyWidth: f64, dirtyHeight: f64) { + fn PutImageData_(self, imagedata: JSRef, dx: Finite, dy: Finite, + dirtyX: Finite, dirtyY: Finite, dirtyWidth: Finite, dirtyHeight: Finite) { let data = imagedata.get_data_array(&self.global.root().r()); let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()), Size2D(imagedata.Width().to_i32().unwrap(), @@ -499,7 +509,13 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect)).unwrap() } - fn CreateLinearGradient(self, x0: f64, y0: f64, x1: f64, y1: f64) -> Fallible> { + fn CreateLinearGradient(self, x0: Finite, y0: Finite, + x1: Finite, y1: Finite) -> Fallible> { + let x0 = *x0; + let y0 = *y0; + let x1 = *x1; + let y1 = *y1; + if [x0, y0, x1, y1].iter().any(|x| x.is_nan() || x.is_infinite()) { return Err(TypeError("One of the arguments of createLinearGradient() is not a finite floating-point value.".to_owned())); } @@ -507,7 +523,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> CanvasGradientStyle::Linear(LinearGradientStyle::new(x0, y0, x1, y1, Vec::new())))) } - fn CreateRadialGradient(self, x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64) -> Fallible> { + fn CreateRadialGradient(self, x0: Finite, y0: Finite, r0: Finite, + x1: Finite, y1: Finite, r1: Finite) -> Fallible> { + let x0 = *x0; + let y0 = *y0; + let r0 = *r0; + let x1 = *x1; + let y1 = *y1; + let r1 = *r1; + if [x0, y0, r0, x1, y1, r1].iter().any(|x| x.is_nan() || x.is_infinite()) { return Err(TypeError("One of the arguments of createRadialGradient() is not a finite floating-point value.".to_owned())); } diff --git a/components/script/dom/webidls/CanvasRenderingContext2D.webidl b/components/script/dom/webidls/CanvasRenderingContext2D.webidl index 0218600bba1..6d686307f46 100644 --- a/components/script/dom/webidls/CanvasRenderingContext2D.webidl +++ b/components/script/dom/webidls/CanvasRenderingContext2D.webidl @@ -31,21 +31,21 @@ interface CanvasRenderingContext2D { // transformations (default transform is the identity matrix) // attribute SVGMatrix currentTransform; - void scale(/*unrestricted*/ double x, /*unrestricted*/ double y); + void scale(unrestricted double x, unrestricted double y); //void rotate(unrestricted double angle); - void translate(/*unrestricted*/ double x, /*unrestricted*/ double y); - void transform(/*unrestricted*/ double a, - /*unrestricted*/ double b, - /*unrestricted*/ double c, - /*unrestricted*/ double d, - /*unrestricted*/ double e, - /*unrestricted*/ double f); - void setTransform(/*unrestricted*/ double a, - /*unrestricted*/ double b, - /*unrestricted*/ double c, - /*unrestricted*/ double d, - /*unrestricted*/ double e, - /*unrestricted*/ double f); + void translate(unrestricted double x, unrestricted double y); + void transform(unrestricted double a, + unrestricted double b, + unrestricted double c, + unrestricted double d, + unrestricted double e, + unrestricted double f); + void setTransform(unrestricted double a, + unrestricted double b, + unrestricted double c, + unrestricted double d, + unrestricted double e, + unrestricted double f); //void resetTransform(); // compositing @@ -71,15 +71,12 @@ interface CanvasRenderingContext2D { // attribute DOMString shadowColor; // (default transparent black) // rects - //void clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); //[LenientFloat] - void clearRect(double x, double y, double w, double h); - //void fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); + void clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); //[LenientFloat] - void fillRect(double x, double y, double w, double h); - //void strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); + void fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); //[LenientFloat] - void strokeRect(double x, double y, double w, double h); + void strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); // path API (see also CanvasPathMethods) void beginPath(); @@ -108,11 +105,15 @@ interface CanvasRenderingContext2D { // drawing images [Throws] - void drawImage(CanvasImageSource image, /* unrestricted */ double dx, /* unrestricted */ double dy); + void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy); [Throws] - void drawImage(CanvasImageSource image, /* unrestricted */ double dx, /* unrestricted */ double dy, /* unrestricted */ double dw, /* unrestricted */ double dh); + void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy, + unrestricted double dw, unrestricted double dh); [Throws] - void drawImage(CanvasImageSource image, /* unrestricted */ double sx, /* unrestricted */ double sy, /* unrestricted */ double sw, /* unrestricted */ double sh, /* unrestricted */ double dx, /* unrestricted */ double dy, /* unrestricted */ double dw, /* unrestricted */ double dh); + void drawImage(CanvasImageSource image, unrestricted double sx, unrestricted double sy, + unrestricted double sw, unrestricted double sh, + unrestricted double dx, unrestricted double dy, + unrestricted double dw, unrestricted double dh); // hit regions //void addHitRegion(optional HitRegionOptions options); @@ -120,7 +121,7 @@ interface CanvasRenderingContext2D { // pixel manipulation [Throws] - ImageData createImageData(double sw, double sh); + ImageData createImageData(unrestricted double sw, unrestricted double sh); [Throws] ImageData createImageData(ImageData imagedata); [Throws] @@ -133,16 +134,16 @@ interface CanvasRenderingContext2D { interface CanvasPathMethods { // shared path API methods void closePath(); - void moveTo(/*unrestricted*/ double x, /*unrestricted*/ double y); - void lineTo(double x, double y); - void quadraticCurveTo(double cpx, double cpy, double x, double y); + void moveTo(unrestricted double x, unrestricted double y); + void lineTo(unrestricted double x, unrestricted double y); + void quadraticCurveTo(unrestricted double cpx, unrestricted double cpy, unrestricted double x, unrestricted double y); - void bezierCurveTo(/*unrestricted*/ double cp1x, - /*unrestricted*/ double cp1y, - /*unrestricted*/ double cp2x, - /*unrestricted*/ double cp2y, - /*unrestricted*/ double x, - /*unrestricted*/ double y); + void bezierCurveTo(unrestricted double cp1x, + unrestricted double cp1y, + unrestricted double cp2x, + unrestricted double cp2y, + unrestricted double x, + unrestricted double y); //void arcTo(double x1, double y1, double x2, double y2, double radius); // NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);