From 9cd1b2c158f6a92aa48ed2702f591109b7a32eaa Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Wed, 25 Mar 2015 01:16:08 +0900 Subject: [PATCH] Use Finite for our dom code (excluding CanvasRenderingContext2D) --- components/script/devtools.rs | 4 ++- components/script/dom/bindings/conversions.rs | 4 +-- components/script/dom/domrect.rs | 27 ++++++++++--------- components/script/dom/performance.rs | 6 +++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/script/devtools.rs b/components/script/devtools.rs index 051002c7478..7071d2fa0f5 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -87,7 +87,9 @@ pub fn handle_get_layout(page: &Rc, pipeline: PipelineId, node_id: String, let node = find_node_by_unique_id(&*page, pipeline, node_id).root(); let elem: JSRef = ElementCast::to_ref(node.r()).expect("should be getting layout of element"); let rect = elem.GetBoundingClientRect().root(); - reply.send((rect.r().Width(), rect.r().Height())).unwrap(); + let width = *rect.r().Width(); + let height = *rect.r().Height(); + reply.send((width, height)).unwrap(); } pub fn handle_modify_attribute(page: &Rc, pipeline: PipelineId, node_id: String, modifications: Vec) { diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index b8cb3ccb84d..1a96dc7c948 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -259,7 +259,7 @@ impl FromJSValConvertible for f32 { impl ToJSValConvertible for Finite { fn to_jsval(&self, cx: *mut JSContext) -> JSVal { - let value = self.clone().unwrap(); + let value = **self; value.to_jsval(cx) } } @@ -293,7 +293,7 @@ impl FromJSValConvertible for f64 { impl ToJSValConvertible for Finite { #[inline] fn to_jsval(&self, cx: *mut JSContext) -> JSVal { - let value = self.clone().unwrap(); + let value = **self; value.to_jsval(cx) } } diff --git a/components/script/dom/domrect.rs b/components/script/dom/domrect.rs index 513e96ef28d..08cacc09be2 100644 --- a/components/script/dom/domrect.rs +++ b/components/script/dom/domrect.rs @@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::DOMRectBinding; use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; 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::window::Window; use util::geometry::Au; @@ -41,28 +42,30 @@ impl DOMRect { } impl<'a> DOMRectMethods for JSRef<'a, DOMRect> { - fn Top(self) -> f32 { - self.top + fn Top(self) -> Finite { + Finite::wrap(self.top) } - fn Bottom(self) -> f32 { - self.bottom + fn Bottom(self) -> Finite { + Finite::wrap(self.bottom) } - fn Left(self) -> f32 { - self.left + fn Left(self) -> Finite { + Finite::wrap(self.left) } - fn Right(self) -> f32 { - self.right + fn Right(self) -> Finite { + Finite::wrap(self.right) } - fn Width(self) -> f32 { - (self.right - self.left).abs() + fn Width(self) -> Finite { + let result = (self.right - self.left).abs(); + Finite::wrap(result) } - fn Height(self) -> f32 { - (self.bottom - self.top).abs() + fn Height(self) -> Finite { + let result = (self.bottom - self.top).abs(); + Finite::wrap(result) } } diff --git a/components/script/dom/performance.rs b/components/script/dom/performance.rs index 31f0fd3b31e..45fa9ffe002 100644 --- a/components/script/dom/performance.rs +++ b/components/script/dom/performance.rs @@ -6,12 +6,13 @@ use dom::bindings::codegen::Bindings::PerformanceBinding; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::performancetiming::{PerformanceTiming, PerformanceTimingHelpers}; use dom::window::Window; use time; -pub type DOMHighResTimeStamp = f64; +pub type DOMHighResTimeStamp = Finite; #[dom_struct] pub struct Performance { @@ -50,7 +51,8 @@ impl<'a> PerformanceMethods for JSRef<'a, Performance> { // https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now fn Now(self) -> DOMHighResTimeStamp { let navStart = self.timing.root().r().NavigationStartPrecise(); - (time::precise_time_ns() as f64 - navStart) * 1000000u as DOMHighResTimeStamp + let now = (time::precise_time_ns() as f64 - navStart) * 1000000u as f64; + Finite::wrap(now) } }