Auto merge of #5852 - nox:rm-unsafe-transmute, r=Ms2ger

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5852)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-04-26 14:40:31 -05:00
commit 56a7981c9c
5 changed files with 13 additions and 52 deletions

View file

@ -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<Node>) -> 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<Node>) -> ThreadSafeLayoutNode<'ln> {
ThreadSafeLayoutNode {
node: LayoutNode {
node: node.transmute_copy(),
chain: self.node.chain,
},
node: self.node.new_with_this_lifetime(node),
pseudo: PseudoElementType::Normal,
}
}

View file

@ -5453,7 +5453,7 @@ impl ${name}Cast {
#[inline(always)]
pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, ${name}>> {
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
}
}
@ -5471,7 +5471,7 @@ impl ${name}Cast {
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
unsafe {
match (*base.unsafe_get()).${checkFn}() {
true => Some(base.transmute_copy()),
true => Some(mem::transmute_copy(base)),
false => None
}
}
@ -5479,33 +5479,31 @@ impl ${name}Cast {
#[inline(always)]
pub fn to_temporary<T: ${toBound}+Reflectable>(base: Temporary<T>) -> Option<Temporary<${name}>> {
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)]
#[allow(unrooted_must_root)]
pub fn from_layout_js<T: ${fromBound}+Reflectable>(derived: &LayoutJS<T>) -> LayoutJS<${name}> {
unsafe { derived.transmute_copy() }
unsafe { mem::transmute_copy(derived) }
}
#[inline(always)]
pub fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<${name}> {
unsafe { derived.transmute() }
unsafe { mem::transmute(derived) }
}
#[inline(always)]

View file

@ -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.
@ -186,13 +185,6 @@ impl<T: Reflectable> Temporary<T> {
unsafe fn inner(&self) -> JS<T> {
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<To>(self) -> Temporary<To> {
mem::transmute(self)
}
}
/// A traced reference to a DOM object. Must only be used as a field in other
@ -438,20 +430,6 @@ impl<T: Reflectable> LayoutJS<T> {
}
}
impl<From> JS<From> {
/// Return `self` as a `JS` of another type.
pub unsafe fn transmute_copy<To>(&self) -> JS<To> {
mem::transmute_copy(self)
}
}
impl<From> LayoutJS<From> {
/// Return `self` as a `LayoutJS` of another type.
pub unsafe fn transmute_copy<To>(&self) -> LayoutJS<To> {
mem::transmute_copy(self)
}
}
/// Get an `Option<JSRef<T>>` out of an `Option<Root<T>>`
pub trait RootedReference<T> {
/// Obtain a safe optional reference to the wrapped JS owned-value that
@ -748,18 +726,6 @@ impl<'a, 'b, T> PartialEq<JSRef<'b, T>> 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<To>(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<T>` for the inner pointer.
pub fn unrooted(&self) -> JS<T> {
JS {

View file

@ -389,7 +389,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
if (*self.unsafe_get()).namespace != ns!(HTML) {
return false
}
let node: LayoutJS<Node> = self.transmute_copy();
let node = NodeCast::from_layout_js(&self);
node.owner_doc_for_layout().is_html_document_for_layout()
}

View file

@ -164,7 +164,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
#[allow(unsafe_code)]
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
let elem: LayoutJS<Element> = 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())
}