Title: [154751] trunk/Source/WebCore
Revision
154751
Author
[email protected]
Date
2013-08-28 09:33:49 -0700 (Wed, 28 Aug 2013)

Log Message

Factor descendant iterator assertions into a class.
https://bugs.webkit.org/show_bug.cgi?id=120422

Reviewed by Darin Adler.

Share the assertions between ChildIterator and DescendantIterator. We can use it for future const iterators too.

* GNUmakefile.list.am:
* Target.pri:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/ChildIterator.h:
(WebCore::::ChildIterator):
(WebCore::::operator):
(WebCore::=):
* dom/DescendantIterator.h:
(WebCore::::DescendantIterator):
(WebCore::::operator):
(WebCore::=):
* dom/DescendantIteratorAssertions.h: Added.
(WebCore::DescendantIteratorAssertions::DescendantIteratorAssertions):
(WebCore::DescendantIteratorAssertions::domTreeHasMutated):
(WebCore::DescendantIteratorAssertions::dropEventDispatchAssertion):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (154750 => 154751)


--- trunk/Source/WebCore/ChangeLog	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/ChangeLog	2013-08-28 16:33:49 UTC (rev 154751)
@@ -1,3 +1,29 @@
+2013-08-28  Antti Koivisto  <[email protected]>
+
+        Factor descendant iterator assertions into a class.
+        https://bugs.webkit.org/show_bug.cgi?id=120422
+
+        Reviewed by Darin Adler.
+
+        Share the assertions between ChildIterator and DescendantIterator. We can use it for future const iterators too.
+
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/ChildIterator.h:
+        (WebCore::::ChildIterator):
+        (WebCore::::operator):
+        (WebCore::=):
+        * dom/DescendantIterator.h:
+        (WebCore::::DescendantIterator):
+        (WebCore::::operator):
+        (WebCore::=):
+        * dom/DescendantIteratorAssertions.h: Added.
+        (WebCore::DescendantIteratorAssertions::DescendantIteratorAssertions):
+        (WebCore::DescendantIteratorAssertions::domTreeHasMutated):
+        (WebCore::DescendantIteratorAssertions::dropEventDispatchAssertion):
+
 2013-08-28  Darin Adler  <[email protected]>
 
         Eliminate Pasteboard::generalPasteboard

Modified: trunk/Source/WebCore/GNUmakefile.list.am (154750 => 154751)


--- trunk/Source/WebCore/GNUmakefile.list.am	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2013-08-28 16:33:49 UTC (rev 154751)
@@ -2819,6 +2819,7 @@
 	Source/WebCore/dom/default/PlatformMessagePortChannel.cpp \
 	Source/WebCore/dom/default/PlatformMessagePortChannel.h \
 	Source/WebCore/dom/DescendantIterator.h \
+	Source/WebCore/dom/DescendantIteratorAssertions.h \
 	Source/WebCore/dom/DeviceMotionClient.h \
 	Source/WebCore/dom/DeviceMotionController.cpp \
 	Source/WebCore/dom/DeviceMotionController.h \

Modified: trunk/Source/WebCore/Target.pri (154750 => 154751)


--- trunk/Source/WebCore/Target.pri	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/Target.pri	2013-08-28 16:33:49 UTC (rev 154751)
@@ -1592,6 +1592,7 @@
     dom/CustomEvent.h \
     dom/default/PlatformMessagePortChannel.h \
     dom/DescendantIterator.h \
+    dom/DescendantIteratorAssertions.h \
     dom/DeviceMotionClient.h \
     dom/DeviceMotionController.h \
     dom/DeviceMotionData.h \

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (154750 => 154751)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-08-28 16:33:49 UTC (rev 154751)
@@ -20238,6 +20238,7 @@
     <ClInclude Include="..\dom\DataTransferItemList.h" />
     <ClInclude Include="..\dom\DecodedDataDocumentParser.h" />
     <ClInclude Include="..\dom\DescendantIterator.h" />
+    <ClInclude Include="..\dom\DescendantIteratorAssertions.h" />
     <ClInclude Include="..\dom\DeviceMotionClient.h" />
     <ClInclude Include="..\dom\DeviceMotionController.h" />
     <ClInclude Include="..\dom\DeviceMotionData.h" />

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (154750 => 154751)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-08-28 16:33:49 UTC (rev 154751)
@@ -5443,6 +5443,7 @@
 		E1F1E8300C3C2BB9006DB391 /* XSLTExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */; };
 		E1FF57A30F01255B00891EBB /* ThreadGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E1FF57A60F01256B00891EBB /* ThreadGlobalData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */; };
