Commit 3eb4c413 authored by akling@apple.com's avatar akling@apple.com

CTTE: Node::treeScope() should return a reference.

<https://webkit.org/b/122399>

Reviewed by Superlative Sam.

Every Node belongs to a TreeScope. To enforce this, I've made
treeScope() return a TreeScope&, and setTreeScope() now takes a
TreeScope& so there is no way to clear it.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156981 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 97a6cb5e
2013-10-05 Andreas Kling <akling@apple.com>
CTTE: Node::treeScope() should return a reference.
<https://webkit.org/b/122399>
Reviewed by Superlative Sam.
Every Node belongs to a TreeScope. To enforce this, I've made
treeScope() return a TreeScope&, and setTreeScope() now takes a
TreeScope& so there is no way to clear it.
2013-10-05 Sam Weinig <sam@webkit.org>
CTTE: Use references more for the Document parser
......@@ -1111,7 +1111,7 @@ HTMLLabelElement* AccessibilityNodeObject::labelForElement(Element* element) con
const AtomicString& id = element->getIdAttribute();
if (!id.isEmpty()) {
if (HTMLLabelElement* label = element->treeScope()->labelElementForId(id))
if (HTMLLabelElement* label = element->treeScope().labelElementForId(id))
return label;
}
......@@ -1819,9 +1819,7 @@ void AccessibilityNodeObject::elementsFromAttribute(Vector<Element*>& elements,
if (!node || !node->isElementNode())
return;
TreeScope* scope = node->treeScope();
if (!scope)
return;
TreeScope& treeScope = node->treeScope();
String idList = getAttribute(attribute).string();
if (idList.isEmpty())
......@@ -1834,7 +1832,7 @@ void AccessibilityNodeObject::elementsFromAttribute(Vector<Element*>& elements,
unsigned size = idVector.size();
for (unsigned i = 0; i < size; ++i) {
AtomicString idName(idVector[i]);
Element* idElement = scope->getElementById(idName);
Element* idElement = treeScope.getElementById(idName);
if (idElement)
elements.append(idElement);
}
......
......@@ -2263,7 +2263,7 @@ AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
return 0;
Element* target = element->treeScope()->getElementById(activeDescendantAttrStr);
Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
if (!target)
return 0;
......
......@@ -163,9 +163,8 @@ void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
// a) it's a UA rule
// b) the tree scope allows author rules
// c) the rules comes from a scoped style sheet within the same tree scope
TreeScope* treeScope = element->treeScope();
if (!MatchingUARulesScope::isMatchingUARules()
&& !treeScope->applyAuthorStyles())
&& !element->treeScope().applyAuthorStyles())
return;
// We need to collect the rules for id, class, tag, and everything else into a buffer and
......
......@@ -156,7 +156,7 @@ void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
// 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());
treeScope().adoptIfNeeded(adoptedChild.get());
if (attached() && !adoptedChild->attached())
attachChild(*adoptedChild.get());
}
......@@ -320,7 +320,7 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
if (child.parentNode())
break;
treeScope()->adoptIfNeeded(&child);
treeScope().adoptIfNeeded(&child);
insertBeforeCommon(next.get(), child);
......@@ -474,7 +474,7 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
if (child.parentNode())
break;
treeScope()->adoptIfNeeded(&child);
treeScope().adoptIfNeeded(&child);
// Add child before "next".
{
......@@ -721,7 +721,7 @@ bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, At
if (child.parentNode())
break;
treeScope()->adoptIfNeeded(&child);
treeScope().adoptIfNeeded(&child);
// Append child to the end of the list
{
......@@ -752,7 +752,7 @@ void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild)
NoEventDispatchAssertion assertNoEventDispatch;
// FIXME: This method should take a PassRefPtr.
appendChildToContainer(newChild.get(), *this);
treeScope()->adoptIfNeeded(newChild.get());
treeScope().adoptIfNeeded(newChild.get());
}
newChild->updateAncestorConnectedSubframeCountForInsertion();
......
......@@ -248,7 +248,7 @@ inline bool Node::needsNodeRenderingTraversalSlowPath() const
inline bool Node::isTreeScope() const
{
return treeScope()->rootNode() == this;
return treeScope().rootNode() == this;
}
// This constant controls how much buffer is initially allocated
......
......@@ -3262,7 +3262,7 @@ void Document::removeFocusedNodeOfSubtree(Node* node, bool amongChildrenOnly)
if (!m_focusedElement || this->inPageCache()) // If the document is in the page cache, then we don't need to clear out the focused node.
return;
Element* focusedElement = node->treeScope()->focusedElement();
Element* focusedElement = node->treeScope().focusedElement();
if (!focusedElement)
return;
......
......@@ -1632,7 +1632,7 @@ inline bool Node::isDocumentNode() const
inline Node::Node(Document* document, ConstructionType type)
: m_nodeFlags(type)
, m_parentNode(0)
, m_treeScope(document ? document : TreeScope::noDocumentInstance())
, m_treeScope(document ? document : &TreeScope::noDocumentInstance())
, m_previous(0)
, m_next(0)
{
......
......@@ -1333,15 +1333,15 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode& insertio
if (hasRareData())
elementRareData()->clearClassListValueForQuirksMode();
TreeScope* newScope = insertionPoint.treeScope();
TreeScope* newScope = &insertionPoint.treeScope();
HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope()->isHTMLDocument() ? toHTMLDocument(newScope->documentScope()) : 0;
if (newScope != treeScope())
if (newScope != &treeScope())
newScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (newScope)
updateIdForTreeScope(newScope, nullAtom, idValue);
updateIdForTreeScope(*newScope, nullAtom, idValue);
if (newDocument)
updateIdForDocument(*newDocument, nullAtom, idValue, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
......@@ -1349,14 +1349,14 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode& insertio
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (newScope)
updateNameForTreeScope(newScope, nullAtom, nameValue);
updateNameForTreeScope(*newScope, nullAtom, nameValue);
if (newDocument)
updateNameForDocument(*newDocument, nullAtom, nameValue);
}
if (newScope && hasTagName(labelTag)) {
if (newScope->shouldCacheLabelsByForAttribute())
updateLabel(newScope, nullAtom, fastGetAttribute(forAttr));
updateLabel(*newScope, nullAtom, fastGetAttribute(forAttr));
}
return InsertionDone;
......@@ -1376,15 +1376,15 @@ void Element::removedFrom(ContainerNode& insertionPoint)
setSavedLayerScrollOffset(IntSize());
if (insertionPoint.isInTreeScope()) {
TreeScope* oldScope = insertionPoint.treeScope();
TreeScope* oldScope = &insertionPoint.treeScope();
HTMLDocument* oldDocument = inDocument() && oldScope->documentScope()->isHTMLDocument() ? toHTMLDocument(oldScope->documentScope()) : 0;
if (oldScope != treeScope())
if (oldScope != &treeScope())
oldScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (oldScope)
updateIdForTreeScope(oldScope, idValue, nullAtom);
updateIdForTreeScope(*oldScope, idValue, nullAtom);
if (oldDocument)
updateIdForDocument(*oldDocument, idValue, nullAtom, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
......@@ -1392,14 +1392,14 @@ void Element::removedFrom(ContainerNode& insertionPoint)
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (oldScope)
updateNameForTreeScope(oldScope, nameValue, nullAtom);
updateNameForTreeScope(*oldScope, nameValue, nullAtom);
if (oldDocument)
updateNameForDocument(*oldDocument, nameValue, nullAtom);
}
if (oldScope && hasTagName(labelTag)) {
if (oldScope->shouldCacheLabelsByForAttribute())
updateLabel(oldScope, fastGetAttribute(forAttr), nullAtom);
updateLabel(*oldScope, fastGetAttribute(forAttr), nullAtom);
}
}
......@@ -1480,7 +1480,7 @@ void Element::addShadowRoot(PassRefPtr<ShadowRoot> newShadowRoot)
ensureElementRareData().setShadowRoot(newShadowRoot);
shadowRoot->setHostElement(this);
shadowRoot->setParentTreeScope(treeScope());
shadowRoot->setParentTreeScope(&treeScope());
shadowRoot->distributor().didShadowBoundaryChange(this);
ChildNodeInsertionNotifier(*this).notify(*shadowRoot);
......@@ -1768,7 +1768,7 @@ PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
attrNode->attachToElement(this);
treeScope()->adoptIfNeeded(attrNode);
treeScope().adoptIfNeeded(attrNode);
ensureAttrNodeListForElement(this).append(attrNode);
return oldAttrNode.release();
......@@ -2009,7 +2009,7 @@ void Element::updateFocusAppearance(bool /*restorePreviousSelection*/)
void Element::blur()
{
cancelFocusAppearanceUpdate();
if (treeScope()->focusedElement() == this) {
if (treeScope().focusedElement() == this) {
if (Frame* frame = document().frame())
frame->page()->focusController().setFocusedElement(0, frame);
else
......@@ -2777,15 +2777,15 @@ inline void Element::updateName(const AtomicString& oldName, const AtomicString&
updateNameForDocument(toHTMLDocument(document()), oldName, newName);
}
void Element::updateNameForTreeScope(TreeScope* scope, const AtomicString& oldName, const AtomicString& newName)
void Element::updateNameForTreeScope(TreeScope& scope, const AtomicString& oldName, const AtomicString& newName)
{
ASSERT(isInTreeScope());
ASSERT(oldName != newName);
if (!oldName.isEmpty())
scope->removeElementByName(*oldName.impl(), *this);
scope.removeElementByName(*oldName.impl(), *this);
if (!newName.isEmpty())
scope->addElementByName(*newName.impl(), *this);
scope.addElementByName(*newName.impl(), *this);
}
void Element::updateNameForDocument(HTMLDocument& document, const AtomicString& oldName, const AtomicString& newName)
......@@ -2827,15 +2827,15 @@ inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
updateIdForDocument(toHTMLDocument(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
}
void Element::updateIdForTreeScope(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
void Element::updateIdForTreeScope(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId)
{
ASSERT(isInTreeScope());
ASSERT(oldId != newId);
if (!oldId.isEmpty())
scope->removeElementById(*oldId.impl(), *this);
scope.removeElementById(*oldId.impl(), *this);
if (!newId.isEmpty())
scope->addElementById(*newId.impl(), *this);
scope.addElementById(*newId.impl(), *this);
}
void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition condition)
......@@ -2860,7 +2860,7 @@ void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& ol
}
}
void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
{
ASSERT(hasTagName(labelTag));
......@@ -2871,9 +2871,9 @@ void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeV
return;
if (!oldForAttributeValue.isEmpty())
scope->removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
scope.removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
if (!newForAttributeValue.isEmpty())
scope->addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
scope.addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
}
void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
......@@ -2883,9 +2883,8 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
else if (name == HTMLNames::nameAttr)
updateName(oldValue, newValue);
else if (name == HTMLNames::forAttr && hasTagName(labelTag)) {
TreeScope* scope = treeScope();
if (scope->shouldCacheLabelsByForAttribute())
updateLabel(scope, oldValue, newValue);
if (treeScope().shouldCacheLabelsByForAttribute())
updateLabel(treeScope(), oldValue, newValue);
}
if (oldValue != newValue) {
......@@ -2971,7 +2970,7 @@ PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name)
RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name);
if (!attrNode) {
attrNode = Attr::create(this, name);
treeScope()->adoptIfNeeded(attrNode.get());
treeScope().adoptIfNeeded(attrNode.get());
attrNodeList.append(attrNode);
}
return attrNode.release();
......
......@@ -616,13 +616,13 @@ private:
void synchronizeAttribute(const AtomicString& localName) const;
void updateName(const AtomicString& oldName, const AtomicString& newName);
void updateNameForTreeScope(TreeScope*, const AtomicString& oldName, const AtomicString& newName);
void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
void updateId(const AtomicString& oldId, const AtomicString& newId);
void updateIdForTreeScope(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId);
enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
void scrollByUnits(int units, ScrollGranularity);
......
......@@ -117,9 +117,9 @@ inline bool EventContext::isUnreachableNode(EventTarget* target)
inline bool EventContext::isReachable(Node* target) const
{
ASSERT(target);
TreeScope* targetScope = target->treeScope();
for (TreeScope* scope = m_node->treeScope(); scope; scope = scope->parentTreeScope()) {
if (scope == targetScope)
TreeScope& targetScope = target->treeScope();
for (TreeScope* scope = &m_node->treeScope(); scope; scope = scope->parentTreeScope()) {
if (scope == &targetScope)
return true;
}
return false;
......
......@@ -37,7 +37,7 @@ namespace WebCore {
static inline bool inTheSameScope(ShadowRoot* shadowRoot, EventTarget* target)
{
return target->toNode() && target->toNode()->treeScope()->rootNode() == shadowRoot;
return target->toNode() && target->toNode()->treeScope().rootNode() == shadowRoot;
}
static inline EventDispatchBehavior determineDispatchBehavior(Event* event, ShadowRoot* shadowRoot, EventTarget* target)
......@@ -192,7 +192,7 @@ void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relat
TreeScope* lastTreeScope = 0;
Node* adjustedNode = 0;
for (EventPath::const_iterator iter = eventPath.begin(); iter < eventPath.end(); ++iter) {
TreeScope* scope = (*iter)->node()->treeScope();
TreeScope* scope = &(*iter)->node()->treeScope();
if (scope == lastTreeScope) {
// Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
adjustedNodes.append(adjustedNode);
......@@ -204,7 +204,7 @@ void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relat
if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
continue;
if (targetIsIdenticalToToRelatedTarget) {
if (node->treeScope()->rootNode() == (*iter)->node()) {
if (node->treeScope().rootNode() == (*iter)->node()) {
eventPath.shrink(iter + 1 - eventPath.begin());
break;
}
......@@ -224,7 +224,7 @@ void EventRetargeter::buildRelatedNodeMap(const Node* relatedNode, RelatedNodeMa
for (Node* node = nodeOrHostIfPseudoElement(const_cast<Node*>(relatedNode)); node; node = node->parentOrShadowHostNode()) {
if (relatedNodeStack.isEmpty())
relatedNodeStack.append(node);
TreeScope* scope = node->treeScope();
TreeScope* scope = &node->treeScope();
// Skips adding a node to the map if treeScope does not change. Just for the performance optimization.
if (scope != lastTreeScope)
relatedNodeMap.add(scope, relatedNodeStack.last());
......
......@@ -90,7 +90,7 @@ inline EventTarget* EventRetargeter::eventTargetRespectingTargetRules(Node* refe
// Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
// as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
Node* rootNode = referenceNode->treeScope()->rootNode();
Node* rootNode = referenceNode->treeScope().rootNode();
Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
// At this time, SVG nodes are not supported in non-<use> shadow trees.
if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
......
......@@ -74,7 +74,7 @@ Node* LiveNodeList::namedItem(const AtomicString& elementId) const
Node* rootNode = this->rootNode();
if (rootNode->inDocument()) {
Element* element = rootNode->treeScope()->getElementById(elementId);
Element* element = rootNode->treeScope().getElementById(elementId);
if (element && nodeMatches(element) && element->isDescendantOf(rootNode))
return element;
if (!element)
......
......@@ -975,7 +975,7 @@ Node* Node::deprecatedShadowAncestorNode() const
ShadowRoot* Node::containingShadowRoot() const
{
ContainerNode* root = treeScope()->rootNode();
ContainerNode* root = treeScope().rootNode();
return root && root->isShadowRoot() ? toShadowRoot(root) : 0;
}
......@@ -1035,7 +1035,7 @@ void Node::removedFrom(ContainerNode& insertionPoint)
ASSERT(insertionPoint.inDocument() || isContainerNode());
if (insertionPoint.inDocument())
clearFlag(InDocumentFlag);
if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
if (isInShadowTree() && !treeScope().rootNode()->isShadowRoot())
clearFlag(IsInShadowTreeFlag);
}
......@@ -1530,7 +1530,7 @@ unsigned short Node::compareDocumentPosition(Node* otherNode)
// If the nodes have different owning documents, they must be disconnected. Note that we avoid
// comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug).
if (start1->inDocument() != start2->inDocument() ||
start1->treeScope() != start2->treeScope())
&start1->treeScope() != &start2->treeScope())
return compareDetachedElementsPosition(this, otherNode);
// We need to find a common ancestor container, and then compare the indices of the two immediate children.
......@@ -2265,7 +2265,7 @@ void Node::removedLastRef()
// 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 (isTreeScope()) {
treeScope()->removedLastRefToScope();
treeScope().removedLastRefToScope();
return;
}
......
......@@ -397,7 +397,11 @@ public:
return *documentInternal();
}
TreeScope* treeScope() const { return m_treeScope; }
TreeScope& treeScope() const
{
ASSERT(m_treeScope);
return *m_treeScope;
}
// Returns true if this node is associated with a document and is in its associated document's
// node tree, false otherwise.
......@@ -650,8 +654,8 @@ protected:
void setNeedsNodeRenderingTraversalSlowPath(bool flag) { setFlag(flag, NeedsNodeRenderingTraversalSlowPathFlag); }
Document* documentInternal() const { return treeScope()->documentScope(); }
void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
Document* documentInternal() const { return treeScope().documentScope(); }
void setTreeScope(TreeScope& scope) { m_treeScope = &scope; }
void setStyleChange(StyleChangeType changeType) { m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType; }
......
......@@ -141,8 +141,8 @@ ALWAYS_INLINE void SelectorDataList::executeFastPathForIdSelector(const Node* ro
ASSERT(idSelector);
const AtomicString& idToMatch = idSelector->value();
if (UNLIKELY(rootNode->treeScope()->containsMultipleElementsWithId(idToMatch))) {
const Vector<Element*>* elements = rootNode->treeScope()->getAllElementsById(idToMatch);
if (UNLIKELY(rootNode->treeScope().containsMultipleElementsWithId(idToMatch))) {
const Vector<Element*>* elements = rootNode->treeScope().getAllElementsById(idToMatch);
ASSERT(elements);
size_t count = elements->size();
bool rootNodeIsTreeScopeRoot = isTreeScopeRoot(rootNode);
......@@ -157,7 +157,7 @@ ALWAYS_INLINE void SelectorDataList::executeFastPathForIdSelector(const Node* ro
return;
}
Element* element = rootNode->treeScope()->getElementById(idToMatch);
Element* element = rootNode->treeScope().getElementById(idToMatch);
if (!element || !(isTreeScopeRoot(rootNode) || element->isDescendantOf(rootNode)))
return;
if (selectorMatches(selectorData, element, rootNode))
......
......@@ -102,7 +102,7 @@ private:
inline Element* ShadowRoot::activeElement() const
{
return treeScope()->focusedElement();
return treeScope().focusedElement();
}
inline const ShadowRoot* toShadowRoot(const Node* node)
......
......@@ -75,7 +75,7 @@ TreeScope::TreeScope(ContainerNode* rootNode, Document* document)
ASSERT(document);
ASSERT(rootNode != document);
m_parentTreeScope->selfOnlyRef();
m_rootNode->setTreeScope(this);
m_rootNode->setTreeScope(*this);
}
TreeScope::TreeScope(Document* document)
......@@ -86,7 +86,7 @@ TreeScope::TreeScope(Document* document)
, m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
{
ASSERT(document);
m_rootNode->setTreeScope(this);
m_rootNode->setTreeScope(*this);
}
TreeScope::TreeScope()
......@@ -198,7 +198,7 @@ void TreeScope::removeElementByName(const AtomicStringImpl& name, Element& eleme
Node* TreeScope::ancestorInThisScope(Node* node) const
{
while (node) {
if (node->treeScope() == this)
if (&node->treeScope() == this)
return node;
if (!node->isInShadowTree())
return 0;
......@@ -371,7 +371,7 @@ void TreeScope::adoptIfNeeded(Node* node)
ASSERT(node);
ASSERT(!node->isDocumentNode());
ASSERT(!node->m_deletionHasBegun);
TreeScopeAdopter adopter(node, this);
TreeScopeAdopter adopter(node, *this);
if (adopter.needsScopeChange())
adopter.execute();
}
......@@ -394,10 +394,10 @@ Element* TreeScope::focusedElement()
element = focusedFrameOwnerElement(document.page()->focusController().focusedFrame(), document.frame());
if (!element)
return 0;
TreeScope* treeScope = element->treeScope();
TreeScope* treeScope = &element->treeScope();
while (treeScope != this && treeScope != &document) {
element = toShadowRoot(treeScope->rootNode())->hostElement();
treeScope = element->treeScope();
treeScope = &element->treeScope();
}
if (this != treeScope)
return 0;
......@@ -407,7 +407,7 @@ Element* TreeScope::focusedElement()
static void listTreeScopes(Node* node, Vector<TreeScope*, 5>& treeScopes)
{
while (true) {
treeScopes.append(node->treeScope());
treeScopes.append(&node->treeScope());
Element* ancestor = node->shadowHost();
if (!ancestor)
break;
......@@ -420,8 +420,8 @@ TreeScope* commonTreeScope(Node* nodeA, Node* nodeB)
if (!nodeA || !nodeB)
return 0;
if (nodeA->treeScope() == nodeB->treeScope())
return nodeA->treeScope();
if (&nodeA->treeScope() == &nodeB->treeScope())
return &nodeA->treeScope();
Vector<TreeScope*, 5> treeScopesA;
listTreeScopes(nodeA, treeScopesA);
......@@ -445,7 +445,7 @@ bool TreeScope::deletionHasBegun()
void TreeScope::beginDeletion()
{
ASSERT(this != noDocumentInstance());
ASSERT(this != &noDocumentInstance());
rootNode()->m_deletionHasBegun = true;
}
#endif
......
......@@ -102,10 +102,10 @@ public:
IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
static TreeScope* noDocumentInstance()
static TreeScope& noDocumentInstance()
{
DEFINE_STATIC_LOCAL(TreeScope, instance, ());
return &instance;
return instance;
}
// Nodes belonging to this scope hold self-only references -
......@@ -123,7 +123,7 @@ public:
{
ASSERT(!deletionHasBegun());
--m_selfOnlyRefCount;
if (!m_selfOnlyRefCount && !refCount() && this != noDocumentInstance()) {
if (!m_selfOnlyRefCount && !refCount() && this != &noDocumentInstance()) {
beginDeletion();
delete this;
}
......@@ -141,7 +141,7 @@ protected:
void setDocumentScope(Document* document)
{
ASSERT(document);
ASSERT(this != noDocumentInstance());
ASSERT(this != &noDocumentInstance());
m_documentScope = document;
}
......
......@@ -40,14 +40,14 @@ void TreeScopeAdopter::moveTreeToNewScope(Node* root) const
{
ASSERT(needsScopeChange());
m_oldScope->selfOnlyRef();
m_oldScope.selfOnlyRef();
// If an element is moved from a document and then eventually back again the collection cache for
// that element may contain stale data as changes made to it will have updated the DOMTreeVersion
// of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
// we ensure that the collection cache will be invalidated as needed when the element is moved back.
Document* oldDocument = m_oldScope->documentScope();
Document* newDocument = m_newScope->documentScope();
Document* oldDocument = m_oldScope.documentScope();
Document* newDocument = m_newScope.documentScope();
bool willMoveToNe