auto merge of #4084 : Ms2ger/servo/tokenlist-robust, r=jdm

Previously, if the attribute was not parsed into a token list, and the
tokens() method returned None, DOMTokenList#contains would silently return
false. This issue was encountered in
<https://github.com/servo/servo/pull/4076> and took quite some time to
figure out.
This commit is contained in:
bors-servo 2014-11-24 10:39:35 -07:00
commit 51aa2fde10

View file

@ -90,10 +90,13 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains
fn Contains(self, token: DOMString) -> Fallible<bool> {
self.check_token_exceptions(token.as_slice()).map(|slice| {
self.attribute().root().and_then(|attr| attr.value().tokens().map(|tokens| {
self.attribute().root().map(|attr| {
let value = attr.value();
let tokens = value.tokens()
.expect("Should have parsed this attribute");
let atom = Atom::from_slice(slice);
tokens.iter().any(|token| *token == atom)
})).unwrap_or(false)
}).unwrap_or(false)
})
}
}