Skip to content

Commit

Permalink
Return a boolean from DOMTokenList::replace to match the spec
Browse files Browse the repository at this point in the history
Fixes #25129
  • Loading branch information
Eijebong committed Dec 7, 2019
1 parent cfa50b8 commit 0bdab6b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 333 deletions.
6 changes: 4 additions & 2 deletions components/script/dom/domtokenlist.rs
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMTokenList.webidl
Expand Up @@ -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;
Expand Down
330 changes: 0 additions & 330 deletions tests/wpt/metadata/dom/nodes/Element-classlist.html.ini
Expand Up @@ -75,333 +75,3 @@
[classList.replace("c", "a") with attribute value "c b a" (foo node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "a" (HTML node)]
expected: FAIL

[classList.replace("A", "b") with attribute value "a" (HTML node)]
expected: FAIL

[classList.replace("b", "A") with attribute value "a b" (HTML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b" (HTML node)]
expected: FAIL

[classList.replace("d", "e") with attribute value "a b c" (HTML node)]
expected: FAIL

[classList.replace("c", "d") with attribute value "a a a b" (HTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value null (HTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "" (HTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " " (HTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " a \\f" (HTML node)]
expected: FAIL

[classList.replace("b", "d") with attribute value "a b c" (HTML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b c" (HTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "a b a" (HTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "a b a" (HTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value " a a b" (HTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value " a a b" (HTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (HTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (HTML node)]
expected: FAIL

[classList.replace(null, "b") with attribute value "a null" (HTML node)]
expected: FAIL

[classList.replace("a", null) with attribute value "a b" (HTML node)]
expected: FAIL

[classList.replace(undefined, "b") with attribute value "a undefined" (HTML node)]
expected: FAIL

[classList.replace("a", undefined) with attribute value "a b" (HTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "a" (XHTML node)]
expected: FAIL

[classList.replace("A", "b") with attribute value "a" (XHTML node)]
expected: FAIL

[classList.replace("b", "A") with attribute value "a b" (XHTML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b" (XHTML node)]
expected: FAIL

[classList.replace("d", "e") with attribute value "a b c" (XHTML node)]
expected: FAIL

[classList.replace("c", "d") with attribute value "a a a b" (XHTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value null (XHTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "" (XHTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " " (XHTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " a \\f" (XHTML node)]
expected: FAIL

[classList.replace("b", "d") with attribute value "a b c" (XHTML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b c" (XHTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "a b a" (XHTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "a b a" (XHTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value " a a b" (XHTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value " a a b" (XHTML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (XHTML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (XHTML node)]
expected: FAIL

[classList.replace(null, "b") with attribute value "a null" (XHTML node)]
expected: FAIL

[classList.replace("a", null) with attribute value "a b" (XHTML node)]
expected: FAIL

[classList.replace(undefined, "b") with attribute value "a undefined" (XHTML node)]
expected: FAIL

[classList.replace("a", undefined) with attribute value "a b" (XHTML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "a" (MathML node)]
expected: FAIL

[classList.replace("A", "b") with attribute value "a" (MathML node)]
expected: FAIL

[classList.replace("b", "A") with attribute value "a b" (MathML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b" (MathML node)]
expected: FAIL

[classList.replace("d", "e") with attribute value "a b c" (MathML node)]
expected: FAIL

[classList.replace("c", "d") with attribute value "a a a b" (MathML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value null (MathML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "" (MathML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " " (MathML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " a \\f" (MathML node)]
expected: FAIL

[classList.replace("b", "d") with attribute value "a b c" (MathML node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b c" (MathML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "a b a" (MathML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "a b a" (MathML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value " a a b" (MathML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value " a a b" (MathML node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (MathML node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (MathML node)]
expected: FAIL

[classList.replace(null, "b") with attribute value "a null" (MathML node)]
expected: FAIL

[classList.replace("a", null) with attribute value "a b" (MathML node)]
expected: FAIL

[classList.replace(undefined, "b") with attribute value "a undefined" (MathML node)]
expected: FAIL

[classList.replace("a", undefined) with attribute value "a b" (MathML node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "a" (XML node with null namespace)]
expected: FAIL

[classList.replace("A", "b") with attribute value "a" (XML node with null namespace)]
expected: FAIL

[classList.replace("b", "A") with attribute value "a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("d", "e") with attribute value "a b c" (XML node with null namespace)]
expected: FAIL

[classList.replace("c", "d") with attribute value "a a a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "b") with attribute value null (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "b") with attribute value "" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "b") with attribute value " " (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "b") with attribute value " a \\f" (XML node with null namespace)]
expected: FAIL

[classList.replace("b", "d") with attribute value "a b c" (XML node with null namespace)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b c" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "c") with attribute value "a b a" (XML node with null namespace)]
expected: FAIL

[classList.replace("b", "c") with attribute value "a b a" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "c") with attribute value " a a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("b", "c") with attribute value " a a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (XML node with null namespace)]
expected: FAIL

[classList.replace("b", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (XML node with null namespace)]
expected: FAIL

[classList.replace(null, "b") with attribute value "a null" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", null) with attribute value "a b" (XML node with null namespace)]
expected: FAIL

[classList.replace(undefined, "b") with attribute value "a undefined" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", undefined) with attribute value "a b" (XML node with null namespace)]
expected: FAIL

[classList.replace("a", "b") with attribute value "a" (foo node)]
expected: FAIL

[classList.replace("A", "b") with attribute value "a" (foo node)]
expected: FAIL

[classList.replace("b", "A") with attribute value "a b" (foo node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b" (foo node)]
expected: FAIL

[classList.replace("d", "e") with attribute value "a b c" (foo node)]
expected: FAIL

[classList.replace("c", "d") with attribute value "a a a b" (foo node)]
expected: FAIL

[classList.replace("a", "b") with attribute value null (foo node)]
expected: FAIL

[classList.replace("a", "b") with attribute value "" (foo node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " " (foo node)]
expected: FAIL

[classList.replace("a", "b") with attribute value " a \\f" (foo node)]
expected: FAIL

[classList.replace("b", "d") with attribute value "a b c" (foo node)]
expected: FAIL

[classList.replace("c", "a") with attribute value "a b c" (foo node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "a b a" (foo node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "a b a" (foo node)]
expected: FAIL

[classList.replace("a", "c") with attribute value " a a b" (foo node)]
expected: FAIL

[classList.replace("b", "c") with attribute value " a a b" (foo node)]
expected: FAIL

[classList.replace("a", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (foo node)]
expected: FAIL

[classList.replace("b", "c") with attribute value "\\t\\n\\f\\r a\\t\\n\\f\\r b\\t\\n\\f\\r " (foo node)]
expected: FAIL

[classList.replace(null, "b") with attribute value "a null" (foo node)]
expected: FAIL

[classList.replace("a", null) with attribute value "a b" (foo node)]
expected: FAIL

[classList.replace(undefined, "b") with attribute value "a undefined" (foo node)]
expected: FAIL

[classList.replace("a", undefined) with attribute value "a b" (foo node)]
expected: FAIL

0 comments on commit 0bdab6b

Please sign in to comment.