From 9369b616ce7c08444f9d2072a2c212165bf4d412 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 26 Apr 2015 17:38:00 +0200 Subject: [PATCH 1/2] Remove useless unsafe methods on JS --- .../dom/bindings/codegen/CodegenRust.py | 16 +++++------- components/script/dom/bindings/js.rs | 26 ------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 1ef3cc0b810..0008790c973 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5453,7 +5453,7 @@ impl ${name}Cast { #[inline(always)] pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option> { match base.${checkFn}() { - true => unsafe { Some(base.transmute()) }, + true => Some(unsafe { mem::transmute(base) }), false => None } } @@ -5461,7 +5461,7 @@ impl ${name}Cast { #[inline(always)] pub fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, ${name}>> { match base.${checkFn}() { - true => unsafe { Some(base.transmute_borrowed()) }, + true => Some(unsafe { mem::transmute(base) }), false => None } } @@ -5479,22 +5479,20 @@ impl ${name}Cast { #[inline(always)] pub fn to_temporary(base: Temporary) -> Option> { - let base = base.root(); - let base = base.r(); - match base.${checkFn}() { - true => Some(Temporary::from_rooted(unsafe { base.transmute() })), + match base.root().r().${checkFn}() { + true => Some(unsafe { mem::transmute(base) }), false => None } } #[inline(always)] pub fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, ${name}> { - unsafe { derived.transmute() } + unsafe { mem::transmute(derived) } } #[inline(always)] pub fn from_borrowed_ref<'a, 'b, T: ${fromBound}+Reflectable>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, ${name}> { - unsafe { derived.transmute_borrowed() } + unsafe { mem::transmute(derived) } } #[inline(always)] @@ -5505,7 +5503,7 @@ impl ${name}Cast { #[inline(always)] pub fn from_temporary(derived: Temporary) -> Temporary<${name}> { - unsafe { derived.transmute() } + unsafe { mem::transmute(derived) } } #[inline(always)] diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 6b3ce4a555c..cc36600318c 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -186,13 +186,6 @@ impl Temporary { unsafe fn inner(&self) -> JS { self.inner.clone() } - - /// Returns `self` as a `Temporary` of another type. For use by - /// `InheritTypes` only. - //XXXjdm It would be lovely if this could be private. - pub unsafe fn transmute(self) -> Temporary { - mem::transmute(self) - } } /// A traced reference to a DOM object. Must only be used as a field in other @@ -438,13 +431,6 @@ impl LayoutJS { } } -impl JS { - /// Return `self` as a `JS` of another type. - pub unsafe fn transmute_copy(&self) -> JS { - mem::transmute_copy(self) - } -} - impl LayoutJS { /// Return `self` as a `LayoutJS` of another type. pub unsafe fn transmute_copy(&self) -> LayoutJS { @@ -748,18 +734,6 @@ impl<'a, 'b, T> PartialEq> for JSRef<'a, T> { } impl<'a,T> JSRef<'a,T> { - /// Return `self` as a `JSRef` of another type. - //XXXjdm It would be lovely if this could be private. - pub unsafe fn transmute(self) -> JSRef<'a, To> { - mem::transmute(self) - } - - /// Return `self` as a borrowed reference to a `JSRef` of another type. - // FIXME(zwarich): It would be nice to get rid of this entirely. - pub unsafe fn transmute_borrowed<'b, To>(&'b self) -> &'b JSRef<'a, To> { - mem::transmute(self) - } - /// Return an unrooted `JS` for the inner pointer. pub fn unrooted(&self) -> JS { JS { From 4e7b9d319c760476e41a1e886b71ed179ed06d5e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 26 Apr 2015 17:38:13 +0200 Subject: [PATCH 2/2] Remove useless unsafe methods on LayoutJS --- components/layout/wrapper.rs | 7 ++----- components/script/dom/bindings/codegen/CodegenRust.py | 4 ++-- components/script/dom/bindings/js.rs | 8 -------- components/script/dom/element.rs | 2 +- components/script/dom/htmlinputelement.rs | 2 +- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 8c30d649db3..40d675bd4d6 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -197,7 +197,7 @@ impl<'a> PartialEq for LayoutNode<'a> { impl<'ln> TLayoutNode for LayoutNode<'ln> { unsafe fn new_with_this_lifetime(&self, node: &LayoutJS) -> LayoutNode<'ln> { LayoutNode { - node: node.transmute_copy(), + node: *node, chain: self.chain, } } @@ -728,10 +728,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { /// Creates a new layout node with the same lifetime as this layout node. unsafe fn new_with_this_lifetime(&self, node: &LayoutJS) -> ThreadSafeLayoutNode<'ln> { ThreadSafeLayoutNode { - node: LayoutNode { - node: node.transmute_copy(), - chain: self.node.chain, - }, + node: self.node.new_with_this_lifetime(node), pseudo: PseudoElementType::Normal, } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 0008790c973..3748917038f 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5471,7 +5471,7 @@ impl ${name}Cast { pub fn to_layout_js(base: &LayoutJS) -> Option> { unsafe { match (*base.unsafe_get()).${checkFn}() { - true => Some(base.transmute_copy()), + true => Some(mem::transmute_copy(base)), false => None } } @@ -5498,7 +5498,7 @@ impl ${name}Cast { #[inline(always)] #[allow(unrooted_must_root)] pub fn from_layout_js(derived: &LayoutJS) -> LayoutJS<${name}> { - unsafe { derived.transmute_copy() } + unsafe { mem::transmute_copy(derived) } } #[inline(always)] diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index cc36600318c..cb8aaf04160 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -64,7 +64,6 @@ use std::cell::{Cell, UnsafeCell}; use std::default::Default; use std::intrinsics::return_address; use std::marker::PhantomData; -use std::mem; use std::ops::Deref; /// An unrooted, JS-owned value. Must not be held across a GC. @@ -431,13 +430,6 @@ impl LayoutJS { } } -impl LayoutJS { - /// Return `self` as a `LayoutJS` of another type. - pub unsafe fn transmute_copy(&self) -> LayoutJS { - mem::transmute_copy(self) - } -} - /// Get an `Option>` out of an `Option>` pub trait RootedReference { /// Obtain a safe optional reference to the wrapped JS owned-value that diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d47cf4feeaa..3f0ba0e8ca1 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -389,7 +389,7 @@ impl LayoutElementHelpers for LayoutJS { if (*self.unsafe_get()).namespace != ns!(HTML) { return false } - let node: LayoutJS = self.transmute_copy(); + let node = NodeCast::from_layout_js(&self); node.owner_doc_for_layout().is_html_document_for_layout() } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index a34357c37b1..d8f5407a9d1 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -164,7 +164,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS { #[allow(unsafe_code)] unsafe fn get_raw_attr_value(input: LayoutJS) -> Option { - let elem: LayoutJS = input.transmute_copy(); + let elem = ElementCast::from_layout_js(&input); (*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value")) .map(|s| s.to_owned()) }