summaryrefslogtreecommitdiff
path: root/Source/WebCore/xml/XPathResult.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/xml/XPathResult.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/xml/XPathResult.cpp')
-rw-r--r--Source/WebCore/xml/XPathResult.cpp171
1 files changed, 72 insertions, 99 deletions
diff --git a/Source/WebCore/xml/XPathResult.cpp b/Source/WebCore/xml/XPathResult.cpp
index 82c6c7fa1..7508c021c 100644
--- a/Source/WebCore/xml/XPathResult.cpp
+++ b/Source/WebCore/xml/XPathResult.cpp
@@ -36,10 +36,8 @@ namespace WebCore {
using namespace XPath;
-XPathResult::XPathResult(Document* document, const Value& value)
+XPathResult::XPathResult(Document& document, const Value& value)
: m_value(value)
- , m_nodeSetPosition(0)
- , m_domTreeVersion(0)
{
switch (m_value.type()) {
case Value::BooleanValue:
@@ -55,8 +53,8 @@ XPathResult::XPathResult(Document* document, const Value& value)
m_resultType = UNORDERED_NODE_ITERATOR_TYPE;
m_nodeSetPosition = 0;
m_nodeSet = m_value.toNodeSet();
- m_document = document;
- m_domTreeVersion = document->domTreeVersion();
+ m_document = &document;
+ m_domTreeVersion = document.domTreeVersion();
return;
}
ASSERT_NOT_REACHED();
@@ -66,50 +64,45 @@ XPathResult::~XPathResult()
{
}
-void XPathResult::convertTo(unsigned short type, ExceptionCode& ec)
+ExceptionOr<void> XPathResult::convertTo(unsigned short type)
{
switch (type) {
- case ANY_TYPE:
- break;
- case NUMBER_TYPE:
- m_resultType = type;
- m_value = m_value.toNumber();
- break;
- case STRING_TYPE:
- m_resultType = type;
- m_value = m_value.toString();
- break;
- case BOOLEAN_TYPE:
- m_resultType = type;
- m_value = m_value.toBoolean();
- break;
- case UNORDERED_NODE_ITERATOR_TYPE:
- case UNORDERED_NODE_SNAPSHOT_TYPE:
- case ANY_UNORDERED_NODE_TYPE:
- case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() will take care of ordering.
- if (!m_value.isNodeSet()) {
- ec = XPathException::TYPE_ERR;
- return;
- }
- m_resultType = type;
- break;
- case ORDERED_NODE_ITERATOR_TYPE:
- if (!m_value.isNodeSet()) {
- ec = XPathException::TYPE_ERR;
- return;
- }
- m_nodeSet.sort();
- m_resultType = type;
- break;
- case ORDERED_NODE_SNAPSHOT_TYPE:
- if (!m_value.isNodeSet()) {
- ec = XPathException::TYPE_ERR;
- return;
- }
- m_value.toNodeSet().sort();
- m_resultType = type;
- break;
+ case ANY_TYPE:
+ break;
+ case NUMBER_TYPE:
+ m_resultType = type;
+ m_value = m_value.toNumber();
+ break;
+ case STRING_TYPE:
+ m_resultType = type;
+ m_value = m_value.toString();
+ break;
+ case BOOLEAN_TYPE:
+ m_resultType = type;
+ m_value = m_value.toBoolean();
+ break;
+ case UNORDERED_NODE_ITERATOR_TYPE:
+ case UNORDERED_NODE_SNAPSHOT_TYPE:
+ case ANY_UNORDERED_NODE_TYPE:
+ case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() will take care of ordering.
+ if (!m_value.isNodeSet())
+ return Exception { XPathException::TYPE_ERR };
+ m_resultType = type;
+ break;
+ case ORDERED_NODE_ITERATOR_TYPE:
+ if (!m_value.isNodeSet())
+ return Exception { XPathException::TYPE_ERR };
+ m_nodeSet.sort();
+ m_resultType = type;
+ break;
+ case ORDERED_NODE_SNAPSHOT_TYPE:
+ if (!m_value.isNodeSet())
+ return Exception { XPathException::TYPE_ERR };
+ m_value.toNodeSet().sort();
+ m_resultType = type;
+ break;
}
+ return { };
}
unsigned short XPathResult::resultType() const
@@ -117,41 +110,33 @@ unsigned short XPathResult::resultType() const
return m_resultType;
}
-double XPathResult::numberValue(ExceptionCode& ec) const
+ExceptionOr<double> XPathResult::numberValue() const
{
- if (resultType() != NUMBER_TYPE) {
- ec = XPathException::TYPE_ERR;
- return 0.0;
- }
+ if (resultType() != NUMBER_TYPE)
+ return Exception { XPathException::TYPE_ERR };
return m_value.toNumber();
}
-String XPathResult::stringValue(ExceptionCode& ec) const
+ExceptionOr<String> XPathResult::stringValue() const
{
- if (resultType() != STRING_TYPE) {
- ec = XPathException::TYPE_ERR;
- return String();
- }
+ if (resultType() != STRING_TYPE)
+ return Exception { XPathException::TYPE_ERR };
return m_value.toString();
}
-bool XPathResult::booleanValue(ExceptionCode& ec) const
+ExceptionOr<bool> XPathResult::booleanValue() const
{
- if (resultType() != BOOLEAN_TYPE) {
- ec = XPathException::TYPE_ERR;
- return false;
- }
+ if (resultType() != BOOLEAN_TYPE)
+ return Exception { XPathException::TYPE_ERR };
return m_value.toBoolean();
}
-Node* XPathResult::singleNodeValue(ExceptionCode& ec) const
+ExceptionOr<Node*> XPathResult::singleNodeValue() const
{
- if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED_NODE_TYPE) {
- ec = XPathException::TYPE_ERR;
- return 0;
- }
-
- const NodeSet& nodes = m_value.toNodeSet();
+ if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED_NODE_TYPE)
+ return Exception { XPathException::TYPE_ERR };
+
+ auto& nodes = m_value.toNodeSet();
if (resultType() == FIRST_ORDERED_NODE_TYPE)
return nodes.firstNode();
else
@@ -167,49 +152,37 @@ bool XPathResult::invalidIteratorState() const
return m_document->domTreeVersion() != m_domTreeVersion;
}
-unsigned long XPathResult::snapshotLength(ExceptionCode& ec) const
+ExceptionOr<unsigned> XPathResult::snapshotLength() const
{
- if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE) {
- ec = XPathException::TYPE_ERR;
- return 0;
- }
+ if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE)
+ return Exception { XPathException::TYPE_ERR };
return m_value.toNodeSet().size();
}
-Node* XPathResult::iterateNext(ExceptionCode& ec)
+ExceptionOr<Node*> XPathResult::iterateNext()
{
- if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_NODE_ITERATOR_TYPE) {
- ec = XPathException::TYPE_ERR;
- return 0;
- }
-
- if (invalidIteratorState()) {
- ec = INVALID_STATE_ERR;
- return 0;
- }
-
- if (m_nodeSetPosition + 1 > m_nodeSet.size())
- return 0;
+ if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_NODE_ITERATOR_TYPE)
+ return Exception { XPathException::TYPE_ERR };
+
+ if (invalidIteratorState())
+ return Exception { INVALID_STATE_ERR };
- Node* node = m_nodeSet[m_nodeSetPosition];
-
- m_nodeSetPosition++;
+ if (m_nodeSetPosition >= m_nodeSet.size())
+ return nullptr;
- return node;
+ return m_nodeSet[m_nodeSetPosition++];
}
-Node* XPathResult::snapshotItem(unsigned long index, ExceptionCode& ec)
+ExceptionOr<Node*> XPathResult::snapshotItem(unsigned index)
{
- if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE) {
- ec = XPathException::TYPE_ERR;
- return 0;
- }
-
- const NodeSet& nodes = m_value.toNodeSet();
+ if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE)
+ return Exception { XPathException::TYPE_ERR };
+
+ auto& nodes = m_value.toNodeSet();
if (index >= nodes.size())
- return 0;
-
+ return nullptr;
+
return nodes[index];
}