Index: Source/WebCore/dom/Node.cpp |
=================================================================== |
--- Source/WebCore/dom/Node.cpp (revision 145445) |
+++ Source/WebCore/dom/Node.cpp (working copy) |
@@ -437,8 +437,7 @@ |
if (m_next) |
m_next->setPreviousSibling(0); |
- if (doc) |
- doc->guardDeref(); |
+ m_treeScope->guardDeref(); |
InspectorCounters::decrementCounter(InspectorCounters::NodeCounter); |
} |
@@ -887,11 +886,6 @@ |
return true; |
} |
-bool Node::isTreeScope() const |
-{ |
- return treeScope()->rootNode() == this; |
-} |
- |
bool Node::isKeyboardFocusable(KeyboardEvent*) const |
{ |
return isFocusable() && tabIndex() >= 0; |
@@ -2561,6 +2555,31 @@ |
} |
#endif |
+// This is here for inlining |
+inline void TreeScope::removedLastRefToScope() |
+{ |
+ ASSERT(!deletionHasBegun()); |
+ if (m_guardRefCount) { |
+ // If removing a child removes the last self-only ref, we don't |
+ // want the scope to be destructed until after |
+ // removeDetachedChildren returns, so we guard ourselves with an |
+ // extra self-only ref. |
+ guardRef(); |
+ dispose(); |
+#ifndef NDEBUG |
+ // We need to do this right now since guardDeref() can delete this. |
+ rootNode()->m_inRemovedLastRefFunction = false; |
+#endif |
+ guardDeref(); |
+ } else { |
+#ifndef NDEBUG |
+ rootNode()->m_inRemovedLastRefFunction = false; |
+ beginDeletion(); |
+#endif |
+ delete this; |
+ } |
+} |
+ |
// It's important not to inline removedLastRef, because we don't want to inline the code to |
// delete a Node at each deref call site. |
void Node::removedLastRef() |
@@ -2568,10 +2587,11 @@ |
// An explicit check for Document here is better than a virtual function since it is |
// faster for non-Document nodes, and because the call to removedLastRef that is inlined |
// at all deref call sites is smaller if it's a non-virtual function. |
- if (isDocumentNode()) { |
- static_cast<Document*>(this)->removedLastRef(); |
+ if (isTreeScope()) { |
+ treeScope()->removedLastRefToScope(); |
return; |
} |
+ |
#ifndef NDEBUG |
m_deletionHasBegun = true; |
#endif |