Title: [206560] trunk
Revision
206560
Author
[email protected]
Date
2016-09-28 16:34:54 -0700 (Wed, 28 Sep 2016)

Log Message

DOMTokenList’s value and stringifier should not return parsed tokens
https://bugs.webkit.org/show_bug.cgi?id=161076

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Rebaselined tests that are now passing.

* web-platform-tests/dom/lists/DOMTokenList-stringifier-expected.txt:
* web-platform-tests/dom/lists/DOMTokenList-value-expected.txt:
* web-platform-tests/dom/nodes/Element-classlist-expected.txt:

Source/WebCore:

Updated our implementation of DOMTokenList.prototype.value and its toString function
to match the latest DOM specification: https://dom.spec.whatwg.org/#interface-domtokenlist

"value" attribute, on getting, runs its serialize steps, which simply gets the attribute value.
On setting, it sets the attribute value with the given value.

The stringification behavior returns the same serialize steps as "value" attribute on getting.

This change simplifies our implementation of DOMTokenList and removes the need for m_cachedValue,
which has been removed in this patch.

No new tests since existing tests cover this.

* html/DOMTokenList.cpp:
(WebCore::DOMTokenList::value): Just call getAttribute.
(WebCore::DOMTokenList::setValue): Just call setAttribute.
(WebCore::DOMTokenList::updateTokensFromAttributeValue):
(WebCore::DOMTokenList::associatedAttributeValueChanged):
(WebCore::DOMTokenList::updateAssociatedAttributeFromTokens): Moved the code to update the tokens
from from the attribute value. This is the "update steps".
* html/DOMTokenList.h:

LayoutTests:

Added more test cases and rebaselined tests. Most of changes are due to the change that DOMTokenList's value
and stringifier now returns the original attribute value with extra whitespaces.

* fast/dom/HTMLLinkElement/sizes-setter-expected.txt:
* fast/dom/HTMLLinkElement/sizes-setter.html:
* fast/dom/HTMLOutputElement/dom-settable-token-list-expected.txt:
* fast/dom/HTMLOutputElement/htmloutputelement-expected.txt:
* fast/dom/HTMLOutputElement/htmloutputelement.html:
* fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js:
* fast/frames/sandbox-attribute-expected.txt:
* fast/frames/sandbox-attribute.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (206559 => 206560)


--- trunk/LayoutTests/ChangeLog	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/ChangeLog	2016-09-28 23:34:54 UTC (rev 206560)
@@ -1,3 +1,22 @@
+2016-09-28  Ryosuke Niwa  <[email protected]>
+
+        DOMTokenList’s value and stringifier should not return parsed tokens
+        https://bugs.webkit.org/show_bug.cgi?id=161076
+
+        Reviewed by Chris Dumez.
+
+        Added more test cases and rebaselined tests. Most of changes are due to the change that DOMTokenList's value
+        and stringifier now returns the original attribute value with extra whitespaces.
+
+        * fast/dom/HTMLLinkElement/sizes-setter-expected.txt:
+        * fast/dom/HTMLLinkElement/sizes-setter.html:
+        * fast/dom/HTMLOutputElement/dom-settable-token-list-expected.txt:
+        * fast/dom/HTMLOutputElement/htmloutputelement-expected.txt:
+        * fast/dom/HTMLOutputElement/htmloutputelement.html:
+        * fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js:
+        * fast/frames/sandbox-attribute-expected.txt:
+        * fast/frames/sandbox-attribute.html:
+
 2016-09-28  Ryan Haddad  <[email protected]>
 
         Marking fast/images/animated-gif-restored-from-bfcache.html as flaky on mac-wk2 debug.

