From 54d3a0b28010cd590ad5ebd4c516ff091b76908f Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Sat, 20 Sep 2014 00:04:02 +0900 Subject: [PATCH 1/2] Reintroduce Untraceable.deref_mut() to make mem::replace() possible to Untracebale field. Some compile errors caused by the compiler's misreading comes back again :( We re-use `deref()`explicitly to hide these errors. --- components/script/dom/bindings/trace.rs | 6 ++++++ components/script/dom/canvasrenderingcontext2d.rs | 8 ++++---- components/script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/workerglobalscope.rs | 4 ++-- components/script/dom/workerlocation.rs | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index b160508a761..837dec61f5a 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -132,6 +132,12 @@ impl Deref for Untraceable { } } +impl DerefMut for Untraceable { + fn deref_mut<'a>(&'a mut self) -> &'a mut T { + &mut self.inner + } +} + /// Encapsulates a type that can be traced but is boxed in a type we don't /// control (such as `RefCell`). /// diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index cc06b7fadfc..c96b63eae7c 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -41,7 +41,7 @@ impl CanvasRenderingContext2D { } pub fn recreate(&self, size: Size2D) { - self.renderer.send(Recreate(size)); + self.renderer.deref().send(Recreate(size)); } } @@ -52,17 +52,17 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> fn FillRect(&self, x: f64, y: f64, width: f64, height: f64) { let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32)); - self.renderer.send(FillRect(rect)); + self.renderer.deref().send(FillRect(rect)); } fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64) { let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32)); - self.renderer.send(ClearRect(rect)); + self.renderer.deref().send(ClearRect(rect)); } fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64) { let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32)); - self.renderer.send(StrokeRect(rect)); + self.renderer.deref().send(StrokeRect(rect)); } } diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 749db8d61f7..a17cd511990 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -120,7 +120,7 @@ impl DedicatedWorkerGlobalScope { let target: JSRef = EventTargetCast::from_ref(*global); loop { - match global.receiver.recv_opt() { + match global.receiver.deref().recv_opt() { Ok(DOMMessage(data, nbytes)) => { let mut message = UndefinedValue(); unsafe { diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 897fe2fbc64..b4aa3603ef4 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -85,7 +85,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> { fn Location(&self) -> Temporary { if self.location.get().is_none() { - let location = WorkerLocation::new(*self, self.worker_url.clone()); + let location = WorkerLocation::new(*self, self.worker_url.deref().clone()); self.location.assign(Some(location)); } Temporary::new(self.location.get().get_ref().clone()) @@ -110,7 +110,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> { } }; - match self.js_context.evaluate_script( + match self.js_context.deref().evaluate_script( self.reflector().get_jsobject(), source, url.serialize(), 1) { Ok(_) => (), Err(_) => { diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs index 7092b2979ec..05112c54a88 100644 --- a/components/script/dom/workerlocation.rs +++ b/components/script/dom/workerlocation.rs @@ -38,7 +38,7 @@ impl WorkerLocation { impl<'a> WorkerLocationMethods for JSRef<'a, WorkerLocation> { fn Href(&self) -> DOMString { - self.url.serialize() + self.url.deref().serialize() } fn Search(&self) -> DOMString { From de0866ab42e8c1b24c10346dac327596c53b42ff Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Sat, 20 Sep 2014 00:17:08 +0900 Subject: [PATCH 2/2] Use Untraceable to hold LayoutDataRef instead of manual Encodable implementation. --- components/layout/util.rs | 6 +++--- components/layout/wrapper.rs | 4 ++-- components/script/dom/node.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/layout/util.rs b/components/layout/util.rs index a0e466e8875..fd8cb10cd09 100644 --- a/components/layout/util.rs +++ b/components/layout/util.rs @@ -77,20 +77,20 @@ pub trait LayoutDataAccess { impl<'ln> LayoutDataAccess for LayoutNode<'ln> { #[inline(always)] unsafe fn borrow_layout_data_unchecked(&self) -> *const Option { - mem::transmute(self.get().layout_data.borrow_unchecked()) + mem::transmute(self.get().layout_data.deref().borrow_unchecked()) } #[inline(always)] fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow()) + mem::transmute(self.get().layout_data.deref().borrow()) } } #[inline(always)] fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow_mut()) + mem::transmute(self.get().layout_data.deref().borrow_mut()) } } } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 8b360452122..36bebcaf760 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -646,7 +646,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { #[inline(always)] pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow()) + mem::transmute(self.get().layout_data.deref().borrow()) } } @@ -654,7 +654,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { #[inline(always)] pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow_mut()) + mem::transmute(self.get().layout_data.deref().borrow_mut()) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index bafce1aaf25..db8c7456b28 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -24,7 +24,7 @@ use dom::bindings::global::{GlobalRef, Window}; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root, OptionalUnrootable}; use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable}; -use dom::bindings::trace::Traceable; +use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::characterdata::CharacterData; @@ -108,7 +108,7 @@ pub struct Node { /// /// Must be sent back to the layout task to be destroyed when this /// node is finalized. - pub layout_data: LayoutDataRef, + pub layout_data: Untraceable, unique_id: RefCell, } @@ -1041,7 +1041,7 @@ impl Node { flags: Traceable::new(RefCell::new(NodeFlags::new(type_id))), - layout_data: LayoutDataRef::new(), + layout_data: Untraceable::new(LayoutDataRef::new()), unique_id: RefCell::new("".to_string()), } @@ -1454,7 +1454,7 @@ impl Node { /// Sends layout data, if any, back to the layout task to be destroyed. unsafe fn reap_layout_data(&mut self) { if self.layout_data.is_present() { - let layout_data = mem::replace(&mut self.layout_data, LayoutDataRef::new()); + let layout_data = mem::replace(self.layout_data.deref_mut(), LayoutDataRef::new()); let layout_chan = layout_data.take_chan(); match layout_chan { None => {}