From bdb8657cf68307249607b6abe9723c8577ea7621 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 18 Apr 2015 16:56:54 +0200 Subject: [PATCH] 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.) --- components/script/dom/element.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 09c5232a264..06eae2592c7 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -214,16 +214,9 @@ impl RawLayoutElementHelpers for Element { #[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]