Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1447)

Side by Side Diff: Source/core/dom/TreeScopeAdopter.cpp

Issue 49613005: Have TreeScrope::adoptIfNeeded() take a reference instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/TreeScopeAdopter.h ('k') | Source/core/dom/shadow/ShadowRoot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 16 matching lines...) Expand all
27 27
28 #include "core/dom/Attr.h" 28 #include "core/dom/Attr.h"
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/dom/NodeRareData.h" 30 #include "core/dom/NodeRareData.h"
31 #include "core/dom/NodeTraversal.h" 31 #include "core/dom/NodeTraversal.h"
32 #include "core/dom/shadow/ElementShadow.h" 32 #include "core/dom/shadow/ElementShadow.h"
33 #include "core/dom/shadow/ShadowRoot.h" 33 #include "core/dom/shadow/ShadowRoot.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 void TreeScopeAdopter::moveTreeToNewScope(Node* root) const 37 void TreeScopeAdopter::moveTreeToNewScope(Node& root) const
38 { 38 {
39 ASSERT(needsScopeChange()); 39 ASSERT(needsScopeChange());
40 40
41 m_oldScope->guardRef(); 41 m_oldScope.guardRef();
42 42
43 // If an element is moved from a document and then eventually back again the collection cache for 43 // If an element is moved from a document and then eventually back again the collection cache for
44 // that element may contain stale data as changes made to it will have updat ed the DOMTreeVersion 44 // that element may contain stale data as changes made to it will have updat ed the DOMTreeVersion
45 // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here 45 // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
46 // we ensure that the collection cache will be invalidated as needed when th e element is moved back. 46 // we ensure that the collection cache will be invalidated as needed when th e element is moved back.
47 Document* oldDocument = m_oldScope->documentScope(); 47 Document* oldDocument = m_oldScope.documentScope();
48 ASSERT(oldDocument); 48 ASSERT(oldDocument);
49 Document* newDocument = m_newScope->documentScope(); 49 Document* newDocument = m_newScope.documentScope();
50 bool willMoveToNewDocument = oldDocument != newDocument; 50 bool willMoveToNewDocument = oldDocument != newDocument;
51 if (willMoveToNewDocument) 51 if (willMoveToNewDocument)
52 oldDocument->incDOMTreeVersion(); 52 oldDocument->incDOMTreeVersion();
53 53
54 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { 54 for (Node* node = &root; node; node = NodeTraversal::next(node, &root)) {
55 updateTreeScope(node); 55 updateTreeScope(*node);
56 56
57 if (willMoveToNewDocument) 57 if (willMoveToNewDocument)
58 moveNodeToNewDocument(node, oldDocument, newDocument); 58 moveNodeToNewDocument(*node, *oldDocument, newDocument);
59 else if (node->hasRareData()) { 59 else if (node->hasRareData()) {
60 NodeRareData* rareData = node->rareData(); 60 NodeRareData* rareData = node->rareData();
61 if (rareData->nodeLists()) 61 if (rareData->nodeLists())
62 rareData->nodeLists()->adoptTreeScope(); 62 rareData->nodeLists()->adoptTreeScope();
63 } 63 }
64 64
65 if (!node->isElementNode()) 65 if (!node->isElementNode())
66 continue; 66 continue;
67 67
68 if (node->hasSyntheticAttrChildNodes()) { 68 if (node->hasSyntheticAttrChildNodes()) {
69 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList() ; 69 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList() ;
70 for (unsigned i = 0; i < attrs.size(); ++i) 70 for (unsigned i = 0; i < attrs.size(); ++i)
71 moveTreeToNewScope(attrs[i].get()); 71 moveTreeToNewScope(*attrs[i]);
72 } 72 }
73 73
74 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) { 74 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) {
75 shadow->setParentTreeScope(m_newScope); 75 shadow->setParentTreeScope(&m_newScope);
76 if (willMoveToNewDocument) 76 if (willMoveToNewDocument)
77 moveTreeToNewDocument(shadow, oldDocument, newDocument); 77 moveTreeToNewDocument(*shadow, *oldDocument, newDocument);
78 } 78 }
79 } 79 }
80 80
81 m_oldScope->guardDeref(); 81 m_oldScope.guardDeref();
82 } 82 }
83 83
84 void TreeScopeAdopter::moveTreeToNewDocument(Node* root, Document* oldDocument, Document* newDocument) const 84 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, Document& oldDocument, Document* newDocument) const
85 { 85 {
86 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { 86 for (Node* node = &root; node; node = NodeTraversal::next(node, &root)) {
87 moveNodeToNewDocument(node, oldDocument, newDocument); 87 moveNodeToNewDocument(*node, oldDocument, newDocument);
88 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) 88 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot())
89 moveTreeToNewDocument(shadow, oldDocument, newDocument); 89 moveTreeToNewDocument(*shadow, oldDocument, newDocument);
90 } 90 }
91 } 91 }
92 92
93 #ifndef NDEBUG 93 #ifndef NDEBUG
94 static bool didMoveToNewDocumentWasCalled = false; 94 static bool didMoveToNewDocumentWasCalled = false;
95 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; 95 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0;
96 96
97 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument ) 97 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument )
98 { 98 {
99 ASSERT(!didMoveToNewDocumentWasCalled); 99 ASSERT(!didMoveToNewDocumentWasCalled);
100 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith); 100 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith);
101 didMoveToNewDocumentWasCalled = true; 101 didMoveToNewDocumentWasCalled = true;
102 } 102 }
103 #endif 103 #endif
104 104
105 inline void TreeScopeAdopter::updateTreeScope(Node* node) const 105 inline void TreeScopeAdopter::updateTreeScope(Node& node) const
106 { 106 {
107 ASSERT(!node->isTreeScope()); 107 ASSERT(!node.isTreeScope());
108 ASSERT(node->treeScope() == m_oldScope); 108 ASSERT(node.treeScope() == m_oldScope);
109 m_newScope->guardRef(); 109 m_newScope.guardRef();
110 m_oldScope->guardDeref(); 110 m_oldScope.guardDeref();
111 node->setTreeScope(m_newScope); 111 node.setTreeScope(&m_newScope);
112 } 112 }
113 113
114 inline void TreeScopeAdopter::moveNodeToNewDocument(Node* node, Document* oldDoc ument, Document* newDocument) const 114 inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDoc ument, Document* newDocument) const
115 { 115 {
116 ASSERT(!node->inDocument() || oldDocument != newDocument); 116 ASSERT(!node.inDocument() || oldDocument != newDocument);
117 ASSERT(oldDocument);
118 117
119 if (node->hasRareData()) { 118 if (node.hasRareData()) {
120 NodeRareData* rareData = node->rareData(); 119 NodeRareData* rareData = node.rareData();
121 if (rareData->nodeLists()) 120 if (rareData->nodeLists())
122 rareData->nodeLists()->adoptDocument(oldDocument, newDocument); 121 rareData->nodeLists()->adoptDocument(&oldDocument, newDocument);
123 } 122 }
124 123
125 oldDocument->moveNodeIteratorsToNewDocument(node, newDocument); 124 oldDocument.moveNodeIteratorsToNewDocument(&node, newDocument);
126 125
127 if (node->isShadowRoot()) 126 if (node.isShadowRoot())
128 toShadowRoot(node)->setDocumentScope(newDocument); 127 toShadowRoot(node).setDocumentScope(newDocument);
129 128
130 #ifndef NDEBUG 129 #ifndef NDEBUG
131 didMoveToNewDocumentWasCalled = false; 130 didMoveToNewDocumentWasCalled = false;
132 oldDocumentDidMoveToNewDocumentWasCalledWith = oldDocument; 131 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument;
133 #endif 132 #endif
134 133
135 node->didMoveToNewDocument(*oldDocument); 134 node.didMoveToNewDocument(oldDocument);
136 ASSERT(didMoveToNewDocumentWasCalled); 135 ASSERT(didMoveToNewDocumentWasCalled);
137 } 136 }
138 137
139 } 138 }
OLDNEW
« no previous file with comments | « Source/core/dom/TreeScopeAdopter.h ('k') | Source/core/dom/shadow/ShadowRoot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698