mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Remove JS::unsafe_get.
The codegen users already migrated to Unrooted, and the layout users are better off using LayoutJS.
This commit is contained in:
parent
8ab7d37ef2
commit
b3f93b25a5
2 changed files with 11 additions and 17 deletions
|
@ -197,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()
|
||||
}
|
||||
|
@ -291,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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -419,12 +419,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
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue