Changeset 154751 in webkit


Ignore:
Timestamp:
Aug 28, 2013 9:33:49 AM (11 years ago)
Author:
Antti Koivisto
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):

Location:
trunk/Source/WebCore
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154750 r154751  
     12013-08-28  Antti Koivisto  <antti@apple.com>
     2
     3        Factor descendant iterator assertions into a class.
     4        https://bugs.webkit.org/show_bug.cgi?id=120422
     5
     6        Reviewed by Darin Adler.
     7
     8        Share the assertions between ChildIterator and DescendantIterator. We can use it for future const iterators too.
     9
     10        * GNUmakefile.list.am:
     11        * Target.pri:
     12        * WebCore.vcxproj/WebCore.vcxproj:
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * dom/ChildIterator.h:
     15        (WebCore::::ChildIterator):
     16        (WebCore::::operator):
     17        (WebCore::=):
     18        * dom/DescendantIterator.h:
     19        (WebCore::::DescendantIterator):
     20        (WebCore::::operator):
     21        (WebCore::=):
     22        * dom/DescendantIteratorAssertions.h: Added.
     23        (WebCore::DescendantIteratorAssertions::DescendantIteratorAssertions):
     24        (WebCore::DescendantIteratorAssertions::domTreeHasMutated):
     25        (WebCore::DescendantIteratorAssertions::dropEventDispatchAssertion):
     26
    1272013-08-28  Darin Adler  <darin@apple.com>
    228
  • trunk/Source/WebCore/GNUmakefile.list.am

    r154629 r154751  
    28202820        Source/WebCore/dom/default/PlatformMessagePortChannel.h \
    28212821        Source/WebCore/dom/DescendantIterator.h \
     2822        Source/WebCore/dom/DescendantIteratorAssertions.h \
    28222823        Source/WebCore/dom/DeviceMotionClient.h \
    28232824        Source/WebCore/dom/DeviceMotionController.cpp \
  • trunk/Source/WebCore/Target.pri

    r154629 r154751  
    15931593    dom/default/PlatformMessagePortChannel.h \
    15941594    dom/DescendantIterator.h \
     1595    dom/DescendantIteratorAssertions.h \
    15951596    dom/DeviceMotionClient.h \
    15961597    dom/DeviceMotionController.h \
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r154629 r154751  
    2023920239    <ClInclude Include="..\dom\DecodedDataDocumentParser.h" />
    2024020240    <ClInclude Include="..\dom\DescendantIterator.h" />
     20241    <ClInclude Include="..\dom\DescendantIteratorAssertions.h" />
    2024120242    <ClInclude Include="..\dom\DeviceMotionClient.h" />
    2024220243    <ClInclude Include="..\dom\DeviceMotionController.h" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r154647 r154751  
    54445444                E1FF57A30F01255B00891EBB /* ThreadGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    54455445                E1FF57A60F01256B00891EBB /* ThreadGlobalData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */; };
     5446                E401C27517CE53EC00C41A35 /* DescendantIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */; };
    54465447                E4295FA412B0614E00D1ACE0 /* ResourceLoadPriority.h in Headers */ = {isa = PBXBuildFile; fileRef = E4295FA312B0614E00D1ACE0 /* ResourceLoadPriority.h */; settings = {ATTRIBUTES = (Private, ); }; };
    54475448                E43105B816750F0C00DB2FB8 /* NodeTraversal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */; };
     
    1222012221                E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadGlobalData.h; sourceTree = "<group>"; };
    1222112222                E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadGlobalData.cpp; sourceTree = "<group>"; };
     12223                E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DescendantIteratorAssertions.h; sourceTree = "<group>"; };
    1222212224                E406F3FB1198307D009D59D6 /* ColorData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorData.cpp; sourceTree = "<group>"; };
    1222312225                E41EA038119836DB00710BC5 /* CSSPropertyNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSPropertyNames.cpp; sourceTree = "<group>"; };
     
    2015320155                                A8C2289F11D5722E00D5A7D3 /* DecodedDataDocumentParser.h */,
    2015420156                                E46A2B1B17CA65B9000DBCD8 /* DescendantIterator.h */,
     20157                                E401C27417CE53EC00C41A35 /* DescendantIteratorAssertions.h */,
    2015520158                                31FB1A4F120A5D0600DC02A0 /* DeviceMotionClient.h */,
    2015620159                                31FB1A50120A5D0600DC02A0 /* DeviceMotionController.cpp */,
     
    2099520998                                93F199BE08245E59001E9ABC /* BlockExceptions.h in Headers */,
    2099620999                                BC5EB5E10E81BE8700B25965 /* BorderData.h in Headers */,
     21000                                E401C27517CE53EC00C41A35 /* DescendantIteratorAssertions.h in Headers */,
    2099721001                                BC5EB5DB0E81B7EA00B25965 /* BorderValue.h in Headers */,
    2099821002                                BCEA4855097D93020094C9E4 /* break_lines.h in Headers */,
  • trunk/Source/WebCore/dom/ChildIterator.h

    r154734 r154751  
    2929#include "ElementTraversal.h"
    3030
    31 #ifndef NDEBUG
    32 #include "Document.h"
     31#if !ASSERT_DISABLED
     32#include "DescendantIteratorAssertions.h"
    3333#endif
    3434
     
    4848    ElementType* m_current;
    4949
    50 #ifndef NDEBUG
    51     bool domTreeHasMutated() const;
    52     OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
    53     uint64_t m_initialDOMTreeVersion;
     50#if !ASSERT_DISABLED
     51    DescendantIteratorAssertions m_assertions;
    5452#endif
    5553};
     
    7270inline ChildIterator<ElementType>::ChildIterator()
    7371    : m_current(nullptr)
    74 #ifndef NDEBUG
    75     , m_initialDOMTreeVersion(0)
    76 #endif
    7772{
    7873}
     
    8176inline ChildIterator<ElementType>::ChildIterator(ElementType* current)
    8277    : m_current(current)
    83 #ifndef NDEBUG
    84     , m_noEventDispatchAssertion(adoptPtr(new NoEventDispatchAssertion))
    85     , m_initialDOMTreeVersion(m_current ? m_current->document()->domTreeVersion() : 0)
     78#if !ASSERT_DISABLED
     79    , m_assertions(current)
    8680#endif
    8781{
    8882}
    89 
    90 #ifndef NDEBUG
    91 template <typename ElementType>
    92 inline bool ChildIterator<ElementType>::domTreeHasMutated() const
    93 {
    94     return m_initialDOMTreeVersion && m_current && m_current->document()->domTreeVersion() != m_initialDOMTreeVersion;
    95 }
    96 #endif
    9783
    9884template <typename ElementType>
     
    10086{
    10187    ASSERT(m_current);
    102     ASSERT(!domTreeHasMutated());
     88    ASSERT(!m_assertions.domTreeHasMutated());
    10389    m_current = Traversal<ElementType>::nextSibling(m_current);
    104 #ifndef NDEBUG
     90#if !ASSERT_DISABLED
    10591    // Drop the assertion when the iterator reaches the end.
    10692    if (!m_current)
    107         m_noEventDispatchAssertion = nullptr;
     93        m_assertions.dropEventDispatchAssertion();
    10894#endif
    10995    return *this;
     
    114100{
    115101    ASSERT(m_current);
    116     ASSERT(!domTreeHasMutated());
     102    ASSERT(!m_assertions.domTreeHasMutated());
    117103    return *m_current;
    118104}
     
    122108{
    123109    ASSERT(m_current);
    124     ASSERT(!domTreeHasMutated());
     110    ASSERT(!m_assertions.domTreeHasMutated());
    125111    return m_current;
    126112}
     
    129115inline bool ChildIterator<ElementType>::operator!=(const ChildIterator& other) const
    130116{
    131     ASSERT(!domTreeHasMutated());
     117    ASSERT(!m_assertions.domTreeHasMutated());
    132118    return m_current != other.m_current;
    133119}
  • trunk/Source/WebCore/dom/DescendantIterator.h

    r154734 r154751  
    2929#include "ElementTraversal.h"
    3030
    31 #ifndef NDEBUG
    32 #include "Document.h"
     31#if !ASSERT_DISABLED
     32#include "DescendantIteratorAssertions.h"
    3333#endif
    3434
     
    4949    ElementType* m_current;
    5050
    51 #ifndef NDEBUG
    52     bool domTreeHasMutated() const;
    53     OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
    54     uint64_t m_initialDOMTreeVersion;
     51#if !ASSERT_DISABLED
     52    DescendantIteratorAssertions m_assertions;
    5553#endif
    5654};
     
    7472    : m_root(root)
    7573    , m_current(nullptr)
    76 #ifndef NDEBUG
    77     , m_initialDOMTreeVersion(0)
    78 #endif
    7974{
    8075}
     
    8479    : m_root(root)
    8580    , m_current(current)
    86 #ifndef NDEBUG
    87     , m_noEventDispatchAssertion(adoptPtr(new NoEventDispatchAssertion))
    88     , m_initialDOMTreeVersion(root->document()->domTreeVersion())
     81#if !ASSERT_DISABLED
     82    , m_assertions(current)
    8983#endif
    9084{
    9185}
    92 
    93 #ifndef NDEBUG
    94 template <typename ElementType>
    95 inline bool DescendantIterator<ElementType>::domTreeHasMutated() const
    96 {
    97     return m_root->document()->domTreeVersion() != m_initialDOMTreeVersion;
    98 }
    99 #endif
    10086
    10187template <typename ElementType>
     
    10389{
    10490    ASSERT(m_current);
    105     ASSERT(!domTreeHasMutated());
     91    ASSERT(!m_assertions.domTreeHasMutated());
    10692    m_current = Traversal<ElementType>::next(m_current, m_root);
    107 #ifndef NDEBUG
     93#if !ASSERT_DISABLED
    10894    // Drop the assertion when the iterator reaches the end.
    10995    if (!m_current)
    110         m_noEventDispatchAssertion = nullptr;
     96        m_assertions.dropEventDispatchAssertion();
    11197#endif
    11298    return *this;
     
    117103{
    118104    ASSERT(m_current);
    119     ASSERT(!domTreeHasMutated());
     105    ASSERT(!m_assertions.domTreeHasMutated());
    120106    return *m_current;
    121107}
     
    125111{
    126112    ASSERT(m_current);
    127     ASSERT(!domTreeHasMutated());
     113    ASSERT(!m_assertions.domTreeHasMutated());
    128114    return m_current;
    129115}
     
    133119{
    134120    ASSERT(m_root == other.m_root);
    135     ASSERT(!domTreeHasMutated());
     121    ASSERT(!m_assertions.domTreeHasMutated());
    136122    return m_current != other.m_current;
    137123}
Note: See TracChangeset for help on using the changeset viewer.