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

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

Issue 23717008: Remove useless null checks from Node::document() call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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/Node.cpp ('k') | Source/core/dom/Position.cpp » ('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 * Copyright (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 3 * Copyright (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 4 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
5 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 node = NodeTraversal::previous(node.get(), root); 72 node = NodeTraversal::previous(node.get(), root);
73 return node; 73 return node;
74 } 74 }
75 75
76 NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned whatToShow, PassR efPtr<NodeFilter> filter) 76 NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned whatToShow, PassR efPtr<NodeFilter> filter)
77 : Traversal(rootNode, whatToShow, filter) 77 : Traversal(rootNode, whatToShow, filter)
78 , m_referenceNode(root(), true) 78 , m_referenceNode(root(), true)
79 , m_detached(false) 79 , m_detached(false)
80 { 80 {
81 // Document type nodes may have a null document. But since they can't have c hildren, there is no need to listen for modifications to these.
82 ASSERT(root()->document() || root()->nodeType() == Node::DOCUMENT_TYPE_NODE) ;
83 ScriptWrappable::init(this); 81 ScriptWrappable::init(this);
84 if (Document* ownerDocument = root()->document()) 82 root()->document()->attachNodeIterator(this);
85 ownerDocument->attachNodeIterator(this);
86 } 83 }
87 84
88 NodeIterator::~NodeIterator() 85 NodeIterator::~NodeIterator()
89 { 86 {
90 if (Document* ownerDocument = root()->document()) 87 root()->document()->detachNodeIterator(this);
91 ownerDocument->detachNodeIterator(this);
92 } 88 }
93 89
94 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& es) 90 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& es)
95 { 91 {
96 if (m_detached) { 92 if (m_detached) {
97 es.throwDOMException(InvalidStateError); 93 es.throwDOMException(InvalidStateError);
98 return 0; 94 return 0;
99 } 95 }
100 96
101 RefPtr<Node> result; 97 RefPtr<Node> result;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 break; 140 break;
145 } 141 }
146 } 142 }
147 143
148 m_candidateNode.clear(); 144 m_candidateNode.clear();
149 return result.release(); 145 return result.release();
150 } 146 }
151 147
152 void NodeIterator::detach() 148 void NodeIterator::detach()
153 { 149 {
154 if (Document* ownerDocument = root()->document()) 150 root()->document()->detachNodeIterator(this);
155 ownerDocument->detachNodeIterator(this);
156 m_detached = true; 151 m_detached = true;
157 m_referenceNode.node.clear(); 152 m_referenceNode.node.clear();
158 } 153 }
159 154
160 void NodeIterator::nodeWillBeRemoved(Node* removedNode) 155 void NodeIterator::nodeWillBeRemoved(Node* removedNode)
161 { 156 {
162 updateForNodeRemoval(removedNode, m_candidateNode); 157 updateForNodeRemoval(removedNode, m_candidateNode);
163 updateForNodeRemoval(removedNode, m_referenceNode); 158 updateForNodeRemoval(removedNode, m_referenceNode);
164 } 159 }
165 160
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 node = NodeTraversal::previous(node, root()); 222 node = NodeTraversal::previous(node, root());
228 } 223 }
229 if (node) 224 if (node)
230 referenceNode.node = node; 225 referenceNode.node = node;
231 } 226 }
232 } 227 }
233 } 228 }
234 229
235 230
236 } // namespace WebCore 231 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698