mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Return a boolean from DOMTokenList::replace to match the spec
Fixes #25129
This commit is contained in:
parent
cfa50b8222
commit
0bdab6bb50
3 changed files with 5 additions and 333 deletions
|
@ -151,7 +151,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-replace
|
||||
fn Replace(&self, token: DOMString, new_token: DOMString) -> ErrorResult {
|
||||
fn Replace(&self, token: DOMString, new_token: DOMString) -> Fallible<bool> {
|
||||
if token.is_empty() || new_token.is_empty() {
|
||||
// Step 1.
|
||||
return Err(Error::Syntax);
|
||||
|
@ -164,6 +164,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
let token = Atom::from(token);
|
||||
let new_token = Atom::from(new_token);
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
let mut result = false;
|
||||
if let Some(pos) = atoms.iter().position(|atom| *atom == token) {
|
||||
if !atoms.contains(&new_token) {
|
||||
atoms[pos] = new_token;
|
||||
|
@ -173,8 +174,9 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
// Step 5.
|
||||
self.element
|
||||
.set_atomic_tokenlist_attribute(&self.local_name, atoms);
|
||||
result = true;
|
||||
}
|
||||
Ok(())
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
// check-tidy: no specs after this line
|
||||
|
|
|
@ -19,7 +19,7 @@ interface DOMTokenList {
|
|||
[CEReactions, Throws]
|
||||
boolean toggle(DOMString token, optional boolean force);
|
||||
[CEReactions, Throws]
|
||||
void replace(DOMString token, DOMString newToken);
|
||||
boolean replace(DOMString token, DOMString newToken);
|
||||
|
||||
[CEReactions, Pure]
|
||||
stringifier attribute DOMString value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue