mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
commit
56a7981c9c
5 changed files with 13 additions and 52 deletions
|
@ -197,7 +197,7 @@ impl<'a> PartialEq for LayoutNode<'a> {
|
||||||
impl<'ln> TLayoutNode for LayoutNode<'ln> {
|
impl<'ln> TLayoutNode for LayoutNode<'ln> {
|
||||||
unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
||||||
LayoutNode {
|
LayoutNode {
|
||||||
node: node.transmute_copy(),
|
node: *node,
|
||||||
chain: self.chain,
|
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.
|
/// 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> {
|
unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> ThreadSafeLayoutNode<'ln> {
|
||||||
ThreadSafeLayoutNode {
|
ThreadSafeLayoutNode {
|
||||||
node: LayoutNode {
|
node: self.node.new_with_this_lifetime(node),
|
||||||
node: node.transmute_copy(),
|
|
||||||
chain: self.node.chain,
|
|
||||||
},
|
|
||||||
pseudo: PseudoElementType::Normal,
|
pseudo: PseudoElementType::Normal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5453,7 +5453,7 @@ impl ${name}Cast {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, ${name}>> {
|
pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, ${name}>> {
|
||||||
match base.${checkFn}() {
|
match base.${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute()) },
|
true => Some(unsafe { mem::transmute(base) }),
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5461,7 +5461,7 @@ impl ${name}Cast {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, ${name}>> {
|
pub fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, ${name}>> {
|
||||||
match base.${checkFn}() {
|
match base.${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute_borrowed()) },
|
true => Some(unsafe { mem::transmute(base) }),
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5471,7 +5471,7 @@ impl ${name}Cast {
|
||||||
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
|
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
match (*base.unsafe_get()).${checkFn}() {
|
match (*base.unsafe_get()).${checkFn}() {
|
||||||
true => Some(base.transmute_copy()),
|
true => Some(mem::transmute_copy(base)),
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5479,33 +5479,31 @@ impl ${name}Cast {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_temporary<T: ${toBound}+Reflectable>(base: Temporary<T>) -> Option<Temporary<${name}>> {
|
pub fn to_temporary<T: ${toBound}+Reflectable>(base: Temporary<T>) -> Option<Temporary<${name}>> {
|
||||||
let base = base.root();
|
match base.root().r().${checkFn}() {
|
||||||
let base = base.r();
|
true => Some(unsafe { mem::transmute(base) }),
|
||||||
match base.${checkFn}() {
|
|
||||||
true => Some(Temporary::from_rooted(unsafe { base.transmute() })),
|
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, ${name}> {
|
pub fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, ${name}> {
|
||||||
unsafe { derived.transmute() }
|
unsafe { mem::transmute(derived) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_borrowed_ref<'a, 'b, T: ${fromBound}+Reflectable>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, ${name}> {
|
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)]
|
#[inline(always)]
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn from_layout_js<T: ${fromBound}+Reflectable>(derived: &LayoutJS<T>) -> LayoutJS<${name}> {
|
pub fn from_layout_js<T: ${fromBound}+Reflectable>(derived: &LayoutJS<T>) -> LayoutJS<${name}> {
|
||||||
unsafe { derived.transmute_copy() }
|
unsafe { mem::transmute_copy(derived) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<${name}> {
|
pub fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<${name}> {
|
||||||
unsafe { derived.transmute() }
|
unsafe { mem::transmute(derived) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -64,7 +64,6 @@ use std::cell::{Cell, UnsafeCell};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::intrinsics::return_address;
|
use std::intrinsics::return_address;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// An unrooted, JS-owned value. Must not be held across a GC.
|
/// 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> {
|
unsafe fn inner(&self) -> JS<T> {
|
||||||
self.inner.clone()
|
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
|
/// 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>>`
|
/// Get an `Option<JSRef<T>>` out of an `Option<Root<T>>`
|
||||||
pub trait RootedReference<T> {
|
pub trait RootedReference<T> {
|
||||||
/// Obtain a safe optional reference to the wrapped JS owned-value that
|
/// 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> {
|
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.
|
/// Return an unrooted `JS<T>` for the inner pointer.
|
||||||
pub fn unrooted(&self) -> JS<T> {
|
pub fn unrooted(&self) -> JS<T> {
|
||||||
JS {
|
JS {
|
||||||
|
|
|
@ -389,7 +389,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
if (*self.unsafe_get()).namespace != ns!(HTML) {
|
if (*self.unsafe_get()).namespace != ns!(HTML) {
|
||||||
return false
|
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()
|
node.owner_doc_for_layout().is_html_document_for_layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
|
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"))
|
(*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue