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

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

Issue 112953007: Make TreeScope::documentScope() return a reference and ensure m_documentScope is never NULL (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added FIXMEs Created 6 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/TreeScopeAdopter.h ('k') | no next file » | 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 26 matching lines...) Expand all
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 Document& newDocument = m_newScope.documentScope();
49 Document* newDocument = m_newScope.documentScope();
50 bool willMoveToNewDocument = oldDocument != newDocument; 49 bool willMoveToNewDocument = oldDocument != newDocument;
51 if (willMoveToNewDocument) 50 if (willMoveToNewDocument)
52 oldDocument->incDOMTreeVersion(); 51 oldDocument.incDOMTreeVersion();
53 52
54 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { 53 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
55 updateTreeScope(*node); 54 updateTreeScope(*node);
56 55
57 if (willMoveToNewDocument) 56 if (willMoveToNewDocument)
58 moveNodeToNewDocument(*node, *oldDocument, newDocument); 57 moveNodeToNewDocument(*node, oldDocument, newDocument);
59 else if (node->hasRareData()) { 58 else if (node->hasRareData()) {
60 NodeRareData* rareData = node->rareData(); 59 NodeRareData* rareData = node->rareData();
61 if (rareData->nodeLists()) 60 if (rareData->nodeLists())
62 rareData->nodeLists()->adoptTreeScope(); 61 rareData->nodeLists()->adoptTreeScope();
63 } 62 }
64 63
65 if (!node->isElementNode()) 64 if (!node->isElementNode())
66 continue; 65 continue;
67 66
68 if (node->hasSyntheticAttrChildNodes()) { 67 if (node->hasSyntheticAttrChildNodes()) {
69 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList() ; 68 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList() ;
70 for (unsigned i = 0; i < attrs.size(); ++i) 69 for (unsigned i = 0; i < attrs.size(); ++i)
71 moveTreeToNewScope(*attrs[i]); 70 moveTreeToNewScope(*attrs[i]);
72 } 71 }
73 72
74 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) { 73 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) {
75 shadow->setParentTreeScope(&m_newScope); 74 shadow->setParentTreeScope(&m_newScope);
76 if (willMoveToNewDocument) 75 if (willMoveToNewDocument)
77 moveTreeToNewDocument(*shadow, *oldDocument, newDocument); 76 moveTreeToNewDocument(*shadow, oldDocument, newDocument);
78 } 77 }
79 } 78 }
80 79
81 m_oldScope.guardDeref(); 80 m_oldScope.guardDeref();
82 } 81 }
83 82
84 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, Document& oldDocument, Document* newDocument) const 83 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, Document& oldDocument, Document& newDocument) const
85 { 84 {
86 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { 85 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
87 moveNodeToNewDocument(*node, oldDocument, newDocument); 86 moveNodeToNewDocument(*node, oldDocument, newDocument);
88 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) 87 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot())
89 moveTreeToNewDocument(*shadow, oldDocument, newDocument); 88 moveTreeToNewDocument(*shadow, oldDocument, newDocument);
90 } 89 }
91 } 90 }
92 91
93 #ifndef NDEBUG 92 #ifndef NDEBUG
94 static bool didMoveToNewDocumentWasCalled = false; 93 static bool didMoveToNewDocumentWasCalled = false;
95 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; 94 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0;
96 95
97 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument ) 96 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument )
98 { 97 {
99 ASSERT(!didMoveToNewDocumentWasCalled); 98 ASSERT(!didMoveToNewDocumentWasCalled);
100 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith); 99 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith);
101 didMoveToNewDocumentWasCalled = true; 100 didMoveToNewDocumentWasCalled = true;
102 } 101 }
103 #endif 102 #endif
104 103
105 inline void TreeScopeAdopter::updateTreeScope(Node& node) const 104 inline void TreeScopeAdopter::updateTreeScope(Node& node) const
106 { 105 {
107 ASSERT(!node.isTreeScope()); 106 ASSERT(!node.isTreeScope());
108 ASSERT(node.treeScope() == m_oldScope); 107 ASSERT(node.treeScope() == m_oldScope);
109 m_newScope.guardRef(); 108 m_newScope.guardRef();
110 m_oldScope.guardDeref(); 109 m_oldScope.guardDeref();
111 node.setTreeScope(&m_newScope); 110 node.setTreeScope(&m_newScope);
112 } 111 }
113 112
114 inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDoc ument, Document* newDocument) const 113 inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDoc ument, Document& newDocument) const
115 { 114 {
116 ASSERT(!node.inDocument() || oldDocument != newDocument); 115 ASSERT(!node.inDocument() || oldDocument != newDocument);
117 116
118 if (node.hasRareData()) { 117 if (node.hasRareData()) {
119 NodeRareData* rareData = node.rareData(); 118 NodeRareData* rareData = node.rareData();
120 if (rareData->nodeLists()) 119 if (rareData->nodeLists())
121 rareData->nodeLists()->adoptDocument(&oldDocument, newDocument); 120 rareData->nodeLists()->adoptDocument(oldDocument, newDocument);
122 } 121 }
123 122
124 oldDocument.moveNodeIteratorsToNewDocument(&node, newDocument); 123 oldDocument.moveNodeIteratorsToNewDocument(node, newDocument);
125 124
126 if (node.isShadowRoot()) 125 if (node.isShadowRoot())
127 toShadowRoot(node).setDocumentScope(newDocument); 126 toShadowRoot(node).setDocumentScope(newDocument);
128 127
129 #ifndef NDEBUG 128 #ifndef NDEBUG
130 didMoveToNewDocumentWasCalled = false; 129 didMoveToNewDocumentWasCalled = false;
131 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument; 130 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument;
132 #endif 131 #endif
133 132
134 node.didMoveToNewDocument(oldDocument); 133 node.didMoveToNewDocument(oldDocument);
135 ASSERT(didMoveToNewDocumentWasCalled); 134 ASSERT(didMoveToNewDocumentWasCalled);
136 } 135 }
137 136
138 } 137 }
OLDNEW
« no previous file with comments | « Source/core/dom/TreeScopeAdopter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698