Changeset 207541 in webkit


Ignore:
Timestamp:
Oct 19, 2016 9:57:31 AM (8 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.

Location:
trunk/Source
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207540 r207541  
     12016-10-19  Darin Adler  <darin@apple.com>
     2
     3        Move XPath from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=163656
     5
     6        Reviewed by Chris Dumez.
     7
     8        * dom/Document.cpp:
     9        (WebCore::Document::createExpression): Use ExceptionOr.
     10        (WebCore::Document::createNSResolver): Return Ref.
     11        (WebCore::Document::evaluate): Use ExceptionOr.
     12        * dom/Document.h: Updated for above changes.
     13        * dom/Document.idl: Use non-legacy exceptions for the functions above.
     14
     15        * inspector/InspectorNodeFinder.cpp:
     16        (WebCore::InspectorNodeFinder::searchUsingXPath): Call XPath functions
     17        with new interface.
     18
     19        * xml/DOMParser.cpp:
     20        (WebCore::DOMParser::DOMParser): Marked inline.
     21        (WebCore::DOMParser::create): Moved here from header.
     22        (WebCore::DOMParser::parseFromString): Use ExceptionOr.
     23        * xml/DOMParser.h: Updated for above changes.
     24        * xml/DOMParser.idl: Use non-legacy exception.
     25
     26        * xml/XPathEvaluator.cpp:
     27        (WebCore::XPathEvaluator::createExpression): Use ExceptionOr.
     28        (WebCore::XPathEvaluator::evaluate): Ditto.
     29        * xml/XPathEvaluator.h: Updated for above changes.
     30        * xml/XPathEvaluator.idl: Use non-legacy exceptions.
     31
     32        * xml/XPathExpression.cpp:
     33        (WebCore::XPathExpression::createExpression): Use ExceptionOr.
     34        (WebCore::XPathExpression::evaluate): Ditto.
     35        * xml/XPathExpression.h: Updated for above changes.
     36        * xml/XPathExpression.idl: Use non-legacy exceptions.
     37
     38        * xml/XPathGrammar.y: Added include of XPathStep.h.
     39
     40        * xml/XPathParser.cpp:
     41        (WebCore::XPath::Parser::Parser): Initialize three scalar data members
     42        in the class definition rather than here.
     43        (WebCore::XPath::Parser::parseStatement): Use ExceptionOr.
     44        * xml/XPathParser.h: Updated for above changes.
     45
     46        * xml/XPathResult.cpp:
     47        (WebCore::XPathResult::XPathResult): Use a reference rather than a
     48        pointer for the document. Alao initialize two scalar data members
     49        in the class definition rather than here.
     50        (WebCore::XPathResult::convertTo): Use ExceptionOr.
     51        (WebCore::XPathResult::numberValue): Ditto.
     52        (WebCore::XPathResult::stringValue): Ditto.
     53        (WebCore::XPathResult::booleanValue): Ditto.
     54        (WebCore::XPathResult::singleNodeValue): Ditto.
     55        (WebCore::XPathResult::snapshotLength): Ditto.
     56        (WebCore::XPathResult::iterateNext): Ditto.
     57        (WebCore::XPathResult::snapshotItem): Ditto.
     58        * xml/XPathResult.h: Updated for the changes above.
     59        * xml/XPathResult.idl: Use non-legacy exceptions.
     60
    1612016-10-19  Nan Wang  <n_wang@apple.com>
    262
  • trunk/Source/WebCore/dom/Document.cpp

    r207486 r207541  
    51185118#endif
    51195119
    5120 RefPtr<XPathExpression> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
     5120ExceptionOr<Ref<XPathExpression>> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
    51215121{
    51225122    if (!m_xpathEvaluator)
    51235123        m_xpathEvaluator = XPathEvaluator::create();
    5124     return m_xpathEvaluator->createExpression(expression, WTFMove(resolver), ec);
    5125 }
    5126 
    5127 RefPtr<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
     5124    return m_xpathEvaluator->createExpression(expression, WTFMove(resolver));
     5125}
     5126
     5127Ref<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
    51285128{
    51295129    if (!m_xpathEvaluator)
     
    51325132}
    51335133
    5134 RefPtr<XPathResult> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)
     5134ExceptionOr<Ref<XPathResult>> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result)
    51355135{
    51365136    if (!m_xpathEvaluator)
    51375137        m_xpathEvaluator = XPathEvaluator::create();
    5138     return m_xpathEvaluator->evaluate(expression, contextNode, WTFMove(resolver), type, result, ec);
     5138    return m_xpathEvaluator->evaluate(expression, contextNode, WTFMove(resolver), type, result);
    51395139}
    51405140
  • trunk/Source/WebCore/dom/Document.h

    r207372 r207541  
    3333#include "DocumentEventQueue.h"
    3434#include "DocumentTiming.h"
     35#include "ExceptionOr.h"
    3536#include "FocusDirection.h"
    3637#include "FontSelectorClient.h"
     
    944945
    945946    // XPathEvaluator methods
    946     WEBCORE_EXPORT RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
    947     WEBCORE_EXPORT RefPtr<XPathNSResolver> createNSResolver(Node* nodeResolver);
    948     WEBCORE_EXPORT RefPtr<XPathResult> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*, ExceptionCode&);
     947    WEBCORE_EXPORT ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
     948    WEBCORE_EXPORT Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
     949    WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
    949950
    950951    enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
  • trunk/Source/WebCore/dom/Document.idl

    r207355 r207541  
    7777
    7878    // FIXME: Using "undefined" as default parameter value is wrong.
    79     [MayThrowLegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
     79    [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
    8080    XPathNSResolver createNSResolver(Node? nodeResolver);
    8181
    8282    // FIXME: Using "undefined" as default parameter value is wrong.
    83     [MayThrowLegacyException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver,
    84         optional unsigned short type = 0, optional XPathResult? inResult);
     83    [MayThrowException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
    8584
    8685    // FIXME: The default value for the last parameter should be the empty string.
  • trunk/Source/WebCore/inspector/InspectorNodeFinder.cpp

    r200550 r207541  
    133133void InspectorNodeFinder::searchUsingXPath(Node* parentNode)
    134134{
    135     ExceptionCode ec = 0;
    136     RefPtr<XPathResult> result = parentNode->document().evaluate(m_whitespaceTrimmedQuery, parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr, ec);
    137     if (ec || !result)
     135    auto evaluateResult = parentNode->document().evaluate(m_whitespaceTrimmedQuery, parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr);
     136    if (evaluateResult.hasException())
    138137        return;
     138    auto result = evaluateResult.releaseReturnValue();
    139139
    140     unsigned long size = result->snapshotLength(ec);
    141     if (ec)
     140    auto snapshotLengthResult = result->snapshotLength();
     141    if (snapshotLengthResult.hasException())
    142142        return;
     143    unsigned size = snapshotLengthResult.releaseReturnValue();
    143144
    144     for (unsigned long i = 0; i < size; ++i) {
    145         Node* node = result->snapshotItem(i, ec);
    146         if (ec)
     145    for (unsigned i = 0; i < size; ++i) {
     146        auto snapshotItemResult = result->snapshotItem(i);
     147        if (snapshotItemResult.hasException())
    147148            return;
     149        Node* node = snapshotItemResult.releaseReturnValue();
    148150
    149151        if (is<Attr>(*node))
  • trunk/Source/WebCore/xml/DOMParser.cpp

    r206469 r207541  
    2222#include "DOMImplementation.h"
    2323#include "ExceptionCode.h"
    24 #include <wtf/text/WTFString.h>
    2524
    2625namespace WebCore {
    2726
    28 DOMParser::DOMParser(Document& contextDocument)
     27inline DOMParser::DOMParser(Document& contextDocument)
    2928    : m_contextDocument(contextDocument.createWeakPtr())
    3029{
    3130}
    3231
    33 RefPtr<Document> DOMParser::parseFromString(const String& string, const String& contentType, ExceptionCode& ec)
     32Ref<DOMParser> DOMParser::create(Document& contextDocument)
    3433{
    35     if (contentType != "text/html"
    36         && contentType != "text/xml"
    37         && contentType != "application/xml"
    38         && contentType != "application/xhtml+xml"
    39         && contentType != "image/svg+xml") {
    40         ec = TypeError;
    41         return nullptr;
    42     }
     34    return adoptRef(*new DOMParser(contextDocument));
     35}
    4336
    44     Ref<Document> document = DOMImplementation::createDocument(contentType, nullptr, URL());
     37ExceptionOr<Ref<Document>> DOMParser::parseFromString(const String& string, const String& contentType)
     38{
     39    if (contentType != "text/html" && contentType != "text/xml" && contentType != "application/xml" && contentType != "application/xhtml+xml" && contentType != "image/svg+xml")
     40        return Exception { TypeError };
     41    auto document = DOMImplementation::createDocument(contentType, nullptr, URL { });
    4542    if (m_contextDocument)
    4643        document->setContextDocument(*m_contextDocument.get());
  • trunk/Source/WebCore/xml/DOMParser.h

    r206469 r207541  
    11/*
    2  *  Copyright (C) 2003, 2006 Apple Inc.
     2 *  Copyright (C) 2003, 2006 Apple Inc. All rights reserved.
    33 *
    44 *  This library is free software; you can redistribute it and/or
     
    1717 */
    1818
    19 #ifndef DOMParser_h
    20 #define DOMParser_h
     19#pragma once
    2120
    22 #include <wtf/Forward.h>
    23 #include <wtf/RefCounted.h>
    24 #include <wtf/RefPtr.h>
     21#include "ExceptionOr.h"
    2522#include <wtf/WeakPtr.h>
    2623
    2724namespace WebCore {
    28 typedef int ExceptionCode;
    2925
    3026class Document;
     
    3228class DOMParser : public RefCounted<DOMParser> {
    3329public:
    34     static Ref<DOMParser> create(Document& contextDocument)
    35     {
    36         return adoptRef(*new DOMParser(contextDocument));
    37     }
    38 
    39     RefPtr<Document> parseFromString(const String&, const String& contentType, ExceptionCode&);
     30    static Ref<DOMParser> create(Document& contextDocument);
     31    ExceptionOr<Ref<Document>> parseFromString(const String&, const String& contentType);
    4032
    4133private:
     
    4638
    4739}
    48 
    49 #endif // XMLSerializer.h
  • trunk/Source/WebCore/xml/DOMParser.idl

    r206723 r207541  
    11/*
    2  * Copyright (C) 2006 Apple Inc.
     2 * Copyright (C) 2006 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    2323    ImplementationLacksVTable,
    2424] interface DOMParser {
    25     [MayThrowLegacyException, NewObject] Document parseFromString(DOMString str, DOMString contentType);
     25    [MayThrowException, NewObject] Document parseFromString(DOMString string, DOMString contentType);
    2626};
  • trunk/Source/WebCore/xml/XPathEvaluator.cpp

    r200550 r207541  
    3838using namespace XPath;
    3939
    40 RefPtr<XPathExpression> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
     40ExceptionOr<Ref<XPathExpression>> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver)
    4141{
    42     return XPathExpression::createExpression(expression, WTFMove(resolver), ec);
     42    return XPathExpression::createExpression(expression, WTFMove(resolver));
    4343}
    4444
     
    4848}
    4949
    50 RefPtr<XPathResult> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)
     50ExceptionOr<Ref<XPathResult>> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result)
    5151{
    52     if (!isValidContextNode(contextNode)) {
    53         ec = NOT_SUPPORTED_ERR;
    54         return nullptr;
    55     }
     52    if (!isValidContextNode(contextNode))
     53        return Exception { NOT_SUPPORTED_ERR };
    5654
    57     ec = 0;
    58     RefPtr<XPathExpression> expr = createExpression(expression, WTFMove(resolver), ec);
    59     if (ec)
    60         return nullptr;
    61    
    62     return expr->evaluate(contextNode, type, result, ec);
     55    auto createResult = createExpression(expression, WTFMove(resolver));
     56    if (createResult.hasException())
     57        return createResult.releaseException();
     58
     59    return createResult.releaseReturnValue()->evaluate(contextNode, type, result);
    6360}
    6461
  • trunk/Source/WebCore/xml/XPathEvaluator.h

    r200550 r207541  
    11/*
    22 * Copyright 2005 Frerich Raabe <raabe@kde.org>
    3  * Copyright (C) 2006 Apple Inc.
     3 * Copyright (C) 2006 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    2525 */
    2626
    27 #ifndef XPathEvaluator_h
    28 #define XPathEvaluator_h
     27#pragma once
    2928
    30 #include <wtf/Forward.h>
    31 #include <wtf/Ref.h>
    32 #include <wtf/RefCounted.h>
     29#include "ExceptionOr.h"
    3330
    3431namespace WebCore {
    3532
    36     typedef int ExceptionCode;
     33class Node;
     34class XPathExpression;
     35class XPathNSResolver;
     36class XPathResult;
    3737
    38     class Node;
    39     class XPathExpression;
    40     class XPathNSResolver;
    41     class XPathResult;
     38class XPathEvaluator : public RefCounted<XPathEvaluator> {
     39public:
     40    static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); }
    4241
    43     class XPathEvaluator : public RefCounted<XPathEvaluator> {
    44     public:
    45         static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); }
    46        
    47         RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
    48         Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
    49         RefPtr<XPathResult> evaluate(const String& expression, Node* contextNode,
    50             RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*, ExceptionCode&);
     42    ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
     43    Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
     44    ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
    5145
    52     private:
    53         XPathEvaluator() { }
    54     };
     46private:
     47    XPathEvaluator() = default;
     48};
    5549
    5650}
    57 
    58 #endif // XPathEvaluator_h
  • trunk/Source/WebCore/xml/XPathEvaluator.idl

    r206723 r207541  
    11/*
    2  * Copyright (C) 2006 Apple Inc.
     2 * Copyright (C) 2006 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    2323] interface XPathEvaluator {
    2424    // FIXME: Using "undefined" as default parameter value is wrong.
    25     [MayThrowLegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
     25    [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);
    2626
    2727    XPathNSResolver createNSResolver(optional Node? nodeResolver);
    2828
    2929    // FIXME: Using "undefined" as default parameter value is wrong.
    30     [MayThrowLegacyException] XPathResult evaluate(optional DOMString expression = "undefined",
    31                          optional Node? contextNode,
    32                          optional XPathNSResolver? resolver,
    33                          optional unsigned short type = 0,
    34                          optional XPathResult? inResult);
     30    [MayThrowException] XPathResult evaluate(optional DOMString expression = "undefined", optional Node? contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
    3531};
  • 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
  • trunk/Source/WebCore/xml/XPathExpression.h

    r204717 r207541  
    2727#pragma once
    2828
    29 #include <wtf/Forward.h>
    30 #include <wtf/RefCounted.h>
     29#include "ExceptionOr.h"
    3130
    3231namespace WebCore {
     
    3736
    3837namespace XPath {
    39     class Expression;
     38class Expression;
    4039}
    41 
    42 using ExceptionCode = int;
    4340
    4441class XPathExpression : public RefCounted<XPathExpression> {
    4542public:
    46     static RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);
     43    static ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
    4744    WEBCORE_EXPORT ~XPathExpression();
    4845
    49     WEBCORE_EXPORT RefPtr<XPathResult> evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode&);
     46    WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(Node* contextNode, unsigned short type, XPathResult*);
    5047
    5148private:
  • trunk/Source/WebCore/xml/XPathExpression.idl

    r206723 r207541  
    2323    ImplementationLacksVTable,
    2424] interface XPathExpression {
    25     [MayThrowLegacyException] XPathResult evaluate(optional Node? contextNode = null, optional unsigned short type = 0, optional XPathResult? inResult = null);
     25    [MayThrowException] XPathResult evaluate(optional Node? contextNode = null, optional unsigned short type = 0, optional XPathResult? inResult = null);
    2626};
  • trunk/Source/WebCore/xml/XPathGrammar.y

    r205011 r207541  
    3333#include "XPathParser.h"
    3434#include "XPathPath.h"
     35#include "XPathStep.h"
    3536#include "XPathVariableReference.h"
    3637
  • trunk/Source/WebCore/xml/XPathParser.cpp

    r203250 r207541  
    3434#include "XPathNSResolver.h"
    3535#include "XPathPath.h"
     36#include "XPathStep.h"
    3637#include <wtf/NeverDestroyed.h>
    3738#include <wtf/StdLibExtras.h>
     
    403404    : m_data(statement)
    404405    , m_resolver(WTFMove(resolver))
    405     , m_nextPos(0)
    406     , m_lastTokenType(0)
    407     , m_sawNamespaceError(false)
    408406{
    409407}
     
    453451    } else
    454452        localName = qualifiedName;
    455 
    456453    return true;
    457454}
    458455
    459 std::unique_ptr<Expression> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)
    460 {
    461     Parser parser(statement, WTFMove(resolver));
     456ExceptionOr<std::unique_ptr<Expression>> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver)
     457{
     458    Parser parser { statement, WTFMove(resolver) };
    462459
    463460    int parseError = xpathyyparse(parser);
    464461
    465     if (parser.m_sawNamespaceError) {
    466         ec = NAMESPACE_ERR;
    467         return nullptr;
    468     }
    469 
    470     if (parseError) {
    471         ec = XPathException::INVALID_EXPRESSION_ERR;
    472         return nullptr;
    473     }
     462    if (parser.m_sawNamespaceError)
     463        return Exception { NAMESPACE_ERR };
     464
     465    if (parseError)
     466        return Exception { XPathException::INVALID_EXPRESSION_ERR };
    474467
    475468    return WTFMove(parser.m_result);
  • trunk/Source/WebCore/xml/XPathParser.h

    r200550 r207541  
    2525 */
    2626
    27 #ifndef XPathParser_h
    28 #define XPathParser_h
     27#pragma once
    2928
    30 #include "XPathStep.h"
     29#include "ExceptionOr.h"
    3130#include "XPathPredicate.h"
    3231
     
    3534namespace WebCore {
    3635
    37     typedef int ExceptionCode;
     36class XPathNSResolver;
    3837
    39     class XPathNSResolver;
     38namespace XPath {
    4039
    41     namespace XPath {
     40class Parser {
     41    WTF_MAKE_NONCOPYABLE(Parser);
     42public:
     43    static ExceptionOr<std::unique_ptr<Expression>> parseStatement(const String& statement, RefPtr<XPathNSResolver>&&);
    4244
    43         class Parser {
    44             WTF_MAKE_NONCOPYABLE(Parser);
    45         public:
    46             static std::unique_ptr<Expression> parseStatement(const String& statement, RefPtr<XPathNSResolver>&&, ExceptionCode&);
     45    int lex(YYSTYPE&);
     46    bool expandQualifiedName(const String& qualifiedName, String& localName, String& namespaceURI);
     47    void setParseResult(std::unique_ptr<Expression>&& expression) { m_result = WTFMove(expression); }
    4748
    48             int lex(YYSTYPE&);
    49             bool expandQualifiedName(const String& qualifiedName, String& localName, String& namespaceURI);
    50             void setParseResult(std::unique_ptr<Expression> expression) { m_result = WTFMove(expression); }
     49private:
     50    Parser(const String&, RefPtr<XPathNSResolver>&&);
    5151
    52         private:
    53             Parser(const String&, RefPtr<XPathNSResolver>&&);
     52    struct Token;
    5453
    55             struct Token;
     54    bool isBinaryOperatorContext() const;
    5655
    57             bool isBinaryOperatorContext() const;
     56    void skipWS();
     57    Token makeTokenAndAdvance(int type, int advance = 1);
     58    Token makeTokenAndAdvance(int type, NumericOp::Opcode, int advance = 1);
     59    Token makeTokenAndAdvance(int type, EqTestOp::Opcode, int advance = 1);
     60    char peekAheadHelper();
     61    char peekCurHelper();
    5862
    59             void skipWS();
    60             Token makeTokenAndAdvance(int type, int advance = 1);
    61             Token makeTokenAndAdvance(int type, NumericOp::Opcode, int advance = 1);
    62             Token makeTokenAndAdvance(int type, EqTestOp::Opcode, int advance = 1);
    63             char peekAheadHelper();
    64             char peekCurHelper();
     63    Token lexString();
     64    Token lexNumber();
     65    bool lexNCName(String&);
     66    bool lexQName(String&);
    6567
    66             Token lexString();
    67             Token lexNumber();
    68             bool lexNCName(String&);
    69             bool lexQName(String&);
     68    Token nextToken();
     69    Token nextTokenInternal();
    7070
    71             Token nextToken();
    72             Token nextTokenInternal();
     71    const String& m_data;
     72    RefPtr<XPathNSResolver> m_resolver;
    7373
    74             const String& m_data;
    75             RefPtr<XPathNSResolver> m_resolver;
     74    unsigned m_nextPos { 0 };
     75    int m_lastTokenType { 0 };
    7676
    77             unsigned m_nextPos;
    78             int m_lastTokenType;
     77    std::unique_ptr<Expression> m_result;
     78    bool m_sawNamespaceError { false };
     79};
    7980
    80             std::unique_ptr<Expression> m_result;
    81             bool m_sawNamespaceError;
    82         };
    83 
    84     }
    85 }
    86 
    87 #endif
     81} }
  • trunk/Source/WebCore/xml/XPathResult.cpp

    r204717 r207541  
    3737using namespace XPath;
    3838
    39 XPathResult::XPathResult(Document* document, const Value& value)
     39XPathResult::XPathResult(Document& document, const Value& value)
    4040    : m_value(value)
    41     , m_nodeSetPosition(0)
    42     , m_domTreeVersion(0)
    4341{
    4442    switch (m_value.type()) {
     
    5654            m_nodeSetPosition = 0;
    5755            m_nodeSet = m_value.toNodeSet();
    58             m_document = document;
    59             m_domTreeVersion = document->domTreeVersion();
     56            m_document = &document;
     57            m_domTreeVersion = document.domTreeVersion();
    6058            return;
    6159    }
     
    6765}
    6866
    69 void XPathResult::convertTo(unsigned short type, ExceptionCode& ec)
     67ExceptionOr<void> XPathResult::convertTo(unsigned short type)
    7068{
    7169    switch (type) {
    72         case ANY_TYPE:
    73             break;
    74         case NUMBER_TYPE:
    75             m_resultType = type;
    76             m_value = m_value.toNumber();
    77             break;
    78         case STRING_TYPE:
    79             m_resultType = type;
    80             m_value = m_value.toString();
    81             break;
    82         case BOOLEAN_TYPE:
    83             m_resultType = type;
    84             m_value = m_value.toBoolean();
    85             break;
    86         case UNORDERED_NODE_ITERATOR_TYPE:
    87         case UNORDERED_NODE_SNAPSHOT_TYPE:
    88         case ANY_UNORDERED_NODE_TYPE:
    89         case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() will take care of ordering.
    90             if (!m_value.isNodeSet()) {
    91                 ec = XPathException::TYPE_ERR;
    92                 return;
    93             }
    94             m_resultType = type;
    95             break;
    96         case ORDERED_NODE_ITERATOR_TYPE:
    97             if (!m_value.isNodeSet()) {
    98                 ec = XPathException::TYPE_ERR;
    99                 return;
    100             }
    101             m_nodeSet.sort();
    102             m_resultType = type;
    103             break;
    104         case ORDERED_NODE_SNAPSHOT_TYPE:
    105             if (!m_value.isNodeSet()) {
    106                 ec = XPathException::TYPE_ERR;
    107                 return;
    108             }
    109             m_value.toNodeSet().sort();
    110             m_resultType = type;
    111             break;
     70    case ANY_TYPE:
     71        break;
     72    case NUMBER_TYPE:
     73        m_resultType = type;
     74        m_value = m_value.toNumber();
     75        break;
     76    case STRING_TYPE:
     77        m_resultType = type;
     78        m_value = m_value.toString();
     79        break;
     80    case BOOLEAN_TYPE:
     81        m_resultType = type;
     82        m_value = m_value.toBoolean();
     83        break;
     84    case UNORDERED_NODE_ITERATOR_TYPE:
     85    case UNORDERED_NODE_SNAPSHOT_TYPE:
     86    case ANY_UNORDERED_NODE_TYPE:
     87    case FIRST_ORDERED_NODE_TYPE: // This is correct - singleNodeValue() will take care of ordering.
     88        if (!m_value.isNodeSet())
     89            return Exception { XPathException::TYPE_ERR };
     90        m_resultType = type;
     91        break;
     92    case ORDERED_NODE_ITERATOR_TYPE:
     93        if (!m_value.isNodeSet())
     94            return Exception { XPathException::TYPE_ERR };
     95        m_nodeSet.sort();
     96        m_resultType = type;
     97        break;
     98    case ORDERED_NODE_SNAPSHOT_TYPE:
     99        if (!m_value.isNodeSet())
     100            return Exception { XPathException::TYPE_ERR };
     101        m_value.toNodeSet().sort();
     102        m_resultType = type;
     103        break;
    112104    }
     105    return { };
    113106}
    114107
     
    118111}
    119112
    120 double XPathResult::numberValue(ExceptionCode& ec) const
     113ExceptionOr<double> XPathResult::numberValue() const
    121114{
    122     if (resultType() != NUMBER_TYPE) {
    123         ec = XPathException::TYPE_ERR;
    124         return 0.0;
    125     }
     115    if (resultType() != NUMBER_TYPE)
     116        return Exception { XPathException::TYPE_ERR };
    126117    return m_value.toNumber();
    127118}
    128119
    129 String XPathResult::stringValue(ExceptionCode& ec) const
     120ExceptionOr<String> XPathResult::stringValue() const
    130121{
    131     if (resultType() != STRING_TYPE) {
    132         ec = XPathException::TYPE_ERR;
    133         return String();
    134     }
     122    if (resultType() != STRING_TYPE)
     123        return Exception { XPathException::TYPE_ERR };
    135124    return m_value.toString();
    136125}
    137126
    138 bool XPathResult::booleanValue(ExceptionCode& ec) const
     127ExceptionOr<bool> XPathResult::booleanValue() const
    139128{
    140     if (resultType() != BOOLEAN_TYPE) {
    141         ec = XPathException::TYPE_ERR;
    142         return false;
    143     }
     129    if (resultType() != BOOLEAN_TYPE)
     130        return Exception { XPathException::TYPE_ERR };
    144131    return m_value.toBoolean();
    145132}
    146133
    147 Node* XPathResult::singleNodeValue(ExceptionCode& ec) const
     134ExceptionOr<Node*> XPathResult::singleNodeValue() const
    148135{
    149     if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED_NODE_TYPE) {
    150         ec = XPathException::TYPE_ERR;
    151         return 0;
    152     }
    153  
    154     const NodeSet& nodes = m_value.toNodeSet();
     136    if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED_NODE_TYPE)
     137        return Exception { XPathException::TYPE_ERR };
     138
     139    auto& nodes = m_value.toNodeSet();
    155140    if (resultType() == FIRST_ORDERED_NODE_TYPE)
    156141        return nodes.firstNode();
     
    168153}
    169154
    170 unsigned XPathResult::snapshotLength(ExceptionCode& ec) const
     155ExceptionOr<unsigned> XPathResult::snapshotLength() const
    171156{
    172     if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE) {
    173         ec = XPathException::TYPE_ERR;
    174         return 0;
    175     }
     157    if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE)
     158        return Exception { XPathException::TYPE_ERR };
    176159
    177160    return m_value.toNodeSet().size();
    178161}
    179162
    180 Node* XPathResult::iterateNext(ExceptionCode& ec)
     163ExceptionOr<Node*> XPathResult::iterateNext()
    181164{
    182     if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_NODE_ITERATOR_TYPE) {
    183         ec = XPathException::TYPE_ERR;
    184         return 0;
    185     }
    186    
    187     if (invalidIteratorState()) {
    188         ec = INVALID_STATE_ERR;
    189         return 0;
    190     }
    191    
    192     if (m_nodeSetPosition + 1 > m_nodeSet.size())
    193         return 0;
     165    if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_NODE_ITERATOR_TYPE)
     166        return Exception { XPathException::TYPE_ERR };
    194167
    195     Node* node = m_nodeSet[m_nodeSetPosition];
    196    
    197     m_nodeSetPosition++;
     168    if (invalidIteratorState())
     169        return Exception { INVALID_STATE_ERR };
    198170
    199     return node;
     171    if (m_nodeSetPosition >= m_nodeSet.size())
     172        return nullptr;
     173
     174    return m_nodeSet[m_nodeSetPosition++];
    200175}
    201176
    202 Node* XPathResult::snapshotItem(unsigned index, ExceptionCode& ec)
     177ExceptionOr<Node*> XPathResult::snapshotItem(unsigned index)
    203178{
    204     if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE) {
    205         ec = XPathException::TYPE_ERR;
    206         return 0;
    207     }
    208    
    209     const NodeSet& nodes = m_value.toNodeSet();
     179    if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE)
     180        return Exception { XPathException::TYPE_ERR };
     181
     182    auto& nodes = m_value.toNodeSet();
    210183    if (index >= nodes.size())
    211         return 0;
    212    
     184        return nullptr;
     185
    213186    return nodes[index];
    214187}
  • trunk/Source/WebCore/xml/XPathResult.h

    r204717 r207541  
    2727#pragma once
    2828
     29#include "ExceptionOr.h"
    2930#include "XPathValue.h"
    30 #include <wtf/Forward.h>
    31 #include <wtf/RefCounted.h>
    3231
    3332namespace WebCore {
    3433
    35     typedef int ExceptionCode;
    36 
    37     class Document;
    38     class Node;
    39 
    40     class XPathResult : public RefCounted<XPathResult> {
    41     public:
    42         enum XPathResultType {
    43             ANY_TYPE = 0,
    44             NUMBER_TYPE = 1,
    45             STRING_TYPE = 2,
    46             BOOLEAN_TYPE = 3,
    47             UNORDERED_NODE_ITERATOR_TYPE = 4,
    48             ORDERED_NODE_ITERATOR_TYPE = 5,
    49             UNORDERED_NODE_SNAPSHOT_TYPE = 6,
    50             ORDERED_NODE_SNAPSHOT_TYPE = 7,
    51             ANY_UNORDERED_NODE_TYPE = 8,
    52             FIRST_ORDERED_NODE_TYPE = 9
    53         };
    54        
    55         static Ref<XPathResult> create(Document* document, const XPath::Value& value) { return adoptRef(*new XPathResult(document, value)); }
    56         WEBCORE_EXPORT ~XPathResult();
    57        
    58         void convertTo(unsigned short type, ExceptionCode&);
    59 
    60         WEBCORE_EXPORT unsigned short resultType() const;
    61 
    62         WEBCORE_EXPORT double numberValue(ExceptionCode&) const;
    63         WEBCORE_EXPORT String stringValue(ExceptionCode&) const;
    64         WEBCORE_EXPORT bool booleanValue(ExceptionCode&) const;
    65         WEBCORE_EXPORT Node* singleNodeValue(ExceptionCode&) const;
    66 
    67         WEBCORE_EXPORT bool invalidIteratorState() const;
    68         WEBCORE_EXPORT unsigned snapshotLength(ExceptionCode&) const;
    69         WEBCORE_EXPORT Node* iterateNext(ExceptionCode&);
    70         WEBCORE_EXPORT Node* snapshotItem(unsigned index, ExceptionCode&);
    71 
    72         const XPath::Value& value() const { return m_value; }
    73 
    74     private:
    75         XPathResult(Document*, const XPath::Value&);
    76        
    77         XPath::Value m_value;
    78         unsigned m_nodeSetPosition;
    79         XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value?
    80         unsigned short m_resultType;
    81         RefPtr<Document> m_document;
    82         uint64_t m_domTreeVersion;
     34class XPathResult : public RefCounted<XPathResult> {
     35public:
     36    enum XPathResultType {
     37        ANY_TYPE = 0,
     38        NUMBER_TYPE = 1,
     39        STRING_TYPE = 2,
     40        BOOLEAN_TYPE = 3,
     41        UNORDERED_NODE_ITERATOR_TYPE = 4,
     42        ORDERED_NODE_ITERATOR_TYPE = 5,
     43        UNORDERED_NODE_SNAPSHOT_TYPE = 6,
     44        ORDERED_NODE_SNAPSHOT_TYPE = 7,
     45        ANY_UNORDERED_NODE_TYPE = 8,
     46        FIRST_ORDERED_NODE_TYPE = 9
    8347    };
    8448
     49    static Ref<XPathResult> create(Document& document, const XPath::Value& value) { return adoptRef(*new XPathResult(document, value)); }
     50    WEBCORE_EXPORT ~XPathResult();
     51
     52    ExceptionOr<void> convertTo(unsigned short type);
     53
     54    WEBCORE_EXPORT unsigned short resultType() const;
     55
     56    WEBCORE_EXPORT ExceptionOr<double> numberValue() const;
     57    WEBCORE_EXPORT ExceptionOr<String> stringValue() const;
     58    WEBCORE_EXPORT ExceptionOr<bool> booleanValue() const;
     59    WEBCORE_EXPORT ExceptionOr<Node*> singleNodeValue() const;
     60
     61    WEBCORE_EXPORT bool invalidIteratorState() const;
     62    WEBCORE_EXPORT ExceptionOr<unsigned> snapshotLength() const;
     63    WEBCORE_EXPORT ExceptionOr<Node*> iterateNext();
     64    WEBCORE_EXPORT ExceptionOr<Node*> snapshotItem(unsigned index);
     65
     66    const XPath::Value& value() const { return m_value; }
     67
     68private:
     69    XPathResult(Document&, const XPath::Value&);
     70
     71    XPath::Value m_value;
     72    unsigned m_nodeSetPosition { 0 };
     73    XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value?
     74    unsigned short m_resultType;
     75    RefPtr<Document> m_document;
     76    uint64_t m_domTreeVersion { 0 };
     77};
     78
    8579} // namespace WebCore
  • trunk/Source/WebCore/xml/XPathResult.idl

    r206723 r207541  
    3535
    3636    readonly attribute unsigned short resultType;
    37     [GetterMayThrowLegacyException] readonly attribute unrestricted double numberValue;
    38     [GetterMayThrowLegacyException] readonly attribute DOMString stringValue;
    39     [GetterMayThrowLegacyException] readonly attribute boolean booleanValue;
    40     [GetterMayThrowLegacyException] readonly attribute Node singleNodeValue;
     37    [GetterMayThrowException] readonly attribute unrestricted double numberValue;
     38    [GetterMayThrowException] readonly attribute DOMString stringValue;
     39    [GetterMayThrowException] readonly attribute boolean booleanValue;
     40    [GetterMayThrowException] readonly attribute Node singleNodeValue;
    4141
    4242    readonly attribute boolean invalidIteratorState;
    43     [GetterMayThrowLegacyException] readonly attribute unsigned long snapshotLength;
     43    [GetterMayThrowException] readonly attribute unsigned long snapshotLength;
    4444
    45     [MayThrowLegacyException] Node iterateNext();
    46     [MayThrowLegacyException] Node snapshotItem(optional unsigned long index = 0);
     45    [MayThrowException] Node iterateNext();
     46    [MayThrowException] Node snapshotItem(optional unsigned long index = 0);
    4747};
  • trunk/Source/WebKit/mac/ChangeLog

    r207517 r207541  
     12016-10-19  Darin Adler  <darin@apple.com>
     2
     3        Move XPath from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=163656
     5
     6        Reviewed by Chris Dumez.
     7
     8        * DOM/DOMDocument.mm:
     9        (wrap): Added. Helper function for wrapping a resolver.
     10        (-[DOMDocument createExpression:resolver:]): Use raiseOnDOMError.
     11        (-[DOMDocument evaluate:contextNode:resolver:type:inResult:]): Ditto.
     12        * DOM/DOMXPathExpression.mm:
     13        (-[DOMXPathExpression evaluate:type:inResult:]): Ditto.
     14        * DOM/DOMXPathResult.mm:
     15        (-[DOMXPathResult numberValue]): Ditto.
     16        (-[DOMXPathResult stringValue]): Ditto.
     17        (-[DOMXPathResult booleanValue]): Ditto.
     18        (-[DOMXPathResult singleNodeValue]): Ditto.
     19        (-[DOMXPathResult snapshotLength]): Ditto.
     20        (-[DOMXPathResult iterateNext]): Ditto.
     21        (-[DOMXPathResult snapshotItem:]): Ditto.
     22
    1232016-10-18  Sam Weinig  <sam@webkit.org>
    224
  • trunk/Source/WebKit/mac/DOM/DOMDocument.mm

    r205468 r207541  
    613613}
    614614
     615static RefPtr<WebCore::XPathNSResolver> wrap(id <DOMXPathNSResolver> resolver)
     616{
     617    if (!resolver)
     618        return nullptr;
     619    if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
     620        return core(static_cast<DOMNativeXPathNSResolver *>(resolver));
     621    return DOMCustomXPathNSResolver::create(resolver);
     622}
     623
    615624- (DOMXPathExpression *)createExpression:(NSString *)expression resolver:(id <DOMXPathNSResolver>)resolver
    616625{
    617626    WebCore::JSMainThreadNullState state;
    618     WebCore::XPathNSResolver* nativeResolver = 0;
    619     RefPtr<WebCore::XPathNSResolver> customResolver;
    620     if (resolver) {
    621         if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
    622             nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>(resolver));
    623         else {
    624             customResolver = DOMCustomXPathNSResolver::create(resolver);
    625             nativeResolver = WTF::getPtr(customResolver);
    626         }
    627     }
    628     WebCore::ExceptionCode ec = 0;
    629     DOMXPathExpression *result = kit(WTF::getPtr(IMPL->createExpression(expression, WTF::getPtr(nativeResolver), ec)));
    630     raiseOnDOMError(ec);
    631     return result;
     627    return kit(raiseOnDOMError(IMPL->createExpression(expression, wrap(resolver))).ptr());
    632628}
    633629
     
    641637{
    642638    WebCore::JSMainThreadNullState state;
    643     WebCore::XPathNSResolver* nativeResolver = 0;
    644     RefPtr<WebCore::XPathNSResolver> customResolver;
    645     if (resolver) {
    646         if ([resolver isMemberOfClass:[DOMNativeXPathNSResolver class]])
    647             nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>(resolver));
    648         else {
    649             customResolver = DOMCustomXPathNSResolver::create(resolver);
    650             nativeResolver = WTF::getPtr(customResolver);
    651         }
    652     }
    653     WebCore::ExceptionCode ec = 0;
    654     DOMXPathResult *result = kit(WTF::getPtr(IMPL->evaluate(expression, core(contextNode), WTF::getPtr(nativeResolver), type, core(inResult), ec)));
    655     raiseOnDOMError(ec);
    656     return result;
     639    return kit(raiseOnDOMError(IMPL->evaluate(expression, core(contextNode), wrap(resolver), type, core(inResult))).ptr());
    657640}
    658641
  • trunk/Source/WebKit/mac/DOM/DOMXPathExpression.mm

    r204717 r207541  
    5656{
    5757    WebCore::JSMainThreadNullState state;
    58     WebCore::ExceptionCode ec = 0;
    59     DOMXPathResult *result = kit(WTF::getPtr(IMPL->evaluate(core(contextNode), type, core(inResult), ec)));
    60     raiseOnDOMError(ec);
    61     return result;
     58    return kit(raiseOnDOMError(IMPL->evaluate(core(contextNode), type, core(inResult))).ptr());
    6259}
    6360
  • trunk/Source/WebKit/mac/DOM/DOMXPathResult.mm

    r204717 r207541  
    6161{
    6262    WebCore::JSMainThreadNullState state;
    63     WebCore::ExceptionCode ec = 0;
    64     double result = IMPL->numberValue(ec);
    65     raiseOnDOMError(ec);
    66     return result;
     63    return raiseOnDOMError(IMPL->numberValue());
    6764}
    6865
     
    7067{
    7168    WebCore::JSMainThreadNullState state;
    72     WebCore::ExceptionCode ec = 0;
    73     NSString *result = IMPL->stringValue(ec);
    74     raiseOnDOMError(ec);
    75     return result;
     69    return raiseOnDOMError(IMPL->stringValue());
    7670}
    7771
     
    7973{
    8074    WebCore::JSMainThreadNullState state;
    81     WebCore::ExceptionCode ec = 0;
    82     BOOL result = IMPL->booleanValue(ec);
    83     raiseOnDOMError(ec);
    84     return result;
     75    return raiseOnDOMError(IMPL->booleanValue());
    8576}
    8677
     
    8879{
    8980    WebCore::JSMainThreadNullState state;
    90     WebCore::ExceptionCode ec = 0;
    91     DOMNode *result = kit(WTF::getPtr(IMPL->singleNodeValue(ec)));
    92     raiseOnDOMError(ec);
    93     return result;
     81    return kit(raiseOnDOMError(IMPL->singleNodeValue()));
    9482}
    9583
     
    10391{
    10492    WebCore::JSMainThreadNullState state;
    105     WebCore::ExceptionCode ec = 0;
    106     unsigned result = IMPL->snapshotLength(ec);
    107     raiseOnDOMError(ec);
    108     return result;
     93    return raiseOnDOMError(IMPL->snapshotLength());
    10994}
    11095
     
    11297{
    11398    WebCore::JSMainThreadNullState state;
    114     WebCore::ExceptionCode ec = 0;
    115     DOMNode *result = kit(WTF::getPtr(IMPL->iterateNext(ec)));
    116     raiseOnDOMError(ec);
    117     return result;
     99    return kit(raiseOnDOMError(IMPL->iterateNext()));
    118100}
    119101
     
    121103{
    122104    WebCore::JSMainThreadNullState state;
    123     WebCore::ExceptionCode ec = 0;
    124     DOMNode *result = kit(WTF::getPtr(IMPL->snapshotItem(index, ec)));
    125     raiseOnDOMError(ec);
    126     return result;
     105    return kit(raiseOnDOMError(IMPL->snapshotItem(index)));
    127106}
    128107
     
    131110WebCore::XPathResult* core(DOMXPathResult *wrapper)
    132111{
    133     return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : 0;
     112    return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : nullptr;
    134113}
    135114
  • trunk/Source/WebKit2/ChangeLog

    r207530 r207541  
     12016-10-19  Darin Adler  <darin@apple.com>
     2
     3        Move XPath from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=163656
     5
     6        Reviewed by Chris Dumez.
     7
     8        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp:
     9        (webkit_dom_document_create_expression): Use ExceptionOr.
     10        (webkit_dom_document_evaluate): Ditto.
     11        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp:
     12        (webkit_dom_xpath_expression_evaluate): Ditto.
     13        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp:
     14        (webkit_dom_xpath_result_iterate_next): Ditto.
     15        (webkit_dom_xpath_result_snapshot_item): Ditto.
     16        (webkit_dom_xpath_result_get_number_value): Ditto.
     17        (webkit_dom_xpath_result_get_string_value): Ditto.
     18        (webkit_dom_xpath_result_get_boolean_value): Ditto.
     19        (webkit_dom_xpath_result_get_single_node_value): Ditto.
     20        (webkit_dom_xpath_result_get_snapshot_length): Ditto.
     21
    1222016-10-19  Carlos Garcia Campos  <cgarcia@igalia.com>
    223
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp

    r205540 r207541  
    11701170    WTF::String convertedExpression = WTF::String::fromUTF8(expression);
    11711171    RefPtr<WebCore::XPathNSResolver> convertedResolver = WebKit::core(resolver);
    1172     WebCore::ExceptionCode ec = 0;
    1173     RefPtr<WebCore::XPathExpression> gobjectResult = WTF::getPtr(item->createExpression(convertedExpression, WTF::getPtr(convertedResolver), ec));
    1174     if (ec) {
    1175         WebCore::ExceptionCodeDescription ecdesc(ec);
     1172    auto result = item->createExpression(convertedExpression, WTFMove(convertedResolver));
     1173    if (result.hasException()) {
     1174        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    11761175        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     1176        return nullptr;
    11771177    }
    1178     return WebKit::kit(gobjectResult.get());
     1178    return WebKit::kit(result.releaseReturnValue().ptr());
    11791179}
    11801180
     
    12041204    RefPtr<WebCore::XPathNSResolver> convertedResolver = WebKit::core(resolver);
    12051205    WebCore::XPathResult* convertedInResult = WebKit::core(inResult);
    1206     WebCore::ExceptionCode ec = 0;
    1207     RefPtr<WebCore::XPathResult> gobjectResult = WTF::getPtr(item->evaluate(convertedExpression, convertedContextNode, WTF::getPtr(convertedResolver), type, convertedInResult, ec));
    1208     if (ec) {
    1209         WebCore::ExceptionCodeDescription ecdesc(ec);
     1206    auto result = item->evaluate(convertedExpression, convertedContextNode, WTFMove(convertedResolver), type, convertedInResult);
     1207    if (result.hasException()) {
     1208        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    12101209        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     1210        return nullptr;
    12111211    }
    1212     return WebKit::kit(gobjectResult.get());
     1212    return WebKit::kit(result.releaseReturnValue().ptr());
    12131213}
    12141214
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp

    r205280 r207541  
    115115    WebCore::Node* convertedContextNode = WebKit::core(contextNode);
    116116    WebCore::XPathResult* convertedInResult = WebKit::core(inResult);
    117     WebCore::ExceptionCode ec = 0;
    118     RefPtr<WebCore::XPathResult> gobjectResult = WTF::getPtr(item->evaluate(convertedContextNode, type, convertedInResult, ec));
    119     if (ec) {
    120         WebCore::ExceptionCodeDescription ecdesc(ec);
     117    auto result = item->evaluate(convertedContextNode, type, convertedInResult);
     118    if (result.hasException()) {
     119        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    121120        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     121        return nullptr;
    122122    }
    123     return WebKit::kit(gobjectResult.get());
     123    return WebKit::kit(result.releaseReturnValue().ptr());
    124124}
    125125
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp

    r205280 r207541  
    225225    g_return_val_if_fail(!error || !*error, 0);
    226226    WebCore::XPathResult* item = WebKit::core(self);
    227     WebCore::ExceptionCode ec = 0;
    228     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->iterateNext(ec));
    229     if (ec) {
    230         WebCore::ExceptionCodeDescription ecdesc(ec);
    231         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    232     }
    233     return WebKit::kit(gobjectResult.get());
     227    auto result = item->iterateNext();
     228    if (result.hasException()) {
     229        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     230        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     231        return nullptr;
     232    }
     233    return WebKit::kit(result.releaseReturnValue());
    234234}
    235235
     
    240240    g_return_val_if_fail(!error || !*error, 0);
    241241    WebCore::XPathResult* item = WebKit::core(self);
    242     WebCore::ExceptionCode ec = 0;
    243     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->snapshotItem(index, ec));
    244     if (ec) {
    245         WebCore::ExceptionCodeDescription ecdesc(ec);
    246         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    247     }
    248     return WebKit::kit(gobjectResult.get());
     242    auto result = item->snapshotItem(index);
     243    if (result.hasException()) {
     244        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     245        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     246        return nullptr;
     247    }
     248    return WebKit::kit(result.releaseReturnValue());
    249249}
    250250
     
    264264    g_return_val_if_fail(!error || !*error, 0);
    265265    WebCore::XPathResult* item = WebKit::core(self);
    266     WebCore::ExceptionCode ec = 0;
    267     gdouble result = item->numberValue(ec);
    268     if (ec) {
    269         WebCore::ExceptionCodeDescription ecdesc(ec);
    270         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    271     }
    272     return result;
     266    auto result = item->numberValue();
     267    if (result.hasException()) {
     268        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     269        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     270        return 0;
     271    }
     272    return result.releaseReturnValue();
    273273}
    274274
     
    279279    g_return_val_if_fail(!error || !*error, 0);
    280280    WebCore::XPathResult* item = WebKit::core(self);
    281     WebCore::ExceptionCode ec = 0;
    282     gchar* result = convertToUTF8String(item->stringValue(ec));
    283     return result;
     281    auto result = item->stringValue();
     282    if (result.hasException())
     283        return nullptr;
     284    return convertToUTF8String(result.releaseReturnValue());
    284285}
    285286
     
    290291    g_return_val_if_fail(!error || !*error, FALSE);
    291292    WebCore::XPathResult* item = WebKit::core(self);
    292     WebCore::ExceptionCode ec = 0;
    293     gboolean result = item->booleanValue(ec);
    294     if (ec) {
    295         WebCore::ExceptionCodeDescription ecdesc(ec);
    296         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    297     }
    298     return result;
     293    auto result = item->booleanValue();
     294    if (result.hasException()) {
     295        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     296        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     297        return false;
     298    }
     299    return result.releaseReturnValue();
    299300}
    300301
     
    305306    g_return_val_if_fail(!error || !*error, 0);
    306307    WebCore::XPathResult* item = WebKit::core(self);
    307     WebCore::ExceptionCode ec = 0;
    308     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->singleNodeValue(ec));
    309     if (ec) {
    310         WebCore::ExceptionCodeDescription ecdesc(ec);
    311         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    312     }
    313     return WebKit::kit(gobjectResult.get());
     308    auto result = item->singleNodeValue();
     309    if (result.hasException()) {
     310        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     311        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     312        return nullptr;
     313    }
     314    return WebKit::kit(result.releaseReturnValue());
    314315}
    315316
     
    329330    g_return_val_if_fail(!error || !*error, 0);
    330331    WebCore::XPathResult* item = WebKit::core(self);
    331     WebCore::ExceptionCode ec = 0;
    332     gulong result = item->snapshotLength(ec);
    333     if (ec) {
    334         WebCore::ExceptionCodeDescription ecdesc(ec);
    335         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    336     }
    337     return result;
    338 }
    339 
     332    auto result = item->snapshotLength();
     333    if (result.hasException()) {
     334        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     335        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     336    }
     337    return result.releaseReturnValue();
     338}
     339
Note: See TracChangeset for help on using the changeset viewer.