Commit 9c732100 authored by antti@apple.com's avatar antti@apple.com

Better mutation and event assertions for descendant iterators

https://bugs.webkit.org/show_bug.cgi?id=120368

Reviewed by Andreas Kling.

Add mutation assertions to all functions.
Drop the no-event-dispatch assertion when the iterator reaches the end. This reduces need for iterator scoping
just to avoid assertions.

* dom/ChildIterator.h:
(WebCore::::domTreeHasMutated):
(WebCore::::operator):
(WebCore::=):
* dom/DescendantIterator.h:
(WebCore::::domTreeHasMutated):
(WebCore::::operator):
(WebCore::=):
* dom/Document.cpp:
(WebCore::Document::childrenChanged):
        
    Make idiomatic.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bde98c8e
2013-08-27 Antti Koivisto <antti@apple.com>
Better mutation and event assertions for descendant iterators
https://bugs.webkit.org/show_bug.cgi?id=120368
Reviewed by Andreas Kling.
Add mutation assertions to all functions.
Drop the no-event-dispatch assertion when the iterator reaches the end. This reduces need for iterator scoping
just to avoid assertions.
* dom/ChildIterator.h:
(WebCore::::domTreeHasMutated):
(WebCore::::operator):
(WebCore::=):
* dom/DescendantIterator.h:
(WebCore::::domTreeHasMutated):
(WebCore::::operator):
(WebCore::=):
* dom/Document.cpp:
(WebCore::Document::childrenChanged):
Make idiomatic.
2013-08-27 Renata Hodovan <reni@webkit.org>
Missing null-check of parent renderer in WebCore::HTMLEmbedElement::rendererIsNeeded()
......@@ -40,13 +40,15 @@ public:
ChildIterator();
ChildIterator(ElementType* current);
ChildIterator& operator++();
ElementType& operator*() { return *m_current; }
ElementType* operator->() { return m_current; }
ElementType& operator*();
ElementType* operator->();
bool operator!=(const ChildIterator& other) const;
private:
ElementType* m_current;
#ifndef NDEBUG
bool domTreeHasMutated() const;
OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
uint64_t m_initialDOMTreeVersion;
#endif
......@@ -87,18 +89,48 @@ inline ChildIterator<ElementType>::ChildIterator(ElementType* current)
{
}
#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(m_current->document()->domTreeVersion() == m_initialDOMTreeVersion);
ASSERT(!domTreeHasMutated());
m_current = Traversal<ElementType>::nextSibling(m_current);
#ifndef NDEBUG
// Drop the assertion when the iterator reaches the end.
if (!m_current)
m_noEventDispatchAssertion = nullptr;
#endif
return *this;
}
template <typename ElementType>
inline ElementType& ChildIterator<ElementType>::operator*()
{
ASSERT(m_current);
ASSERT(!domTreeHasMutated());
return *m_current;
}
template <typename ElementType>
inline ElementType* ChildIterator<ElementType>::operator->()
{
ASSERT(m_current);
ASSERT(!domTreeHasMutated());
return m_current;
}
template <typename ElementType>
inline bool ChildIterator<ElementType>::operator!=(const ChildIterator& other) const
{
ASSERT(!domTreeHasMutated());
return m_current != other.m_current;
}
......
......@@ -40,14 +40,16 @@ public:
DescendantIterator(const Node* root);
DescendantIterator(const Node* root, ElementType* current);
DescendantIterator& operator++();
ElementType& operator*() { return *m_current; }
ElementType* operator->() { return m_current; }
ElementType& operator*();
ElementType* operator->();
bool operator!=(const DescendantIterator& other) const;
private:
const Node* m_root;
ElementType* m_current;
#ifndef NDEBUG
bool domTreeHasMutated() const;
OwnPtr<NoEventDispatchAssertion> m_noEventDispatchAssertion;
uint64_t m_initialDOMTreeVersion;
#endif
......@@ -85,24 +87,54 @@ inline DescendantIterator<ElementType>::DescendantIterator(const Node* root, Ele
, m_current(current)
#ifndef NDEBUG
, m_noEventDispatchAssertion(adoptPtr(new NoEventDispatchAssertion))
, m_initialDOMTreeVersion(m_current ? m_current->document()->domTreeVersion() : 0)
, m_initialDOMTreeVersion(root->document()->domTreeVersion())
#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(m_current->document()->domTreeVersion() == m_initialDOMTreeVersion);
ASSERT(!domTreeHasMutated());
m_current = Traversal<ElementType>::next(m_current, m_root);
#ifndef NDEBUG
// Drop the assertion when the iterator reaches the end.
if (!m_current)
m_noEventDispatchAssertion = nullptr;
#endif
return *this;
}
template <typename ElementType>
inline ElementType& DescendantIterator<ElementType>::operator*()
{
ASSERT(m_current);
ASSERT(!domTreeHasMutated());
return *m_current;
}
template <typename ElementType>
inline ElementType* DescendantIterator<ElementType>::operator->()
{
ASSERT(m_current);
ASSERT(!domTreeHasMutated());
return m_current;
}
template <typename ElementType>
inline bool DescendantIterator<ElementType>::operator!=(const DescendantIterator& other) const
{
ASSERT(m_root == other.m_root);
ASSERT(!domTreeHasMutated());
return m_current != other.m_current;
}
......
......@@ -776,8 +776,12 @@ bool Document::hasManifest() const
void Document::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
Element* newDocumentElement = &*elementChildren(this).begin();
Element* newDocumentElement = 0;
auto firstElementChild = elementChildren(this).begin();
if (firstElementChild != elementChildren(this).end())
newDocumentElement = &*firstElementChild;
if (newDocumentElement == m_documentElement)
return;
m_documentElement = newDocumentElement;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment