| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 m_domTreeVersion = document->domTreeVersion(); | 60 m_domTreeVersion = document->domTreeVersion(); |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 ASSERT_NOT_REACHED(); | 63 ASSERT_NOT_REACHED(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 XPathResult::~XPathResult() | 66 XPathResult::~XPathResult() |
| 67 { | 67 { |
| 68 } | 68 } |
| 69 | 69 |
| 70 void XPathResult::convertTo(unsigned short type, ExceptionState& es) | 70 void XPathResult::convertTo(unsigned short type, ExceptionState& exceptionState) |
| 71 { | 71 { |
| 72 switch (type) { | 72 switch (type) { |
| 73 case ANY_TYPE: | 73 case ANY_TYPE: |
| 74 break; | 74 break; |
| 75 case NUMBER_TYPE: | 75 case NUMBER_TYPE: |
| 76 m_resultType = type; | 76 m_resultType = type; |
| 77 m_value = m_value.toNumber(); | 77 m_value = m_value.toNumber(); |
| 78 break; | 78 break; |
| 79 case STRING_TYPE: | 79 case STRING_TYPE: |
| 80 m_resultType = type; | 80 m_resultType = type; |
| 81 m_value = m_value.toString(); | 81 m_value = m_value.toString(); |
| 82 break; | 82 break; |
| 83 case BOOLEAN_TYPE: | 83 case BOOLEAN_TYPE: |
| 84 m_resultType = type; | 84 m_resultType = type; |
| 85 m_value = m_value.toBoolean(); | 85 m_value = m_value.toBoolean(); |
| 86 break; | 86 break; |
| 87 case UNORDERED_NODE_ITERATOR_TYPE: | 87 case UNORDERED_NODE_ITERATOR_TYPE: |
| 88 case UNORDERED_NODE_SNAPSHOT_TYPE: | 88 case UNORDERED_NODE_SNAPSHOT_TYPE: |
| 89 case ANY_UNORDERED_NODE_TYPE: | 89 case ANY_UNORDERED_NODE_TYPE: |
| 90 case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() wil
l take care of ordering. | 90 case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() wil
l take care of ordering. |
| 91 if (!m_value.isNodeSet()) { | 91 if (!m_value.isNodeSet()) { |
| 92 es.throwUninformativeAndGenericTypeError(); | 92 exceptionState.throwUninformativeAndGenericTypeError(); |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 m_resultType = type; | 95 m_resultType = type; |
| 96 break; | 96 break; |
| 97 case ORDERED_NODE_ITERATOR_TYPE: | 97 case ORDERED_NODE_ITERATOR_TYPE: |
| 98 if (!m_value.isNodeSet()) { | 98 if (!m_value.isNodeSet()) { |
| 99 es.throwUninformativeAndGenericTypeError(); | 99 exceptionState.throwUninformativeAndGenericTypeError(); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 m_nodeSet.sort(); | 102 m_nodeSet.sort(); |
| 103 m_resultType = type; | 103 m_resultType = type; |
| 104 break; | 104 break; |
| 105 case ORDERED_NODE_SNAPSHOT_TYPE: | 105 case ORDERED_NODE_SNAPSHOT_TYPE: |
| 106 if (!m_value.isNodeSet()) { | 106 if (!m_value.isNodeSet()) { |
| 107 es.throwUninformativeAndGenericTypeError(); | 107 exceptionState.throwUninformativeAndGenericTypeError(); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 m_value.toNodeSet().sort(); | 110 m_value.toNodeSet().sort(); |
| 111 m_resultType = type; | 111 m_resultType = type; |
| 112 break; | 112 break; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 unsigned short XPathResult::resultType() const | 116 unsigned short XPathResult::resultType() const |
| 117 { | 117 { |
| 118 return m_resultType; | 118 return m_resultType; |
| 119 } | 119 } |
| 120 | 120 |
| 121 double XPathResult::numberValue(ExceptionState& es) const | 121 double XPathResult::numberValue(ExceptionState& exceptionState) const |
| 122 { | 122 { |
| 123 if (resultType() != NUMBER_TYPE) { | 123 if (resultType() != NUMBER_TYPE) { |
| 124 es.throwUninformativeAndGenericTypeError(); | 124 exceptionState.throwUninformativeAndGenericTypeError(); |
| 125 return 0.0; | 125 return 0.0; |
| 126 } | 126 } |
| 127 return m_value.toNumber(); | 127 return m_value.toNumber(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 String XPathResult::stringValue(ExceptionState& es) const | 130 String XPathResult::stringValue(ExceptionState& exceptionState) const |
| 131 { | 131 { |
| 132 if (resultType() != STRING_TYPE) { | 132 if (resultType() != STRING_TYPE) { |
| 133 es.throwUninformativeAndGenericTypeError(); | 133 exceptionState.throwUninformativeAndGenericTypeError(); |
| 134 return String(); | 134 return String(); |
| 135 } | 135 } |
| 136 return m_value.toString(); | 136 return m_value.toString(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool XPathResult::booleanValue(ExceptionState& es) const | 139 bool XPathResult::booleanValue(ExceptionState& exceptionState) const |
| 140 { | 140 { |
| 141 if (resultType() != BOOLEAN_TYPE) { | 141 if (resultType() != BOOLEAN_TYPE) { |
| 142 es.throwUninformativeAndGenericTypeError(); | 142 exceptionState.throwUninformativeAndGenericTypeError(); |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 return m_value.toBoolean(); | 145 return m_value.toBoolean(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 Node* XPathResult::singleNodeValue(ExceptionState& es) const | 148 Node* XPathResult::singleNodeValue(ExceptionState& exceptionState) const |
| 149 { | 149 { |
| 150 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED
_NODE_TYPE) { | 150 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED
_NODE_TYPE) { |
| 151 es.throwUninformativeAndGenericTypeError(); | 151 exceptionState.throwUninformativeAndGenericTypeError(); |
| 152 return 0; | 152 return 0; |
| 153 } | 153 } |
| 154 | 154 |
| 155 const NodeSet& nodes = m_value.toNodeSet(); | 155 const NodeSet& nodes = m_value.toNodeSet(); |
| 156 if (resultType() == FIRST_ORDERED_NODE_TYPE) | 156 if (resultType() == FIRST_ORDERED_NODE_TYPE) |
| 157 return nodes.firstNode(); | 157 return nodes.firstNode(); |
| 158 else | 158 else |
| 159 return nodes.anyNode(); | 159 return nodes.anyNode(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool XPathResult::invalidIteratorState() const | 162 bool XPathResult::invalidIteratorState() const |
| 163 { | 163 { |
| 164 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) | 164 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) |
| 165 return false; | 165 return false; |
| 166 | 166 |
| 167 ASSERT(m_document); | 167 ASSERT(m_document); |
| 168 return m_document->domTreeVersion() != m_domTreeVersion; | 168 return m_document->domTreeVersion() != m_domTreeVersion; |
| 169 } | 169 } |
| 170 | 170 |
| 171 unsigned long XPathResult::snapshotLength(ExceptionState& es) const | 171 unsigned long XPathResult::snapshotLength(ExceptionState& exceptionState) const |
| 172 { | 172 { |
| 173 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_
NODE_SNAPSHOT_TYPE) { | 173 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_
NODE_SNAPSHOT_TYPE) { |
| 174 es.throwUninformativeAndGenericTypeError(); | 174 exceptionState.throwUninformativeAndGenericTypeError(); |
| 175 return 0; | 175 return 0; |
| 176 } | 176 } |
| 177 | 177 |
| 178 return m_value.toNodeSet().size(); | 178 return m_value.toNodeSet().size(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 Node* XPathResult::iterateNext(ExceptionState& es) | 181 Node* XPathResult::iterateNext(ExceptionState& exceptionState) |
| 182 { | 182 { |
| 183 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) { | 183 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) { |
| 184 es.throwUninformativeAndGenericTypeError(); | 184 exceptionState.throwUninformativeAndGenericTypeError(); |
| 185 return 0; | 185 return 0; |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (invalidIteratorState()) { | 188 if (invalidIteratorState()) { |
| 189 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 189 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); |
| 190 return 0; | 190 return 0; |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (m_nodeSetPosition + 1 > m_nodeSet.size()) | 193 if (m_nodeSetPosition + 1 > m_nodeSet.size()) |
| 194 return 0; | 194 return 0; |
| 195 | 195 |
| 196 Node* node = m_nodeSet[m_nodeSetPosition]; | 196 Node* node = m_nodeSet[m_nodeSetPosition]; |
| 197 | 197 |
| 198 m_nodeSetPosition++; | 198 m_nodeSetPosition++; |
| 199 | 199 |
| 200 return node; | 200 return node; |
| 201 } | 201 } |
| 202 | 202 |
| 203 Node* XPathResult::snapshotItem(unsigned long index, ExceptionState& es) | 203 Node* XPathResult::snapshotItem(unsigned long index, ExceptionState& exceptionSt
ate) |
| 204 { | 204 { |
| 205 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_
NODE_SNAPSHOT_TYPE) { | 205 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_
NODE_SNAPSHOT_TYPE) { |
| 206 es.throwUninformativeAndGenericTypeError(); | 206 exceptionState.throwUninformativeAndGenericTypeError(); |
| 207 return 0; | 207 return 0; |
| 208 } | 208 } |
| 209 | 209 |
| 210 const NodeSet& nodes = m_value.toNodeSet(); | 210 const NodeSet& nodes = m_value.toNodeSet(); |
| 211 if (index >= nodes.size()) | 211 if (index >= nodes.size()) |
| 212 return 0; | 212 return 0; |
| 213 | 213 |
| 214 return nodes[index]; | 214 return nodes[index]; |
| 215 } | 215 } |
| 216 | 216 |
| 217 } | 217 } |
| OLD | NEW |