Do not root DOMTokenList::element

This commit is contained in:
Anthony Ramine 2015-10-17 14:30:41 +02:00
parent 822e6f0d48
commit 71dcabfad8

View file

@ -39,8 +39,7 @@ impl DOMTokenList {
} }
fn attribute(&self) -> Option<Root<Attr>> { fn attribute(&self) -> Option<Root<Attr>> {
let element = self.element.root(); self.element.get_attribute(&ns!(""), &self.local_name)
element.r().get_attribute(&ns!(""), &self.local_name)
} }
fn check_token_exceptions(&self, token: &str) -> Fallible<Atom> { fn check_token_exceptions(&self, token: &str) -> Fallible<Atom> {
@ -87,43 +86,40 @@ impl DOMTokenListMethods for DOMTokenList {
// https://dom.spec.whatwg.org/#dom-domtokenlist-add // https://dom.spec.whatwg.org/#dom-domtokenlist-add
fn Add(&self, tokens: Vec<DOMString>) -> ErrorResult { fn Add(&self, tokens: Vec<DOMString>) -> ErrorResult {
let element = self.element.root(); let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
for token in &tokens { for token in &tokens {
let token = try!(self.check_token_exceptions(&token)); let token = try!(self.check_token_exceptions(&token));
if !atoms.iter().any(|atom| *atom == token) { if !atoms.iter().any(|atom| *atom == token) {
atoms.push(token); atoms.push(token);
} }
} }
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms); self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(()) Ok(())
} }
// https://dom.spec.whatwg.org/#dom-domtokenlist-remove // https://dom.spec.whatwg.org/#dom-domtokenlist-remove
fn Remove(&self, tokens: Vec<DOMString>) -> ErrorResult { fn Remove(&self, tokens: Vec<DOMString>) -> ErrorResult {
let element = self.element.root(); let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
for token in &tokens { for token in &tokens {
let token = try!(self.check_token_exceptions(&token)); let token = try!(self.check_token_exceptions(&token));
atoms.iter().position(|atom| *atom == token).map(|index| { atoms.iter().position(|atom| *atom == token).map(|index| {
atoms.remove(index) atoms.remove(index)
}); });
} }
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms); self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(()) Ok(())
} }
// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle // https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
fn Toggle(&self, token: DOMString, force: Option<bool>) -> Fallible<bool> { fn Toggle(&self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
let element = self.element.root(); let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
let token = try!(self.check_token_exceptions(&token)); let token = try!(self.check_token_exceptions(&token));
match atoms.iter().position(|atom| *atom == token) { match atoms.iter().position(|atom| *atom == token) {
Some(index) => match force { Some(index) => match force {
Some(true) => Ok(true), Some(true) => Ok(true),
_ => { _ => {
atoms.remove(index); atoms.remove(index);
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms); self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(false) Ok(false)
} }
}, },
@ -131,7 +127,7 @@ impl DOMTokenListMethods for DOMTokenList {
Some(false) => Ok(false), Some(false) => Ok(false),
_ => { _ => {
atoms.push(token); atoms.push(token);
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms); self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(true) Ok(true)
} }
} }
@ -140,7 +136,7 @@ impl DOMTokenListMethods for DOMTokenList {
// https://dom.spec.whatwg.org/#stringification-behavior // https://dom.spec.whatwg.org/#stringification-behavior
fn Stringifier(&self) -> DOMString { fn Stringifier(&self) -> DOMString {
let tokenlist = self.element.root().r().get_tokenlist_attribute(&self.local_name); let tokenlist = self.element.get_tokenlist_attribute(&self.local_name);
str_join(&tokenlist, "\x20") str_join(&tokenlist, "\x20")
} }