Move XPath from ExceptionCode to Exception
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Oct 2016 16:57:31 +0000 (16:57 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Oct 2016 16:57:31 +0000 (16:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163656

Reviewed by Chris Dumez.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::createExpression): Use ExceptionOr.
(WebCore::Document::createNSResolver): Return Ref.
(WebCore::Document::evaluate): Use ExceptionOr.
* dom/Document.h: Updated for above changes.
* dom/Document.idl: Use non-legacy exceptions for the functions above.

* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::searchUsingXPath): Call XPath functions
with new interface.

* xml/DOMParser.cpp:
(WebCore::DOMParser::DOMParser): Marked inline.
(WebCore::DOMParser::create): Moved here from header.
(WebCore::DOMParser::parseFromString): Use ExceptionOr.
* xml/DOMParser.h: Updated for above changes.
* xml/DOMParser.idl: Use non-legacy exception.

* xml/XPathEvaluator.cpp:
(WebCore::XPathEvaluator::createExpression): Use ExceptionOr.
(WebCore::XPathEvaluator::evaluate): Ditto.
* xml/XPathEvaluator.h: Updated for above changes.
* xml/XPathEvaluator.idl: Use non-legacy exceptions.

* xml/XPathExpression.cpp:
(WebCore::XPathExpression::createExpression): Use ExceptionOr.
(WebCore::XPathExpression::evaluate): Ditto.
* xml/XPathExpression.h: Updated for above changes.
* xml/XPathExpression.idl: Use non-legacy exceptions.

* xml/XPathGrammar.y: Added include of XPathStep.h.

* xml/XPathParser.cpp:
(WebCore::XPath::Parser::Parser): Initialize three scalar data members
in the class definition rather than here.
(WebCore::XPath::Parser::parseStatement): Use ExceptionOr.
* xml/XPathParser.h: Updated for above changes.

* xml/XPathResult.cpp:
(WebCore::XPathResult::XPathResult): Use a reference rather than a
pointer for the document. Alao initialize two scalar data members
in the class definition rather than here.
(WebCore::XPathResult::convertTo): Use ExceptionOr.
(WebCore::XPathResult::numberValue): Ditto.
(WebCore::XPathResult::stringValue): Ditto.
(WebCore::XPathResult::booleanValue): Ditto.
(WebCore::XPathResult::singleNodeValue): Ditto.
(WebCore::XPathResult::snapshotLength): Ditto.
(WebCore::XPathResult::iterateNext): Ditto.
(WebCore::XPathResult::snapshotItem): Ditto.
* xml/XPathResult.h: Updated for the changes above.
* xml/XPathResult.idl: Use non-legacy exceptions.

Source/WebKit/mac:

* DOM/DOMDocument.mm:
(wrap): Added. Helper function for wrapping a resolver.
(-[DOMDocument createExpression:resolver:]): Use raiseOnDOMError.
(-[DOMDocument evaluate:contextNode:resolver:type:inResult:]): Ditto.
* DOM/DOMXPathExpression.mm:
(-[DOMXPathExpression evaluate:type:inResult:]): Ditto.
* DOM/DOMXPathResult.mm:
(-[DOMXPathResult numberValue]): Ditto.
(-[DOMXPathResult stringValue]): Ditto.
(-[DOMXPathResult booleanValue]): Ditto.
(-[DOMXPathResult singleNodeValue]): Ditto.
(-[DOMXPathResult snapshotLength]): Ditto.
(-[DOMXPathResult iterateNext]): Ditto.
(-[DOMXPathResult snapshotItem:]): Ditto.

Source/WebKit2:

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp:
(webkit_dom_document_create_expression): Use ExceptionOr.
(webkit_dom_document_evaluate): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp:
(webkit_dom_xpath_expression_evaluate): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp:
(webkit_dom_xpath_result_iterate_next): Ditto.
(webkit_dom_xpath_result_snapshot_item): Ditto.
(webkit_dom_xpath_result_get_number_value): Ditto.
(webkit_dom_xpath_result_get_string_value): Ditto.
(webkit_dom_xpath_result_get_boolean_value): Ditto.
(webkit_dom_xpath_result_get_single_node_value): Ditto.
(webkit_dom_xpath_result_get_snapshot_length): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207541 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/inspector/InspectorNodeFinder.cpp
Source/WebCore/xml/DOMParser.cpp
Source/WebCore/xml/DOMParser.h
Source/WebCore/xml/DOMParser.idl
Source/WebCore/xml/XPathEvaluator.cpp
Source/WebCore/xml/XPathEvaluator.h
Source/WebCore/xml/XPathEvaluator.idl
Source/WebCore/xml/XPathExpression.cpp
Source/WebCore/xml/XPathExpression.h
Source/WebCore/xml/XPathExpression.idl
Source/WebCore/xml/XPathGrammar.y
Source/WebCore/xml/XPathParser.cpp
Source/WebCore/xml/XPathParser.h
Source/WebCore/xml/XPathResult.cpp
Source/WebCore/xml/XPathResult.h
Source/WebCore/xml/XPathResult.idl
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOMDocument.mm
Source/WebKit/mac/DOM/DOMXPathExpression.mm
Source/WebKit/mac/DOM/DOMXPathResult.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp

index b1cec89..3fd0e86 100644 (file)
@@ -1,3 +1,63 @@
+2016-10-19  Darin Adler  <darin@apple.com>
+
+        Move XPath from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=163656
+
+        Reviewed by Chris Dumez.
+
+        * dom/Document.cpp:
+        (WebCore::Document::createExpression): Use ExceptionOr.
+        (WebCore::Document::createNSResolver): Return Ref.
+        (WebCore::Document::evaluate): Use ExceptionOr.
+        * dom/Document.h: Updated for above changes.
+        * dom/Document.idl: Use non-legacy exceptions for the functions above.
+
+        * inspector/InspectorNodeFinder.cpp:
+        (WebCore::InspectorNodeFinder::searchUsingXPath): Call XPath functions
+        with new interface.
+
+        * xml/DOMParser.cpp:
+        (WebCore::DOMParser::DOMParser): Marked inline.
+        (WebCore::DOMParser::create): Moved here from header.
+        (WebCore::DOMParser::parseFromString): Use ExceptionOr.
+        * xml/DOMParser.h: Updated for above changes.
+        * xml/DOMParser.idl: Use non-legacy exception.
+
+        * xml/XPathEvaluator.cpp:
+        (WebCore::XPathEvaluator::createExpression): Use ExceptionOr.
+        (WebCore::XPathEvaluator::evaluate): Ditto.
+        * xml/XPathEvaluator.h: Updated for above changes.
+        * xml/XPathEvaluator.idl: Use non-legacy exceptions.
+
+        * xml/XPathExpression.cpp:
+        (WebCore::XPathExpression::createExpression): Use ExceptionOr.
+        (WebCore::XPathExpression::evaluate): Ditto.
+        * xml/XPathExpression.h: Updated for above changes.
+        * xml/XPathExpression.idl: Use non-legacy exceptions.
+
+        * xml/XPathGrammar.y: Added include of XPathStep.h.
+
+        * xml/XPathParser.cpp:
+        (WebCore::XPath::Parser::Parser): Initialize three scalar data members
+        in the class definition rather than here.
+        (WebCore::XPath::Parser::parseStatement): Use ExceptionOr.
+        * xml/XPathParser.h: Updated for above changes.
+
+        * xml/XPathResult.cpp:
+        (WebCore::XPathResult::XPathResult): Use a reference rather than a
+        pointer for the document. Alao initialize two scalar data members
+        in the class definition rather than here.
+        (WebCore::XPathResult::convertTo): Use ExceptionOr.
+        (WebCore::XPathResult::numberValue): Ditto.
+        (WebCore::XPathResult::stringValue): Ditto.
+        (WebCore::XPathResult::booleanValue): Ditto.
+        (WebCore::XPathResult::singleNodeValue): Ditto.
+        (WebCore::XPathResult::snapshotLength): Ditto.
+        (WebCore::XPathResult::iterateNext): Ditto.
+        (WebCore::XPathResult::snapshotItem): Ditto.
+        * xml/XPathResult.h: Updated for the changes above.
+        * xml/XPathResult.idl: Use non-legacy exceptions.
+
 2016-10-19  Nan Wang  <n_wang@apple.com>
 
         AX: [Mac] Meter element should use AXValueDescription to descrbe the status of the value
index ffbcb80..861808b 100644 (file)
@@ -5117,25 +5117,25 @@ bool Document::isTelephoneNumberParsingAllowed() const
 
 #endif
 
-RefPtr<XPathExpression> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
+ExceptionOr<Ref<XPathExpression>> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
 {
     if (!m_xpathEvaluator)
         m_xpathEvaluator = XPathEvaluator::create();
-    return m_xpathEvaluator->createExpression(expression, WTFMove(resolver), ec);
+    return m_xpathEvaluator->createExpression(expression, WTFMove(resolver));
 }
 
-RefPtr<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
+Ref<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
 {
     if (!m_xpathEvaluator)
         m_xpathEvaluator = XPathEvaluator::create();
     return m_xpathEvaluator->createNSResolver(nodeResolver);
 }
 
-RefPtr<XPathResult> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)
+ExceptionOr<Ref<XPathResult>> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result)
 {
     if (!m_xpathEvaluator)
         m_xpathEvaluator = XPathEvaluator::create();
-    return m_xpathEvaluator->evaluate(expression, contextNode, WTFMove(resolver), type, result, ec);
+    return m_xpathEvaluator->evaluate(expression, contextNode, WTFMove(resolver), type, result);
 }
 
 static bool shouldInheritSecurityOriginFromOwner(const URL& url)
index 77fa0fb..9a540b5 100644 (file)
@@ -32,6 +32,7 @@
 #include "ContainerNode.h"
 #include "DocumentEventQueue.h"
 #include "DocumentTiming.h"
+#include "ExceptionOr.h"
 #include "FocusDirection.h"
 #include "FontSelectorClient.h"
 #include "MediaProducer.h"
@@ -943,9 +944,9 @@ public:
     uint64_t domTreeVersion() const { return m_domTreeVersion; }
 
     // XPathEvaluator methods
-    WEBCORE_EXPORT RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
-    WEBCORE_EXPORT RefPtr<XPathNSResolver> createNSResolver(Node* nodeResolver);
-    WEBCORE_EXPORT RefPtr<XPathResult> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
+    WEBCORE_EXPORT Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
+    WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
 
     enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
 
index c962c0c..1470e5e 100644 (file)
     readonly attribute DOMString contentType;
 
     // FIXME: Using "undefined" as default parameter value is wrong.
