diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-02-12 13:21:47 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-02-12 13:21:47 -0700 |
commit | b351b216c6ac5df1913ddd589d3300d7cd07ebb0 (patch) | |
tree | 4298fb09dd103b1a92d1eb0ff4fac7909304ee60 /components/script/dom | |
parent | b655b54f8022d963460e510511ad774a1a1d9ccd (diff) | |
parent | 7b1b030f8a35c3bc52ff0eb10d6d0d4e7d9c08d7 (diff) | |
download | servo-b351b216c6ac5df1913ddd589d3300d7cd07ebb0.tar.gz servo-b351b216c6ac5df1913ddd589d3300d7cd07ebb0.zip |
auto merge of #4908 : Ms2ger/servo/dead-code-js, r=jdm
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/js.rs | 26 | ||||
-rw-r--r-- | components/script/dom/element.rs | 18 | ||||
-rw-r--r-- | components/script/dom/formdata.rs | 4 |
3 files changed, 21 insertions, 27 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 970281c2977..a842583cecb 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -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 diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 56e971b8522..ad1e70b30d1 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -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() }) } diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 85f3279aa9b..5d8e5a8f809 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -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 { |