Title: [204161] trunk
Revision
204161
Author
cdu...@apple.com
Date
2016-08-04 19:59:13 -0700 (Thu, 04 Aug 2016)

Log Message

Add support for DOMTokenList.replace()
https://bugs.webkit.org/show_bug.cgi?id=160573

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline several W3C tests now that more checks are passing.

* web-platform-tests/dom/interfaces-expected.txt:
* web-platform-tests/dom/nodes/Element-classlist-expected.txt:

Source/WebCore:

Add support for DOMTokenList.replace():
https://dom.spec.whatwg.org/#dom-domtokenlist-replace

No new tests, rebaselined existing tests.

* html/DOMTokenList.cpp:
(WebCore::tokenContainsHTMLSpace):
(WebCore::DOMTokenList::validateToken):
(WebCore::DOMTokenList::replace):
* html/DOMTokenList.h:
* html/DOMTokenList.idl:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (204160 => 204161)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-05 02:59:13 UTC (rev 204161)
@@ -1,5 +1,17 @@
 2016-08-04  Chris Dumez  <cdu...@apple.com>
 
+        Add support for DOMTokenList.replace()
+        https://bugs.webkit.org/show_bug.cgi?id=160573
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline several W3C tests now that more checks are passing.
+
+        * web-platform-tests/dom/interfaces-expected.txt:
+        * web-platform-tests/dom/nodes/Element-classlist-expected.txt:
+
+2016-08-04  Chris Dumez  <cdu...@apple.com>
+
         Move insertAdjacent*() API from HTMLElement to Element
         https://bugs.webkit.org/show_bug.cgi?id=160567
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt (204160 => 204161)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-08-05 02:59:13 UTC (rev 204161)
@@ -1506,7 +1506,7 @@
 PASS DOMTokenList interface: operation add(DOMString) 
 PASS DOMTokenList interface: operation remove(DOMString) 
 PASS DOMTokenList interface: operation toggle(DOMString,boolean) 
-FAIL DOMTokenList interface: operation replace(DOMString,DOMString) assert_own_property: interface prototype object missing non-static operation expected property "replace" missing
+PASS DOMTokenList interface: operation replace(DOMString,DOMString) 
 FAIL DOMTokenList interface: operation supports(DOMString) assert_own_property: interface prototype object missing non-static operation expected property "supports" missing
 PASS DOMTokenList interface: attribute value 
 PASS DOMTokenList interface: stringifier 
@@ -1523,8 +1523,8 @@
 PASS DOMTokenList interface: calling remove(DOMString) on document.body.classList with too few arguments must throw TypeError 
 PASS DOMTokenList interface: document.body.classList must inherit property "toggle" with the proper type (5) 
 PASS DOMTokenList interface: calling toggle(DOMString,boolean) on document.body.classList with too few arguments must throw TypeError 
-FAIL DOMTokenList interface: document.body.classList must inherit property "replace" with the proper type (6) assert_inherits: property "replace" not found in prototype chain
-FAIL DOMTokenList interface: calling replace(DOMString,DOMString) on document.body.classList with too few arguments must throw TypeError assert_inherits: property "replace" not found in prototype chain
+PASS DOMTokenList interface: document.body.classList must inherit property "replace" with the proper type (6) 
+PASS DOMTokenList interface: calling replace(DOMString,DOMString) on document.body.classList with too few arguments must throw TypeError 
 FAIL DOMTokenList interface: document.body.classList must inherit property "supports" with the proper type (7) assert_inherits: property "supports" not found in prototype chain
 FAIL DOMTokenList interface: calling supports(DOMString) on document.body.classList with too few arguments must throw TypeError assert_inherits: property "supports" not found in prototype chain
 PASS DOMTokenList interface: document.body.classList must inherit property "value" with the proper type (8) 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-classlist-expected.txt (204160 => 204161)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-classlist-expected.txt	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-classlist-expected.txt	2016-08-05 02:59:13 UTC (rev 204161)
@@ -18,13 +18,13 @@
 PASS .add(empty_string) must throw a SYNTAX_ERR 
 PASS .remove(empty_string) must throw a SYNTAX_ERR 
 PASS .toggle(empty_string) must throw a SYNTAX_ERR 
-FAIL .replace with empty_string must throw a SYNTAX_ERR assert_throws: function "function () { elem.classList.replace('', 'foo'); }" threw object "TypeError: elem.classList.replace is not a function. (In ..." that is not a DOMException SYNTAX_ERR: property "code" is equal to undefined, expected 12
+PASS .replace with empty_string must throw a SYNTAX_ERR 
 PASS .contains(string_with_spaces) must return false 
 PASS .add(string_with_spaces) must throw an INVALID_CHARACTER_ERR 
 PASS .remove(string_with_spaces) must throw an INVALID_CHARACTER_ERR 
 PASS .toggle(string_with_spaces) must throw an INVALID_CHARACTER_ERR 
-FAIL .replace with string_with_spaces must throw a INVALID_CHARACTER_ERR assert_throws: function "function () { elem.classList.replace('z', 'a b'); }" threw object "TypeError: elem.classList.replace is not a function. (In ..." that is not a DOMException INVALID_CHARACTER_ERR: property "code" is equal to undefined, expected 5
-FAIL .replace with an already existing token foo.classList.replace is not a function. (In 'foo.classList.replace('token1', 'token3')', 'foo.classList.replace' is undefined)
+PASS .replace with string_with_spaces must throw a INVALID_CHARACTER_ERR 
+PASS .replace with an already existing token 
 PASS computed style must update when setting .className 
 PASS classList.contains must update when .className is changed 
 PASS classList.contains must be case sensitive 
@@ -54,14 +54,14 @@
 PASS classList.toggle must not break case-sensitive CSS selector matching 
 PASS classList.toggle must be able to remove tokens 
 PASS classList.toggle must be case-sensitive when removing tokens 
-FAIL classList.replace replaces arguments passed, if they are present. secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('bar', 'baz')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must replace existing tokens secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('foo', 'bar')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must not break case-sensitive CSS selector matching assert_not_equals: got disallowed value "italic"
-FAIL classList.replace must replace duplicated tokens secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('token1', 'token3')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must collapse whitespace around replaced tokens secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('token2', 'token4')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must collapse whitespaces around each token secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('token2', 'token3')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must collapse whitespaces around each token and remove duplicates secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('token2', 'token3')', 'secondelem.classList.replace' is undefined)
-FAIL classList.replace must collapse whitespace when replacing duplicate tokens secondelem.classList.replace is not a function. (In 'secondelem.classList.replace('token1', 'token3')', 'secondelem.classList.replace' is undefined)
+PASS classList.replace replaces arguments passed, if they are present. 
+PASS classList.replace must replace existing tokens 
+PASS classList.replace must not break case-sensitive CSS selector matching 
+PASS classList.replace must replace duplicated tokens 
+PASS classList.replace must collapse whitespace around replaced tokens 
+PASS classList.replace must collapse whitespaces around each token 
+PASS classList.replace must collapse whitespaces around each token and remove duplicates 
+PASS classList.replace must collapse whitespace when replacing duplicate tokens 
 PASS CSS class selectors must stop matching when all classes have been removed 
 PASS className must be empty when all classes have been removed 
 PASS classList must stringify to an empty string when all classes have been removed 
@@ -75,6 +75,6 @@
 PASS classList.add should treat \f as a space 
 PASS classList.length must be read-only 
 PASS classList must have [PutForwards=value] 
-FAIL classList.replace should work foo.classList.replace is not a function. (In 'foo.classList.replace('token1', 'token2')', 'foo.classList.replace' is undefined)
+PASS classList.replace should work 
 PASS classList.supports should throw 
 

Modified: trunk/Source/WebCore/ChangeLog (204160 => 204161)


--- trunk/Source/WebCore/ChangeLog	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/Source/WebCore/ChangeLog	2016-08-05 02:59:13 UTC (rev 204161)
@@ -1,3 +1,22 @@
+2016-08-04  Chris Dumez  <cdu...@apple.com>
+
+        Add support for DOMTokenList.replace()
+        https://bugs.webkit.org/show_bug.cgi?id=160573
+
+        Reviewed by Alex Christensen.
+
+        Add support for DOMTokenList.replace():
+        https://dom.spec.whatwg.org/#dom-domtokenlist-replace
+
+        No new tests, rebaselined existing tests.
+
+        * html/DOMTokenList.cpp:
+        (WebCore::tokenContainsHTMLSpace):
+        (WebCore::DOMTokenList::validateToken):
+        (WebCore::DOMTokenList::replace):
+        * html/DOMTokenList.h:
+        * html/DOMTokenList.idl:
+
 2016-08-04  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [iOS] Some videos in iBooks erroneously go fullscreen

Modified: trunk/Source/WebCore/html/DOMTokenList.cpp (204160 => 204161)


--- trunk/Source/WebCore/html/DOMTokenList.cpp	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/Source/WebCore/html/DOMTokenList.cpp	2016-08-05 02:59:13 UTC (rev 204161)
@@ -42,6 +42,11 @@
 {
 }
 
+static inline bool tokenContainsHTMLSpace(const String& token)
+{
+    return token.find(isHTMLSpace) != notFound;
+}
+
 bool DOMTokenList::validateToken(const String& token, ExceptionCode& ec)
 {
     if (token.isEmpty()) {
@@ -49,12 +54,9 @@
         return false;
     }
 
-    unsigned length = token.length();
-    for (unsigned i = 0; i < length; ++i) {
-        if (isHTMLSpace(token[i])) {
-            ec = INVALID_CHARACTER_ERR;
-            return false;
-        }
+    if (tokenContainsHTMLSpace(token)) {
+        ec = INVALID_CHARACTER_ERR;
+        return false;
     }
 
     return true;
@@ -150,6 +152,31 @@
     return true;
 }
 
+void DOMTokenList::replace(const AtomicString& token, const AtomicString& newToken, ExceptionCode& ec)
+{
+    if (token.isEmpty() || newToken.isEmpty()) {
+        ec = SYNTAX_ERR;
+        return;
+    }
+
+    if (tokenContainsHTMLSpace(token) || tokenContainsHTMLSpace(newToken)) {
+        ec = INVALID_CHARACTER_ERR;
+        return;
+    }
+
+    auto& tokens = this->tokens();
+    size_t index = tokens.find(token);
+    if (index == notFound)
+        return;
+
+    if (tokens.find(newToken) != notFound)
+        tokens.remove(index);
+    else
+        tokens[index] = newToken;
+
+    updateAssociatedAttributeFromTokens();
+}
+
 const AtomicString& DOMTokenList::value() const
 {
     if (m_cachedValue.isNull()) {

Modified: trunk/Source/WebCore/html/DOMTokenList.h (204160 => 204161)


--- trunk/Source/WebCore/html/DOMTokenList.h	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/Source/WebCore/html/DOMTokenList.h	2016-08-05 02:59:13 UTC (rev 204161)
@@ -54,6 +54,7 @@
     void remove(const Vector<String>&, ExceptionCode&);
     void remove(const AtomicString&, ExceptionCode&);
     bool toggle(const AtomicString&, Optional<bool> force, ExceptionCode&);
+    void replace(const AtomicString& token, const AtomicString& newToken, ExceptionCode&);
 
     const AtomicString& toString() const { return value(); }
 

Modified: trunk/Source/WebCore/html/DOMTokenList.idl (204160 => 204161)


--- trunk/Source/WebCore/html/DOMTokenList.idl	2016-08-05 02:50:19 UTC (rev 204160)
+++ trunk/Source/WebCore/html/DOMTokenList.idl	2016-08-05 02:59:13 UTC (rev 204161)
@@ -33,6 +33,7 @@
     [RaisesException] void add(DOMString... tokens);
     [RaisesException] void remove(DOMString... tokens);
     [RaisesException] boolean toggle(DOMString token, optional boolean force);
+    [RaisesException] void replace(DOMString token, DOMString newToken);
 
     iterable<DOMString>;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to