Ignore:
Timestamp:
Oct 19, 2016, 9:57:31 AM (9 years ago)
Author:
Darin Adler
Message:

Move XPath from ExceptionCode to Exception
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/xml/XPathExpression.cpp

    r200550 r207541  
    3535#include "XPathResult.h"
    3636#include "XPathUtil.h"
    37 #include <wtf/text/WTFString.h>
    3837
    3938namespace WebCore {
     
    4645}
    4746
    48 RefPtr<XPathExpression> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
     47ExceptionOr<Ref<XPathExpression>> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
    4948{
    50     auto parsedExpression = Parser::parseStatement(expression, WTFMove(resolver), ec);
    51     if (!parsedExpression)
    52         return nullptr;
     49    auto parseResult = Parser::parseStatement(expression, WTFMove(resolver));
     50    if (parseResult.hasException())
     51        return parseResult.releaseException();
    5352
    54     return adoptRef(*new XPathExpression(WTFMove(parsedExpression)));
     53    return adoptRef(*new XPathExpression(parseResult.releaseReturnValue()));
    5554}
    5655
     
    5958}
    6059
    61 RefPtr<XPathResult> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode& ec)
     60// FIXME: Why does this take an XPathResult that it ignores?
     61ExceptionOr<Ref<XPathResult>> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*)
    6262{
    63     if (!isValidContextNode(contextNode)) {
    64         ec = NOT_SUPPORTED_ERR;
    65         return nullptr;
    66     }
     63    if (!isValidContextNode(contextNode))
     64        return Exception { NOT_SUPPORTED_ERR };
    6765
    6866    EvaluationContext& evaluationContext = Expression::evaluationContext();
     
    7169    evaluationContext.position = 1;
    7270    evaluationContext.hadTypeConversionError = false;
    73     RefPtr<XPathResult> result = XPathResult::create(&contextNode->document(), m_topExpression->evaluate());
     71    auto result = XPathResult::create(contextNode->document(), m_topExpression->evaluate());
    7472    evaluationContext.node = nullptr; // Do not hold a reference to the context node, as this may prevent the whole document from being destroyed in time.
    7573
     
    7775        // It is not specified what to do if type conversion fails while evaluating an expression, and INVALID_EXPRESSION_ERR is not exactly right
    7876        // when the failure happens in an otherwise valid expression because of a variable. But XPathEvaluator does not support variables, so it's close enough.
    79         ec = XPathException::INVALID_EXPRESSION_ERR;
    80         return nullptr;
     77        return Exception { XPathException::INVALID_EXPRESSION_ERR };
    8178    }
    8279
    8380    if (type != XPathResult::ANY_TYPE) {
    84         ec = 0;
    85         result->convertTo(type, ec);
    86         if (ec)
    87             return nullptr;
     81        auto convertToResult = result->convertTo(type);
     82        if (convertToResult.hasException())
     83            return convertToResult.releaseException();
    8884    }
    8985
    90     return result;
     86    return WTFMove(result);
    9187}
    9288
Note: See TracChangeset for help on using the changeset viewer.