+		E401C27517CE53EC00C41A35 /* DescendantIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */; };
 		E4295FA412B0614E00D1ACE0 /* ResourceLoadPriority.h in Headers */ = {isa = PBXBuildFile; fileRef = E4295FA312B0614E00D1ACE0 /* ResourceLoadPriority.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E43105B816750F0C00DB2FB8 /* NodeTraversal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */; };
 		E43105BB16750F1600DB2FB8 /* NodeTraversal.h in Headers */ = {isa = PBXBuildFile; fileRef = E43105BA16750F1600DB2FB8 /* NodeTraversal.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12219,6 +12220,7 @@
 		E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTExtensions.h; sourceTree = "<group>"; };
 		E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadGlobalData.h; sourceTree = "<group>"; };
 		E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadGlobalData.cpp; sourceTree = "<group>"; };
+		E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DescendantIteratorAssertions.h; sourceTree = "<group>"; };
 		E406F3FB1198307D009D59D6 /* ColorData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorData.cpp; sourceTree = "<group>"; };
 		E41EA038119836DB00710BC5 /* CSSPropertyNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSPropertyNames.cpp; sourceTree = "<group>"; };
 		E41EA0391198374900710BC5 /* CSSValueKeywords.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSValueKeywords.cpp; sourceTree = "<group>"; };
@@ -20152,6 +20154,7 @@
 				A8C228A011D5722E00D5A7D3 /* DecodedDataDocumentParser.cpp */,
 				A8C2289F11D5722E00D5A7D3 /* DecodedDataDocumentParser.h */,
 				E46A2B1B17CA65B9000DBCD8 /* DescendantIterator.h */,
+				E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */,
 				31FB1A4F120A5D0600DC02A0 /* DeviceMotionClient.h */,
 				31FB1A50120A5D0600DC02A0 /* DeviceMotionController.cpp */,
 				31FB1A51120A5D0600DC02A0 /* DeviceMotionController.h */,
@@ -20994,6 +20997,7 @@
 				976D6C7F122B8A3D001FD1F7 /* BlobURL.h in Headers */,
 				93F199BE08245E59001E9ABC /* BlockExceptions.h in Headers */,
 				BC5EB5E10E81BE8700B25965 /* BorderData.h in Headers */,
+				E401C27517CE53EC00C41A35 /* DescendantIteratorAssertions.h in Headers */,
 				BC5EB5DB0E81B7EA00B25965 /* BorderValue.h in Headers */,
 				BCEA4855097D93020094C9E4 /* break_lines.h in Headers */,
 				93309DDB099E64920056E581 /* BreakBlockquoteCommand.h in Headers */,

Modified: trunk/Source/WebCore/dom/ChildIterator.h (154750 => 154751)


--- trunk/Source/WebCore/dom/ChildIterator.h	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/dom/ChildIterator.h	2013-08-28 16:33:49 UTC (rev 154751)
@@ -28,8 +28,8 @@
 
 #include "ElementTraversal.h"
 
-#ifndef NDEBUG
-#include "Document.h"
+#if !ASSERT_DISABLED
+#include "DescendantIteratorAssertions.h"
 #endif
 
 namespace WebCore {
@@ -47,10 +47,8 @@
 private:
     ElementType* m_current;
 
-#ifndef NDEBUG
-    bool domTreeHasMutated() const;
-    OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
-    uint64_t m_initialDOMTreeVersion;
+#if !ASSERT_DISABLED
+    DescendantIteratorAssertions m_assertions;
 #endif
 };
 
@@ -71,40 +69,28 @@
 template <typename ElementType>
 inline ChildIterator<ElementType>::ChildIterator()
     : m_current(nullptr)
-#ifndef NDEBUG
-    , m_initialDOMTreeVersion(0)
-#endif
 {
 }
 
 template <typename ElementType>
 inline ChildIterator<ElementType>::ChildIterator(ElementType* current)
     : m_current(current)
-#ifndef NDEBUG
-    , m_noEventDispatchAssertion(adoptPtr(new NoEventDispatchAssertion))
-    , m_initialDOMTreeVersion(m_current ? m_current->document()->domTreeVersion() : 0)
+#if !ASSERT_DISABLED
+    , m_assertions(current)
 #endif
 {
 }
 
-#ifndef NDEBUG
 template <typename ElementType>
-inline bool ChildIterator<ElementType>::domTreeHasMutated() const
-{
-    return m_initialDOMTreeVersion && m_current && m_current->document()->domTreeVersion() != m_initialDOMTreeVersion;
-}
-#endif
-
-template <typename ElementType>
 inline ChildIterator<ElementType>& ChildIterator<ElementType>::operator++()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     m_current = Traversal<ElementType>::nextSibling(m_current);
-#ifndef NDEBUG
+#if !ASSERT_DISABLED
     // Drop the assertion when the iterator reaches the end.
     if (!m_current)
-        m_noEventDispatchAssertion = nullptr;
+        m_assertions.dropEventDispatchAssertion();
 #endif
     return *this;
 }
@@ -113,7 +99,7 @@
 inline ElementType& ChildIterator<ElementType>::operator*()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return *m_current;
 }
 
@@ -121,14 +107,14 @@
 inline ElementType* ChildIterator<ElementType>::operator->()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return m_current;
 }
 
 template <typename ElementType>
 inline bool ChildIterator<ElementType>::operator!=(const ChildIterator& other) const
 {
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return m_current != other.m_current;
 }
 

Modified: trunk/Source/WebCore/dom/DescendantIterator.h (154750 => 154751)


--- trunk/Source/WebCore/dom/DescendantIterator.h	2013-08-28 15:30:01 UTC (rev 154750)
+++ trunk/Source/WebCore/dom/DescendantIterator.h	2013-08-28 16:33:49 UTC (rev 154751)
@@ -28,8 +28,8 @@
 
 #include "ElementTraversal.h"
 
-#ifndef NDEBUG
-#include "Document.h"
+#if !ASSERT_DISABLED
+#include "DescendantIteratorAssertions.h"
 #endif
 
 namespace WebCore {
@@ -48,10 +48,8 @@
     const ContainerNode* m_root;
     ElementType* m_current;
 
-#ifndef NDEBUG
-    bool domTreeHasMutated() const;
-    OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
-    uint64_t m_initialDOMTreeVersion;
+#if !ASSERT_DISABLED
+    DescendantIteratorAssertions m_assertions;
 #endif
 };
 
@@ -73,9 +71,6 @@
 inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root)
     : m_root(root)
     , m_current(nullptr)
-#ifndef NDEBUG
-    , m_initialDOMTreeVersion(0)
-#endif
 {
 }
 
@@ -83,31 +78,22 @@
 inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root, ElementType* current)
     : m_root(root)
     , m_current(current)
-#ifndef NDEBUG
-    , m_noEventDispatchAssertion(adoptPtr(new NoEventDispatchAssertion))
-    , m_initialDOMTreeVersion(root->document()->domTreeVersion())
+#if !ASSERT_DISABLED
+    , m_assertions(current)
 #endif
 {
 }
 
-#ifndef NDEBUG
 template <typename ElementType>
-inline bool DescendantIterator<ElementType>::domTreeHasMutated() const
-{
-    return m_root->document()->domTreeVersion() != m_initialDOMTreeVersion;
-}
-#endif
-
-template <typename ElementType>
 inline DescendantIterator<ElementType>& DescendantIterator<ElementType>::operator++()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     m_current = Traversal<ElementType>::next(m_current, m_root);
-#ifndef NDEBUG
+#if !ASSERT_DISABLED
     // Drop the assertion when the iterator reaches the end.
     if (!m_current)
-        m_noEventDispatchAssertion = nullptr;
+        m_assertions.dropEventDispatchAssertion();
 #endif
     return *this;
 }
@@ -116,7 +102,7 @@
 inline ElementType& DescendantIterator<ElementType>::operator*()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return *m_current;
 }
 
@@ -124,7 +110,7 @@
 inline ElementType* DescendantIterator<ElementType>::operator->()
 {
     ASSERT(m_current);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return m_current;
 }
 
@@ -132,7 +118,7 @@
 inline bool DescendantIterator<ElementType>::operator!=(const DescendantIterator& other) const
 {
     ASSERT(m_root == other.m_root);
-    ASSERT(!domTreeHasMutated());
+    ASSERT(!m_assertions.domTreeHasMutated());
     return m_current != other.m_current;
 }
 

Added: trunk/Source/WebCore/dom/DescendantIteratorAssertions.h (0 => 154751)


--- trunk/Source/WebCore/dom/DescendantIteratorAssertions.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/DescendantIteratorAssertions.h	2013-08-28 16:33:49 UTC (rev 154751)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DescendantIteratorAssertions_h
+#define DescendantIteratorAssertions_h
+
+#include "Document.h"
+#include "Element.h"
+
+namespace WebCore {
+
+class DescendantIteratorAssertions {
+public:
+    DescendantIteratorAssertions();
+    DescendantIteratorAssertions(const Element* first);
+    bool domTreeHasMutated() const;
+    void dropEventDispatchAssertion();
+
+private:
+    const Document* m_document;
+    uint64_t m_initialDOMTreeVersion;
+    OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
+};
+
+inline DescendantIteratorAssertions::DescendantIteratorAssertions()
+    : m_document(nullptr)
+    , m_initialDOMTreeVersion(0)
+{
+}
+
+inline DescendantIteratorAssertions::DescendantIteratorAssertions(const Element* first)
+    : m_document(first ? first->document() : nullptr)
+    , m_initialDOMTreeVersion(m_document ? m_document->domTreeVersion() : 0)
+    , m_noEventDispatchAssertion(m_document ? adoptPtr(new NoEventDispatchAssertion) : nullptr)
+{
+}
+
+inline bool DescendantIteratorAssertions::domTreeHasMutated() const
+{
+    return m_initialDOMTreeVersion && m_document && m_document->domTreeVersion() != m_initialDOMTreeVersion;
+}
+
+inline void DescendantIteratorAssertions::dropEventDispatchAssertion()
+{
+    m_noEventDispatchAssertion = nullptr;
+}
+
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to