Use get_attr_for_layout in ghas_class_for_layout.

This fixes a panic if this code was ever called on an element with a class
attribute in a non-null namespace. In this case, the attribute would not have
been parsed into a list of tokens, so value_tokens_forever() would have
returned None.

However, this function is, as far as I can tell, never called, because of the
way selectors are evaluated in layout. ('Return the selectors that match this
node' rather than 'return the nodes that match this selector'; the latter
uses only each_class.)
This commit is contained in:
Ms2ger 2015-04-18 16:56:54 +02:00
parent 39e3ace817
commit bdb8657cf6

View file

@ -214,16 +214,9 @@ impl RawLayoutElementHelpers for Element {
#[inline] #[inline]
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool { unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
let attrs = self.attrs.borrow_for_layout(); get_attr_for_layout(self, &ns!(""), &atom!("class")).map_or(false, |attr| {
(*attrs).iter().find(|attr: & &JS<Attr>| { (*attr.unsafe_get()).value_tokens_forever().unwrap().iter().any(|atom| atom == name)
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())
} }
#[inline] #[inline]