CTTE: Use references more in ContainerNode, ContainerNodeAlgorithms and related classes
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 03:40:47 +0000 (03:40 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 03:40:47 +0000 (03:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121772

Reviewed by Andreas Kling.

../WebCore:

Use references for never null Nodes in ContainerNode and related classes.

../WebKit/qt:

* Api/qwebelement.cpp:
(QWebElementCollection::append):
Update to work with the new StaticNodeList adopt function.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156256 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/dom/CharacterData.cpp
Source/WebCore/dom/ChildListMutationScope.cpp
Source/WebCore/dom/ChildListMutationScope.h
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNode.h
Source/WebCore/dom/ContainerNodeAlgorithms.cpp
Source/WebCore/dom/ContainerNodeAlgorithms.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/MutationObserverInterestGroup.cpp
Source/WebCore/dom/MutationObserverInterestGroup.h
Source/WebCore/dom/MutationRecord.cpp
Source/WebCore/dom/MutationRecord.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/StaticNodeList.cpp
Source/WebCore/dom/StaticNodeList.h
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/ReplaceNodeWithSpanCommand.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLFrameElementBase.cpp
Source/WebCore/html/HTMLFrameOwnerElement.cpp
Source/WebCore/html/HTMLFrameOwnerElement.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/parser/HTMLTreeBuilder.cpp
Source/WebCore/svg/SVGElementInstance.cpp
Source/WebCore/svg/SVGElementInstance.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/xml/XMLErrors.cpp
Source/WebKit/qt/Api/qwebelement.cpp
Source/WebKit/qt/ChangeLog

index 65d3207..63694f0 100644 (file)
@@ -1,3 +1,12 @@
+2013-09-22  Sam Weinig  <sam@webkit.org>
+
+        CTTE: Use references more in ContainerNode, ContainerNodeAlgorithms and related classes
+        https://bugs.webkit.org/show_bug.cgi?id=121772
+
+        Reviewed by Andreas Kling.
+
+        Use references for never null Nodes in ContainerNode and related classes.
+
 2013-09-22  Antti Koivisto  <antti@apple.com>
 
         Fix functions calling to RenderObject superclass to call RenderElement instead
index d6c0355..8989b46 100644 (file)
@@ -57,7 +57,7 @@ public:
 
         bool shouldReadOldValue = false;
 
-        m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(s_currentDecl->parentElement(), HTMLNames::styleAttr);
+        m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(*s_currentDecl->parentElement(), HTMLNames::styleAttr);
         if (m_mutationRecipients && m_mutationRecipients->isOldValueRequested())
             shouldReadOldValue = true;
 
@@ -67,7 +67,7 @@ public:
 
         if (m_mutationRecipients) {
             AtomicString requestedOldValue = m_mutationRecipients->isOldValueRequested() ? oldValue : nullAtom;
-            m_mutation = MutationRecord::createAttributes(s_currentDecl->parentElement(), HTMLNames::styleAttr, requestedOldValue);
+            m_mutation = MutationRecord::createAttributes(*s_currentDecl->parentElement(), HTMLNames::styleAttr, requestedOldValue);
         }
     }
 
index 8c84460..a2c763c 100644 (file)
@@ -215,8 +215,9 @@ void CharacterData::setDataAndUpdate(const String& newData, unsigned offsetOfRep
 
 void CharacterData::dispatchModifiedEvent(const String& oldData)
 {
-    if (OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForCharacterDataMutation(this))
-        mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacterData(this, oldData));
+    if (OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForCharacterDataMutation(*this))
+        mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacterData(*this, oldData));
+
     if (!isInShadowTree()) {
         if (parentNode()) {
             ContainerNode::ChildChange change = {
index 391483e..004793f 100644 (file)
 
 namespace WebCore {
 
-typedef HashMap<Node*, ChildListMutationAccumulator*> AccumulatorMap;
+typedef HashMap<ContainerNode*, ChildListMutationAccumulator*> AccumulatorMap;
 static AccumulatorMap& accumulatorMap()
 {
     DEFINE_STATIC_LOCAL(AccumulatorMap, map, ());
     return map;
 }
 
-ChildListMutationAccumulator::ChildListMutationAccumulator(PassRefPtr<Node> target, PassOwnPtr<MutationObserverInterestGroup> observers)
+ChildListMutationAccumulator::ChildListMutationAccumulator(ContainerNode& target, PassOwnPtr<MutationObserverInterestGroup> observers)
     : m_target(target)
     , m_lastAdded(0)
     , m_observers(observers)
@@ -62,12 +62,12 @@ ChildListMutationAccumulator::~ChildListMutationAccumulator()
 {
     if (!isEmpty())
         enqueueMutationRecord();
-    accumulatorMap().remove(m_target.get());
+    accumulatorMap().remove(&m_target.get());
 }
 
-PassRefPtr<ChildListMutationAccumulator> ChildListMutationAccumulator::getOrCreate(Node* target)
+PassRefPtr<ChildListMutationAccumulator> ChildListMutationAccumulator::getOrCreate(ContainerNode& target)
 {
-    AccumulatorMap::AddResult result = accumulatorMap().add(target, nullptr);
+    AccumulatorMap::AddResult result = accumulatorMap().add(&target, nullptr);
     RefPtr<ChildListMutationAccumulator> accumulator;
     if (!result.isNewEntry)
         accumulator = result.iterator->value;
@@ -78,16 +78,16 @@ PassRefPtr<ChildListMutationAccumulator> ChildListMutationAccumulator::getOrCrea
     return accumulator.release();
 }
 
-inline bool ChildListMutationAccumulator::isAddedNodeInOrder(Node* child)
+inline bool ChildListMutationAccumulator::isAddedNodeInOrder(Node& child)
 {
-    return isEmpty() || (m_lastAdded == child->previousSibling() && m_nextSibling == child->nextSibling());
+    return isEmpty() || (m_lastAdded == child.previousSibling() && m_nextSibling == child.nextSibling());
 }
 
-void ChildListMutationAccumulator::childAdded(PassRefPtr<Node> prpChild)
+void ChildListMutationAccumulator::childAdded(Node& childRef)
 {
     ASSERT(hasObservers());
 
-    RefPtr<Node> child = prpChild;
+    Ref<Node> child(childRef);
 
     if (!isAddedNodeInOrder(child.get()))
         enqueueMutationRecord();
@@ -97,20 +97,20 @@ void ChildListMutationAccumulator::childAdded(PassRefPtr<Node> prpChild)
         m_nextSibling = child->nextSibling();
     }
 
-    m_lastAdded = child.get();
-    m_addedNodes.append(child.release());
+    m_lastAdded = &child.get();
+    m_addedNodes.append(child.get());
 }
 
-inline bool ChildListMutationAccumulator::isRemovedNodeInOrder(Node* child)
+inline bool ChildListMutationAccumulator::isRemovedNodeInOrder(Node& child)
 {
-    return isEmpty() || m_nextSibling == child;
+    return isEmpty() || m_nextSibling == &child;
 }
 
-void ChildListMutationAccumulator::willRemoveChild(PassRefPtr<Node> prpChild)
+void ChildListMutationAccumulator::willRemoveChild(Node& childRef)
 {
     ASSERT(hasObservers());
 
-    RefPtr<Node> child = prpChild;
+    Ref<Node> child(childRef);
 
     if (!m_addedNodes.isEmpty() || !isRemovedNodeInOrder(child.get()))
         enqueueMutationRecord();
@@ -122,7 +122,7 @@ void ChildListMutationAccumulator::willRemoveChild(PassRefPtr<Node> prpChild)
     } else
         m_nextSibling = child->nextSibling();
 
-    m_removedNodes.append(child.release());
+    m_removedNodes.append(child.get());
 }
 
 void ChildListMutationAccumulator::enqueueMutationRecord()
@@ -132,7 +132,7 @@ void ChildListMutationAccumulator::enqueueMutationRecord()
 
     RefPtr<NodeList> addedNodes = StaticNodeList::adopt(m_addedNodes);
     RefPtr<NodeList> removedNodes = StaticNodeList::adopt(m_removedNodes);
-    RefPtr<MutationRecord> record = MutationRecord::createChildList(m_target, addedNodes.release(), removedNodes.release(), m_previousSibling.release(), m_nextSibling.release());
+    RefPtr<MutationRecord> record = MutationRecord::createChildList(m_target.get(), addedNodes.release(), removedNodes.release(), m_previousSibling.release(), m_nextSibling.release());
     m_observers->enqueueMutationRecord(record.release());
     m_lastAdded = 0;
     ASSERT(isEmpty());
index a33d910..a179f59 100644 (file)
@@ -46,26 +46,26 @@ class MutationObserverInterestGroup;
 // ChildListMutationAccumulator is not meant to be used directly; ChildListMutationScope is the public interface.
 class ChildListMutationAccumulator : public RefCounted<ChildListMutationAccumulator> {
 public:
-    static PassRefPtr<ChildListMutationAccumulator> getOrCreate(Node*);
+    static PassRefPtr<ChildListMutationAccumulator> getOrCreate(ContainerNode&);
     ~ChildListMutationAccumulator();
 
-    void childAdded(PassRefPtr<Node>);
-    void willRemoveChild(PassRefPtr<Node>);
+    void childAdded(Node&);
+    void willRemoveChild(Node&);
 
     bool hasObservers() const { return m_observers; }
 
 private:
-    ChildListMutationAccumulator(PassRefPtr<Node>, PassOwnPtr<MutationObserverInterestGroup>);
+    ChildListMutationAccumulator(ContainerNode&, PassOwnPtr<MutationObserverInterestGroup>);
 
     void enqueueMutationRecord();
     bool isEmpty();
-    bool isAddedNodeInOrder(Node*);
-    bool isRemovedNodeInOrder(Node*);
+    bool isAddedNodeInOrder(Node&);
+    bool isRemovedNodeInOrder(Node&);
 
-    RefPtr<Node> m_target;
+    Ref<ContainerNode> m_target;
 
-    Vector<RefPtr<Node> > m_removedNodes;
-    Vector<RefPtr<Node> > m_addedNodes;
+    Vector<Ref<Node>> m_removedNodes;
+    Vector<Ref<Node>> m_addedNodes;
     RefPtr<Node> m_previousSibling;
     RefPtr<Node> m_nextSibling;
     Node* m_lastAdded;
@@ -76,19 +76,19 @@ private:
 class ChildListMutationScope {
     WTF_MAKE_NONCOPYABLE(ChildListMutationScope);
 public:
-    explicit ChildListMutationScope(Node* target)
+    explicit ChildListMutationScope(ContainerNode& target)
     {
-        if (target->document().hasMutationObserversOfType(MutationObserver::ChildList))
+        if (target.document().hasMutationObserversOfType(MutationObserver::ChildList))
             m_accumulator = ChildListMutationAccumulator::getOrCreate(target);
     }
 
-    void childAdded(Node* child)
+    void childAdded(Node& child)
     {
         if (m_accumulator && m_accumulator->hasObservers())
             m_accumulator->childAdded(child);
     }
 
-    void willRemoveChild(Node* child)
+    void willRemoveChild(Node& child)
     {
         if (m_accumulator && m_accumulator->hasObservers())
             m_accumulator->willRemoveChild(child);
index 69ac4e2..4d430c5 100644 (file)
@@ -67,8 +67,8 @@ using namespace std;
 
 namespace WebCore {
 
-static void dispatchChildInsertionEvents(Node*);
-static void dispatchChildRemovalEvents(Node*);
+static void dispatchChildInsertionEvents(Node&);
+static void dispatchChildRemovalEvents(Node&);
 
 typedef pair<RefPtr<Node>, unsigned> CallbackParameters;
 typedef pair<NodeCallback, CallbackParameters> CallbackInfo;
@@ -85,16 +85,17 @@ ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0;
 unsigned NoEventDispatchAssertion::s_count = 0;
 #endif
 
-static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec)
+static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes, ExceptionCode& ec)
 {
-    if (node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) {
+    if (node.nodeType() != Node::DOCUMENT_FRAGMENT_NODE) {
         nodes.append(node);
-        if (ContainerNode* oldParent = node->parentNode())
-            oldParent->removeChild(node, ec);
+        if (ContainerNode* oldParent = node.parentNode())
+            oldParent->removeChild(&node, ec);
         return;
     }
+
     getChildNodes(node, nodes);
-    toContainerNode(node)->removeChildren();
+    toContainerNode(node).removeChildren();
 }
 
 // FIXME: This function must get a new name.
@@ -107,32 +108,34 @@ void ContainerNode::removeDetachedChildren()
             child->updateAncestorConnectedSubframeCountForRemoval();
     }
     // FIXME: We should be able to ASSERT(!attached()) here: https://bugs.webkit.org/show_bug.cgi?id=107801
-    removeDetachedChildrenInContainer<Node, ContainerNode>(this);
+    removeDetachedChildrenInContainer<Node, ContainerNode>(*this);
 }
 
-static inline void attachChild(Node* child)
+static inline void attachChild(Node& child)
 {
-    if (child->isElementNode())
-        Style::attachRenderTree(*toElement(child));
-    else if (child->isTextNode())
-        Style::attachTextRenderer(*toText(child));
+    if (child.isElementNode())
+        Style::attachRenderTree(toElement(child));
+    else if (child.isTextNode())
+        Style::attachTextRenderer(toText(child));
 }
 
-static inline void detachChild(Node* child)
+static inline void detachChild(Node& child)
 {
-    if (child->isElementNode())
-        Style::detachRenderTree(*toElement(child));
-    else if (child->isTextNode())
-        Style::detachTextRenderer(*toText(child));
+    if (child.isElementNode())
+        Style::detachRenderTree(toElement(child));
+    else if (child.isTextNode())
+        Style::detachTextRenderer(toText(child));
 }
 
 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
 {
+    ASSERT(oldParent);
+
     NodeVector children;
-    getChildNodes(oldParent, children);
+    getChildNodes(*oldParent, children);
 
     if (oldParent->document().hasMutationObserversOfType(MutationObserver::ChildList)) {
-        ChildListMutationScope mutation(oldParent);
+        ChildListMutationScope mutation(*oldParent);
         for (unsigned i = 0; i < children.size(); ++i)
             mutation.willRemoveChild(children[i].get());
     }
@@ -143,18 +146,19 @@ void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
     oldParent->removeDetachedChildren();
 
     for (unsigned i = 0; i < children.size(); ++i) {
-        Node* child = children[i].get();
-        if (child->attached())
+        Node& child = children[i].get();
+        if (child.attached())
             detachChild(child);
+
         // FIXME: We need a no mutation event version of adoptNode.
-        RefPtr<Node> adoptedChild = document().adoptNode(children[i].release(), ASSERT_NO_EXCEPTION);
+        RefPtr<Node> adoptedChild = document().adoptNode(&children[i].get(), ASSERT_NO_EXCEPTION);
         parserAppendChild(adoptedChild.get());
         // FIXME: Together with adoptNode above, the tree scope might get updated recursively twice
         // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree).
         // Can we do better?
         treeScope()->adoptIfNeeded(adoptedChild.get());
         if (attached() && !adoptedChild->attached())
-            attachChild(adoptedChild.get());
+            attachChild(*adoptedChild.get());
     }
 }
 
@@ -291,7 +295,7 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
     Ref<Node> next(*refChild);
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
+    collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
     if (ec)
         return false;
     if (targets.isEmpty())
@@ -303,9 +307,9 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
 
     InspectorInstrumentation::willInsertDOMNode(&document(), this);
 
-    ChildListMutationScope mutation(this);
-    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
-        Node* child = it->get();
+    ChildListMutationScope mutation(*this);
+    for (auto it = targets.begin(), end = targets.end(); it != end; ++it) {
+        Node& child = it->get();
 
         // Due to arbitrary code running in response to a DOM mutation event it's
         // possible that "next" is no longer a child of "this".
@@ -313,12 +317,12 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
         // In either of those cases, we'll just stop.
         if (next->parentNode() != this)
             break;
-        if (child->parentNode())
+        if (child.parentNode())
             break;
 
-        treeScope()->adoptIfNeeded(child);
+        treeScope()->adoptIfNeeded(&child);
 
-        insertBeforeCommon(&next.get(), child);
+        insertBeforeCommon(next.get(), child);
 
         updateTreeAfterInsertion(child, attachBehavior);
     }
@@ -327,47 +331,46 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
     return true;
 }
 
-void ContainerNode::insertBeforeCommon(Node* nextChild, Node* newChild)
+void ContainerNode::insertBeforeCommon(Node& nextChild, Node& newChild)
 {
     NoEventDispatchAssertion assertNoEventDispatch;
 
-    ASSERT(newChild);
-    ASSERT(!newChild->parentNode()); // Use insertBefore if you need to handle reparenting (and want DOM mutation events).
-    ASSERT(!newChild->nextSibling());
-    ASSERT(!newChild->previousSibling());
-    ASSERT(!newChild->isShadowRoot());
+    ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle reparenting (and want DOM mutation events).
+    ASSERT(!newChild.nextSibling());
+    ASSERT(!newChild.previousSibling());
+    ASSERT(!newChild.isShadowRoot());
 
-    Node* prev = nextChild->previousSibling();
+    Node* prev = nextChild.previousSibling();
     ASSERT(m_lastChild != prev);
-    nextChild->setPreviousSibling(newChild);
+    nextChild.setPreviousSibling(&newChild);
     if (prev) {
-        ASSERT(m_firstChild != nextChild);
-        ASSERT(prev->nextSibling() == nextChild);
-        prev->setNextSibling(newChild);
+        ASSERT(m_firstChild != &nextChild);
+        ASSERT(prev->nextSibling() == &nextChild);
+        prev->setNextSibling(&newChild);
     } else {
-        ASSERT(m_firstChild == nextChild);
-        m_firstChild = newChild;
+        ASSERT(m_firstChild == &nextChild);
+        m_firstChild = &newChild;
     }
-    newChild->setParentNode(this);
-    newChild->setPreviousSibling(prev);
-    newChild->setNextSibling(nextChild);
+    newChild.setParentNode(this);
+    newChild.setPreviousSibling(prev);
+    newChild.setNextSibling(&nextChild);
 }
 
-void ContainerNode::notifyChildInserted(Node* child, ChildChangeSource source)
+void ContainerNode::notifyChildInserted(Node& child, ChildChangeSource source)
 {
     ChildChange change;
-    change.type = child->isElementNode() ? ElementInserted : child->isTextNode() ? TextInserted : NonContentsChildChanged;
-    change.previousSiblingElement =  ElementTraversal::previousSibling(child);
-    change.nextSiblingElement = ElementTraversal::nextSibling(child);
+    change.type = child.isElementNode() ? ElementInserted : child.isTextNode() ? TextInserted : NonContentsChildChanged;
+    change.previousSiblingElement = ElementTraversal::previousSibling(&child);
+    change.nextSiblingElement = ElementTraversal::nextSibling(&child);
     change.source = source;
 
     childrenChanged(change);
 }
 
-void ContainerNode::notifyChildRemoved(Node* child, Node* previousSibling, Node* nextSibling, ChildChangeSource source)
+void ContainerNode::notifyChildRemoved(Node& child, Node* previousSibling, Node* nextSibling, ChildChangeSource source)
 {
     ChildChange change;
-    change.type = child->isElementNode() ? ElementRemoved : child->isTextNode() ? TextRemoved : NonContentsChildChanged;
+    change.type = child.isElementNode() ? ElementRemoved : child.isTextNode() ? TextRemoved : NonContentsChildChanged;
     change.previousSiblingElement = (!previousSibling || previousSibling->isElementNode()) ? toElement(previousSibling) : ElementTraversal::previousSibling(previousSibling);
     change.nextSiblingElement = (!nextSibling || nextSibling->isElementNode()) ? toElement(nextSibling) : ElementTraversal::nextSibling(nextSibling);
     change.source = source;
@@ -391,15 +394,15 @@ void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node* nextChil
     if (&document() != &newChild->document())
         document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
 
-    insertBeforeCommon(nextChild, newChild.get());
+    insertBeforeCommon(*nextChild, *newChild.get());
 
     newChild->updateAncestorConnectedSubframeCountForInsertion();
 
-    ChildListMutationScope(this).childAdded(newChild.get());
+    ChildListMutationScope(*this).childAdded(*newChild);
 
-    notifyChildInserted(newChild.get(), ChildChangeSourceParser);
+    notifyChildInserted(*newChild, ChildChangeSourceParser);
 
-    ChildNodeInsertionNotifier(this).notify(newChild.get());
+    ChildNodeInsertionNotifier(*this).notify(*newChild);
 }
 
 bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, AttachBehavior attachBehavior)
@@ -430,7 +433,7 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
         return false;
     }
 
-    ChildListMutationScope mutation(this);
+    ChildListMutationScope mutation(*this);
 
     RefPtr<Node> next = oldChild->nextSibling();
 
@@ -448,7 +451,7 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
         return false;
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
+    collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
     if (ec)
         return false;
 
@@ -459,8 +462,8 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
     InspectorInstrumentation::willInsertDOMNode(&document(), this);
 
     // Add the new child(ren)
-    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
-        Node* child = it->get();
+    for (auto it = targets.begin(), end = targets.end(); it != end; ++it) {
+        Node& child = it->get();
 
         // Due to arbitrary code running in response to a DOM mutation event it's
         // possible that "next" is no longer a child of "this".
@@ -468,18 +471,18 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
         // In either of those cases, we'll just stop.
         if (next && next->parentNode() != this)
             break;
-        if (child->parentNode())
+        if (child.parentNode())
             break;
 
-        treeScope()->adoptIfNeeded(child);
+        treeScope()->adoptIfNeeded(&child);
 
         // Add child before "next".
         {
             NoEventDispatchAssertion assertNoEventDispatch;
             if (next)
-                insertBeforeCommon(next.get(), child);
+                insertBeforeCommon(*next, child);
             else
-                appendChildToContainer(child, this);
+                appendChildToContainer(&child, *this);
         }
 
         updateTreeAfterInsertion(child, attachBehavior);
@@ -489,29 +492,30 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
     return true;
 }
 
-static void willRemoveChild(Node* child)
+static void willRemoveChild(Node& child)
 {
-    ASSERT(child->parentNode());
-    ChildListMutationScope(child->parentNode()).willRemoveChild(child);
-    child->notifyMutationObserversNodeWillDetach();
+    ASSERT(child.parentNode());
+
+    ChildListMutationScope(*child.parentNode()).willRemoveChild(child);
+    child.notifyMutationObserversNodeWillDetach();
     dispatchChildRemovalEvents(child);
-    child->document().nodeWillBeRemoved(child); // e.g. mutation event listener can create a new range.
-    if (child->isContainerNode())
+    child.document().nodeWillBeRemoved(&child); // e.g. mutation event listener can create a new range.
+    if (child.isContainerNode())
         ChildFrameDisconnector(toContainerNode(child)).disconnect();
 }
 
-static void willRemoveChildren(ContainerNode* container)
+static void willRemoveChildren(ContainerNode& container)
 {
     NodeVector children;
     getChildNodes(container, children);
 
-    container->document().nodeChildrenWillBeRemoved(container);
+    container.document().nodeChildrenWillBeRemoved(container);
 
     ChildListMutationScope mutation(container);
-    for (NodeVector::const_iterator it = children.begin(); it != children.end(); ++it) {
-        Node* child = it->get();
+    for (auto it = children.begin(); it != children.end(); ++it) {
+        Node& child = it->get();
         mutation.willRemoveChild(child);
-        child->notifyMutationObserversNodeWillDetach();
+        child.notifyMutationObserversNodeWillDetach();
 
         // fire removed from document mutation events.
         dispatchChildRemovalEvents(child);
@@ -522,7 +526,7 @@ static void willRemoveChildren(ContainerNode* container)
 
 void ContainerNode::disconnectDescendantFrames()
 {
-    ChildFrameDisconnector(this).disconnect();
+    ChildFrameDisconnector(*this).disconnect();
 }
 
 bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
@@ -562,7 +566,7 @@ bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
         return false;
     }
 
-    willRemoveChild(&child.get());
+    willRemoveChild(child.get());
 
     // Mutation events might have moved this child into a different parent.
     if (child->parentNode() != this) {
@@ -575,63 +579,61 @@ bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
 
         Node* prev = child->previousSibling();
         Node* next = child->nextSibling();
-        removeBetween(prev, next, &child.get());
+        removeBetween(prev, next, child.get());
 
-        notifyChildRemoved(&child.get(), prev, next, ChildChangeSourceAPI);
+        notifyChildRemoved(child.get(), prev, next, ChildChangeSourceAPI);
 
-        ChildNodeRemovalNotifier(this).notify(&child.get());
+        ChildNodeRemovalNotifier(*this).notify(child.get());
     }
     dispatchSubtreeModifiedEvent();
 
     return true;
 }
 
-void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node* oldChild)
+void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& oldChild)
 {
     NoEventDispatchAssertion assertNoEventDispatch;
 
-    ASSERT(oldChild);
-    ASSERT(oldChild->parentNode() == this);
+    ASSERT(oldChild.parentNode() == this);
 
     // Remove from rendering tree
-    if (oldChild->attached())
+    if (oldChild.attached())
         detachChild(oldChild);
 
     if (nextChild)
         nextChild->setPreviousSibling(previousChild);
     if (previousChild)
         previousChild->setNextSibling(nextChild);
-    if (m_firstChild == oldChild)
+    if (m_firstChild == &oldChild)
         m_firstChild = nextChild;
-    if (m_lastChild == oldChild)
+    if (m_lastChild == &oldChild)
         m_lastChild = previousChild;
 
-    oldChild->setPreviousSibling(0);
-    oldChild->setNextSibling(0);
-    oldChild->setParentNode(0);
+    oldChild.setPreviousSibling(0);
+    oldChild.setNextSibling(0);
+    oldChild.setParentNode(0);
 
-    document().adoptIfNeeded(oldChild);
+    document().adoptIfNeeded(&oldChild);
 }
 
-void ContainerNode::parserRemoveChild(Node* oldChild)
+void ContainerNode::parserRemoveChild(Node& oldChild)
 {
-    ASSERT(oldChild);
-    ASSERT(oldChild->parentNode() == this);
-    ASSERT(!oldChild->isDocumentFragment());
+    ASSERT(oldChild.parentNode() == this);
+    ASSERT(!oldChild.isDocumentFragment());
 
-    Node* prev = oldChild->previousSibling();
-    Node* next = oldChild->nextSibling();
+    Node* prev = oldChild.previousSibling();
+    Node* next = oldChild.nextSibling();
 
-    oldChild->updateAncestorConnectedSubframeCountForRemoval();
+    oldChild.updateAncestorConnectedSubframeCountForRemoval();
 
-    ChildListMutationScope(this).willRemoveChild(oldChild);
-    oldChild->notifyMutationObserversNodeWillDetach();
+    ChildListMutationScope(*this).willRemoveChild(oldChild);
+    oldChild.notifyMutationObserversNodeWillDetach();
 
     removeBetween(prev, next, oldChild);
 
     notifyChildRemoved(oldChild, prev, next, ChildChangeSourceParser);
 
-    ChildNodeRemovalNotifier(this).notify(oldChild);
+    ChildNodeRemovalNotifier(*this).notify(oldChild);
 }
 
 // this differs from other remove functions because it forcibly removes all the children,
@@ -653,7 +655,7 @@ void ContainerNode::removeChildren()
 
     // Do any prep work needed before actually starting to detach
     // and remove... e.g. stop loading frames, fire unload events.
-    willRemoveChildren(this);
+    willRemoveChildren(*this);
 
     NodeVector removedChildren;
     {
@@ -662,8 +664,8 @@ void ContainerNode::removeChildren()
             NoEventDispatchAssertion assertNoEventDispatch;
             removedChildren.reserveInitialCapacity(childNodeCount());
             while (RefPtr<Node> n = m_firstChild) {
-                removedChildren.append(m_firstChild);
-                removeBetween(0, m_firstChild->nextSibling(), m_firstChild);
+                removedChildren.append(*m_firstChild);
+                removeBetween(0, m_firstChild->nextSibling(), *m_firstChild);
             }
         }
 
@@ -671,7 +673,7 @@ void ContainerNode::removeChildren()
         childrenChanged(change);
         
         for (size_t i = 0; i < removedChildren.size(); ++i)
-            ChildNodeRemovalNotifier(this).notify(removedChildren[i].get());
+            ChildNodeRemovalNotifier(*this).notify(removedChildren[i].get());
     }
 
     dispatchSubtreeModifiedEvent();
@@ -695,7 +697,7 @@ bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, At
         return newChild;
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
+    collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
     if (ec)
         return false;
 
@@ -709,22 +711,22 @@ bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, At
     InspectorInstrumentation::willInsertDOMNode(&document(), this);
 
     // Now actually add the child(ren)
-    ChildListMutationScope mutation(this);
-    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
-        Node* child = it->get();
+    ChildListMutationScope mutation(*this);
+    for (auto it = targets.begin(), end = targets.end(); it != end; ++it) {
+        Node& child = it->get();
 
         // If the child has a parent again, just stop what we're doing, because
         // that means someone is doing something with DOM mutation -- can't re-parent
         // a child that already has a parent.
-        if (child->parentNode())
+        if (child.parentNode())
             break;
 
-        treeScope()->adoptIfNeeded(child);
+        treeScope()->adoptIfNeeded(&child);
 
         // Append child to the end of the list
         {
             NoEventDispatchAssertion assertNoEventDispatch;
-            appendChildToContainer(child, this);
+            appendChildToContainer(&child, *this);
         }
 
         updateTreeAfterInsertion(child, attachBehavior);
@@ -749,17 +751,17 @@ void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild)
     {
         NoEventDispatchAssertion assertNoEventDispatch;
         // FIXME: This method should take a PassRefPtr.
-        appendChildToContainer(newChild.get(), this);
+        appendChildToContainer(newChild.get(), *this);
         treeScope()->adoptIfNeeded(newChild.get());
     }
 
     newChild->updateAncestorConnectedSubframeCountForInsertion();
 
-    ChildListMutationScope(this).childAdded(newChild.get());
+    ChildListMutationScope(*this).childAdded(*newChild);
 
-    notifyChildInserted(newChild.get(), ChildChangeSourceParser);
+    notifyChildInserted(*newChild, ChildChangeSourceParser);
 
-    ChildNodeInsertionNotifier(this).notify(newChild.get());
+    ChildNodeInsertionNotifier(*this).notify(*newChild);
 }
 
 void ContainerNode::suspendPostAttachCallbacks()
@@ -840,7 +842,7 @@ void ContainerNode::childrenChanged(const ChildChange& change)
 {
     document().incDOMTreeVersion();
     if (change.source == ChildChangeSourceAPI && change.type != TextChanged)
-        document().updateRangesAfterChildrenChanged(this);
+        document().updateRangesAfterChildrenChanged(*this);
     invalidateNodeListCachesInAncestors();
 }
 
@@ -1022,40 +1024,40 @@ Node *ContainerNode::childNode(unsigned index) const
     return n;
 }
 
-static void dispatchChildInsertionEvents(Node* child)
+static void dispatchChildInsertionEvents(Node& child)
 {
-    if (child->isInShadowTree())
+    if (child.isInShadowTree())
         return;
 
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
 
-    RefPtr<Node> c = child;
-    Ref<Document> document(child->document());
+    RefPtr<Node> c = &child;
+    Ref<Document> document(child.document());
 
     if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_LISTENER))
         c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedEvent, true, c->parentNode()));
 
     // dispatch the DOMNodeInsertedIntoDocument event to all descendants
     if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) {
-        for (; c; c = NodeTraversal::next(c.get(), child))
+        for (; c; c = NodeTraversal::next(c.get(), &child))
             c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedIntoDocumentEvent, false));
     }
 }
 
-static void dispatchChildRemovalEvents(Node* child)
+static void dispatchChildRemovalEvents(Node& child)
 {
-    if (child->isInShadowTree()) {
-        InspectorInstrumentation::willRemoveDOMNode(&child->document(), child);
+    if (child.isInShadowTree()) {
+        InspectorInstrumentation::willRemoveDOMNode(&child.document(), &child);
         return;
     }
 
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
 
-    willCreatePossiblyOrphanedTreeByRemoval(child);
-    InspectorInstrumentation::willRemoveDOMNode(&child->document(), child);
+    willCreatePossiblyOrphanedTreeByRemoval(&child);
+    InspectorInstrumentation::willRemoveDOMNode(&child.document(), &child);
 
-    RefPtr<Node> c = child;
-    Ref<Document> document(child->document());
+    RefPtr<Node> c = &child;
+    Ref<Document> document(child.document());
 
     // dispatch pre-removal mutation events
     if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LISTENER))
@@ -1063,30 +1065,30 @@ static void dispatchChildRemovalEvents(Node* child)
 
     // dispatch the DOMNodeRemovedFromDocument event to all descendants
     if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {
-        for (; c; c = NodeTraversal::next(c.get(), child))
+        for (; c; c = NodeTraversal::next(c.get(), &child))
             c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemovedFromDocumentEvent, false));
     }
 }
 
-void ContainerNode::updateTreeAfterInsertion(Node* child, AttachBehavior attachBehavior)
+void ContainerNode::updateTreeAfterInsertion(Node& child, AttachBehavior attachBehavior)
 {
-    ASSERT(child->refCount());
+    ASSERT(child.refCount());
 
-    ChildListMutationScope(this).childAdded(child);
+    ChildListMutationScope(*this).childAdded(child);
 
     notifyChildInserted(child, ChildChangeSourceAPI);
 
-    ChildNodeInsertionNotifier(this).notify(child);
+    ChildNodeInsertionNotifier(*this).notify(child);
 
     // FIXME: Attachment should be the first operation in this function, but some code
     // (for example, HTMLFormControlElement's autofocus support) requires this ordering.
-    if (attached() && !child->attached() && child->parentNode() == this) {
+    if (attached() && !child.attached() && child.parentNode() == this) {
         if (attachBehavior == AttachLazily) {
-            if (child->isElementNode())
-                toElement(child)->lazyAttach();
-            else if (child->isTextNode()) {
-                child->setAttached(true);
-                child->setNeedsStyleRecalc();
+            if (child.isElementNode())
+                toElement(child).lazyAttach();
+            else if (child.isTextNode()) {
+                child.setAttached(true);
+                child.setNeedsStyleRecalc();
             }
         } else
             attachChild(child);
index a21ffc6..41ff8f8 100644 (file)
@@ -38,7 +38,7 @@ typedef void (*NodeCallback)(Node*, unsigned);
 
 namespace Private { 
     template<class GenericNode, class GenericNodeContainer>
-    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer*);
+    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
 };
 
 class NoEventDispatchAssertion {
@@ -98,7 +98,7 @@ public:
     // They don't send DOM mutation events or handle reparenting.
     // However, arbitrary code may be run by beforeload handlers.
     void parserAppendChild(PassRefPtr<Node>);
-    void parserRemoveChild(Node*);
+    void parserRemoveChild(Node&);
     void parserInsertBefore(PassRefPtr<Node> newChild, Node* refChild);
 
     void removeChildren();
@@ -133,18 +133,18 @@ protected:
     static bool postAttachCallbacksAreSuspended();
 
     template<class GenericNode, class GenericNodeContainer>
-    friend void appendChildToContainer(GenericNode* child, GenericNodeContainer*);
+    friend void appendChildToContainer(GenericNode* child, GenericNodeContainer&);
 
     template<class GenericNode, class GenericNodeContainer>
-    friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer*);
+    friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
 
     void removeDetachedChildren();
     void setFirstChild(Node* child) { m_firstChild = child; }
     void setLastChild(Node* child) { m_lastChild = child; }
 
 private:
-    void removeBetween(Node* previousChild, Node* nextChild, Node* oldChild);
-    void insertBeforeCommon(Node* nextChild, Node* oldChild);
+    void removeBetween(Node* previousChild, Node* nextChild, Node& oldChild);
+    void insertBeforeCommon(Node& nextChild, Node& oldChild);
 
     static void dispatchPostAttachCallbacks();
     void suspendPostAttachCallbacks();
@@ -153,10 +153,10 @@ private:
     bool getUpperLeftCorner(FloatPoint&) const;
     bool getLowerRightCorner(FloatPoint&) const;
 
-    void notifyChildInserted(Node* child, ChildChangeSource);
-    void notifyChildRemoved(Node* child, Node* previousSibling, Node* nextSibling, ChildChangeSource);
+    void notifyChildInserted(Node& child, ChildChangeSource);
+    void notifyChildRemoved(Node& child, Node* previousSibling, Node* nextSibling, ChildChangeSource);
 
-    void updateTreeAfterInsertion(Node* child, AttachBehavior);
+    void updateTreeAfterInsertion(Node& child, AttachBehavior);
 
     bool isContainerNode() const WTF_DELETED_FUNCTION;
 
@@ -176,8 +176,20 @@ inline const ContainerNode* toContainerNode(const Node* node)
     return static_cast<const ContainerNode*>(node);
 }
 
+inline ContainerNode& toContainerNode(Node& node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(node.isContainerNode());
+    return static_cast<ContainerNode&>(node);
+}
+inline const ContainerNode& toContainerNode(const Node& node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(node.isContainerNode());
+    return static_cast<const ContainerNode&>(node);
+}
+
 // This will catch anyone doing an unnecessary cast.
 void toContainerNode(const ContainerNode*);
+void toContainerNode(const ContainerNode&);
 
 inline ContainerNode::ContainerNode(Document* document, ConstructionType type)
     : Node(document, type)
@@ -240,21 +252,21 @@ inline bool Node::isTreeScope() const
 // for a Node Vector that is used to store child Nodes of a given Node.
 // FIXME: Optimize the value.
 const int initialNodeVectorSize = 11;
-typedef Vector<RefPtr<Node>, initialNodeVectorSize> NodeVector;
+typedef Vector<Ref<Node>, initialNodeVectorSize> NodeVector;
 
-inline void getChildNodes(Node* node, NodeVector& nodes)
+inline void getChildNodes(Node& node, NodeVector& nodes)
 {
-    ASSERT(!nodes.size());
-    for (Node* child = node->firstChild(); child; child = child->nextSibling())
-        nodes.append(child);
+    ASSERT(nodes.isEmpty());
+    for (Node* child = node.firstChild(); child; child = child->nextSibling())
+        nodes.append(*child);
 }
 
 class ChildNodesLazySnapshot {
     WTF_MAKE_NONCOPYABLE(ChildNodesLazySnapshot);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit ChildNodesLazySnapshot(Node* parentNode)
-        : m_currentNode(parentNode->firstChild())
+    explicit ChildNodesLazySnapshot(Node& parentNode)
+        : m_currentNode(parentNode.firstChild())
         , m_currentIndex(0)
     {
         m_nextSnapshot = latestSnapshot;
index 63c919d..162381d 100644 (file)
 
 namespace WebCore {
 
-void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode* node)
+void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode& node)
 {
     ChildNodesLazySnapshot snapshot(node);
     while (RefPtr<Node> child = snapshot.nextNode()) {
         // If we have been removed from the document during this loop, then
         // we don't want to tell the rest of our children that they've been
         // inserted into the document because they haven't.
-        if (node->inDocument() && child->parentNode() == node)
-            notifyNodeInsertedIntoDocument(child.get());
+        if (node.inDocument() && child->parentNode() == &node)
+            notifyNodeInsertedIntoDocument(*child.get());
     }
 
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return;
 
-    if (RefPtr<ShadowRoot> root = toElement(node)->shadowRoot()) {
-        if (node->inDocument() && root->hostElement() == node)
-            notifyNodeInsertedIntoDocument(root.get());
+    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
+        if (node.inDocument() && root->hostElement() == &node)
+            notifyNodeInsertedIntoDocument(*root.get());
     }
 }
 
-void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode* node)
+void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode& node)
 {
-    for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
+    for (Node* child = node.firstChild(); child; child = child->nextSibling()) {
         if (child->isContainerNode())
-            notifyNodeInsertedIntoTree(toContainerNode(child));
+            notifyNodeInsertedIntoTree(*toContainerNode(child));
     }
 
-    if (ShadowRoot* root = node->shadowRoot())
-        notifyNodeInsertedIntoTree(root);
+    if (ShadowRoot* root = node.shadowRoot())
+        notifyNodeInsertedIntoTree(*root);
 }
 
-void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode* node)
+void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode& node)
 {
     ChildNodesLazySnapshot snapshot(node);
     while (RefPtr<Node> child = snapshot.nextNode()) {
         // If we have been added to the document during this loop, then we
         // don't want to tell the rest of our children that they've been
         // removed from the document because they haven't.
-        if (!node->inDocument() && child->parentNode() == node)
-            notifyNodeRemovedFromDocument(child.get());
+        if (!node.inDocument() && child->parentNode() == &node)
+            notifyNodeRemovedFromDocument(*child.get());
     }
 
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return;
 
-    if (node->document().cssTarget() == node)
-        node->document().setCSSTarget(0);
+    if (node.document().cssTarget() == &node)
+        node.document().setCSSTarget(0);
 
-    if (RefPtr<ShadowRoot> root = toElement(node)->shadowRoot()) {
-        if (!node->inDocument() && root->hostElement() == node)
-            notifyNodeRemovedFromDocument(root.get());
+    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
+        if (!node.inDocument() && root->hostElement() == &node)
+            notifyNodeRemovedFromDocument(*root.get());
     }
 }
 
-void ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree(ContainerNode* node)
+void ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree(ContainerNode& node)
 {
-    for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
+    for (Node* child = node.firstChild(); child; child = child->nextSibling()) {
         if (child->isContainerNode())
-            notifyNodeRemovedFromTree(toContainerNode(child));
+            notifyNodeRemovedFromTree(*toContainerNode(child));
     }
 
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return;
 
-    if (RefPtr<ShadowRoot> root = toElement(node)->shadowRoot())
-        notifyNodeRemovedFromTree(root.get());
+    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot())
+        notifyNodeRemovedFromTree(*root.get());
 }
 
 #ifndef NDEBUG
-unsigned assertConnectedSubrameCountIsConsistent(Node* node)
+unsigned assertConnectedSubrameCountIsConsistent(Node& node)
 {
     unsigned count = 0;
 
-    if (node->isElementNode()) {
-        if (node->isFrameOwnerElement() && toFrameOwnerElement(node)->contentFrame())
+    if (node.isElementNode()) {
+        if (node.isFrameOwnerElement() && toFrameOwnerElement(node).contentFrame())
             count++;
 
-        if (ShadowRoot* root = toElement(node)->shadowRoot())
-            count += assertConnectedSubrameCountIsConsistent(root);
+        if (ShadowRoot* root = toElement(node).shadowRoot())
+            count += assertConnectedSubrameCountIsConsistent(*root);
     }
 
-    for (Node* child = node->firstChild(); child; child = child->nextSibling())
-        count += assertConnectedSubrameCountIsConsistent(child);
+    for (Node* child = node.firstChild(); child; child = child->nextSibling())
+        count += assertConnectedSubrameCountIsConsistent(*child);
 
     // If we undercount there's possibly a security bug since we'd leave frames
     // in subtrees outside the document.
-    ASSERT(node->connectedSubframeCount() >= count);
+    ASSERT(node.connectedSubframeCount() >= count);
 
     // If we overcount it's safe, but not optimal because it means we'll traverse
     // through the document in ChildFrameDisconnector looking for frames that have
     // already been disconnected.
-    ASSERT(node->connectedSubframeCount() == count);
+    ASSERT(node.connectedSubframeCount() == count);
 
     return count;
 }
index 151b3f2..076ce98 100644 (file)
@@ -36,52 +36,52 @@ namespace WebCore {
 
 class ChildNodeInsertionNotifier {
 public:
-    explicit ChildNodeInsertionNotifier(ContainerNode* insertionPoint)
+    explicit ChildNodeInsertionNotifier(ContainerNode& insertionPoint)
         : m_insertionPoint(insertionPoint)
     {
     }
 
-    void notify(Node*);
+    void notify(Node&);
 
 private:
-    void notifyDescendantInsertedIntoDocument(ContainerNode*);
-    void notifyDescendantInsertedIntoTree(ContainerNode*);
-    void notifyNodeInsertedIntoDocument(Node*);
-    void notifyNodeInsertedIntoTree(ContainerNode*);
+    void notifyDescendantInsertedIntoDocument(ContainerNode&);
+    void notifyDescendantInsertedIntoTree(ContainerNode&);
+    void notifyNodeInsertedIntoDocument(Node&);
+    void notifyNodeInsertedIntoTree(ContainerNode&);
 
-    ContainerNode* m_insertionPoint;
-    Vector< RefPtr<Node> > m_postInsertionNotificationTargets;
+    ContainerNode& m_insertionPoint;
+    Vector<Ref<Node>> m_postInsertionNotificationTargets;
 };
 
 class ChildNodeRemovalNotifier {
 public:
-    explicit ChildNodeRemovalNotifier(ContainerNode* insertionPoint)
+    explicit ChildNodeRemovalNotifier(ContainerNode& insertionPoint)
         : m_insertionPoint(insertionPoint)
     {
     }
 
-    void notify(Node*);
+    void notify(Node&);
 
 private:
-    void notifyDescendantRemovedFromDocument(ContainerNode*);
-    void notifyDescendantRemovedFromTree(ContainerNode*);
-    void notifyNodeRemovedFromDocument(Node*);
-    void notifyNodeRemovedFromTree(ContainerNode*);
+    void notifyDescendantRemovedFromDocument(ContainerNode&);
+    void notifyDescendantRemovedFromTree(ContainerNode&);
+    void notifyNodeRemovedFromDocument(Node&);
+    void notifyNodeRemovedFromTree(ContainerNode&);
 
-    ContainerNode* m_insertionPoint;
+    ContainerNode& m_insertionPoint;
 };
 
 namespace Private {
 
     template<class GenericNode, class GenericNodeContainer>
-    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer*);
+    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
 
 }
 
 // Helper functions for TreeShared-derived classes, which have a 'Node' style interface
 // This applies to 'ContainerNode' and 'SVGElementInstance'
 template<class GenericNode, class GenericNodeContainer>
-inline void removeDetachedChildrenInContainer(GenericNodeContainer* container)
+inline void removeDetachedChildrenInContainer(GenericNodeContainer& container)
 {
     // List of nodes to be deleted.
     GenericNode* head = 0;
@@ -102,25 +102,25 @@ inline void removeDetachedChildrenInContainer(GenericNodeContainer* container)
             tail = 0;
 
         if (n->hasChildNodes())
-            Private::addChildNodesToDeletionQueue<GenericNode, GenericNodeContainer>(head, tail, static_cast<GenericNodeContainer*>(n));
+            Private::addChildNodesToDeletionQueue<GenericNode, GenericNodeContainer>(head, tail, *static_cast<GenericNodeContainer*>(n));
 
         delete n;
     }
 }
 
 template<class GenericNode, class GenericNodeContainer>
-inline void appendChildToContainer(GenericNode* child, GenericNodeContainer* container)
+inline void appendChildToContainer(GenericNode* child, GenericNodeContainer& container)
 {
-    child->setParentNode(container);
+    child->setParentNode(&container);
 
-    GenericNode* lastChild = container->lastChild();
+    GenericNode* lastChild = container.lastChild();
     if (lastChild) {
         child->setPreviousSibling(lastChild);
         lastChild->setNextSibling(child);
     } else
-        container->setFirstChild(child);
+        container.setFirstChild(child);
 
-    container->setLastChild(child);
+    container.setLastChild(child);
 }
 
 // Helper methods for removeDetachedChildrenInContainer, hidden from WebCore namespace
