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

Side by Side Diff: Source/core/xml/XPathResult.cpp

Issue 17239008: Remove XPathException (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 12 matching lines...) Expand all
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/xml/XPathResult.h" 28 #include "core/xml/XPathResult.h"
29 29
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/xml/XPathEvaluator.h" 32 #include "core/xml/XPathEvaluator.h"
33 #include "core/xml/XPathException.h"
34 33
35 namespace WebCore { 34 namespace WebCore {
36 35
37 using namespace XPath; 36 using namespace XPath;
38 37
39 XPathResult::XPathResult(Document* document, const Value& value) 38 XPathResult::XPathResult(Document* document, const Value& value)
40 : m_value(value) 39 : m_value(value)
41 , m_nodeSetPosition(0) 40 , m_nodeSetPosition(0)
42 , m_domTreeVersion(0) 41 , m_domTreeVersion(0)
43 { 42 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 break; 81 break;
83 case BOOLEAN_TYPE: 82 case BOOLEAN_TYPE:
84 m_resultType = type; 83 m_resultType = type;
85 m_value = m_value.toBoolean(); 84 m_value = m_value.toBoolean();
86 break; 85 break;
87 case UNORDERED_NODE_ITERATOR_TYPE: 86 case UNORDERED_NODE_ITERATOR_TYPE:
88 case UNORDERED_NODE_SNAPSHOT_TYPE: 87 case UNORDERED_NODE_SNAPSHOT_TYPE:
89 case ANY_UNORDERED_NODE_TYPE: 88 case ANY_UNORDERED_NODE_TYPE:
90 case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() wil l take care of ordering. 89 case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() wil l take care of ordering.
91 if (!m_value.isNodeSet()) { 90 if (!m_value.isNodeSet()) {
92 ec = XPathException::TYPE_ERR; 91 ec = TypeError;
93 return; 92 return;
94 } 93 }
95 m_resultType = type; 94 m_resultType = type;
96 break; 95 break;
97 case ORDERED_NODE_ITERATOR_TYPE: 96 case ORDERED_NODE_ITERATOR_TYPE:
98 if (!m_value.isNodeSet()) { 97 if (!m_value.isNodeSet()) {
99 ec = XPathException::TYPE_ERR; 98 ec = TypeError;
100 return; 99 return;
101 } 100 }
102 m_nodeSet.sort(); 101 m_nodeSet.sort();
103 m_resultType = type; 102 m_resultType = type;
104 break; 103 break;
105 case ORDERED_NODE_SNAPSHOT_TYPE: 104 case ORDERED_NODE_SNAPSHOT_TYPE:
106 if (!m_value.isNodeSet()) { 105 if (!m_value.isNodeSet()) {
107 ec = XPathException::TYPE_ERR; 106 ec = TypeError;
108 return; 107 return;
109 } 108 }
110 m_value.toNodeSet().sort(); 109 m_value.toNodeSet().sort();
111 m_resultType = type; 110 m_resultType = type;
112 break; 111 break;
113 } 112 }
114 } 113 }
115 114
116 unsigned short XPathResult::resultType() const 115 unsigned short XPathResult::resultType() const
117 { 116 {
118 return m_resultType; 117 return m_resultType;
119 } 118 }
120 119
121 double XPathResult::numberValue(ExceptionCode& ec) const 120 double XPathResult::numberValue(ExceptionCode& ec) const
122 { 121 {
123 if (resultType() != NUMBER_TYPE) { 122 if (resultType() != NUMBER_TYPE) {
124 ec = XPathException::TYPE_ERR; 123 ec = TypeError;
125 return 0.0; 124 return 0.0;
126 } 125 }
127 return m_value.toNumber(); 126 return m_value.toNumber();
128 } 127 }
129 128
130 String XPathResult::stringValue(ExceptionCode& ec) const 129 String XPathResult::stringValue(ExceptionCode& ec) const
131 { 130 {
132 if (resultType() != STRING_TYPE) { 131 if (resultType() != STRING_TYPE) {
133 ec = XPathException::TYPE_ERR; 132 ec = TypeError;
134 return String(); 133 return String();
135 } 134 }
136 return m_value.toString(); 135 return m_value.toString();
137 } 136 }
138 137
139 bool XPathResult::booleanValue(ExceptionCode& ec) const 138 bool XPathResult::booleanValue(ExceptionCode& ec) const
140 { 139 {
141 if (resultType() != BOOLEAN_TYPE) { 140 if (resultType() != BOOLEAN_TYPE) {
142 ec = XPathException::TYPE_ERR; 141 ec = TypeError;
143 return false; 142 return false;
144 } 143 }
145 return m_value.toBoolean(); 144 return m_value.toBoolean();
146 } 145 }
147 146
148 Node* XPathResult::singleNodeValue(ExceptionCode& ec) const 147 Node* XPathResult::singleNodeValue(ExceptionCode& ec) const
149 { 148 {
150 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED _NODE_TYPE) { 149 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED _NODE_TYPE) {
151 ec = XPathException::TYPE_ERR; 150 ec = TypeError;
152 return 0; 151 return 0;
153 } 152 }
154 153
155 const NodeSet& nodes = m_value.toNodeSet(); 154 const NodeSet& nodes = m_value.toNodeSet();
156 if (resultType() == FIRST_ORDERED_NODE_TYPE) 155 if (resultType() == FIRST_ORDERED_NODE_TYPE)
157 return nodes.firstNode(); 156 return nodes.firstNode();
158 else 157 else
159 return nodes.anyNode(); 158 return nodes.anyNode();
160 } 159 }
161 160
162 bool XPathResult::invalidIteratorState() const 161 bool XPathResult::invalidIteratorState() const
163 { 162 {
164 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE) 163 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE)
165 return false; 164 return false;
166 165
167 ASSERT(m_document); 166 ASSERT(m_document);
168 return m_document->domTreeVersion() != m_domTreeVersion; 167 return m_document->domTreeVersion() != m_domTreeVersion;
169 } 168 }
170 169
171 unsigned long XPathResult::snapshotLength(ExceptionCode& ec) const 170 unsigned long XPathResult::snapshotLength(ExceptionCode& ec) const
172 { 171 {
173 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) { 172 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) {
174 ec = XPathException::TYPE_ERR; 173 ec = TypeError;
175 return 0; 174 return 0;
176 } 175 }
177 176
178 return m_value.toNodeSet().size(); 177 return m_value.toNodeSet().size();
179 } 178 }
180 179
181 Node* XPathResult::iterateNext(ExceptionCode& ec) 180 Node* XPathResult::iterateNext(ExceptionCode& ec)
182 { 181 {
183 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE) { 182 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE) {
184 ec = XPathException::TYPE_ERR; 183 ec = TypeError;
185 return 0; 184 return 0;
186 } 185 }
187 186
188 if (invalidIteratorState()) { 187 if (invalidIteratorState()) {
189 ec = INVALID_STATE_ERR; 188 ec = INVALID_STATE_ERR;
190 return 0; 189 return 0;
191 } 190 }
192 191
193 if (m_nodeSetPosition + 1 > m_nodeSet.size()) 192 if (m_nodeSetPosition + 1 > m_nodeSet.size())
194 return 0; 193 return 0;
195 194
196 Node* node = m_nodeSet[m_nodeSetPosition]; 195 Node* node = m_nodeSet[m_nodeSetPosition];
197 196
198 m_nodeSetPosition++; 197 m_nodeSetPosition++;
199 198
200 return node; 199 return node;
201 } 200 }
202 201
203 Node* XPathResult::snapshotItem(unsigned long index, ExceptionCode& ec) 202 Node* XPathResult::snapshotItem(unsigned long index, ExceptionCode& ec)
204 { 203 {
205 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) { 204 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) {
206 ec = XPathException::TYPE_ERR; 205 ec = TypeError;
207 return 0; 206 return 0;
208 } 207 }
209 208
210 const NodeSet& nodes = m_value.toNodeSet(); 209 const NodeSet& nodes = m_value.toNodeSet();
211 if (index >= nodes.size()) 210 if (index >= nodes.size())
212 return 0; 211 return 0;
213 212
214 return nodes[index]; 213 return nodes[index];
215 } 214 }
216 215
217 } 216 }
OLDNEW
« Source/core/xml/XPathExpression.cpp ('K') | « Source/core/xml/XPathParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698