-    [MayThrowLegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
+    [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
     XPathNSResolver createNSResolver(Node? nodeResolver);
 
     // FIXME: Using "undefined" as default parameter value is wrong.
-    [MayThrowLegacyException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver,
-        optional unsigned short type = 0, optional XPathResult? inResult);
+    [MayThrowException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
 
     // FIXME: The default value for the last parameter should be the empty string.
     boolean execCommand(DOMString command, optional boolean userInterface = false, optional DOMString? value = null);
index 645636e..55b2c28 100644 (file)
@@ -132,19 +132,21 @@ bool InspectorNodeFinder::matchesElement(const Element& element)
 
 void InspectorNodeFinder::searchUsingXPath(Node* parentNode)
 {
-    ExceptionCode ec = 0;
-    RefPtr<XPathResult> result = parentNode->document().evaluate(m_whitespaceTrimmedQuery, parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr, ec);
-    if (ec || !result)
+    auto evaluateResult = parentNode->document().evaluate(m_whitespaceTrimmedQuery, parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr);
+    if (evaluateResult.hasException())
         return;
+    auto result = evaluateResult.releaseReturnValue();
 
-    unsigned long size = result->snapshotLength(ec);
-    if (ec)
+    auto snapshotLengthResult = result->snapshotLength();
+    if (snapshotLengthResult.hasException())
         return;
+    unsigned size = snapshotLengthResult.releaseReturnValue();
 
-    for (unsigned long i = 0; i < size; ++i) {
-        Node* node = result->snapshotItem(i, ec);
-        if (ec)
+    for (unsigned i = 0; i < size; ++i) {
+        auto snapshotItemResult = result->snapshotItem(i);
+        if (snapshotItemResult.hasException())
             return;
+        Node* node = snapshotItemResult.releaseReturnValue();
 
         if (is<Attr>(*node))
             node = downcast<Attr>(*node).ownerElement();
index 65a9230..490ad35 100644 (file)
 
 #include "DOMImplementation.h"
 #include "ExceptionCode.h"
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-DOMParser::DOMParser(Document& contextDocument)
+inline DOMParser::DOMParser(Document& contextDocument)
     : m_contextDocument(contextDocument.createWeakPtr())
 {
 }
 
-RefPtr<Document> DOMParser::parseFromString(const String& string, const String& contentType, ExceptionCode& ec)
+Ref<DOMParser> DOMParser::create(Document& contextDocument)
 {
-    if (contentType != "text/html"
-        && contentType != "text/xml"
-        && contentType != "application/xml"
-        && contentType != "application/xhtml+xml"
-        && contentType != "image/svg+xml") {
-        ec = TypeError;
-        return nullptr;
-    }
+    return adoptRef(*new DOMParser(contextDocument));
+}
 
-    Ref<Document> document = DOMImplementation::createDocument(contentType, nullptr, URL());
+ExceptionOr<Ref<Document>> DOMParser::parseFromString(const String& string, const String& contentType)
+{
+    if (contentType != "text/html" && contentType != "text/xml" && contentType != "application/xml" && contentType != "application/xhtml+xml" && contentType != "image/svg+xml")
+        return Exception { TypeError };
+    auto document = DOMImplementation::createDocument(contentType, nullptr, URL { });
     if (m_contextDocument)
         document->setContextDocument(*m_contextDocument.get());
     document->setContent(string);
index 817b01a..42ceeb9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2003, 2006 Apple Inc.
+ *  Copyright (C) 2003, 2006 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef DOMParser_h
-#define DOMParser_h
+#pragma once
 
-#include <wtf/Forward.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
+#include "ExceptionOr.h"
 #include <wtf/WeakPtr.h>
 
 namespace WebCore {
-typedef int ExceptionCode;
 
 class Document;
 
 class DOMParser : public RefCounted<DOMParser> {
 public:
-    static Ref<DOMParser> create(Document& contextDocument)
-    {
-        return adoptRef(*new DOMParser(contextDocument));
-    }
-
-    RefPtr<Document> parseFromString(const String&, const String& contentType, ExceptionCode&);
+    static Ref<DOMParser> create(Document& contextDocument);
+    ExceptionOr<Ref<Document>> parseFromString(const String&, const String& contentType);
 
 private:
     explicit DOMParser(Document& contextDocument);
@@ -45,5 +37,3 @@ private:
 };
 
 }
-
-#endif // XMLSerializer.h
index 2903d18..964e4ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Apple Inc.
+ * Copyright (C) 2006 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -22,5 +22,5 @@
     ConstructorCallWith=Document,
     ImplementationLacksVTable,
 ] interface DOMParser {
-    [MayThrowLegacyException, NewObject] Document parseFromString(DOMString str, DOMString contentType);
+    [MayThrowException, NewObject] Document parseFromString(DOMString string, DOMString contentType);
 };
index fc75c31..3aa141b 100644 (file)
@@ -37,9 +37,9 @@ namespace WebCore {
 
 using namespace XPath;
 
-RefPtr<XPathExpression> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
+ExceptionOr<Ref<XPathExpression>> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
 {
-    return XPathExpression::createExpression(expression, WTFMove(resolver), ec);
+    return XPathExpression::createExpression(expression, WTFMove(resolver));
 }
 
 Ref<XPathNSResolver> XPathEvaluator::createNSResolver(Node* nodeResolver)
@@ -47,19 +47,16 @@ Ref<XPathNSResolver> XPathEvaluator::createNSResolver(Node* nodeResolver)
     return NativeXPathNSResolver::create(nodeResolver);
 }
 
-RefPtr<XPathResult> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)
+ExceptionOr<Ref<XPathResult>> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result)
 {
-    if (!isValidContextNode(contextNode)) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
+    if (!isValidContextNode(contextNode))
+        return Exception { NOT_SUPPORTED_ERR };
 
-    ec = 0;
-    RefPtr<XPathExpression> expr = createExpression(expression, WTFMove(resolver), ec);
-    if (ec)
-        return nullptr;
-    
-    return expr->evaluate(contextNode, type, result, ec);
+    auto createResult = createExpression(expression, WTFMove(resolver));
+    if (createResult.hasException())
+        return createResult.releaseException();
+
+    return createResult.releaseReturnValue()->evaluate(contextNode, type, result);
 }
 
 }
index f2bb5cb..4a47854 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright 2005 Frerich Raabe <raabe@kde.org>
- * Copyright (C) 2006 Apple Inc.
+ * Copyright (C) 2006 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef XPathEvaluator_h
-#define XPathEvaluator_h
+#pragma once
 
-#include <wtf/Forward.h>
-#include <wtf/Ref.h>
-#include <wtf/RefCounted.h>
+#include "ExceptionOr.h"
 
 namespace WebCore {
 
-    typedef int ExceptionCode;
+class Node;
+class XPathExpression;
+class XPathNSResolver;
+class XPathResult;
 
-    class Node;
-    class XPathExpression;
-    class XPathNSResolver;
-    class XPathResult;
+class XPathEvaluator : public RefCounted<XPathEvaluator> {
+public:
+    static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); }
 
-    class XPathEvaluator : public RefCounted<XPathEvaluator> {
-    public:
-        static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); }
-        
-        RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
-        Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
-        RefPtr<XPathResult> evaluate(const String& expression, Node* contextNode,
-            RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*, ExceptionCode&);
+    ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
+    Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
+    ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
 
-    private:
-        XPathEvaluator() { }
-    };
+private:
+    XPathEvaluator() = default;
+};
 
 }
-
-#endif // XPathEvaluator_h
index 7d10582..faad618 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Apple Inc.
+ * Copyright (C) 2006 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
     ImplementationLacksVTable,
 ] interface XPathEvaluator {
     // FIXME: Using "undefined" as default parameter value is wrong.
-    [MayThrowLegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
+    [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
 
     XPathNSResolver createNSResolver(optional Node? nodeResolver);
 
     // FIXME: Using "undefined" as default parameter value is wrong.
-    [MayThrowLegacyException] XPathResult evaluate(optional DOMString expression = "undefined",
-                         optional Node? contextNode,
-                         optional XPathNSResolver? resolver,
-                         optional unsigned short type = 0,
-                         optional XPathResult? inResult);
+    [MayThrowException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
 };
index 8d53f03..99aacfd 100644 (file)
@@ -34,7 +34,6 @@
 #include "XPathParser.h"
 #include "XPathResult.h"
 #include "XPathUtil.h"
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -45,49 +44,46 @@ inline XPathExpression::XPathExpression(std::unique_ptr<XPath::Expression> expre
 {
 }
 
-RefPtr<XPathExpression> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
+ExceptionOr<Ref<XPathExpression>> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
 {
-    auto parsedExpression = Parser::parseStatement(expression, WTFMove(resolver), ec);
-    if (!parsedExpression)
-        return nullptr;
+    auto parseResult = Parser::parseStatement(expression, WTFMove(resolver));
+    if (parseResult.hasException())
+        return parseResult.releaseException();
 
-    return adoptRef(*new XPathExpression(WTFMove(parsedExpression)));
+    return adoptRef(*new XPathExpression(parseResult.releaseReturnValue()));
 }
 
 XPathExpression::~XPathExpression()
 {
 }
 
-RefPtr<XPathResult> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode& ec)
+// FIXME: Why does this take an XPathResult that it ignores?
+ExceptionOr<Ref<XPathResult>> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*)
 {
-    if (!isValidContextNode(contextNode)) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
+    if (!isValidContextNode(contextNode))
+        return Exception { NOT_SUPPORTED_ERR };
 
     EvaluationContext& evaluationContext = Expression::evaluationContext();
     evaluationContext.node = contextNode;
     evaluationContext.size = 1;
     evaluationContext.position = 1;
     evaluationContext.hadTypeConversionError = false;
-    RefPtr<XPathResult> result = XPathResult::create(&contextNode->document(), m_topExpression->evaluate());
+    auto result = XPathResult::create(contextNode->document(), m_topExpression->evaluate());
     evaluationContext.node = nullptr; // Do not hold a reference to the context node, as this may prevent the whole document from being destroyed in time.
 
     if (evaluationContext.hadTypeConversionError) {
         // It is not specified what to do if type conversion fails while evaluating an expression, and INVALID_EXPRESSION_ERR is not exactly right
         // when the failure happens in an otherwise valid expression because of a variable. But XPathEvaluator does not support variables, so it's close enough.
-        ec = XPathException::INVALID_EXPRESSION_ERR;
-        return nullptr;
+        return Exception { XPathException::INVALID_EXPRESSION_ERR };
     }
 
     if (type != XPathResult::ANY_TYPE) {
-        ec = 0;
-        result->convertTo(type, ec);
-        if (ec)
-            return nullptr;
+        auto convertToResult = result->convertTo(type);
+        if (convertToResult.hasException())
+            return convertToResult.releaseException();
     }
 
-    return result;
+    return WTFMove(result);
 }
 
 }
index b1eae8a..5a478a8 100644 (file)
@@ -26,8 +26,7 @@
 
 #pragma once
 
-#include <wtf/Forward.h>
-#include <wtf/RefCounted.h>
+#include "ExceptionOr.h"
 
 namespace WebCore {
 
@@ -36,17 +35,15 @@ class XPathNSResolver;
 class XPathResult;
 
 namespace XPath {
-    class Expression;
+class Expression;
 }
 
-using ExceptionCode = int;
-
 class XPathExpression : public RefCounted<XPathExpression> {
 public:
-    static RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
+    static ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
     WEBCORE_EXPORT ~XPathExpression();
 
-    WEBCORE_EXPORT RefPtr<XPathResult> evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(Node* contextNode, unsigned short type, XPathResult*);
 
 private:
     explicit XPathExpression(std::unique_ptr<XPath::Expression>);
index 674ce8d..19758dc 100644 (file)
@@ -22,5 +22,5 @@
     ExportToWrappedFunction,
     ImplementationLacksVTable,
 ] interface XPathExpression {
-    [MayThrowLegacyException] XPathResult evaluate(optional Node? contextNode = null, optional unsigned short type = 0, optional XPathResult? inResult = null);
+    [MayThrowException] XPathResult evaluate(optional Node? contextNode = null, optional unsigned short type = 0, optional XPathResult? inResult = null);
 };
index 01c6fe0..a3cc401 100644 (file)
@@ -32,6 +32,7 @@
 #include "XPathFunctions.h"
 #include "XPathParser.h"
 #include "XPathPath.h"
+#include "XPathStep.h"
 #include "XPathVariableReference.h"
 
 #if COMPILER(MSVC)
index 536619e..6a80da1 100644 (file)
@@ -33,6 +33,7 @@
 #include "XPathException.h"
 #include "XPathNSResolver.h"
 #include "XPathPath.h"
+#include "XPathStep.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringHash.h>
@@ -402,9 +403,6 @@ inline Parser::Token Parser::nextToken()
 Parser::Parser(const String& statement, RefPtr<XPathNSResolver>&& resolver)
     : m_data(statement)
     , m_resolver(WTFMove(resolver))
-    , m_nextPos(0)
-    , m_lastTokenType(0)
-    , m_sawNamespaceError(false)
 {
 }
 
@@ -452,25 +450,20 @@ bool Parser::expandQualifiedName(const String& qualifiedName, String& localName,
         localName = qualifiedName.substring(colon + 1);
     } else
         localName = qualifiedName;
-
     return true;
 }
 
-std::unique_ptr<Expression> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
+ExceptionOr<std::unique_ptr<Expression>> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver)
 {
-    Parser parser(statement, WTFMove(resolver));
+    Parser parser { statement, WTFMove(resolver) };
 
     int parseError = xpathyyparse(parser);
 
-    if (parser.m_sawNamespaceError) {
-        ec = NAMESPACE_ERR;
-        return nullptr;
-    }
+    if (parser.m_sawNamespaceError)
+        return Exception { NAMESPACE_ERR };
 
-    if (parseError) {
-        ec = XPathException::INVALID_EXPRESSION_ERR;
-        return nullptr;
-    }
+    if (parseError)
+        return Exception { XPathException::INVALID_EXPRESSION_ERR };
 
     return WTFMove(parser.m_result);
 }
index e419591..68289ca 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef XPathParser_h
-#define XPathParser_h
+#pragma once
 
-#include "XPathStep.h"
+#include "ExceptionOr.h"
 #include "XPathPredicate.h"
 
 union YYSTYPE;
 
 namespace WebCore {
 
-    typedef int ExceptionCode;
+class XPathNSResolver;
 
-    class XPathNSResolver;
+namespace XPath {
 
-    namespace XPath {
+class Parser {
+    WTF_MAKE_NONCOPYABLE(Parser);
+public:
+    static ExceptionOr<std::unique_ptr<Expression>> parseStatement(const String& statement, RefPtr<XPathNSResolver>&&);
 
-        class Parser {
-            WTF_MAKE_NONCOPYABLE(Parser);
-        public:
-            static std::unique_ptr<Expression> parseStatement(const String& statement, RefPtr<XPathNSResolver>&&, ExceptionCode&);
+    int lex(YYSTYPE&);
+    bool expandQualifiedName(const String& qualifiedName, String& localName, String& namespaceURI);
+    void setParseResult(std::unique_ptr<Expression>&& expression) { m_result = WTFMove(expression); }
 
-            int lex(YYSTYPE&);
-            bool expandQualifiedName(const String& qualifiedName, String& localName, String& namespaceURI);
-            void setParseResult(std::unique_ptr<Expression> expression) { m_result = WTFMove(expression); }
+private:
+    Parser(const String&, RefPtr<XPathNSResolver>&&);
 
-        private:
-            Parser(const String&, RefPtr<XPathNSResolver>&&);
+    struct Token;
 
-            struct Token;
+    bool isBinaryOperatorContext() const;
 
-            bool isBinaryOperatorContext() const;
+    void skipWS();
+    Token makeTokenAndAdvance(int type, int advance = 1);
+    Token makeTokenAndAdvance(int type, NumericOp::Opcode, int advance = 1);
+    Token makeTokenAndAdvance(int type, EqTestOp::Opcode, int advance = 1);
+    char peekAheadHelper();
+    char peekCurHelper();
 
-            void skipWS();
-            Token makeTokenAndAdvance(int type, int advance = 1);
-            Token makeTokenAndAdvance(int type, NumericOp::Opcode, int advance = 1);
-            Token makeTokenAndAdvance(int type, EqTestOp::Opcode, int advance = 1);
-            char peekAheadHelper();
-            char peekCurHelper();
+    Token lexString();
+    Token lexNumber();
+    bool lexNCName(String&);
+    bool lexQName(String&);
 
-            Token lexString();
-            Token lexNumber();
-            bool lexNCName(String&);
-            bool lexQName(String&);
+    Token nextToken();
+    Token nextTokenInternal();
 
-            Token nextToken();
-            Token nextTokenInternal();
+    const String& m_data;
+    RefPtr<XPathNSResolver> m_resolver;
 
-            const String& m_data;
-            RefPtr<XPathNSResolver> m_resolver;
+    unsigned m_nextPos { 0 };
+    int m_lastTokenType { 0 };
 
-            unsigned m_nextPos;
-            int m_lastTokenType;
+    std::unique_ptr<Expression> m_result;
+    bool m_sawNamespaceError { false };
+};
 
-            std::unique_ptr<Expression> m_result;
-            bool m_sawNamespaceError;
-        };
-
-    }
-}
-
-#endif
+} }
index 9cf5746..7508c02 100644 (file)
@@ -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 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 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];
 }
 
index bc02a15..aea8535 100644 (file)
 
 #pragma once
 
+#include "ExceptionOr.h"
 #include "XPathValue.h"
-#include <wtf/Forward.h>
-#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
-    typedef int ExceptionCode;
+class XPathResult : public RefCounted<XPathResult> {
+public:
+    enum XPathResultType {
+        ANY_TYPE = 0,
+        NUMBER_TYPE = 1,
+        STRING_TYPE = 2,
+        BOOLEAN_TYPE = 3,
+        UNORDERED_NODE_ITERATOR_TYPE = 4,
+        ORDERED_NODE_ITERATOR_TYPE = 5,
+        UNORDERED_NODE_SNAPSHOT_TYPE = 6,
+        ORDERED_NODE_SNAPSHOT_TYPE = 7,
+        ANY_UNORDERED_NODE_TYPE = 8,
+        FIRST_ORDERED_NODE_TYPE = 9
+    };
 
-    class Document;
-    class Node;
+    static Ref<XPathResult> create(Document& document, const XPath::Value& value) { return adoptRef(*new XPathResult(document, value)); }
+    WEBCORE_EXPORT ~XPathResult();
 
-    class XPathResult : public RefCounted<XPathResult> {
-    public:
-        enum XPathResultType {
-            ANY_TYPE = 0,
-            NUMBER_TYPE = 1,
-            STRING_TYPE = 2,
-            BOOLEAN_TYPE = 3,
-            UNORDERED_NODE_ITERATOR_TYPE = 4,
-            ORDERED_NODE_ITERATOR_TYPE = 5,
-            UNORDERED_NODE_SNAPSHOT_TYPE = 6,
-            ORDERED_NODE_SNAPSHOT_TYPE = 7,
-            ANY_UNORDERED_NODE_TYPE = 8,
-            FIRST_ORDERED_NODE_TYPE = 9
-        };
-        
-        static Ref<XPathResult> create(Document* document, const XPath::Value& value) { return adoptRef(*new XPathResult(document, value)); }
-        WEBCORE_EXPORT ~XPathResult();
-        
-        void convertTo(unsigned short type, ExceptionCode&);
+    ExceptionOr<void> convertTo(unsigned short type);
 
-        WEBCORE_EXPORT unsigned short resultType() const;
+    WEBCORE_EXPORT unsigned short resultType() const;
 
-        WEBCORE_EXPORT double numberValue(ExceptionCode&) const;
-        WEBCORE_EXPORT String stringValue(ExceptionCode&) const;
-        WEBCORE_EXPORT bool booleanValue(ExceptionCode&) const;
-        WEBCORE_EXPORT Node* singleNodeValue(ExceptionCode&) const;
+    WEBCORE_EXPORT ExceptionOr<double> numberValue() const;
+    WEBCORE_EXPORT ExceptionOr<String> stringValue() const;
+    WEBCORE_EXPORT ExceptionOr<bool> booleanValue() const;
+    WEBCORE_EXPORT ExceptionOr<Node*> singleNodeValue() const;
 
-        WEBCORE_EXPORT bool invalidIteratorState() const;
-        WEBCORE_EXPORT unsigned snapshotLength(ExceptionCode&) const;
-        WEBCORE_EXPORT Node* iterateNext(ExceptionCode&);
-        WEBCORE_EXPORT Node* snapshotItem(unsigned index, ExceptionCode&);
+    WEBCORE_EXPORT bool invalidIteratorState() const;
+    WEBCORE_EXPORT ExceptionOr<unsigned> snapshotLength() const;
+    WEBCORE_EXPORT ExceptionOr<Node*> iterateNext();
+    WEBCORE_EXPORT ExceptionOr<Node*> snapshotItem(unsigned index);
 
-        const XPath::Value& value() const { return m_value; }
+    const XPath::Value& value() const { return m_value; }
 
-    private:
-        XPathResult(Document*, const XPath::Value&);
-        
-        XPath::Value m_value;
-        unsigned m_nodeSetPosition;
-        XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value?
-        unsigned short m_resultType;
-        RefPtr<Document> m_document;
-        uint64_t m_domTreeVersion;
-    };
+private:
+    XPathResult(Document&, const XPath::Value&);
+
+    XPath::Value m_value;
+    unsigned m_nodeSetPosition { 0 };
+    XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value?
+    unsigned short m_resultType;
+    RefPtr<Document> m_document;
+    uint64_t m_domTreeVersion { 0 };
+};
 
 } // namespace WebCore
index cdacb66..9752cf6 100644 (file)
     const unsigned short FIRST_ORDERED_NODE_TYPE = 9;
 
     readonly attribute unsigned short resultType;
-    [GetterMayThrowLegacyException] readonly attribute unrestricted double numberValue;
-    [GetterMayThrowLegacyException] readonly attribute DOMString stringValue;
-    [GetterMayThrowLegacyException] readonly attribute boolean booleanValue;
-    [GetterMayThrowLegacyException] readonly attribute Node singleNodeValue;
+    [GetterMayThrowException] readonly attribute unrestricted double numberValue;
+    [GetterMayThrowException] readonly attribute DOMString stringValue;
+    [GetterMayThrowException] readonly attribute boolean booleanValue;
+    [GetterMayThrowException] readonly attribute Node singleNodeValue;
 
     readonly attribute boolean invalidIteratorState;
-    [GetterMayThrowLegacyException] readonly attribute unsigned long snapshotLength;
+    [GetterMayThrowException] readonly attribute unsigned long snapshotLength;
 
-    [MayThrowLegacyException] Node iterateNext();
-    [MayThrowLegacyException] Node snapshotItem(optional unsigned long index = 0);
+    [MayThrowException] Node iterateNext();
+    [MayThrowException] Node snapshotItem(optional unsigned long index = 0);
 };