@@ -128,7 +128,7 @@ namespace Private {
 
     template<class GenericNode, class GenericNodeContainer, bool dispatchRemovalNotification>
     struct NodeRemovalDispatcher {
-        static void dispatch(GenericNode*, GenericNodeContainer*)
+        static void dispatch(GenericNode&, GenericNodeContainer&)
         {
             // no-op, by default
         }
@@ -136,12 +136,12 @@ namespace Private {
 
     template<class GenericNode, class GenericNodeContainer>
     struct NodeRemovalDispatcher<GenericNode, GenericNodeContainer, true> {
-        static void dispatch(GenericNode* node, GenericNodeContainer* container)
+        static void dispatch(GenericNode& node, GenericNodeContainer& container)
         {
             // Clean up any TreeScope to a removed tree.
-            if (Document* containerDocument = container->ownerDocument())
-                containerDocument->adoptIfNeeded(node);
-            if (node->inDocument())
+            if (Document* containerDocument = container.ownerDocument())
+                containerDocument->adoptIfNeeded(&node);
+            if (node.inDocument())
                 ChildNodeRemovalNotifier(container).notify(node);
         }
     };
@@ -157,17 +157,17 @@ namespace Private {
     };
 
     template<class GenericNode, class GenericNodeContainer>
-    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container)
+    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer& container)
     {
         // We have to tell all children that their parent has died.
         GenericNode* next = 0;
-        for (GenericNode* n = container->firstChild(); n != 0; n = next) {
+        for (GenericNode* n = container.firstChild(); n != 0; n = next) {
             ASSERT(!n->m_deletionHasBegun);
 
             next = n->nextSibling();
             n->setNextSibling(0);
             n->setParentNode(0);
-            container->setFirstChild(next);
+            container.setFirstChild(next);
             if (next)
                 next->setPreviousSibling(0);
 
@@ -185,80 +185,80 @@ namespace Private {
                 tail = n;
             } else {
                 Ref<GenericNode> protect(*n); // removedFromDocument may remove remove all references to this node.
-                NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldDispatchRemovalNotification<GenericNode>::value>::dispatch(n, container);
+                NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldDispatchRemovalNotification<GenericNode>::value>::dispatch(*n, container);
             }
         }
 
-        container->setLastChild(0);
+        container.setLastChild(0);
     }
 
 } // namespace Private
 
-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node* node)
+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node& node)
 {
-    ASSERT(m_insertionPoint->inDocument());
-    Ref<Node> protect(*node);
-    if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->insertedInto(m_insertionPoint))
+    ASSERT(m_insertionPoint.inDocument());
+    Ref<Node> protect(node);
+    if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(&m_insertionPoint))
         m_postInsertionNotificationTargets.append(node);
-    if (node->isContainerNode())
+    if (node.isContainerNode())
         notifyDescendantInsertedIntoDocument(toContainerNode(node));
 }
 
-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode* node)
+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode& node)
 {
     NoEventDispatchAssertion assertNoEventDispatch;
-    ASSERT(!m_insertionPoint->inDocument());
+    ASSERT(!m_insertionPoint.inDocument());
 
-    if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->insertedInto(m_insertionPoint))
+    if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(&m_insertionPoint))
         m_postInsertionNotificationTargets.append(node);
     notifyDescendantInsertedIntoTree(node);
 }
 
-inline void ChildNodeInsertionNotifier::notify(Node* node)
+inline void ChildNodeInsertionNotifier::notify(Node& node)
 {
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
 
 #if ENABLE(INSPECTOR)
-    InspectorInstrumentation::didInsertDOMNode(&node->document(), node);
+    InspectorInstrumentation::didInsertDOMNode(&node.document(), &node);
 #endif
 
-    Ref<Document> protectDocument(node->document());
-    Ref<Node> protectNode(*node);
+    Ref<Document> protectDocument(node.document());
+    Ref<Node> protectNode(node);
 
-    if (m_insertionPoint->inDocument())
+    if (m_insertionPoint.inDocument())
         notifyNodeInsertedIntoDocument(node);
-    else if (node->isContainerNode())
+    else if (node.isContainerNode())
         notifyNodeInsertedIntoTree(toContainerNode(node));
 
     for (size_t i = 0; i < m_postInsertionNotificationTargets.size(); ++i)
-        m_postInsertionNotificationTargets[i]->didNotifySubtreeInsertions(m_insertionPoint);
+        m_postInsertionNotificationTargets[i]->didNotifySubtreeInsertions(&m_insertionPoint);
 }
 
 
-inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument(Node* node)
+inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument(Node& node)
 {
-    ASSERT(m_insertionPoint->inDocument());
-    node->removedFrom(m_insertionPoint);
+    ASSERT(m_insertionPoint.inDocument());
+    node.removedFrom(&m_insertionPoint);
 
-    if (node->isContainerNode())
+    if (node.isContainerNode())
         notifyDescendantRemovedFromDocument(toContainerNode(node));
 }
 
-inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromTree(ContainerNode* node)
+inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromTree(ContainerNode& node)
 {
     NoEventDispatchAssertion assertNoEventDispatch;
-    ASSERT(!m_insertionPoint->inDocument());
+    ASSERT(!m_insertionPoint.inDocument());
 
-    node->removedFrom(m_insertionPoint);
+    node.removedFrom(&m_insertionPoint);
     notifyDescendantRemovedFromTree(node);
 }
 
-inline void ChildNodeRemovalNotifier::notify(Node* node)
+inline void ChildNodeRemovalNotifier::notify(Node& node)
 {
-    if (node->inDocument()) {
+    if (node.inDocument()) {
         notifyNodeRemovedFromDocument(node);
-        node->document().notifyRemovePendingSheetIfNeeded();
-    } else if (node->isContainerNode())
+        node.document().notifyRemovePendingSheetIfNeeded();
+    } else if (node.isContainerNode())
         notifyNodeRemovedFromTree(toContainerNode(node));
 }
 
@@ -269,7 +269,7 @@ public:
         DescendantsOnly
     };
 
-    explicit ChildFrameDisconnector(ContainerNode* root)
+    explicit ChildFrameDisconnector(ContainerNode& root)
         : m_root(root)
     {
     }
@@ -277,31 +277,31 @@ public:
     void disconnect(DisconnectPolicy = RootAndDescendants);
 
 private:
-    void collectFrameOwners(ContainerNode* root);
+    void collectFrameOwners(ContainerNode& root);
     void disconnectCollectedFrameOwners();
 
-    Vector<RefPtr<HTMLFrameOwnerElement>, 10> m_frameOwners;
-    ContainerNode* m_root;
+    Vector<Ref<HTMLFrameOwnerElement>, 10> m_frameOwners;
+    ContainerNode& m_root;
 };
 
 #ifndef NDEBUG
-unsigned assertConnectedSubrameCountIsConsistent(Node*);
+unsigned assertConnectedSubrameCountIsConsistent(Node&);
 #endif
 
-inline void ChildFrameDisconnector::collectFrameOwners(ContainerNode* root)
+inline void ChildFrameDisconnector::collectFrameOwners(ContainerNode& root)
 {
-    if (!root->connectedSubframeCount())
+    if (!root.connectedSubframeCount())
         return;
 
-    if (root->isHTMLElement() && root->isFrameOwnerElement())
+    if (root.isHTMLElement() && root.isFrameOwnerElement())
         m_frameOwners.append(toFrameOwnerElement(root));
 
-    for (Element* child = ElementTraversal::firstChild(root); child; child = ElementTraversal::nextSibling(child))
-        collectFrameOwners(child);
+    for (Element* child = ElementTraversal::firstChild(&root); child; child = ElementTraversal::nextSibling(child))
+        collectFrameOwners(*child);
 
-    ShadowRoot* shadow = root->isElementNode() ? toElement(root)->shadowRoot() : 0;
+    ShadowRoot* shadow = root.isElementNode() ? toElement(root).shadowRoot() : 0;
     if (shadow)
-        collectFrameOwners(shadow);
+        collectFrameOwners(*shadow);
 }
 
 inline void ChildFrameDisconnector::disconnectCollectedFrameOwners()
@@ -311,11 +311,11 @@ inline void ChildFrameDisconnector::disconnectCollectedFrameOwners()
     SubframeLoadingDisabler disabler(m_root);
 
     for (unsigned i = 0; i < m_frameOwners.size(); ++i) {
-        HTMLFrameOwnerElement* owner = m_frameOwners[i].get();
+        HTMLFrameOwnerElement& owner = m_frameOwners[i].get();
         // Don't need to traverse up the tree for the first owner since no
         // script could have moved it.
-        if (!i || m_root->containsIncludingShadowDOM(owner))
-            owner->disconnectContentFrame();
+        if (!i || m_root.containsIncludingShadowDOM(&owner))
+            owner.disconnectContentFrame();
     }
 }
 
@@ -325,14 +325,14 @@ inline void ChildFrameDisconnector::disconnect(DisconnectPolicy policy)
     assertConnectedSubrameCountIsConsistent(m_root);
 #endif
 
-    if (!m_root->connectedSubframeCount())
+    if (!m_root.connectedSubframeCount())
         return;
 
     if (policy == RootAndDescendants)
         collectFrameOwners(m_root);
     else {
-        for (Element* child = ElementTraversal::firstChild(m_root); child; child = ElementTraversal::nextSibling(child))
-            collectFrameOwners(child);
+        for (Element* child = ElementTraversal::firstChild(&m_root); child; child = ElementTraversal::nextSibling(child))
+            collectFrameOwners(*child);
     }
 
     disconnectCollectedFrameOwners();
index 7ad76e1..46b0e3d 100644 (file)
@@ -3492,31 +3492,28 @@ void Document::moveNodeIteratorsToNewDocument(Node* node, Document* newDocument)
     }
 }
 
-void Document::updateRangesAfterChildrenChanged(ContainerNode* container)
+void Document::updateRangesAfterChildrenChanged(ContainerNode& container)
 {
     if (!m_ranges.isEmpty()) {
-        HashSet<Range*>::const_iterator end = m_ranges.end();
-        for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
+        for (auto it = m_ranges.begin(), end = m_ranges.end(); it != end; ++it)
             (*it)->nodeChildrenChanged(container);
     }
 }
 
