auto merge of #4908 : Ms2ger/servo/dead-code-js, r=jdm

This commit is contained in:
bors-servo 2015-02-12 13:21:47 -07:00
commit b351b216c6
3 changed files with 21 additions and 27 deletions

View file

@ -83,6 +83,14 @@ impl<T: Reflectable> Unrooted<T> {
}
}
/// Create a new unrooted value from a `JS<T>`.
#[allow(unrooted_must_root)]
pub fn from_js(ptr: JS<T>) -> Unrooted<T> {
Unrooted {
ptr: ptr.ptr
}
}
/// Get the `Reflector` for this pointer.
pub fn reflector<'a>(&'a self) -> &'a Reflector {
unsafe {
@ -189,7 +197,7 @@ pub struct JS<T> {
impl<T> JS<T> {
/// Returns `LayoutJS<T>` containing the same pointer.
fn to_layout(self) -> LayoutJS<T> {
pub unsafe fn to_layout(self) -> LayoutJS<T> {
LayoutJS {
ptr: self.ptr.clone()
}
@ -283,7 +291,7 @@ impl<U: Reflectable> JS<U> {
impl<T: Reflectable> Reflectable for JS<T> {
fn reflector<'a>(&'a self) -> &'a Reflector {
unsafe {
(*self.unsafe_get()).reflector()
(**self.ptr).reflector()
}
}
}
@ -382,16 +390,10 @@ impl<T: Reflectable> MutNullableJS<T> {
self.ptr.get().map(Temporary::new)
}
/// Retrieve a copy of the inner optional `JS<T>`. For use by layout, which
/// can't use safe types like Temporary.
pub unsafe fn get_inner(&self) -> Option<JS<T>> {
self.ptr.get()
}
/// Retrieve a copy of the inner optional `JS<T>` as `LayoutJS<T>`.
/// For use by layout, which can't use safe types like Temporary.
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
self.get_inner().map(|js| js.to_layout())
self.ptr.get().map(|js| js.to_layout())
}
/// Retrieve a copy of the current inner value. If it is `None`, it is
@ -411,12 +413,6 @@ impl<T: Reflectable> MutNullableJS<T> {
}
impl<T: Reflectable> JS<T> {
/// Returns an unsafe pointer to the interior of this object.
/// This should only be used by the DOM bindings.
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<T> values are only used as fields in DOM types that
/// are reachable in the GC graph, so this unrooted value becomes

View file

@ -163,7 +163,7 @@ unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name
// cast to point to T in RefCell<T> directly
let attrs = elem.attrs.borrow_for_layout();
attrs.iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
*name == (*attr).local_name_atom_forever() &&
(*attr).namespace() == namespace
})
@ -174,7 +174,7 @@ impl RawLayoutElementHelpers for Element {
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
-> Option<&'a str> {
get_attr_for_layout(self, namespace, name).map(|attr| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).value_ref_forever()
})
}
@ -183,7 +183,7 @@ impl RawLayoutElementHelpers for Element {
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str> {
let attrs = self.attrs.borrow_for_layout();
(*attrs).iter().filter_map(|attr: &JS<Attr>| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
if *name == (*attr).local_name_atom_forever() {
Some((*attr).value_ref_forever())
} else {
@ -197,11 +197,11 @@ impl RawLayoutElementHelpers for Element {
-> Option<Atom> {
let attrs = self.attrs.borrow_for_layout();
(*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
*name == (*attr).local_name_atom_forever() &&
(*attr).namespace() == namespace
}).and_then(|attr| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).value_atom_forever()
})
}
@ -210,10 +210,10 @@ impl RawLayoutElementHelpers for Element {
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
let attrs = self.attrs.borrow_for_layout();
(*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).local_name_atom_forever() == atom!("class")
}).map_or(false, |attr| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).value_tokens_forever().map(|tokens| {
tokens.iter().any(|atom| atom == name)
})
@ -224,10 +224,10 @@ impl RawLayoutElementHelpers for Element {
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> {
let attrs = self.attrs.borrow_for_layout();
(*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).local_name_atom_forever() == atom!("class")
}).and_then(|attr| {
let attr = attr.unsafe_get();
let attr = attr.to_layout().unsafe_get();
(*attr).value_tokens_forever()
})
}

View file

@ -88,9 +88,7 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> {
match (*self.data.borrow())[name][0].clone() {
FormDatum::StringData(ref s) => Some(eString(s.clone())),
FormDatum::FileData(ref f) => {
Some(eFile(unsafe {
Unrooted::from_raw(f.unsafe_get())
}))
Some(eFile(Unrooted::from_js(*f)))
}
}
} else {