index 15819b8..f0a581c 100644 (file)
@@ -1,3 +1,25 @@
+2016-10-19  Darin Adler  <darin@apple.com>
+
+        Move XPath from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=163656
+
+        Reviewed by Chris Dumez.
+
+        * DOM/DOMDocument.mm:
+        (wrap): Added. Helper function for wrapping a resolver.
+        (-[DOMDocument createExpression:resolver:]): Use raiseOnDOMError.
+        (-[DOMDocument evaluate:contextNode:resolver:type:inResult:]): Ditto.
+        * DOM/DOMXPathExpression.mm:
+        (-[DOMXPathExpression evaluate:type:inResult:]): Ditto.
+        * DOM/DOMXPathResult.mm:
+        (-[DOMXPathResult numberValue]): Ditto.
+        (-[DOMXPathResult stringValue]): Ditto.
+        (-[DOMXPathResult booleanValue]): Ditto.
+        (-[DOMXPathResult singleNodeValue]): Ditto.
+        (-[DOMXPathResult snapshotLength]): Ditto.
+        (-[DOMXPathResult iterateNext]): Ditto.
+        (-[DOMXPathResult snapshotItem:]): Ditto.
+
 2016-10-18  Sam Weinig  <sam@webkit.org>
 
         Replace std::experimental::variant with WTF::Variant (or similar)
index a2a0caa..fe196f1 100644 (file)
     return kit(WTF::getPtr(IMPL->getOverrideStyle(core(element), pseudoElement)));
 }
 
+static RefPtr<WebCore::XPathNSResolver> wrap(id <DOMXPathNSResolver> resolver)
+{
+    if (!resolver)
+        return nullptr;
+    if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
+        return core(static_cast<DOMNativeXPathNSResolver *>(resolver));
+    return DOMCustomXPathNSResolver::create(resolver);
+}
+
 - (DOMXPathExpression *)createExpression:(NSString *)expression resolver:(id <DOMXPathNSResolver>)resolver
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::XPathNSResolver* nativeResolver = 0;
-    RefPtr<WebCore::XPathNSResolver> customResolver;
-    if (resolver) {
-        if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
-            nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>(resolver));
-        else {
-            customResolver = DOMCustomXPathNSResolver::create(resolver);
-            nativeResolver = WTF::getPtr(customResolver);
-        }
-    }
-    WebCore::ExceptionCode ec = 0;
-    DOMXPathExpression *result = kit(WTF::getPtr(IMPL->createExpression(expression, WTF::getPtr(nativeResolver), ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->createExpression(expression, wrap(resolver))).ptr());
 }
 
 - (id <DOMXPathNSResolver>)createNSResolver:(DOMNode *)nodeResolver
 - (DOMXPathResult *)evaluate:(NSString *)expression contextNode:(DOMNode *)contextNode resolver:(id <DOMXPathNSResolver>)resolver type:(unsigned short)type inResult:(DOMXPathResult *)inResult
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::XPathNSResolver* nativeResolver = 0;
-    RefPtr<WebCore::XPathNSResolver> customResolver;
-    if (resolver) {
-        if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
-            nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>(resolver));
-        else {
-            customResolver = DOMCustomXPathNSResolver::create(resolver);
-            nativeResolver = WTF::getPtr(customResolver);
-        }
-    }
-    WebCore::ExceptionCode ec = 0;
-    DOMXPathResult *result = kit(WTF::getPtr(IMPL->evaluate(expression, core(contextNode), WTF::getPtr(nativeResolver), type, core(inResult), ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->evaluate(expression, core(contextNode), wrap(resolver), type, core(inResult))).ptr());
 }
 
 - (BOOL)execCommand:(NSString *)command userInterface:(BOOL)userInterface value:(NSString *)value
index 31e7907..0e0e069 100644 (file)
 - (DOMXPathResult *)evaluate:(DOMNode *)contextNode type:(unsigned short)type inResult:(DOMXPathResult *)inResult
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMXPathResult *result = kit(WTF::getPtr(IMPL->evaluate(core(contextNode), type, core(inResult), ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->evaluate(core(contextNode), type, core(inResult))).ptr());
 }
 
 @end
index 14d7e41..9e21ffc 100644 (file)
 - (double)numberValue
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    double result = IMPL->numberValue(ec);
-    raiseOnDOMError(ec);
-    return result;
+    return raiseOnDOMError(IMPL->numberValue());
 }
 
 - (NSString *)stringValue
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    NSString *result = IMPL->stringValue(ec);
-    raiseOnDOMError(ec);
-    return result;
+    return raiseOnDOMError(IMPL->stringValue());
 }
 
 - (BOOL)booleanValue
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    BOOL result = IMPL->booleanValue(ec);
-    raiseOnDOMError(ec);
-    return result;
+    return raiseOnDOMError(IMPL->booleanValue());
 }
 
 - (DOMNode *)singleNodeValue
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMNode *result = kit(WTF::getPtr(IMPL->singleNodeValue(ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->singleNodeValue()));
 }
 
 - (BOOL)invalidIteratorState
 - (unsigned)snapshotLength
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    unsigned result = IMPL->snapshotLength(ec);
-    raiseOnDOMError(ec);
-    return result;
+    return raiseOnDOMError(IMPL->snapshotLength());
 }
 
 - (DOMNode *)iterateNext
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMNode *result = kit(WTF::getPtr(IMPL->iterateNext(ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->iterateNext()));
 }
 
 - (DOMNode *)snapshotItem:(unsigned)index
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMNode *result = kit(WTF::getPtr(IMPL->snapshotItem(index, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->snapshotItem(index)));
 }
 
 @end
 
 WebCore::XPathResult* core(DOMXPathResult *wrapper)
 {
-    return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : 0;
+    return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : nullptr;
 }
 
 DOMXPathResult *kit(WebCore::XPathResult* value)