Modified: trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter-expected.txt (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -5,8 +5,11 @@
 
 PASS link.sizes.__proto__ is DOMTokenList.prototype
 link.sizes = '10x10  20x20'
-PASS String(link.sizes) is "10x10 20x20"
-PASS link.getAttribute('sizes') is "10x10 20x20"
+PASS String(link.sizes) is "10x10  20x20"
+PASS link.getAttribute('sizes') is "10x10  20x20"
+link.sizes.add('30x30')
+PASS String(link.sizes) is "10x10 20x20 30x30"
+PASS link.getAttribute('sizes') is "10x10 20x20 30x30"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter.html (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter.html	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLLinkElement/sizes-setter.html	2016-09-28 23:34:54 UTC (rev 206560)
@@ -8,8 +8,11 @@
 var link = document.createElement("link");
 shouldBe("link.sizes.__proto__", "DOMTokenList.prototype");
 evalAndLog("link.sizes = '10x10  20x20'");
-shouldBeEqualToString("String(link.sizes)", "10x10 20x20");
-shouldBeEqualToString("link.getAttribute('sizes')", "10x10 20x20");
+shouldBeEqualToString("String(link.sizes)", "10x10  20x20");
+shouldBeEqualToString("link.getAttribute('sizes')", "10x10  20x20");
+evalAndLog("link.sizes.add('30x30')");
+shouldBeEqualToString("String(link.sizes)", "10x10 20x20 30x30");
+shouldBeEqualToString("link.getAttribute('sizes')", "10x10 20x20 30x30");
 </script>
 <script src=""
 </body>

Modified: trunk/LayoutTests/fast/dom/HTMLOutputElement/dom-settable-token-list-expected.txt (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLOutputElement/dom-settable-token-list-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLOutputElement/dom-settable-token-list-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -5,8 +5,9 @@
 
 - Tests from http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/
 PASS element.htmlFor.__proto__ is DOMTokenList.prototype
-PASS String(element.htmlFor) is "y z"
-PASS element.getAttribute("for") is "y z"
+PASS String(element.htmlFor) is "y  z"
+PASS element.htmlFor.value is "y  z"
+PASS element.getAttribute("for") is "y  z"
 PASS String(element.htmlFor) is "r s t"
 PASS element.htmlFor.length is 0
 PASS element.htmlFor.length is 1

Modified: trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement-expected.txt (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -8,11 +8,13 @@
 PASS output1.value is "A value"
 PASS output2.htmlFor.length is 1
 PASS output2.htmlFor[0] is "for-target1"
+PASS String(output2.htmlFor) is "for-target1"
 PASS output2.htmlFor.value is "for-target1"
 PASS output3.htmlFor.length is 2
 PASS output3.htmlFor[0] is "for-target1"
 PASS output3.htmlFor[1] is "for-target2"
-PASS output3.htmlFor.value is "for-target1 for-target2"
+PASS String(output3.htmlFor) is " for-target1 for-target2 "
+PASS output3.htmlFor.value is " for-target1 for-target2 "
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement.html (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement.html	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLOutputElement/htmloutputelement.html	2016-09-28 23:34:54 UTC (rev 206560)
@@ -23,12 +23,14 @@
 
 shouldEvaluateTo('output2.htmlFor.length', 1);
 shouldBeEqualToString('output2.htmlFor[0]', 'for-target1');
+shouldBeEqualToString('String(output2.htmlFor)', 'for-target1');
 shouldBeEqualToString('output2.htmlFor.value', 'for-target1');
 
 shouldEvaluateTo('output3.htmlFor.length', 2);
 shouldBeEqualToString('output3.htmlFor[0]', 'for-target1');
 shouldBeEqualToString('output3.htmlFor[1]', 'for-target2');
-shouldBeEqualToString('output3.htmlFor.value', 'for-target1 for-target2');
+shouldBeEqualToString('String(output3.htmlFor)', ' for-target1 for-target2 ');
+shouldBeEqualToString('output3.htmlFor.value', ' for-target1 for-target2 ');
 </script>
 <script src=""
 </body>

Modified: trunk/LayoutTests/fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js (206559 => 206560)


--- trunk/LayoutTests/fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js	2016-09-28 23:34:54 UTC (rev 206560)
@@ -18,8 +18,9 @@
 createElement('x');
 shouldBe('element.htmlFor.__proto__', 'DOMTokenList.prototype');
 element.htmlFor = 'y  z';
-shouldBeEqualToString('String(element.htmlFor)', 'y z');
-shouldBeEqualToString('element.getAttribute("for")', 'y z');
+shouldBeEqualToString('String(element.htmlFor)', 'y  z');
+shouldBeEqualToString('element.htmlFor.value', 'y  z');
+shouldBeEqualToString('element.getAttribute("for")', 'y  z');
 element.setAttribute('for', 'r s t');
 shouldBeEqualToString('String(element.htmlFor)', 'r s t');
 

Modified: trunk/LayoutTests/fast/frames/sandbox-attribute-expected.txt (206559 => 206560)


--- trunk/LayoutTests/fast/frames/sandbox-attribute-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/frames/sandbox-attribute-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -10,8 +10,8 @@
 PASS iframe.sandbox[0] is "allow-popups"
 PASS iframe.sandbox[1] is "allow-scripts"
 PASS iframe.sandbox[2] is "allow-same-origin"
-PASS String(iframe.sandbox) is "allow-popups allow-scripts allow-same-origin"
-PASS iframe.getAttribute('sandbox') is "allow-popups allow-scripts allow-same-origin"
+PASS String(iframe.sandbox) is "allow-popups   allow-scripts  allow-scripts  allow-same-origin"
+PASS iframe.getAttribute('sandbox') is "allow-popups   allow-scripts  allow-scripts  allow-same-origin"
 
 iframe.setAttribute('sandbox', 'allow-popups allow-scripts')
 PASS iframe.sandbox.length is 2

Modified: trunk/LayoutTests/fast/frames/sandbox-attribute.html (206559 => 206560)


--- trunk/LayoutTests/fast/frames/sandbox-attribute.html	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/fast/frames/sandbox-attribute.html	2016-09-28 23:34:54 UTC (rev 206560)
@@ -14,8 +14,8 @@
 shouldBeEqualToString("iframe.sandbox[0]", "allow-popups");
 shouldBeEqualToString("iframe.sandbox[1]", "allow-scripts");
 shouldBeEqualToString("iframe.sandbox[2]", "allow-same-origin");
-shouldBeEqualToString("String(iframe.sandbox)", "allow-popups allow-scripts allow-same-origin");
-shouldBeEqualToString("iframe.getAttribute('sandbox')", "allow-popups allow-scripts allow-same-origin");
+shouldBeEqualToString("String(iframe.sandbox)", "allow-popups   allow-scripts  allow-scripts  allow-same-origin");
+shouldBeEqualToString("iframe.getAttribute('sandbox')", 'allow-popups   allow-scripts  allow-scripts  allow-same-origin');
 
 debug("");
 evalAndLog("iframe.setAttribute('sandbox', 'allow-popups allow-scripts')");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206559 => 206560)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-28 23:34:54 UTC (rev 206560)
@@ -1,5 +1,18 @@
 2016-09-28  Ryosuke Niwa  <[email protected]>
 
+        DOMTokenList’s value and stringifier should not return parsed tokens
+        https://bugs.webkit.org/show_bug.cgi?id=161076
+
+        Reviewed by Chris Dumez.
+
+        Rebaselined tests that are now passing.
+
+        * web-platform-tests/dom/lists/DOMTokenList-stringifier-expected.txt:
+        * web-platform-tests/dom/lists/DOMTokenList-value-expected.txt:
+        * web-platform-tests/dom/nodes/Element-classlist-expected.txt:
+
+2016-09-28  Ryosuke Niwa  <[email protected]>
+
         assignedNodes should include fallback contents when flattened option is set
         https://bugs.webkit.org/show_bug.cgi?id=162656
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-stringifier-expected.txt (206559 => 206560)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-stringifier-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-stringifier-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -1,3 +1,3 @@
 
-FAIL DOMTokenList stringifier assert_equals: String(classList) should return the literal value expected "   a  a b " but got "a b"
+PASS DOMTokenList stringifier 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-value-expected.txt (206559 => 206560)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-value-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/lists/DOMTokenList-value-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -1,3 +1,3 @@
 
-FAIL DOMTokenList value assert_equals: value should return the literal value expected "   a  a b " but got "a b"
+PASS DOMTokenList value 
 

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-classlist-expected.txt	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-classlist-expected.txt	2016-09-28 23:34:54 UTC (rev 206560)
@@ -13,7 +13,7 @@
 PASS classList[index] must be undefined for out-of-range index 
 PASS classList[index] must be undefined for negative index 
 PASS className should contain initial markup whitespace 
-FAIL classList should contain initial markup whitespace assert_equals: implicit expected " " but got ""
+PASS classList should contain initial markup whitespace 
 PASS .contains(empty_string) must return false 
 PASS .add(empty_string) must throw a SYNTAX_ERR 
 PASS .remove(empty_string) must throw a SYNTAX_ERR 

Modified: trunk/Source/WebCore/ChangeLog (206559 => 206560)


--- trunk/Source/WebCore/ChangeLog	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/Source/WebCore/ChangeLog	2016-09-28 23:34:54 UTC (rev 206560)
@@ -1,3 +1,32 @@
+2016-09-28  Ryosuke Niwa  <[email protected]>
+
+        DOMTokenList’s value and stringifier should not return parsed tokens
+        https://bugs.webkit.org/show_bug.cgi?id=161076
+
+        Reviewed by Chris Dumez.
+
+        Updated our implementation of DOMTokenList.prototype.value and its toString function
+        to match the latest DOM specification: https://dom.spec.whatwg.org/#interface-domtokenlist
+
+        "value" attribute, on getting, runs its serialize steps, which simply gets the attribute value.
+        On setting, it sets the attribute value with the given value.
+
+        The stringification behavior returns the same serialize steps as "value" attribute on getting.
+
+        This change simplifies our implementation of DOMTokenList and removes the need for m_cachedValue,
+        which has been removed in this patch.
+
+        No new tests since existing tests cover this.
+
+        * html/DOMTokenList.cpp:
+        (WebCore::DOMTokenList::value): Just call getAttribute.
+        (WebCore::DOMTokenList::setValue): Just call setAttribute.
+        (WebCore::DOMTokenList::updateTokensFromAttributeValue):
+        (WebCore::DOMTokenList::associatedAttributeValueChanged):
+        (WebCore::DOMTokenList::updateAssociatedAttributeFromTokens): Moved the code to update the tokens
+        from from the attribute value. This is the "update steps".
+        * html/DOMTokenList.h:
+
 2016-09-28  Jer Noble  <[email protected]>
 
         CRASH at WebCore::CDMSessionAVStreamSession::update + 950

Modified: trunk/Source/WebCore/html/DOMTokenList.cpp (206559 => 206560)


--- trunk/Source/WebCore/html/DOMTokenList.cpp	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/Source/WebCore/html/DOMTokenList.cpp	2016-09-28 23:34:54 UTC (rev 206560)
@@ -177,27 +177,15 @@
     updateAssociatedAttributeFromTokens();
 }
 
+// https://dom.spec.whatwg.org/#dom-domtokenlist-value
 const AtomicString& DOMTokenList::value() const
 {
-    if (m_cachedValue.isNull()) {
-        // https://dom.spec.whatwg.org/#concept-ordered-set-serializer
-        StringBuilder builder;
-        for (auto& token : tokens()) {
-            if (!builder.isEmpty())
-                builder.append(' ');
-            builder.append(token);
-        }
-        m_cachedValue = builder.toAtomicString();
-        ASSERT(!m_cachedValue.isNull());
-    }
-    ASSERT(!m_tokensNeedUpdating);
-    return m_cachedValue;
+    return m_element.getAttribute(m_attributeName);
 }
 
 void DOMTokenList::setValue(const String& value)
 {
-    updateTokensFromAttributeValue(value);
-    updateAssociatedAttributeFromTokens();
+    m_element.setAttribute(m_attributeName, value);
 }
 
 void DOMTokenList::updateTokensFromAttributeValue(const String& value)
@@ -227,7 +215,6 @@
 
     m_tokens.shrinkToFit();
     m_tokensNeedUpdating = false;
-    m_cachedValue = nullAtom;
 }
 
 void DOMTokenList::associatedAttributeValueChanged(const AtomicString&)
@@ -237,7 +224,6 @@
         return;
 
     m_tokensNeedUpdating = true;
-    m_cachedValue = nullAtom;
 }
 
 // https://dom.spec.whatwg.org/#concept-dtl-update
@@ -245,11 +231,17 @@
 {
     ASSERT(!m_tokensNeedUpdating);
 
-    m_cachedValue = nullAtom;
+    // https://dom.spec.whatwg.org/#concept-ordered-set-serializer
+    StringBuilder builder;
+    for (auto& token : tokens()) {
+        if (!builder.isEmpty())
+            builder.append(' ');
+        builder.append(token);
+    }
+    AtomicString serializedValue = builder.toAtomicString();
 
     TemporaryChange<bool> inAttributeUpdate(m_inUpdateAssociatedAttributeFromTokens, true);
-    m_element.setAttribute(m_attributeName, value());
-    ASSERT_WITH_MESSAGE(m_cachedValue, "Calling value() should have cached its results");
+    m_element.setAttribute(m_attributeName, serializedValue);
 }
 
 Vector<AtomicString>& DOMTokenList::tokens()

Modified: trunk/Source/WebCore/html/DOMTokenList.h (206559 => 206560)


--- trunk/Source/WebCore/html/DOMTokenList.h	2016-09-28 23:22:57 UTC (rev 206559)
+++ trunk/Source/WebCore/html/DOMTokenList.h	2016-09-28 23:34:54 UTC (rev 206560)
@@ -72,7 +72,6 @@
     bool m_inUpdateAssociatedAttributeFromTokens { false };
     bool m_tokensNeedUpdating { true };
     Vector<AtomicString> m_tokens;
-    mutable AtomicString m_cachedValue;
 };
 
 inline unsigned DOMTokenList::length() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to