diff options
author | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-08-25 13:37:19 -0400 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-08-25 13:58:42 -0400 |
commit | 400a31443b68df6dfd0f0b5520dbf67c1ff20c1b (patch) | |
tree | 52430c67b2c9819777f71c2ce2aa8a4c50b5b30c /src | |
parent | caa55bf9edd425abe58336248a45a89c10d81eb0 (diff) | |
download | servo-400a31443b68df6dfd0f0b5520dbf67c1ff20c1b.tar.gz servo-400a31443b68df6dfd0f0b5520dbf67c1ff20c1b.zip |
Cleaned DOMTokenList code duplication
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/dom/domtokenlist.rs | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/components/script/dom/domtokenlist.rs b/src/components/script/dom/domtokenlist.rs index 3d252d36731..11f7eaf59d0 100644 --- a/src/components/script/dom/domtokenlist.rs +++ b/src/components/script/dom/domtokenlist.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, TokenListAttrValue}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::DOMTokenListBinding; use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods; use dom::bindings::error::{Fallible, InvalidCharacter, Syntax}; @@ -71,31 +71,16 @@ impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> { impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { // http://dom.spec.whatwg.org/#dom-domtokenlist-length fn Length(&self) -> u32 { - let attribute = self.attribute().root(); - match attribute { - Some(attribute) => { - match *attribute.deref().value() { - TokenListAttrValue(_, ref indexes) => indexes.len() as u32, - _ => fail!("Expected a TokenListAttrValue"), - } - } - None => 0, - } + self.attribute().root().map(|attr| { + attr.value().tokens().map(|tokens| tokens.len()).unwrap_or(0) + }).unwrap_or(0) as u32 } // http://dom.spec.whatwg.org/#dom-domtokenlist-item fn Item(&self, index: u32) -> Option<DOMString> { - let attribute = self.attribute().root(); - attribute.and_then(|attribute| { - match *attribute.deref().value() { - TokenListAttrValue(ref value, ref indexes) => { - indexes.as_slice().get(index as uint).map(|&(start, end)| { - value.as_slice().slice(start, end).to_string() - }) - }, - _ => fail!("Expected a TokenListAttrValue"), - } - }) + self.attribute().root().and_then(|attr| attr.value().tokens().and_then(|mut tokens| { + tokens.idx(index as uint).map(|token| token.as_slice().to_string()) + })) } fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<DOMString> { |