-void Document::nodeChildrenWillBeRemoved(ContainerNode* container)
+void Document::nodeChildrenWillBeRemoved(ContainerNode& container)
 {
     if (!m_ranges.isEmpty()) {
-        HashSet<Range*>::const_iterator end = m_ranges.end();
-        for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
+        for (auto it = m_ranges.begin(), end = m_ranges.end(); it != end; ++it)
             (*it)->nodeChildrenWillBeRemoved(container);
     }
 
-    HashSet<NodeIterator*>::const_iterator nodeIteratorsEnd = m_nodeIterators.end();
-    for (HashSet<NodeIterator*>::const_iterator it = m_nodeIterators.begin(); it != nodeIteratorsEnd; ++it) {
-        for (Node* n = container->firstChild(); n; n = n->nextSibling())
+    for (auto it = m_nodeIterators.begin(), end = m_nodeIterators.end(); it != end; ++it) {
+        for (Node* n = container.firstChild(); n; n = n->nextSibling())
             (*it)->nodeWillBeRemoved(n);
     }
 
     if (Frame* frame = this->frame()) {
-        for (Node* n = container->firstChild(); n; n = n->nextSibling()) {
+        for (Node* n = container.firstChild(); n; n = n->nextSibling()) {
             frame->eventHandler().nodeWillBeRemoved(n);
             frame->selection().nodeWillBeRemoved(n);
             frame->page()->dragCaretController().nodeWillBeRemoved(n);
index 239f13b..72bd73e 100644 (file)
@@ -709,9 +709,9 @@ public:
     void attachRange(Range*);
     void detachRange(Range*);
 
-    void updateRangesAfterChildrenChanged(ContainerNode*);
+    void updateRangesAfterChildrenChanged(ContainerNode&);
     // nodeChildrenWillBeRemoved is used when removing all node children at once.
-    void nodeChildrenWillBeRemoved(ContainerNode*);
+    void nodeChildrenWillBeRemoved(ContainerNode&);
     // nodeWillBeRemoved is only safe when removing one node at a time.
     void nodeWillBeRemoved(Node*);
     bool canReplaceChild(Node* newChild, Node* oldChild);
index 65d3af4..499010d 100644 (file)
@@ -1436,7 +1436,7 @@ void Element::addShadowRoot(PassRefPtr<ShadowRoot> newShadowRoot)
     shadowRoot->setParentTreeScope(treeScope());
     shadowRoot->distributor().didShadowBoundaryChange(this);
 
-    ChildNodeInsertionNotifier(this).notify(shadowRoot);
+    ChildNodeInsertionNotifier(*this).notify(*shadowRoot);
 
     resetNeedsNodeRenderingTraversalSlowPath();
 
@@ -1464,7 +1464,7 @@ void Element::removeShadowRoot()
     oldRoot->setHostElement(0);
     oldRoot->setParentTreeScope(&document());
 
-    ChildNodeRemovalNotifier(this).notify(oldRoot.get());
+    ChildNodeRemovalNotifier(*this).notify(*oldRoot);
 
     oldRoot->distributor().invalidateDistribution(this);
 }
@@ -2848,8 +2848,8 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
             setNeedsStyleRecalc();
     }
 
-    if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
-        recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
+    if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(*this, name))
+        recipients->enqueueMutationRecord(MutationRecord::createAttributes(*this, name, oldValue));
 
 #if ENABLE(INSPECTOR)
     InspectorInstrumentation::willModifyDOMAttr(&document(), this, oldValue, newValue);
index 2ad5634..d345f66 100644 (file)
 
 namespace WebCore {
 
-PassOwnPtr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node* target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
+PassOwnPtr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
 {
     ASSERT((type == MutationObserver::Attributes && attributeName) || !attributeName);
     HashMap<MutationObserver*, MutationRecordDeliveryOptions> observers;
-    target->getRegisteredMutationObserversOfType(observers, type, attributeName);
+    target.getRegisteredMutationObserversOfType(observers, type, attributeName);
     if (observers.isEmpty())
         return nullptr;
 
index 7850b5c..84cef99 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "Document.h"
 #include "MutationObserver.h"
-#include "Node.h"
 #include "QualifiedName.h"
 #include <wtf/HashMap.h>
 #include <wtf/PassOwnPtr.h>
@@ -42,26 +41,26 @@ namespace WebCore {
 
 class MutationObserverInterestGroup {
 public:
-    static PassOwnPtr<MutationObserverInterestGroup> createForChildListMutation(Node* target)
+    static PassOwnPtr<MutationObserverInterestGroup> createForChildListMutation(Node& target)
     {
-        if (!target->document().hasMutationObserversOfType(MutationObserver::ChildList))
+        if (!target.document().hasMutationObserversOfType(MutationObserver::ChildList))
             return nullptr;
 
         MutationRecordDeliveryOptions oldValueFlag = 0;
         return createIfNeeded(target, MutationObserver::ChildList, oldValueFlag);
     }
 
-    static PassOwnPtr<MutationObserverInterestGroup> createForCharacterDataMutation(Node* target)
+    static PassOwnPtr<MutationObserverInterestGroup> createForCharacterDataMutation(Node& target)
     {
-        if (!target->document().hasMutationObserversOfType(MutationObserver::CharacterData))
+        if (!target.document().hasMutationObserversOfType(MutationObserver::CharacterData))
             return nullptr;
 
         return createIfNeeded(target, MutationObserver::CharacterData, MutationObserver::CharacterDataOldValue);
     }
 
-    static PassOwnPtr<MutationObserverInterestGroup> createForAttributesMutation(Node* target, const QualifiedName& attributeName)
+    static PassOwnPtr<MutationObserverInterestGroup> createForAttributesMutation(Node& target, const QualifiedName& attributeName)
     {
-        if (!target->document().hasMutationObserversOfType(MutationObserver::Attributes))
+        if (!target.document().hasMutationObserversOfType(MutationObserver::Attributes))
             return nullptr;
 
         return createIfNeeded(target, MutationObserver::Attributes, MutationObserver::AttributeOldValue, &attributeName);
@@ -71,7 +70,7 @@ public:
     void enqueueMutationRecord(PassRefPtr<MutationRecord>);
 
 private:
-    static PassOwnPtr<MutationObserverInterestGroup> createIfNeeded(Node* target, MutationObserver::MutationType, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName = 0);
+    static PassOwnPtr<MutationObserverInterestGroup> createIfNeeded(Node& target, MutationObserver::MutationType, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName = 0);
     MutationObserverInterestGroup(HashMap<MutationObserver*, MutationRecordDeliveryOptions>& observers, MutationRecordDeliveryOptions oldValueFlag);
 
     bool hasOldValue(MutationRecordDeliveryOptions options) { return options & m_oldValueFlag; }
index a19f09b..21b188b 100644 (file)
  */
 
 #include "config.h"
-
 #include "MutationRecord.h"
 
-#include "Node.h"
+#include "CharacterData.h"
+#include "Element.h"
 #include "NodeList.h"
 #include "QualifiedName.h"
 #include "StaticNodeList.h"
@@ -45,7 +45,7 @@ namespace {
 
 class ChildListRecord : public MutationRecord {
 public:
-    ChildListRecord(PassRefPtr<Node> target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
+    ChildListRecord(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
         : m_target(target)
         , m_addedNodes(added)
         , m_removedNodes(removed)
@@ -56,13 +56,13 @@ public:
 
 private:
     virtual const AtomicString& type() OVERRIDE;
-    virtual Node* target() OVERRIDE { return m_target.get(); }
+    virtual Node* target() OVERRIDE { return &m_target.get(); }
     virtual NodeList* addedNodes() OVERRIDE { return m_addedNodes.get(); }
     virtual NodeList* removedNodes() OVERRIDE { return m_removedNodes.get(); }
     virtual Node* previousSibling() OVERRIDE { return m_previousSibling.get(); }
     virtual Node* nextSibling() OVERRIDE { return m_nextSibling.get(); }
 
-    RefPtr<Node> m_target;
+    Ref<ContainerNode> m_target;
     RefPtr<NodeList> m_addedNodes;
     RefPtr<NodeList> m_removedNodes;
     RefPtr<Node> m_previousSibling;
@@ -71,14 +71,14 @@ private:
 
 class RecordWithEmptyNodeLists : public MutationRecord {
 public:
-    RecordWithEmptyNodeLists(PassRefPtr<Node> target, const String& oldValue)
+    RecordWithEmptyNodeLists(Node& target, const String& oldValue)
         : m_target(target)
         , m_oldValue(oldValue)
     {
     }
 
 private:
-    virtual Node* target() OVERRIDE { return m_target.get(); }
+    virtual Node* target() OVERRIDE { return &m_target.get(); }
     virtual String oldValue() OVERRIDE { return m_oldValue; }
     virtual NodeList* addedNodes() OVERRIDE { return lazilyInitializeEmptyNodeList(m_addedNodes); }
     virtual NodeList* removedNodes() OVERRIDE { return lazilyInitializeEmptyNodeList(m_removedNodes); }
@@ -90,7 +90,7 @@ private:
         return nodeList.get();
     }
 
-    RefPtr<Node> m_target;
+    Ref<Node> m_target;
     String m_oldValue;
     RefPtr<NodeList> m_addedNodes;
     RefPtr<NodeList> m_removedNodes;
@@ -98,7 +98,7 @@ private:
 
 class AttributesRecord : public RecordWithEmptyNodeLists {
 public:
-    AttributesRecord(PassRefPtr<Node> target, const QualifiedName& name, const AtomicString& oldValue)
+    AttributesRecord(Element& target, const QualifiedName& name, const AtomicString& oldValue)
         : RecordWithEmptyNodeLists(target, oldValue)
         , m_attributeName(name.localName())
         , m_attributeNamespace(name.namespaceURI())
@@ -116,7 +116,7 @@ private:
 
 class CharacterDataRecord : public RecordWithEmptyNodeLists {
 public:
-    CharacterDataRecord(PassRefPtr<Node> target, const String& oldValue)
+    CharacterDataRecord(CharacterData& target, const String& oldValue)
         : RecordWithEmptyNodeLists(target, oldValue)
     {
     }
@@ -167,17 +167,17 @@ const AtomicString& CharacterDataRecord::type()
 
 } // namespace
 
-PassRefPtr<MutationRecord> MutationRecord::createChildList(PassRefPtr<Node> target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
+PassRefPtr<MutationRecord> MutationRecord::createChildList(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
 {
     return adoptRef(static_cast<MutationRecord*>(new ChildListRecord(target, added, removed, previousSibling, nextSibling)));
 }
 
-PassRefPtr<MutationRecord> MutationRecord::createAttributes(PassRefPtr<Node> target, const QualifiedName& name, const AtomicString& oldValue)
+PassRefPtr<MutationRecord> MutationRecord::createAttributes(Element& target, const QualifiedName& name, const AtomicString& oldValue)
 {
     return adoptRef(static_cast<MutationRecord*>(new AttributesRecord(target, name, oldValue)));
 }
 
-PassRefPtr<MutationRecord> MutationRecord::createCharacterData(PassRefPtr<Node> target, const String& oldValue)
+PassRefPtr<MutationRecord> MutationRecord::createCharacterData(CharacterData& target, const String& oldValue)
 {
     return adoptRef(static_cast<MutationRecord*>(new CharacterDataRecord(target, oldValue)));
 }
index 4606df0..6cbb493 100644 (file)
 
 namespace WebCore {
 
+class CharacterData;
+class ContainerNode;
+class Element;
 class Node;
 class NodeList;
 class QualifiedName;
 
 class MutationRecord : public RefCounted<MutationRecord> {
 public:
-    static PassRefPtr<MutationRecord> createChildList(PassRefPtr<Node> target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling);
-    static PassRefPtr<MutationRecord> createAttributes(PassRefPtr<Node> target, const QualifiedName&, const AtomicString& oldValue);
-    static PassRefPtr<MutationRecord> createCharacterData(PassRefPtr<Node> target, const String& oldValue);
+    static PassRefPtr<MutationRecord> createChildList(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling);
+    static PassRefPtr<MutationRecord> createAttributes(Element& target, const QualifiedName&, const AtomicString& oldValue);
+    static PassRefPtr<MutationRecord> createCharacterData(CharacterData& target, const String& oldValue);
 
     static PassRefPtr<MutationRecord> createWithNullOldValue(PassRefPtr<MutationRecord>);
 
index 71250ad..657beed 100644 (file)
@@ -1434,7 +1434,7 @@ void Node::setTextContent(const String& text, ExceptionCode& ec)
         case ENTITY_REFERENCE_NODE:
         case DOCUMENT_FRAGMENT_NODE: {
             Ref<ContainerNode> container(*toContainerNode(this));
-            ChildListMutationScope mutation(this);
+            ChildListMutationScope mutation(container.get());
             container->removeChildren();
             if (!text.isEmpty())
                 container->appendChild(document().createTextNode(text), ec);
index 1768be2..8ff177c 100644 (file)
@@ -1725,44 +1725,42 @@ int Range::maxEndOffset() const
     return m_end.container()->maxCharacterOffset();
 }
 
-static inline void boundaryNodeChildrenChanged(RangeBoundaryPoint& boundary, ContainerNode* container)
+static inline void boundaryNodeChildrenChanged(RangeBoundaryPoint& boundary, ContainerNode& container)
 {
     if (!boundary.childBefore())
         return;
-    if (boundary.container() != container)
+    if (boundary.container() != &container)
         return;
     boundary.invalidateOffset();
 }
 
-void Range::nodeChildrenChanged(ContainerNode* container)
+void Range::nodeChildrenChanged(ContainerNode& container)
 {
-    ASSERT(container);
-    ASSERT(&container->document() == m_ownerDocument);
+    ASSERT(&container.document() == m_ownerDocument);
     boundaryNodeChildrenChanged(m_start, container);
     boundaryNodeChildrenChanged(m_end, container);
 }
 
-static inline void boundaryNodeChildrenWillBeRemoved(RangeBoundaryPoint& boundary, ContainerNode* container)
+static inline void boundaryNodeChildrenWillBeRemoved(RangeBoundaryPoint& boundary, ContainerNode& container)
 {
-    for (Node* nodeToBeRemoved = container->firstChild(); nodeToBeRemoved; nodeToBeRemoved = nodeToBeRemoved->nextSibling()) {
+    for (Node* nodeToBeRemoved = container.firstChild(); nodeToBeRemoved; nodeToBeRemoved = nodeToBeRemoved->nextSibling()) {
         if (boundary.childBefore() == nodeToBeRemoved) {
-            boundary.setToStartOfNode(container);
+            boundary.setToStartOfNode(&container);
             return;
         }
 
         for (Node* n = boundary.container(); n; n = n->parentNode()) {
             if (n == nodeToBeRemoved) {
-                boundary.setToStartOfNode(container);
+                boundary.setToStartOfNode(&container);
                 return;
             }
         }
     }
 }
 
-void Range::nodeChildrenWillBeRemoved(ContainerNode* container)
+void Range::nodeChildrenWillBeRemoved(ContainerNode& container)
 {
-    ASSERT(container);
-    ASSERT(&container->document() == m_ownerDocument);
+    ASSERT(&container.document() == m_ownerDocument);
     boundaryNodeChildrenWillBeRemoved(m_start, container);
     boundaryNodeChildrenWillBeRemoved(m_end, container);
 }
index 3b23b63..a47b9ef 100644 (file)
@@ -127,8 +127,8 @@ public:
     void getBorderAndTextQuads(Vector<FloatQuad>&) const;
     FloatRect boundingRect() const;
 
-    void nodeChildrenChanged(ContainerNode*);
-    void nodeChildrenWillBeRemoved(ContainerNode*);
+    void nodeChildrenChanged(ContainerNode&);
+    void nodeChildrenWillBeRemoved(ContainerNode&);
     void nodeWillBeRemoved(Node*);
 
     void textInserted(Node*, unsigned offset, unsigned length);
index 97c4c35..4543653 100644 (file)
@@ -108,7 +108,7 @@ void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
     }
 
     if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, hostElement(), AllowScriptingContent, ec))
-        replaceChildrenWithFragment(this, fragment.release(), ec);
+        replaceChildrenWithFragment(*this, fragment.release(), ec);
 }
 
 bool ShadowRoot::childTypeAllowed(NodeType type) const
index 820df87..e277c50 100644 (file)
@@ -29,8 +29,6 @@
 #include "config.h"
 #include "StaticNodeList.h"
 
-#include "Element.h"
-
 namespace WebCore {
 
 unsigned StaticNodeList::length() const
@@ -41,20 +39,18 @@ unsigned StaticNodeList::length() const
 Node* StaticNodeList::item(unsigned index) const
 {
     if (index < m_nodes.size())
-        return m_nodes[index].get();
-    return 0;
+        return &const_cast<Node&>(m_nodes[index].get());
+    return nullptr;
 }
 
 Node* StaticNodeList::namedItem(const AtomicString& elementId) const
 {
-    size_t length = m_nodes.size();
-    for (size_t i = 0; i < length; ++i) {
-        Node* node = m_nodes[i].get();
-        if (node->isElementNode() && toElement(node)->getIdAttribute() == elementId)
-            return node;
+    for (unsigned i = 0, length = m_nodes.size(); i < length; ++i) {
+        Node& node = const_cast<Node&>(m_nodes[i].get());
+        if (node.isElementNode() && toElement(node).getIdAttribute() == elementId)
+            return &node;
     }
-
-    return 0;
+    return nullptr;
 }
 
 unsigned StaticElementList::length() const
@@ -66,19 +62,17 @@ Node* StaticElementList::item(unsigned index) const
 {
     if (index < m_elements.size())
         return &const_cast<Element&>(m_elements[index].get());
-    return 0;
+    return nullptr;
 }
 
 Node* StaticElementList::namedItem(const AtomicString& elementId) const
 {
-    size_t length = m_elements.size();
-    for (size_t i = 0; i < length; ++i) {
+    for (unsigned i = 0, length = m_elements.size(); i < length; ++i) {
         Element& element = const_cast<Element&>(m_elements[i].get());
         if (element.getIdAttribute() == elementId)
             return &element;
     }
-
-    return 0;
+    return nullptr;
 }
 
 } // namespace WebCore
index fe3dd9f..13d24c1 100644 (file)
@@ -39,7 +39,7 @@ namespace WebCore {
 
 class StaticNodeList FINAL : public NodeList {
 public:
-    static PassRefPtr<StaticNodeList> adopt(Vector<RefPtr<Node>>& nodes)
+    static PassRefPtr<StaticNodeList> adopt(Vector<Ref<Node>>& nodes)
     {
         RefPtr<StaticNodeList> nodeList = adoptRef(new StaticNodeList);
         nodeList->m_nodes.swap(nodes);
@@ -58,7 +58,7 @@ public:
 private:
     StaticNodeList() { }
 
-    Vector<RefPtr<Node>> m_nodes;
+    Vector<Ref<Node>> m_nodes;
 };
 
 class StaticElementList FINAL : public NodeList {
index a62cadd..5a2a924 100644 (file)
@@ -1039,14 +1039,15 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
     RefPtr<Node> current = highestAncestor;
     // Along the way, styled elements that contain targetNode are removed and accumulated into elementsToPushDown.
     // Each child of the removed element, exclusing ancestors of targetNode, is then wrapped by clones of elements in elementsToPushDown.
-    Vector<RefPtr<Element> > elementsToPushDown;
+    Vector<Ref<Element>> elementsToPushDown;
     while (current && current != targetNode && current->contains(targetNode)) {
         NodeVector currentChildren;
-        getChildNodes(current.get(), currentChildren);
+        getChildNodes(*current.get(), currentChildren);
+
         RefPtr<StyledElement> styledElement;
         if (current->isStyledElement() && isStyledInlineElementToRemove(toElement(current.get()))) {
             styledElement = static_cast<StyledElement*>(current.get());
-            elementsToPushDown.append(styledElement);
+            elementsToPushDown.append(*styledElement);
         }
 
         RefPtr<EditingStyle> styleToPushDown = EditingStyle::create();
@@ -1056,26 +1057,26 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
         // The inner loop will go through children on each level
         // FIXME: we should aggregate inline child elements together so that we don't wrap each child separately.
         for (size_t i = 0; i < currentChildren.size(); ++i) {
-            Node* child = currentChildren[i].get();
-            if (!child->parentNode())
+            Node& child = currentChildren[i].get();
+            if (!child.parentNode())
                 continue;
-            if (!child->contains(targetNode) && elementsToPushDown.size()) {
+            if (!child.contains(targetNode) && elementsToPushDown.size()) {
                 for (size_t i = 0; i < elementsToPushDown.size(); i++) {
                     RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElementWithoutChildren();
                     wrapper->removeAttribute(styleAttr);
-                    surroundNodeRangeWithElement(child, child, wrapper);
+                    surroundNodeRangeWithElement(&child, &child, wrapper);
                 }
             }
 
             // Apply style to all nodes containing targetNode and their siblings but NOT to targetNode
             // But if we've removed styledElement then go ahead and always apply the style.
-            if (child != targetNode || styledElement)
-                applyInlineStyleToPushDown(child, styleToPushDown.get());
+            if (&child != targetNode || styledElement)
+                applyInlineStyleToPushDown(&child, styleToPushDown.get());
 
             // We found the next node for the outer loop (contains targetNode)
             // When reached targetNode, stop the outer loop upon the completion of the current inner loop
-            if (child == targetNode || child->contains(targetNode))
-                current = child;
+            if (&child == targetNode || child.contains(targetNode))
+                current = &child;
         }
     }
 }
index ee99002..6a8b6c1 100644 (file)
@@ -420,11 +420,11 @@ void CompositeEditCommand::moveRemainingSiblingsToNewParent(Node* node, Node* pa
     RefPtr<Element> newParent = prpNewParent;
 
     for (; node && node != pastLastNodeToMove; node = node->nextSibling())
-        nodesToRemove.append(node);
+        nodesToRemove.append(*node);
 
     for (unsigned i = 0; i < nodesToRemove.size(); i++) {
-        removeNode(nodesToRemove[i]);
-        appendNode(nodesToRemove[i], newParent);
+        removeNode(&nodesToRemove[i].get());
+        appendNode(&nodesToRemove[i].get(), newParent);
     }
 }
 
index 38bd06c..ff5e07c 100644 (file)
@@ -56,9 +56,9 @@ static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTML
     // FIXME: Fix this to send the proper MutationRecords when MutationObservers are present.
     newNode->cloneDataFromElement(*nodeToReplace);
     NodeVector children;
-    getChildNodes(nodeToReplace, children);
+    getChildNodes(*nodeToReplace, children);
     for (size_t i = 0; i < children.size(); ++i)
-        newNode->appendChild(children[i], ASSERT_NO_EXCEPTION);
+        newNode->appendChild(&children[i].get(), ASSERT_NO_EXCEPTION);
 
     parentNode->insertBefore(newNode, nodeToReplace, ASSERT_NO_EXCEPTION);
     parentNode->removeChild(nodeToReplace, ASSERT_NO_EXCEPTION);
index 5769b7f..9f479cd 100644 (file)
@@ -1065,10 +1065,9 @@ static inline bool hasOneTextChild(ContainerNode* node)
     return hasOneChild(node) && node->firstChild()->isTextNode();
 }
 
-void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec)
+void replaceChildrenWithFragment(ContainerNode& container, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec)
 {
-    RefPtr<ContainerNode> containerNode(container);
-
+    Ref<ContainerNode> containerNode(container);
     ChildListMutationScope mutation(containerNode.get());
 
     if (!fragment->firstChild()) {
@@ -1076,12 +1075,12 @@ void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFr
         return;
     }
 
-    if (hasOneTextChild(containerNode.get()) && hasOneTextChild(fragment.get())) {
+    if (hasOneTextChild(&containerNode.get()) && hasOneTextChild(fragment.get())) {
         toText(containerNode->firstChild())->setData(toText(fragment->firstChild())->data(), ec);
         return;
     }
 
-    if (hasOneChild(containerNode.get())) {
+    if (hasOneChild(&containerNode.get())) {
         containerNode->replaceChild(fragment, containerNode->firstChild(), ec);
         return;
     }
@@ -1090,20 +1089,19 @@ void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFr
     containerNode->appendChild(fragment, ec);
 }
 
-void replaceChildrenWithText(ContainerNode* container, const String& text, ExceptionCode& ec)
+void replaceChildrenWithText(ContainerNode& container, const String& text, ExceptionCode& ec)
 {
-    RefPtr<ContainerNode> containerNode(container);
-
+    Ref<ContainerNode> containerNode(container);
     ChildListMutationScope mutation(containerNode.get());
 
-    if (hasOneTextChild(containerNode.get())) {
+    if (hasOneTextChild(&containerNode.get())) {
         toText(containerNode->firstChild())->setData(text, ec);
         return;
     }
 
     RefPtr<Text> textNode = Text::create(containerNode->document(), text);
 
-    if (hasOneChild(containerNode.get())) {
+    if (hasOneChild(&containerNode.get())) {
         containerNode->replaceChild(textNode.release(), containerNode->firstChild(), ec);
         return;
     }
index d9aef08..ca120a4 100644 (file)
@@ -61,8 +61,8 @@ bool isPlainTextMarkup(Node*);
 
 // These methods are used by HTMLElement & ShadowRoot to replace the
 // children with respected fragment/text.
-void replaceChildrenWithFragment(ContainerNode*, PassRefPtr<DocumentFragment>, ExceptionCode&);
-void replaceChildrenWithText(ContainerNode*, const String&, ExceptionCode&);
+void replaceChildrenWithFragment(ContainerNode&, PassRefPtr<DocumentFragment>, ExceptionCode&);
+void replaceChildrenWithText(ContainerNode&, const String&, ExceptionCode&);
 
 String createMarkup(const Range*, Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
 String createMarkup(const Node*, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs, Vector<QualifiedName>* tagNamesToSkip = 0, EFragmentSerialization = HTMLFragmentSerialization);
index 1182dc2..c4ef85b 100644 (file)
@@ -361,7 +361,7 @@ void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec)
         if (hasLocalName(templateTag))
             container = toHTMLTemplateElement(this)->content();
 #endif
-        replaceChildrenWithFragment(container, fragment.release(), ec);
+        replaceChildrenWithFragment(*container, fragment.release(), ec);
     }
 }
 
@@ -459,7 +459,7 @@ void HTMLElement::setInnerText(const String& text, ExceptionCode& ec)
             removeChildren();
             return;
         }
-        replaceChildrenWithText(this, text, ec);
+        replaceChildrenWithText(*this, text, ec);
         return;
     }
 
@@ -469,13 +469,13 @@ void HTMLElement::setInnerText(const String& text, ExceptionCode& ec)
     RenderObject* r = renderer();
     if (r && r->style()->preserveNewline()) {
         if (!text.contains('\r')) {
-            replaceChildrenWithText(this, text, ec);
+            replaceChildrenWithText(*this, text, ec);
             return;
         }
         String textWithConsistentLineBreaks = text;
         textWithConsistentLineBreaks.replace("\r\n", "\n");
         textWithConsistentLineBreaks.replace('\r', '\n');
-        replaceChildrenWithText(this, textWithConsistentLineBreaks, ec);
+        replaceChildrenWithText(*this, textWithConsistentLineBreaks, ec);
         return;
     }
 
@@ -483,7 +483,7 @@ void HTMLElement::setInnerText(const String& text, ExceptionCode& ec)
     ec = 0;
     RefPtr<DocumentFragment> fragment = textToFragment(text, ec);
     if (!ec)
-        replaceChildrenWithFragment(this, fragment.release(), ec);
+        replaceChildrenWithFragment(*this, fragment.release(), ec);
 }
 
 void HTMLElement::setOuterText(const String &text, ExceptionCode& ec)
index e1a62bd..300192d 100644 (file)
@@ -159,7 +159,7 @@ void HTMLFrameElementBase::didNotifySubtreeInsertions(ContainerNode*)
     if (!document().frame())
         return;
 
-    if (!SubframeLoadingDisabler::canLoadFrame(this))
+    if (!SubframeLoadingDisabler::canLoadFrame(*this))
         return;
 
     // JavaScript in src=javascript: and beforeonload can access the renderer
index 016f4c2..e58cb78 100644 (file)
@@ -126,9 +126,9 @@ SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionCode& ec) const
 }
 #endif
 
-bool SubframeLoadingDisabler::canLoadFrame(HTMLFrameOwnerElement* owner)
+bool SubframeLoadingDisabler::canLoadFrame(HTMLFrameOwnerElement& owner)
 {
-    for (Node* node = owner; node; node = node->parentOrShadowHostNode()) {
+    for (ContainerNode* node = &owner; node; node = node->parentOrShadowHostNode()) {
         if (disabledSubtreeRoots().contains(node))
             return false;
     }
index 5b626cf..cae2250 100644 (file)
@@ -85,27 +85,27 @@ inline HTMLFrameOwnerElement* toFrameOwnerElement(Node* node)
 
 class SubframeLoadingDisabler {
 public:
-    explicit SubframeLoadingDisabler(Node* root)
+    explicit SubframeLoadingDisabler(ContainerNode& root)
         : m_root(root)
     {
-        disabledSubtreeRoots().add(m_root);
+        disabledSubtreeRoots().add(&m_root);
     }
 
     ~SubframeLoadingDisabler()
     {
-        disabledSubtreeRoots().remove(m_root);
+        disabledSubtreeRoots().remove(&m_root);
     }
 
-    static bool canLoadFrame(HTMLFrameOwnerElement*);
+    static bool canLoadFrame(HTMLFrameOwnerElement&);
 
 private:
-    static HashSet<Node*>& disabledSubtreeRoots()
+    static HashSet<ContainerNode*>& disabledSubtreeRoots()
     {
-        DEFINE_STATIC_LOCAL(HashSet<Node*>, nodes, ());
+        DEFINE_STATIC_LOCAL(HashSet<ContainerNode*>, nodes, ());
         return nodes;
     }
 
-    Node* m_root;
+    ContainerNode& m_root;
 };
 
 } // namespace WebCore
index 8ddd85b..f88f806 100644 (file)
@@ -3450,7 +3450,6 @@ KURL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* k
     }
 
     KURL mediaURL;
-    Node* node;
     HTMLSourceElement* source = 0;
     String type;
     String system;
@@ -3459,20 +3458,20 @@ KURL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* k
     bool okToLoadSourceURL;
 
     NodeVector potentialSourceNodes;
-    getChildNodes(this, potentialSourceNodes);
+    getChildNodes(*this, potentialSourceNodes);
 
     for (unsigned i = 0; !canUseSourceElement && i < potentialSourceNodes.size(); ++i) {
-        node = potentialSourceNodes[i].get();
-        if (lookingForStartNode && m_nextChildNodeToConsider != node)
+        Node& node = potentialSourceNodes[i].get();
+        if (lookingForStartNode && m_nextChildNodeToConsider != &node)
             continue;
         lookingForStartNode = false;
 
-        if (!node->hasTagName(sourceTag))
+        if (!node.hasTagName(sourceTag))
             continue;
-        if (node->parentNode() != this)
+        if (node.parentNode() != this)
             continue;
 
-        source = static_cast<HTMLSourceElement*>(node);
+        source = static_cast<HTMLSourceElement*>(&node);
 
         // If candidate does not have a src attribute, or if its src attribute's value is the empty string ... jump down to the failed step below
         mediaURL = source->getNonEmptyURLAttribute(srcAttr);
@@ -3511,7 +3510,7 @@ KURL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* k
         okToLoadSourceURL = isSafeToLoadURL(mediaURL, actionIfInvalid) && dispatchBeforeLoadEvent(mediaURL.string());
 
         // A 'beforeload' event handler can mutate the DOM, so check to see if the source element is still a child node.
-        if (node->parentNode() != this) {
+        if (node.parentNode() != this) {
             LOG(Media, "HTMLMediaElement::selectNextSourceChild : 'beforeload' removed current element");
             source = 0;
             goto check_again;
index 32619b3..b3c047a 100644 (file)
@@ -284,7 +284,7 @@ void HTMLObjectElement::updateWidget(PluginCreationOption pluginCreationOption)
     // FIXME: I'm not sure it's ever possible to get into updateWidget during a
     // removal, but just in case we should avoid loading the frame to prevent
     // security bugs.
-    if (!SubframeLoadingDisabler::canLoadFrame(this))
+    if (!SubframeLoadingDisabler::canLoadFrame(*this))
         return;
 
     String url = this->url();
index 0bc7bff..0d09a44 100644 (file)
@@ -1581,7 +1581,7 @@ void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken* token)
                 bookmark.moveToAfter(nodeEntry);
             // 9.9
             if (ContainerNode* parent = lastNode->element()->parentNode())
-                parent->parserRemoveChild(lastNode->element());
+                parent->parserRemoveChild(*lastNode->element());
             node->element()->parserAppendChild(lastNode->element());
             if (lastNode->element()->parentElement()->attached() && !lastNode->element()->attached())
                 lastNode->element()->lazyAttach();
@@ -1590,7 +1590,7 @@ void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken* token)
         }
         // 10.
         if (ContainerNode* parent = lastNode->element()->parentNode())
-            parent->parserRemoveChild(lastNode->element());
+            parent->parserRemoveChild(*lastNode->element());
         if (commonAncestor->causesFosterParenting())
             m_tree.fosterParent(lastNode->element());
         else {
index 9353dbb..b002986 100644 (file)
@@ -157,7 +157,7 @@ void SVGElementInstance::detach()
     m_directUseElement = 0;
     m_correspondingUseElement = 0;
 
-    removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(this);
+    removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*this);
 }
 
 PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
@@ -178,7 +178,7 @@ void SVGElementInstance::setShadowTreeElement(SVGElement* element)
 
 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
 {
-    appendChildToContainer<SVGElementInstance, SVGElementInstance>(child.get(), this);
+    appendChildToContainer<SVGElementInstance, SVGElementInstance>(child.get(), *this);
 }
 
 void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element)
index b336cd7..c737cd9 100644 (file)
@@ -29,7 +29,7 @@ namespace WebCore {
 
 namespace Private {
 template<class GenericNode, class GenericNodeContainer>
-void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
+void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer& container);
 };
 
 class Document;
@@ -159,13 +159,13 @@ private:
     void setShadowTreeElement(SVGElement*);
 
     template<class GenericNode, class GenericNodeContainer>
-    friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
+    friend void appendChildToContainer(GenericNode* child, GenericNodeContainer& container);
 
     template<class GenericNode, class GenericNodeContainer>
-    friend void removeDetachedChildrenInContainer(GenericNodeContainer*);
+    friend void removeDetachedChildrenInContainer(GenericNodeContainer&);
 
     template<class GenericNode, class GenericNodeContainer>
-    friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
+    friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer& container);
 
     bool hasChildNodes() const { return m_firstChild; }
 
index 02f681b..de6ccda 100644 (file)
@@ -1246,7 +1246,7 @@ PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, i
     if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
         return 0;
 
-    Vector<RefPtr<Node> > matches;
+    Vector<Ref<Node>> matches;
 
     // Need padding to trigger a rect based hit test, but we want to return a NodeList
     // so we special case this.
@@ -1254,11 +1254,15 @@ PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, i
         HitTestResult result(point);
         renderView->hitTest(request, result);
         if (result.innerNode())
-            matches.append(result.innerNode()->deprecatedShadowAncestorNode());
+            matches.append(*result.innerNode()->deprecatedShadowAncestorNode());
     } else {
         HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
         renderView->hitTest(request, result);
-        copyToVector(result.rectBasedTestResult(), matches);
+        
+        const HitTestResult::NodeSet& nodeSet = result.rectBasedTestResult();
+        matches.reserveInitialCapacity(nodeSet.size());
+        for (auto it = nodeSet.begin(), end = nodeSet.end(); it != end; ++it)
+            matches.uncheckedAppend(*it->get());
     }
 
     return StaticNodeList::adopt(matches);
index 1021ebc..8a701b5 100644 (file)
@@ -137,7 +137,7 @@ void XMLErrors::insertErrorMessageBlock()
         RefPtr<Element> body = m_document->createElement(bodyTag, true);
         rootElement->parserAppendChild(body);
 
-        documentElement->parentNode()->parserRemoveChild(documentElement.get());
+        documentElement->parentNode()->parserRemoveChild(*documentElement);
         if (documentElement->attached())
             Style::detachRenderTree(*documentElement);
 
index aae65d7..de93452 100644 (file)
@@ -1602,7 +1602,7 @@ void QWebElementCollection::append(const QWebElementCollection &other)
     }
     if (!other.d)
         return;
-    Vector<RefPtr<Node> > nodes;
+    Vector<Ref<Node>> nodes;
     RefPtr<NodeList> results[] = { d->m_result, other.d->m_result };
     nodes.reserveInitialCapacity(results[0]->length() + results[1]->length());
 
@@ -1610,7 +1610,7 @@ void QWebElementCollection::append(const QWebElementCollection &other)
         int j = 0;
         Node* n = results[i]->item(j);
         while (n) {
-            nodes.append(n);
+            nodes.append(*n);
             n = results[i]->item(++j);
         }
     }
index fc21e7d..2367a5a 100644 (file)
@@ -1,3 +1,14 @@
+2013-09-22  Sam Weinig  <sam@webkit.org>
+
+        CTTE: Use references more in ContainerNode, ContainerNodeAlgorithms and related classes
+        https://bugs.webkit.org/show_bug.cgi?id=121772
+
+        Reviewed by Andreas Kling.
+
+        * Api/qwebelement.cpp:
+        (QWebElementCollection::append):
+        Update to work with the new StaticNodeList adopt function.
+
 2013-09-19  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         Keep chasing the definition of QAccessibleWidget