mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
DOMTokenList::check_token_exceptions now returns an Atom
This commit is contained in:
parent
51fac3d2cc
commit
08e7cf24cd
1 changed files with 11 additions and 11 deletions
|
@ -5,7 +5,7 @@
|
||||||
use dom::attr::{Attr, AttrHelpers};
|
use dom::attr::{Attr, AttrHelpers};
|
||||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding;
|
use dom::bindings::codegen::Bindings::DOMTokenListBinding;
|
||||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::error::Error::{InvalidCharacter, Syntax};
|
use dom::bindings::error::Error::{InvalidCharacter, Syntax};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
|
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
|
||||||
|
@ -48,7 +48,7 @@ impl Reflectable for DOMTokenList {
|
||||||
|
|
||||||
trait PrivateDOMTokenListHelpers {
|
trait PrivateDOMTokenListHelpers {
|
||||||
fn attribute(self) -> Option<Temporary<Attr>>;
|
fn attribute(self) -> Option<Temporary<Attr>>;
|
||||||
fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<&'a str>;
|
fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<Atom>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
||||||
|
@ -57,11 +57,11 @@ impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
||||||
element.get_attribute(ns!(""), &self.local_name)
|
element.get_attribute(ns!(""), &self.local_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<&'a str> {
|
fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<Atom> {
|
||||||
match token {
|
match token {
|
||||||
"" => Err(Syntax),
|
"" => Err(Syntax),
|
||||||
token if token.find(HTML_SPACE_CHARACTERS).is_some() => Err(InvalidCharacter),
|
slice if slice.find(HTML_SPACE_CHARACTERS).is_some() => Err(InvalidCharacter),
|
||||||
token => Ok(token)
|
slice => Ok(Atom::from_slice(slice))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,13 +90,13 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
||||||
fn Contains(self, token: DOMString) -> Fallible<bool> {
|
fn Contains(self, token: DOMString) -> Fallible<bool> {
|
||||||
self.check_token_exceptions(token.as_slice()).map(|slice| {
|
self.check_token_exceptions(token.as_slice()).map(|token| {
|
||||||
self.attribute().root().map(|attr| {
|
self.attribute().root().map(|attr| {
|
||||||
let value = attr.value();
|
attr.value()
|
||||||
let tokens = value.tokens()
|
.tokens()
|
||||||
.expect("Should have parsed this attribute");
|
.expect("Should have parsed this attribute")
|
||||||
let atom = Atom::from_slice(slice);
|
.iter()
|
||||||
tokens.iter().any(|token| *token == atom)
|
.any(|atom| *atom == token)
|
||||||
}).unwrap_or(false)
|
}).unwrap_or(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue