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

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

Issue 225783003: Remove ScriptState from NodeIterator, NodeFilter, NodeFilterCondition and TreeWalker (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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/NodeIterator.h ('k') | Source/core/dom/NodeIterator.idl » ('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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/dom/NodeIterator.h" 26 #include "core/dom/NodeIterator.h"
27 27
28 #include "bindings/v8/ExceptionState.h" 28 #include "bindings/v8/ExceptionState.h"
29 #include "bindings/v8/ScriptState.h"
30 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
31 #include "core/dom/ExceptionCode.h" 30 #include "core/dom/ExceptionCode.h"
32 #include "core/dom/NodeTraversal.h" 31 #include "core/dom/NodeTraversal.h"
33 32
34 namespace WebCore { 33 namespace WebCore {
35 34
36 NodeIterator::NodePointer::NodePointer() 35 NodeIterator::NodePointer::NodePointer()
37 { 36 {
38 } 37 }
39 38
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 { 78 {
80 ScriptWrappable::init(this); 79 ScriptWrappable::init(this);
81 root()->document().attachNodeIterator(this); 80 root()->document().attachNodeIterator(this);
82 } 81 }
83 82
84 NodeIterator::~NodeIterator() 83 NodeIterator::~NodeIterator()
85 { 84 {
86 root()->document().detachNodeIterator(this); 85 root()->document().detachNodeIterator(this);
87 } 86 }
88 87
89 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& exce ptionState) 88 PassRefPtr<Node> NodeIterator::nextNode(ExceptionState& exceptionState)
90 { 89 {
91 if (m_detached) { 90 if (m_detached) {
92 exceptionState.throwDOMException(InvalidStateError, "The iterator is det ached."); 91 exceptionState.throwDOMException(InvalidStateError, "The iterator is det ached.");
93 return nullptr; 92 return nullptr;
94 } 93 }
95 94
96 RefPtr<Node> result; 95 RefPtr<Node> result;
97 96
98 m_candidateNode = m_referenceNode; 97 m_candidateNode = m_referenceNode;
99 while (m_candidateNode.moveToNext(root())) { 98 while (m_candidateNode.moveToNext(root())) {
100 // NodeIterators treat the DOM tree as a flat list of nodes. 99 // NodeIterators treat the DOM tree as a flat list of nodes.
101 // In other words, FILTER_REJECT does not pass over descendants 100 // In other words, FILTER_REJECT does not pass over descendants
102 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP . 101 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP .
103 RefPtr<Node> provisionalResult = m_candidateNode.node; 102 RefPtr<Node> provisionalResult = m_candidateNode.node;
104 bool nodeWasAccepted = acceptNode(state, provisionalResult.get()) == Nod eFilter::FILTER_ACCEPT; 103 bool nodeWasAccepted = acceptNode(provisionalResult.get(), exceptionStat e) == NodeFilter::FILTER_ACCEPT;
105 if (state && state->hadException()) 104 if (exceptionState.hadException())
106 break; 105 break;
107 if (nodeWasAccepted) { 106 if (nodeWasAccepted) {
108 m_referenceNode = m_candidateNode; 107 m_referenceNode = m_candidateNode;
109 result = provisionalResult.release(); 108 result = provisionalResult.release();
110 break; 109 break;
111 } 110 }
112 } 111 }
113 112
114 m_candidateNode.clear(); 113 m_candidateNode.clear();
115 return result.release(); 114 return result.release();
116 } 115 }
117 116
118 PassRefPtr<Node> NodeIterator::previousNode(ScriptState* state, ExceptionState& exceptionState) 117 PassRefPtr<Node> NodeIterator::previousNode(ExceptionState& exceptionState)
119 { 118 {
120 if (m_detached) { 119 if (m_detached) {
121 exceptionState.throwDOMException(InvalidStateError, "The iterator is det ached."); 120 exceptionState.throwDOMException(InvalidStateError, "The iterator is det ached.");
122 return nullptr; 121 return nullptr;
123 } 122 }
124 123
125 RefPtr<Node> result; 124 RefPtr<Node> result;
126 125
127 m_candidateNode = m_referenceNode; 126 m_candidateNode = m_referenceNode;
128 while (m_candidateNode.moveToPrevious(root())) { 127 while (m_candidateNode.moveToPrevious(root())) {
129 // NodeIterators treat the DOM tree as a flat list of nodes. 128 // NodeIterators treat the DOM tree as a flat list of nodes.
130 // In other words, FILTER_REJECT does not pass over descendants 129 // In other words, FILTER_REJECT does not pass over descendants
131 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP . 130 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP .
132 RefPtr<Node> provisionalResult = m_candidateNode.node; 131 RefPtr<Node> provisionalResult = m_candidateNode.node;
133 bool nodeWasAccepted = acceptNode(state, provisionalResult.get()) == Nod eFilter::FILTER_ACCEPT; 132 bool nodeWasAccepted = acceptNode(provisionalResult.get(), exceptionStat e) == NodeFilter::FILTER_ACCEPT;
134 if (state && state->hadException()) 133 if (exceptionState.hadException())
135 break; 134 break;
136 if (nodeWasAccepted) { 135 if (nodeWasAccepted) {
137 m_referenceNode = m_candidateNode; 136 m_referenceNode = m_candidateNode;
138 result = provisionalResult.release(); 137 result = provisionalResult.release();
139 break; 138 break;
140 } 139 }
141 } 140 }
142 141
143 m_candidateNode.clear(); 142 m_candidateNode.clear();
144 return result.release(); 143 return result.release();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 node = NodeTraversal::previous(*node, root()); 218 node = NodeTraversal::previous(*node, root());
220 } 219 }
221 if (node) 220 if (node)
222 referenceNode.node = node; 221 referenceNode.node = node;
223 } 222 }
224 } 223 }
225 } 224 }
226 225
227 226
228 } // namespace WebCore 227 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/NodeIterator.h ('k') | Source/core/dom/NodeIterator.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698