From 0bdab6bb50073c4dbcd54610d03fdc7ed7c0a8d2 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 7 Dec 2019 13:22:10 +0100 Subject: [PATCH] Return a boolean from DOMTokenList::replace to match the spec Fixes #25129 --- components/script/dom/domtokenlist.rs | 6 +- .../script/dom/webidls/DOMTokenList.webidl | 2 +- .../dom/nodes/Element-classlist.html.ini | 330 ------------------ 3 files changed, 5 insertions(+), 333 deletions(-) diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index d6c5ac1537f5..b870ab4f16da 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -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 { 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 diff --git a/components/script/dom/webidls/DOMTokenList.webidl b/components/script/dom/webidls/DOMTokenList.webidl index ed4a541f7303..b2d604ee2a9a 100644 --- a/components/script/dom/webidls/DOMTokenList.webidl +++ b/components/script/dom/webidls/DOMTokenList.webidl @@ -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; diff --git a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini index 7bfd658f0722..95c9293d9955 100644 --- a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini +++ b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini @@ -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 -