index 058c754..f96c946 100644 (file)
@@ -1,3 +1,24 @@
+2016-10-19  Darin Adler  <darin@apple.com>
+
+        Move XPath from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=163656
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp:
+        (webkit_dom_document_create_expression): Use ExceptionOr.
+        (webkit_dom_document_evaluate): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp:
+        (webkit_dom_xpath_expression_evaluate): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp:
+        (webkit_dom_xpath_result_iterate_next): Ditto.
+        (webkit_dom_xpath_result_snapshot_item): Ditto.
+        (webkit_dom_xpath_result_get_number_value): Ditto.
+        (webkit_dom_xpath_result_get_string_value): Ditto.
+        (webkit_dom_xpath_result_get_boolean_value): Ditto.
+        (webkit_dom_xpath_result_get_single_node_value): Ditto.
+        (webkit_dom_xpath_result_get_snapshot_length): Ditto.
+
 2016-10-19  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         NetworkSession: updatedRequest parameter of NetworkProcess::findPendingDownloadLocation is unused since r206988
index e282ab4..15a5897 100644 (file)
@@ -1169,13 +1169,13 @@ WebKitDOMXPathExpression* webkit_dom_document_create_expression(WebKitDOMDocumen
     WebCore::Document* item = WebKit::core(self);
     WTF::String convertedExpression = WTF::String::fromUTF8(expression);
     RefPtr<WebCore::XPathNSResolver> convertedResolver = WebKit::core(resolver);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::XPathExpression> gobjectResult = WTF::getPtr(item->createExpression(convertedExpression, WTF::getPtr(convertedResolver), ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->createExpression(convertedExpression, WTFMove(convertedResolver));
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
 WebKitDOMXPathNSResolver* webkit_dom_document_create_ns_resolver(WebKitDOMDocument* self, WebKitDOMNode* nodeResolver)
@@ -1203,13 +1203,13 @@ WebKitDOMXPathResult* webkit_dom_document_evaluate(WebKitDOMDocument* self, cons
     WebCore::Node* convertedContextNode = WebKit::core(contextNode);
     RefPtr<WebCore::XPathNSResolver> convertedResolver = WebKit::core(resolver);
     WebCore::XPathResult* convertedInResult = WebKit::core(inResult);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::XPathResult> gobjectResult = WTF::getPtr(item->evaluate(convertedExpression, convertedContextNode, WTF::getPtr(convertedResolver), type, convertedInResult, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->evaluate(convertedExpression, convertedContextNode, WTFMove(convertedResolver), type, convertedInResult);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
 gboolean webkit_dom_document_exec_command(WebKitDOMDocument* self, const gchar* command, gboolean userInterface, const gchar* value)
index 4d7c939..9ed937b 100644 (file)
@@ -114,12 +114,12 @@ WebKitDOMXPathResult* webkit_dom_xpath_expression_evaluate(WebKitDOMXPathExpress
     WebCore::XPathExpression* item = WebKit::core(self);
     WebCore::Node* convertedContextNode = WebKit::core(contextNode);
     WebCore::XPathResult* convertedInResult = WebKit::core(inResult);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::XPathResult> gobjectResult = WTF::getPtr(item->evaluate(convertedContextNode, type, convertedInResult, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->evaluate(convertedContextNode, type, convertedInResult);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
index 919f0aa..fc75c07 100644 (file)
@@ -224,13 +224,13 @@ WebKitDOMNode* webkit_dom_xpath_result_iterate_next(WebKitDOMXPathResult* self,
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->iterateNext(ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->iterateNext();
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 WebKitDOMNode* webkit_dom_xpath_result_snapshot_item(WebKitDOMXPathResult* self, gulong index, GError** error)
@@ -239,13 +239,13 @@ WebKitDOMNode* webkit_dom_xpath_result_snapshot_item(WebKitDOMXPathResult* self,
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->snapshotItem(index, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->snapshotItem(index);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 gushort webkit_dom_xpath_result_get_result_type(WebKitDOMXPathResult* self)
@@ -263,13 +263,13 @@ gdouble webkit_dom_xpath_result_get_number_value(WebKitDOMXPathResult* self, GEr
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    gdouble result = item->numberValue(ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->numberValue();
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return 0;
     }
-    return result;
+    return result.releaseReturnValue();
 }
 
 gchar* webkit_dom_xpath_result_get_string_value(WebKitDOMXPathResult* self, GError** error)
@@ -278,9 +278,10 @@ gchar* webkit_dom_xpath_result_get_string_value(WebKitDOMXPathResult* self, GErr
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    gchar* result = convertToUTF8String(item->stringValue(ec));
-    return result;
+    auto result = item->stringValue();
+    if (result.hasException())
+        return nullptr;
+    return convertToUTF8String(result.releaseReturnValue());
 }
 
 gboolean webkit_dom_xpath_result_get_boolean_value(WebKitDOMXPathResult* self, GError** error)
@@ -289,13 +290,13 @@ gboolean webkit_dom_xpath_result_get_boolean_value(WebKitDOMXPathResult* self, G
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), FALSE);
     g_return_val_if_fail(!error || !*error, FALSE);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    gboolean result = item->booleanValue(ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->booleanValue();
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return false;
     }
-    return result;
+    return result.releaseReturnValue();
 }
 
 WebKitDOMNode* webkit_dom_xpath_result_get_single_node_value(WebKitDOMXPathResult* self, GError** error)
@@ -304,13 +305,13 @@ WebKitDOMNode* webkit_dom_xpath_result_get_single_node_value(WebKitDOMXPathResul
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->singleNodeValue(ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->singleNodeValue();
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 gboolean webkit_dom_xpath_result_get_invalid_iterator_state(WebKitDOMXPathResult* self)
@@ -328,12 +329,11 @@ gulong webkit_dom_xpath_result_get_snapshot_length(WebKitDOMXPathResult* self, G
     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::XPathResult* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    gulong result = item->snapshotLength(ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->snapshotLength();
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     }
-    return result;
+    return result.releaseReturnValue();
 }