mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Do not root DOMTokenList::element
This commit is contained in:
parent
822e6f0d48
commit
71dcabfad8
1 changed files with 9 additions and 13 deletions
|
@ -39,8 +39,7 @@ impl DOMTokenList {
|
|||
}
|
||||
|
||||
fn attribute(&self) -> Option<Root<Attr>> {
|
||||
let element = self.element.root();
|
||||
element.r().get_attribute(&ns!(""), &self.local_name)
|
||||
self.element.get_attribute(&ns!(""), &self.local_name)
|
||||
}
|
||||
|
||||
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
|
||||
fn Add(&self, tokens: Vec<DOMString>) -> ErrorResult {
|
||||
let element = self.element.root();
|
||||
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
for token in &tokens {
|
||||
let token = try!(self.check_token_exceptions(&token));
|
||||
if !atoms.iter().any(|atom| *atom == 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(())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-remove
|
||||
fn Remove(&self, tokens: Vec<DOMString>) -> ErrorResult {
|
||||
let element = self.element.root();
|
||||
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
for token in &tokens {
|
||||
let token = try!(self.check_token_exceptions(&token));
|
||||
atoms.iter().position(|atom| *atom == token).map(|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(())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
|
||||
fn Toggle(&self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
|
||||
let element = self.element.root();
|
||||
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
let token = try!(self.check_token_exceptions(&token));
|
||||
match atoms.iter().position(|atom| *atom == token) {
|
||||
Some(index) => match force {
|
||||
Some(true) => Ok(true),
|
||||
_ => {
|
||||
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)
|
||||
}
|
||||
},
|
||||
|
@ -131,7 +127,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
Some(false) => Ok(false),
|
||||
_ => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +136,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
|
||||
// https://dom.spec.whatwg.org/#stringification-behavior
|
||||
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")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue