From 801949556d1a697fe93495cd2417707e54e49c7e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 24 Jan 2015 16:36:54 +0100 Subject: [PATCH] Return *const T from JS::unsafe_get() (fixes #4712). --- components/layout/wrapper.rs | 8 +++----- components/script/dom/bindings/js.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 94b536e1a4e..6b8db9b1b98 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -369,10 +369,8 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { None => panic!("not an element") }; - let element = &*elem.unsafe_get(); - LayoutElement { - element: mem::transmute(element), + element: &*elem.unsafe_get(), } } } @@ -719,7 +717,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { } unsafe fn get<'a>(&'a self) -> &'a Node { // this change. - mem::transmute::<*mut Node,&'a Node>(self.get_jsmanaged().unsafe_get()) + &*self.get_jsmanaged().unsafe_get() } fn first_child(&self) -> Option> { @@ -819,7 +817,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { // FIXME(pcwalton): Workaround until Rust gets multiple lifetime parameters on // implementations. ThreadSafeLayoutElement { - element: &mut *element, + element: &*element, } } } diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index e220f181a34..bc2d52a24bd 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -311,8 +311,8 @@ impl JS { /// Returns an unsafe pointer to the interior of this object. This is the /// only method that be safely accessed from layout. (The fact that this is /// unsafe is what necessitates the layout wrappers.) - pub unsafe fn unsafe_get(&self) -> *mut T { - self.ptr as *mut T + pub unsafe fn unsafe_get(&self) -> *const T { + self.ptr } /// Store an unrooted value in this field. This is safe under the assumption that JS