diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 24eda14cab5..88366f591d2 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -171,14 +171,14 @@ pub trait RawLayoutElementHelpers { #[inline] #[allow(unsafe_code)] -unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom) -> Option<&'a JS> { +unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom) -> Option> { // cast to point to T in RefCell directly let attrs = elem.attrs.borrow_for_layout(); attrs.iter().find(|attr: & &JS| { let attr = attr.to_layout().unsafe_get(); *name == (*attr).local_name_atom_forever() && (*attr).namespace() == namespace - }) + }).map(|attr| attr.to_layout()) } #[allow(unsafe_code)] @@ -187,8 +187,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.to_layout().unsafe_get(); - (*attr).value_ref_forever() + (*attr.unsafe_get()).value_ref_forever() }) } @@ -208,40 +207,22 @@ impl RawLayoutElementHelpers for Element { #[inline] unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &Atom) -> Option { - let attrs = self.attrs.borrow_for_layout(); - (*attrs).iter().find(|attr: & &JS| { - let attr = attr.to_layout().unsafe_get(); - *name == (*attr).local_name_atom_forever() && - (*attr).namespace() == namespace - }).and_then(|attr| { - let attr = attr.to_layout().unsafe_get(); - (*attr).value_atom_forever() + get_attr_for_layout(self, namespace, name).and_then(|attr| { + (*attr.unsafe_get()).value_atom_forever() }) } #[inline] unsafe fn has_class_for_layout(&self, name: &Atom) -> bool { - let attrs = self.attrs.borrow_for_layout(); - (*attrs).iter().find(|attr: & &JS| { - let attr = attr.to_layout().unsafe_get(); - (*attr).local_name_atom_forever() == atom!("class") - }).map_or(false, |attr| { - let attr = attr.to_layout().unsafe_get(); - (*attr).value_tokens_forever().map(|tokens| { - tokens.iter().any(|atom| atom == name) - }) - }.take().unwrap()) + get_attr_for_layout(self, &ns!(""), &atom!("class")).map_or(false, |attr| { + (*attr.unsafe_get()).value_tokens_forever().unwrap().iter().any(|atom| atom == name) + }) } #[inline] unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> { - let attrs = self.attrs.borrow_for_layout(); - (*attrs).iter().find(|attr: & &JS| { - let attr = attr.to_layout().unsafe_get(); - (*attr).local_name_atom_forever() == atom!("class") - }).and_then(|attr| { - let attr = attr.to_layout().unsafe_get(); - (*attr).value_tokens_forever() + get_attr_for_layout(self, &ns!(""), &atom!("class")).map(|attr| { + (*attr.unsafe_get()).value_tokens_forever().unwrap() }) } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index de093bd00a2..efd18936509 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -14,6 +14,20 @@ "local_changes": { "deleted": [], "items": { + "reftest": { + "css/class-namespaces.html": [ + { + "path": "css/class-namespaces.html", + "references": [ + [ + "/_mozilla/css/class-namespaces-ref.html", + "==" + ] + ], + "url": "/_mozilla/css/class-namespaces.html" + } + ] + }, "testharness": { "mozilla/DOMParser.html": [ { @@ -515,7 +529,20 @@ ] } }, - "reftest_nodes": {} + "reftest_nodes": { + "css/class-namespaces.html": [ + { + "path": "css/class-namespaces.html", + "references": [ + [ + "/_mozilla/css/class-namespaces-ref.html", + "==" + ] + ], + "url": "/_mozilla/css/class-namespaces.html" + } + ] + } }, "reftest_nodes": {}, "rev": null, diff --git a/tests/wpt/mozilla/tests/css/class-namespaces-ref.html b/tests/wpt/mozilla/tests/css/class-namespaces-ref.html new file mode 100644 index 00000000000..96c68eff366 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/class-namespaces-ref.html @@ -0,0 +1,5 @@ + + +

AAA

BBB

diff --git a/tests/wpt/mozilla/tests/css/class-namespaces.html b/tests/wpt/mozilla/tests/css/class-namespaces.html new file mode 100644 index 00000000000..239d1629fc3 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/class-namespaces.html @@ -0,0 +1,16 @@ + + + +