Title: [134102] trunk
Revision
134102
Author
[email protected]
Date
2012-11-09 12:54:52 -0800 (Fri, 09 Nov 2012)

Log Message

REGRESSION (r125239): classList contains() doesn't work after element was moved from strict mode document to quirks mode document
https://bugs.webkit.org/show_bug.cgi?id=101627

Reviewed by Alexey Proskuryakov.

We used to only create m_classNamesForQuirksMode in the constructor or when the class attribute
was changed. If an element is moved from a standards document to a quirks mode document the
m_classNamesForQuirksMode would not be up to date which lead to wrong results.

Now we alway check if m_classNamesForQuirksMode is up to date (in quirks mode only).

Source/WebCore:

Test: fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html

* html/ClassList.cpp:
(WebCore::ClassList::classNames): Create the m_classNamesForQuirksMode lazily as needed so that
                                  it is up to date.
* html/ClassList.h:

LayoutTests:

* fast/dom/Element/class-list-move-between-document-with-different-quirks-mode-expected.txt: Added.
* fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (134101 => 134102)


--- trunk/LayoutTests/ChangeLog	2012-11-09 20:47:12 UTC (rev 134101)
+++ trunk/LayoutTests/ChangeLog	2012-11-09 20:54:52 UTC (rev 134102)
@@ -1,3 +1,19 @@
+2012-11-09  Erik Arvidsson  <[email protected]>
+
+        REGRESSION (r125239): classList contains() doesn't work after element was moved from strict mode document to quirks mode document
+        https://bugs.webkit.org/show_bug.cgi?id=101627
+
+        Reviewed by Alexey Proskuryakov.
+
+        We used to only create m_classNamesForQuirksMode in the constructor or when the class attribute
+        was changed. If an element is moved from a standards document to a quirks mode document the
+        m_classNamesForQuirksMode would not be up to date which lead to wrong results.
+
+        Now we alway check if m_classNamesForQuirksMode is up to date (in quirks mode only).
+
+        * fast/dom/Element/class-list-move-between-document-with-different-quirks-mode-expected.txt: Added.
+        * fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html: Added.
+
 2012-10-28  Timothy Hatcher  <[email protected]>
 
         Test if -webkit-canvas in CSS uses the full backing store instead

Added: trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode-expected.txt (0 => 134102)


--- trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode-expected.txt	2012-11-09 20:54:52 UTC (rev 134102)
@@ -0,0 +1,25 @@
+Tests that moving an element between documents with different quirks mode works
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+In standards mode
+PASS htmlElement.classList.contains("A") is true
+PASS htmlElement.classList.contains("a") is true
+PASS htmlElement.classList.contains("B") is true
+PASS htmlElement.classList.contains("b") is false
+Moved to quirks mode
+PASS htmlElement.classList.contains("A") is true
+PASS htmlElement.classList.contains("a") is true
+PASS htmlElement.classList.contains("B") is true
+PASS htmlElement.classList.contains("b") is false
+Moved back to standards mode
+PASS htmlElement.classList.contains("A") is true
+PASS htmlElement.classList.contains("a") is true
+PASS htmlElement.classList.contains("B") is true
+PASS htmlElement.classList.contains("b") is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+

Added: trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html (0 => 134102)


--- trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html	2012-11-09 20:54:52 UTC (rev 134102)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src=""
+<iframe></iframe>
+<script>
+
+description('Tests that moving an element between documents with different quirks mode works');
+
+var htmlElement = document.createElement('div');
+htmlElement.className = "A a B";
+
+debug('In standards mode');
+shouldBeTrue('htmlElement.classList.contains("A")');
+shouldBeTrue('htmlElement.classList.contains("a")');
+shouldBeTrue('htmlElement.classList.contains("B")');
+shouldBeFalse('htmlElement.classList.contains("b")');
+
+var doc = frames[0].document;
+doc.open();
+doc.write('<body></body>');
+doc.close();
+
+debug('Moved to quirks mode');
+doc.body.appendChild(htmlElement);
+shouldBeTrue('htmlElement.classList.contains("A")');
+shouldBeTrue('htmlElement.classList.contains("a")');
+shouldBeTrue('htmlElement.classList.contains("B")');
+shouldBeFalse('htmlElement.classList.contains("b")');
+
+debug('Moved back to standards mode');
+document.body.appendChild(htmlElement);
+shouldBeTrue('htmlElement.classList.contains("A")');
+shouldBeTrue('htmlElement.classList.contains("a")');
+shouldBeTrue('htmlElement.classList.contains("B")');
+shouldBeFalse('htmlElement.classList.contains("b")');
+
+</script>
+<script src=""

Modified: trunk/Source/WebCore/ChangeLog (134101 => 134102)


--- trunk/Source/WebCore/ChangeLog	2012-11-09 20:47:12 UTC (rev 134101)
+++ trunk/Source/WebCore/ChangeLog	2012-11-09 20:54:52 UTC (rev 134102)
@@ -1,3 +1,23 @@
+2012-11-09  Erik Arvidsson  <[email protected]>
+
+        REGRESSION (r125239): classList contains() doesn't work after element was moved from strict mode document to quirks mode document
+        https://bugs.webkit.org/show_bug.cgi?id=101627
+
+        Reviewed by Alexey Proskuryakov.
+
+        We used to only create m_classNamesForQuirksMode in the constructor or when the class attribute
+        was changed. If an element is moved from a standards document to a quirks mode document the
+        m_classNamesForQuirksMode would not be up to date which lead to wrong results.
+
+        Now we alway check if m_classNamesForQuirksMode is up to date (in quirks mode only).
+
+        Test: fast/dom/Element/class-list-move-between-document-with-different-quirks-mode.html
+
+        * html/ClassList.cpp:
+        (WebCore::ClassList::classNames): Create the m_classNamesForQuirksMode lazily as needed so that
+                                          it is up to date.
+        * html/ClassList.h:
+
 2012-11-09  Alec Flett  <[email protected]>
 
         IndexedDB: Combine IDBBackingStore and IDBLevelDBBackingStore

Modified: trunk/Source/WebCore/html/ClassList.cpp (134101 => 134102)


--- trunk/Source/WebCore/html/ClassList.cpp	2012-11-09 20:47:12 UTC (rev 134101)
+++ trunk/Source/WebCore/html/ClassList.cpp	2012-11-09 20:54:52 UTC (rev 134102)
@@ -31,12 +31,7 @@
 
 namespace WebCore {
 
-ClassList::ClassList(Element* element)
-    : m_element(element)
-{
-    if (m_element->document()->inQuirksMode())
-        m_classNamesForQuirksMode.set(value(), false);
-}
+ClassList::ClassList(Element* element) : m_element(element) { }
 
 void ClassList::ref()
 {
@@ -68,14 +63,17 @@
 void ClassList::reset(const String& newClassName)
 {
     if (m_element->document()->inQuirksMode())
-        m_classNamesForQuirksMode.set(newClassName, false);
+        m_classNamesForQuirksMode = adoptPtr(new SpaceSplitString(newClassName, false));
 }
 
 const SpaceSplitString& ClassList::classNames() const
 {
     ASSERT(m_element->hasClass());
-    if (m_element->document()->inQuirksMode())
-        return m_classNamesForQuirksMode;
+    if (m_element->document()->inQuirksMode()) {
+        if (!m_classNamesForQuirksMode)
+            m_classNamesForQuirksMode = adoptPtr(new SpaceSplitString(value(), false));
+        return *m_classNamesForQuirksMode.get();
+    }
     return m_element->attributeData()->classNames();
 }
 

Modified: trunk/Source/WebCore/html/ClassList.h (134101 => 134102)


--- trunk/Source/WebCore/html/ClassList.h	2012-11-09 20:47:12 UTC (rev 134101)
+++ trunk/Source/WebCore/html/ClassList.h	2012-11-09 20:54:52 UTC (rev 134102)
@@ -29,10 +29,10 @@
 #include "Element.h"
 #include "HTMLNames.h"
 #include "SpaceSplitString.h"
+#include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
-
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -69,7 +69,7 @@
     virtual void setValue(const AtomicString& value) OVERRIDE { m_element->setAttribute(classAttr, value); }
 
     Element* m_element;
-    SpaceSplitString m_classNamesForQuirksMode;
+    mutable OwnPtr<SpaceSplitString> m_classNamesForQuirksMode;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to