| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 using namespace XPath; | 37 using namespace XPath; |
| 38 | 38 |
| 39 XPathResult::XPathResult(Document* document, const Value& value) | 39 XPathResult::XPathResult(Document* document, const Value& value) |
| 40 : m_value(value) | 40 : m_value(value) |
| 41 , m_nodeSetPosition(0) | 41 , m_nodeSetPosition(0) |
| 42 , m_domTreeVersion(0) | 42 , m_domTreeVersion(0) |
| 43 { | 43 { |
| 44 ScriptWrappable::init(this); | 44 ScriptWrappable::init(this); |
| 45 switch (m_value.type()) { | 45 switch (m_value.type()) { |
| 46 case Value::BooleanValue: | 46 case Value::BooleanValue: |
| 47 m_resultType = BOOLEAN_TYPE; | 47 m_resultType = BOOLEAN_TYPE; |
| 48 return; | 48 return; |
| 49 case Value::NumberValue: | 49 case Value::NumberValue: |
| 50 m_resultType = NUMBER_TYPE; | 50 m_resultType = NUMBER_TYPE; |
| 51 return; | 51 return; |
| 52 case Value::StringValue: | 52 case Value::StringValue: |
| 53 m_resultType = STRING_TYPE; | 53 m_resultType = STRING_TYPE; |
| 54 return; | 54 return; |
| 55 case Value::NodeSetValue: | 55 case Value::NodeSetValue: |
| 56 m_resultType = UNORDERED_NODE_ITERATOR_TYPE; | 56 m_resultType = UNORDERED_NODE_ITERATOR_TYPE; |
| 57 m_nodeSetPosition = 0; | 57 m_nodeSetPosition = 0; |
| 58 m_nodeSet = NodeSet::create(m_value.toNodeSet()); | 58 m_nodeSet = NodeSet::create(m_value.toNodeSet()); |
| 59 m_document = document; | 59 m_document = document; |
| 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::trace(Visitor* visitor) | 70 void XPathResult::trace(Visitor* visitor) |
| 71 { | 71 { |
| 72 visitor->trace(m_value); | 72 visitor->trace(m_value); |
| 73 visitor->trace(m_nodeSet); | 73 visitor->trace(m_nodeSet); |
| 74 visitor->trace(m_document); | 74 visitor->trace(m_document); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void XPathResult::convertTo(unsigned short type, ExceptionState& exceptionState) | 77 void XPathResult::convertTo(unsigned short type, ExceptionState& exceptionState) |
| 78 { | 78 { |
| 79 switch (type) { | 79 switch (type) { |
| 80 case ANY_TYPE: | 80 case ANY_TYPE: |
| 81 break; | 81 break; |
| 82 case NUMBER_TYPE: | 82 case NUMBER_TYPE: |
| 83 m_resultType = type; | 83 m_resultType = type; |
| 84 m_value = m_value.toNumber(); | 84 m_value = m_value.toNumber(); |
| 85 break; | 85 break; |
| 86 case STRING_TYPE: | 86 case STRING_TYPE: |
| 87 m_resultType = type; | 87 m_resultType = type; |
| 88 m_value = m_value.toString(); | 88 m_value = m_value.toString(); |
| 89 break; | 89 break; |
| 90 case BOOLEAN_TYPE: | 90 case BOOLEAN_TYPE: |
| 91 m_resultType = type; | 91 m_resultType = type; |
| 92 m_value = m_value.toBoolean(); | 92 m_value = m_value.toBoolean(); |
| 93 break; | 93 break; |
| 94 case UNORDERED_NODE_ITERATOR_TYPE: | 94 case UNORDERED_NODE_ITERATOR_TYPE: |
| 95 case UNORDERED_NODE_SNAPSHOT_TYPE: | 95 case UNORDERED_NODE_SNAPSHOT_TYPE: |
| 96 case ANY_UNORDERED_NODE_TYPE: | 96 case ANY_UNORDERED_NODE_TYPE: |
| 97 case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() wil
l take care of ordering. | 97 // This is correct - singleNodeValue() will take care of ordering. |
| 98 if (!m_value.isNodeSet()) { | 98 case FIRST_ORDERED_NODE_TYPE: |
| 99 exceptionState.throwTypeError("The result is not a node set, and
therefore cannot be converted to the desired type."); | 99 if (!m_value.isNodeSet()) { |
| 100 return; | 100 exceptionState.throwTypeError("The result is not a node set, and the
refore cannot be converted to the desired type."); |
| 101 } | 101 return; |
| 102 m_resultType = type; | 102 } |
| 103 break; | 103 m_resultType = type; |
| 104 case ORDERED_NODE_ITERATOR_TYPE: | 104 break; |
| 105 if (!m_value.isNodeSet()) { | 105 case ORDERED_NODE_ITERATOR_TYPE: |
| 106 exceptionState.throwTypeError("The result is not a node set, and
therefore cannot be converted to the desired type."); | 106 if (!m_value.isNodeSet()) { |
| 107 return; | 107 exceptionState.throwTypeError("The result is not a node set, and the
refore cannot be converted to the desired type."); |
| 108 } | 108 return; |
| 109 nodeSet().sort(); | 109 } |
| 110 m_resultType = type; | 110 nodeSet().sort(); |
| 111 break; | 111 m_resultType = type; |
| 112 case ORDERED_NODE_SNAPSHOT_TYPE: | 112 break; |
| 113 if (!m_value.isNodeSet()) { | 113 case ORDERED_NODE_SNAPSHOT_TYPE: |
| 114 exceptionState.throwTypeError("The result is not a node set, and
therefore cannot be converted to the desired type."); | 114 if (!m_value.isNodeSet()) { |
| 115 return; | 115 exceptionState.throwTypeError("The result is not a node set, and the
refore cannot be converted to the desired type."); |
| 116 } | 116 return; |
| 117 m_value.toNodeSet().sort(); | 117 } |
| 118 m_resultType = type; | 118 m_value.toNodeSet().sort(); |
| 119 break; | 119 m_resultType = type; |
| 120 break; |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 123 unsigned short XPathResult::resultType() const | 124 unsigned short XPathResult::resultType() const |
| 124 { | 125 { |
| 125 return m_resultType; | 126 return m_resultType; |
| 126 } | 127 } |
| 127 | 128 |
| 128 double XPathResult::numberValue(ExceptionState& exceptionState) const | 129 double XPathResult::numberValue(ExceptionState& exceptionState) const |
| 129 { | 130 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 155 Node* XPathResult::singleNodeValue(ExceptionState& exceptionState) const | 156 Node* XPathResult::singleNodeValue(ExceptionState& exceptionState) const |
| 156 { | 157 { |
| 157 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED
_NODE_TYPE) { | 158 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED
_NODE_TYPE) { |
| 158 exceptionState.throwTypeError("The result type is not a single node."); | 159 exceptionState.throwTypeError("The result type is not a single node."); |
| 159 return 0; | 160 return 0; |
| 160 } | 161 } |
| 161 | 162 |
| 162 const NodeSet& nodes = m_value.toNodeSet(); | 163 const NodeSet& nodes = m_value.toNodeSet(); |
| 163 if (resultType() == FIRST_ORDERED_NODE_TYPE) | 164 if (resultType() == FIRST_ORDERED_NODE_TYPE) |
| 164 return nodes.firstNode(); | 165 return nodes.firstNode(); |
| 165 else | 166 return nodes.anyNode(); |
| 166 return nodes.anyNode(); | |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool XPathResult::invalidIteratorState() const | 169 bool XPathResult::invalidIteratorState() const |
| 170 { | 170 { |
| 171 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) | 171 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_
NODE_ITERATOR_TYPE) |
| 172 return false; | 172 return false; |
| 173 | 173 |
| 174 ASSERT(m_document); | 174 ASSERT(m_document); |
| 175 return m_document->domTreeVersion() != m_domTreeVersion; | 175 return m_document->domTreeVersion() != m_domTreeVersion; |
| 176 } | 176 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 | 216 |
| 217 const NodeSet& nodes = m_value.toNodeSet(); | 217 const NodeSet& nodes = m_value.toNodeSet(); |
| 218 if (index >= nodes.size()) | 218 if (index >= nodes.size()) |
| 219 return 0; | 219 return 0; |
| 220 | 220 |
| 221 return nodes[index]; | 221 return nodes[index]; |
| 222 } | 222 } |
| 223 | 223 |
| 224 } | 224 } |
| OLD | NEW |