Changeset 207541 in webkit
- Timestamp:
- Oct 19, 2016 9:57:31 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207540 r207541 1 2016-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 1 61 2016-10-19 Nan Wang <n_wang@apple.com> 2 62 -
trunk/Source/WebCore/dom/Document.cpp
r207486 r207541 5118 5118 #endif 5119 5119 5120 RefPtr<XPathExpression> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)5120 ExceptionOr<Ref<XPathExpression>> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver) 5121 5121 { 5122 5122 if (!m_xpathEvaluator) 5123 5123 m_xpathEvaluator = XPathEvaluator::create(); 5124 return m_xpathEvaluator->createExpression(expression, WTFMove(resolver) , ec);5125 } 5126 5127 Ref Ptr<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)5124 return m_xpathEvaluator->createExpression(expression, WTFMove(resolver)); 5125 } 5126 5127 Ref<XPathNSResolver> Document::createNSResolver(Node* nodeResolver) 5128 5128 { 5129 5129 if (!m_xpathEvaluator) … … 5132 5132 } 5133 5133 5134 RefPtr<XPathResult> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)5134 ExceptionOr<Ref<XPathResult>> Document::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result) 5135 5135 { 5136 5136 if (!m_xpathEvaluator) 5137 5137 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); 5139 5139 } 5140 5140 -
trunk/Source/WebCore/dom/Document.h
r207372 r207541 33 33 #include "DocumentEventQueue.h" 34 34 #include "DocumentTiming.h" 35 #include "ExceptionOr.h" 35 36 #include "FocusDirection.h" 36 37 #include "FontSelectorClient.h" … … 944 945 945 946 // XPathEvaluator methods 946 WEBCORE_EXPORT RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);947 WEBCORE_EXPORT Ref Ptr<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*); 949 950 950 951 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets }; -
trunk/Source/WebCore/dom/Document.idl
r207355 r207541 77 77 78 78 // FIXME: Using "undefined" as default parameter value is wrong. 79 [MayThrow LegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);79 [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver); 80 80 XPathNSResolver createNSResolver(Node? nodeResolver); 81 81 82 82 // 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); 85 84 86 85 // FIXME: The default value for the last parameter should be the empty string. -
trunk/Source/WebCore/inspector/InspectorNodeFinder.cpp
r200550 r207541 133 133 void InspectorNodeFinder::searchUsingXPath(Node* parentNode) 134 134 { 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()) 138 137 return; 138 auto result = evaluateResult.releaseReturnValue(); 139 139 140 unsigned long size = result->snapshotLength(ec);141 if ( ec)140 auto snapshotLengthResult = result->snapshotLength(); 141 if (snapshotLengthResult.hasException()) 142 142 return; 143 unsigned size = snapshotLengthResult.releaseReturnValue(); 143 144 144 for (unsigned longi = 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()) 147 148 return; 149 Node* node = snapshotItemResult.releaseReturnValue(); 148 150 149 151 if (is<Attr>(*node)) -
trunk/Source/WebCore/xml/DOMParser.cpp
r206469 r207541 22 22 #include "DOMImplementation.h" 23 23 #include "ExceptionCode.h" 24 #include <wtf/text/WTFString.h>25 24 26 25 namespace WebCore { 27 26 28 DOMParser::DOMParser(Document& contextDocument)27 inline DOMParser::DOMParser(Document& contextDocument) 29 28 : m_contextDocument(contextDocument.createWeakPtr()) 30 29 { 31 30 } 32 31 33 Ref Ptr<Document> DOMParser::parseFromString(const String& string, const String& contentType, ExceptionCode& ec)32 Ref<DOMParser> DOMParser::create(Document& contextDocument) 34 33 { 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 } 43 36 44 Ref<Document> document = DOMImplementation::createDocument(contentType, nullptr, URL()); 37 ExceptionOr<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 { }); 45 42 if (m_contextDocument) 46 43 document->setContextDocument(*m_contextDocument.get()); -
trunk/Source/WebCore/xml/DOMParser.h
r206469 r207541 1 1 /* 2 * Copyright (C) 2003, 2006 Apple Inc. 2 * Copyright (C) 2003, 2006 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 17 17 */ 18 18 19 #ifndef DOMParser_h 20 #define DOMParser_h 19 #pragma once 21 20 22 #include <wtf/Forward.h> 23 #include <wtf/RefCounted.h> 24 #include <wtf/RefPtr.h> 21 #include "ExceptionOr.h" 25 22 #include <wtf/WeakPtr.h> 26 23 27 24 namespace WebCore { 28 typedef int ExceptionCode;29 25 30 26 class Document; … … 32 28 class DOMParser : public RefCounted<DOMParser> { 33 29 public: 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); 40 32 41 33 private: … … 46 38 47 39 } 48 49 #endif // XMLSerializer.h -
trunk/Source/WebCore/xml/DOMParser.idl
r206723 r207541 1 1 /* 2 * Copyright (C) 2006 Apple Inc. 2 * Copyright (C) 2006 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 23 23 ImplementationLacksVTable, 24 24 ] interface DOMParser { 25 [MayThrow LegacyException, NewObject] Document parseFromString(DOMString str, DOMString contentType);25 [MayThrowException, NewObject] Document parseFromString(DOMString string, DOMString contentType); 26 26 }; -
trunk/Source/WebCore/xml/XPathEvaluator.cpp
r200550 r207541 38 38 using namespace XPath; 39 39 40 RefPtr<XPathExpression> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)40 ExceptionOr<Ref<XPathExpression>> XPathEvaluator::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver) 41 41 { 42 return XPathExpression::createExpression(expression, WTFMove(resolver) , ec);42 return XPathExpression::createExpression(expression, WTFMove(resolver)); 43 43 } 44 44 … … 48 48 } 49 49 50 RefPtr<XPathResult> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result, ExceptionCode& ec)50 ExceptionOr<Ref<XPathResult>> XPathEvaluator::evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&& resolver, unsigned short type, XPathResult* result) 51 51 { 52 if (!isValidContextNode(contextNode)) { 53 ec = NOT_SUPPORTED_ERR; 54 return nullptr; 55 } 52 if (!isValidContextNode(contextNode)) 53 return Exception { NOT_SUPPORTED_ERR }; 56 54 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); 63 60 } 64 61 -
trunk/Source/WebCore/xml/XPathEvaluator.h
r200550 r207541 1 1 /* 2 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> 3 * Copyright (C) 2006 Apple Inc. 3 * Copyright (C) 2006 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 25 25 */ 26 26 27 #ifndef XPathEvaluator_h 28 #define XPathEvaluator_h 27 #pragma once 29 28 30 #include <wtf/Forward.h> 31 #include <wtf/Ref.h> 32 #include <wtf/RefCounted.h> 29 #include "ExceptionOr.h" 33 30 34 31 namespace WebCore { 35 32 36 typedef int ExceptionCode; 33 class Node; 34 class XPathExpression; 35 class XPathNSResolver; 36 class XPathResult; 37 37 38 class Node; 39 class XPathExpression; 40 class XPathNSResolver; 41 class XPathResult; 38 class XPathEvaluator : public RefCounted<XPathEvaluator> { 39 public: 40 static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); } 42 41 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*); 51 45 52 53 XPathEvaluator() { }54 46 private: 47 XPathEvaluator() = default; 48 }; 55 49 56 50 } 57 58 #endif // XPathEvaluator_h -
trunk/Source/WebCore/xml/XPathEvaluator.idl
r206723 r207541 1 1 /* 2 * Copyright (C) 2006 Apple Inc. 2 * Copyright (C) 2006 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 23 23 ] interface XPathEvaluator { 24 24 // FIXME: Using "undefined" as default parameter value is wrong. 25 [MayThrow LegacyException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver);25 [MayThrowException] XPathExpression createExpression(optional DOMString expression = "undefined", optional XPathNSResolver? resolver); 26 26 27 27 XPathNSResolver createNSResolver(optional Node? nodeResolver); 28 28 29 29 // 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); 35 31 }; -
trunk/Source/WebCore/xml/XPathExpression.cpp
r200550 r207541 35 35 #include "XPathResult.h" 36 36 #include "XPathUtil.h" 37 #include <wtf/text/WTFString.h>38 37 39 38 namespace WebCore { … … 46 45 } 47 46 48 RefPtr<XPathExpression> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)47 ExceptionOr<Ref<XPathExpression>> XPathExpression::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver) 49 48 { 50 auto parse dExpression = 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(); 53 52 54 return adoptRef(*new XPathExpression( WTFMove(parsedExpression)));53 return adoptRef(*new XPathExpression(parseResult.releaseReturnValue())); 55 54 } 56 55 … … 59 58 } 60 59 61 RefPtr<XPathResult> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode& ec) 60 // FIXME: Why does this take an XPathResult that it ignores? 61 ExceptionOr<Ref<XPathResult>> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*) 62 62 { 63 if (!isValidContextNode(contextNode)) { 64 ec = NOT_SUPPORTED_ERR; 65 return nullptr; 66 } 63 if (!isValidContextNode(contextNode)) 64 return Exception { NOT_SUPPORTED_ERR }; 67 65 68 66 EvaluationContext& evaluationContext = Expression::evaluationContext(); … … 71 69 evaluationContext.position = 1; 72 70 evaluationContext.hadTypeConversionError = false; 73 RefPtr<XPathResult> result = XPathResult::create(&contextNode->document(), m_topExpression->evaluate());71 auto result = XPathResult::create(contextNode->document(), m_topExpression->evaluate()); 74 72 evaluationContext.node = nullptr; // Do not hold a reference to the context node, as this may prevent the whole document from being destroyed in time. 75 73 … … 77 75 // It is not specified what to do if type conversion fails while evaluating an expression, and INVALID_EXPRESSION_ERR is not exactly right 78 76 // 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 }; 81 78 } 82 79 83 80 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(); 88 84 } 89 85 90 return result;86 return WTFMove(result); 91 87 } 92 88 -
trunk/Source/WebCore/xml/XPathExpression.h
r204717 r207541 27 27 #pragma once 28 28 29 #include <wtf/Forward.h> 30 #include <wtf/RefCounted.h> 29 #include "ExceptionOr.h" 31 30 32 31 namespace WebCore { … … 37 36 38 37 namespace XPath { 39 38 class Expression; 40 39 } 41 42 using ExceptionCode = int;43 40 44 41 class XPathExpression : public RefCounted<XPathExpression> { 45 42 public: 46 static RefPtr<XPathExpression> createExpression(const String& expression, RefPtr<XPathNSResolver>&&, ExceptionCode&);43 static ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&); 47 44 WEBCORE_EXPORT ~XPathExpression(); 48 45 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*); 50 47 51 48 private: -
trunk/Source/WebCore/xml/XPathExpression.idl
r206723 r207541 23 23 ImplementationLacksVTable, 24 24 ] interface XPathExpression { 25 [MayThrow LegacyException] 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); 26 26 }; -
trunk/Source/WebCore/xml/XPathGrammar.y
r205011 r207541 33 33 #include "XPathParser.h" 34 34 #include "XPathPath.h" 35 #include "XPathStep.h" 35 36 #include "XPathVariableReference.h" 36 37 -
trunk/Source/WebCore/xml/XPathParser.cpp
r203250 r207541 34 34 #include "XPathNSResolver.h" 35 35 #include "XPathPath.h" 36 #include "XPathStep.h" 36 37 #include <wtf/NeverDestroyed.h> 37 38 #include <wtf/StdLibExtras.h> … … 403 404 : m_data(statement) 404 405 , m_resolver(WTFMove(resolver)) 405 , m_nextPos(0)406 , m_lastTokenType(0)407 , m_sawNamespaceError(false)408 406 { 409 407 } … … 453 451 } else 454 452 localName = qualifiedName; 455 456 453 return true; 457 454 } 458 455 459 std::unique_ptr<Expression> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver, ExceptionCode& ec)460 { 461 Parser parser (statement, WTFMove(resolver));456 ExceptionOr<std::unique_ptr<Expression>> Parser::parseStatement(const String& statement, RefPtr<XPathNSResolver>&& resolver) 457 { 458 Parser parser { statement, WTFMove(resolver) }; 462 459 463 460 int parseError = xpathyyparse(parser); 464 461 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 }; 474 467 475 468 return WTFMove(parser.m_result); -
trunk/Source/WebCore/xml/XPathParser.h
r200550 r207541 25 25 */ 26 26 27 #ifndef XPathParser_h 28 #define XPathParser_h 27 #pragma once 29 28 30 #include " XPathStep.h"29 #include "ExceptionOr.h" 31 30 #include "XPathPredicate.h" 32 31 … … 35 34 namespace WebCore { 36 35 37 typedef int ExceptionCode;36 class XPathNSResolver; 38 37 39 class XPathNSResolver; 38 namespace XPath { 40 39 41 namespace XPath { 40 class Parser { 41 WTF_MAKE_NONCOPYABLE(Parser); 42 public: 43 static ExceptionOr<std::unique_ptr<Expression>> parseStatement(const String& statement, RefPtr<XPathNSResolver>&&); 42 44 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); } 47 48 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); } 49 private: 50 Parser(const String&, RefPtr<XPathNSResolver>&&); 51 51 52 private: 53 Parser(const String&, RefPtr<XPathNSResolver>&&); 52 struct Token; 54 53 55 struct Token;54 bool isBinaryOperatorContext() const; 56 55 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(); 58 62 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&); 65 67 66 Token lexString(); 67 Token lexNumber(); 68 bool lexNCName(String&); 69 bool lexQName(String&); 68 Token nextToken(); 69 Token nextTokenInternal(); 70 70 71 Token nextToken();72 Token nextTokenInternal();71 const String& m_data; 72 RefPtr<XPathNSResolver> m_resolver; 73 73 74 const String& m_data;75 RefPtr<XPathNSResolver> m_resolver;74 unsigned m_nextPos { 0 }; 75 int m_lastTokenType { 0 }; 76 76 77 unsigned m_nextPos; 78 int m_lastTokenType; 77 std::unique_ptr<Expression> m_result; 78 bool m_sawNamespaceError { false }; 79 }; 79 80 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 37 37 using namespace XPath; 38 38 39 XPathResult::XPathResult(Document *document, const Value& value)39 XPathResult::XPathResult(Document& document, const Value& value) 40 40 : m_value(value) 41 , m_nodeSetPosition(0)42 , m_domTreeVersion(0)43 41 { 44 42 switch (m_value.type()) { … … 56 54 m_nodeSetPosition = 0; 57 55 m_nodeSet = m_value.toNodeSet(); 58 m_document = document;59 m_domTreeVersion = document ->domTreeVersion();56 m_document = &document; 57 m_domTreeVersion = document.domTreeVersion(); 60 58 return; 61 59 } … … 67 65 } 68 66 69 void XPathResult::convertTo(unsigned short type, ExceptionCode& ec)67 ExceptionOr<void> XPathResult::convertTo(unsigned short type) 70 68 { 71 69 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; 112 104 } 105 return { }; 113 106 } 114 107 … … 118 111 } 119 112 120 double XPathResult::numberValue(ExceptionCode& ec) const113 ExceptionOr<double> XPathResult::numberValue() const 121 114 { 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 }; 126 117 return m_value.toNumber(); 127 118 } 128 119 129 String XPathResult::stringValue(ExceptionCode& ec) const120 ExceptionOr<String> XPathResult::stringValue() const 130 121 { 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 }; 135 124 return m_value.toString(); 136 125 } 137 126 138 bool XPathResult::booleanValue(ExceptionCode& ec) const127 ExceptionOr<bool> XPathResult::booleanValue() const 139 128 { 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 }; 144 131 return m_value.toBoolean(); 145 132 } 146 133 147 Node* XPathResult::singleNodeValue(ExceptionCode& ec) const134 ExceptionOr<Node*> XPathResult::singleNodeValue() const 148 135 { 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(); 155 140 if (resultType() == FIRST_ORDERED_NODE_TYPE) 156 141 return nodes.firstNode(); … … 168 153 } 169 154 170 unsigned XPathResult::snapshotLength(ExceptionCode& ec) const155 ExceptionOr<unsigned> XPathResult::snapshotLength() const 171 156 { 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 }; 176 159 177 160 return m_value.toNodeSet().size(); 178 161 } 179 162 180 Node* XPathResult::iterateNext(ExceptionCode& ec)163 ExceptionOr<Node*> XPathResult::iterateNext() 181 164 { 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 }; 194 167 195 Node* node = m_nodeSet[m_nodeSetPosition]; 196 197 m_nodeSetPosition++; 168 if (invalidIteratorState()) 169 return Exception { INVALID_STATE_ERR }; 198 170 199 return node; 171 if (m_nodeSetPosition >= m_nodeSet.size()) 172 return nullptr; 173 174 return m_nodeSet[m_nodeSetPosition++]; 200 175 } 201 176 202 Node* XPathResult::snapshotItem(unsigned index, ExceptionCode& ec)177 ExceptionOr<Node*> XPathResult::snapshotItem(unsigned index) 203 178 { 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(); 210 183 if (index >= nodes.size()) 211 return 0;212 184 return nullptr; 185 213 186 return nodes[index]; 214 187 } -
trunk/Source/WebCore/xml/XPathResult.h
r204717 r207541 27 27 #pragma once 28 28 29 #include "ExceptionOr.h" 29 30 #include "XPathValue.h" 30 #include <wtf/Forward.h>31 #include <wtf/RefCounted.h>32 31 33 32 namespace WebCore { 34 33 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; 34 class XPathResult : public RefCounted<XPathResult> { 35 public: 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 83 47 }; 84 48 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 68 private: 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 85 79 } // namespace WebCore -
trunk/Source/WebCore/xml/XPathResult.idl
r206723 r207541 35 35 36 36 readonly attribute unsigned short resultType; 37 [GetterMayThrow LegacyException] readonly attribute unrestricted double numberValue;38 [GetterMayThrow LegacyException] readonly attribute DOMString stringValue;39 [GetterMayThrow LegacyException] readonly attribute boolean booleanValue;40 [GetterMayThrow LegacyException] 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; 41 41 42 42 readonly attribute boolean invalidIteratorState; 43 [GetterMayThrow LegacyException] readonly attribute unsigned long snapshotLength;43 [GetterMayThrowException] readonly attribute unsigned long snapshotLength; 44 44 45 [MayThrow LegacyException] Node iterateNext();46 [MayThrow LegacyException] Node snapshotItem(optional unsigned long index = 0);45 [MayThrowException] Node iterateNext(); 46 [MayThrowException] Node snapshotItem(optional unsigned long index = 0); 47 47 }; -
trunk/Source/WebKit/mac/ChangeLog
r207517 r207541 1 2016-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 1 23 2016-10-18 Sam Weinig <sam@webkit.org> 2 24 -
trunk/Source/WebKit/mac/DOM/DOMDocument.mm
r205468 r207541 613 613 } 614 614 615 static 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 615 624 - (DOMXPathExpression *)createExpression:(NSString *)expression resolver:(id <DOMXPathNSResolver>)resolver 616 625 { 617 626 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()); 632 628 } 633 629 … … 641 637 { 642 638 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()); 657 640 } 658 641 -
trunk/Source/WebKit/mac/DOM/DOMXPathExpression.mm
r204717 r207541 56 56 { 57 57 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()); 62 59 } 63 60 -
trunk/Source/WebKit/mac/DOM/DOMXPathResult.mm
r204717 r207541 61 61 { 62 62 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()); 67 64 } 68 65 … … 70 67 { 71 68 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()); 76 70 } 77 71 … … 79 73 { 80 74 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()); 85 76 } 86 77 … … 88 79 { 89 80 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())); 94 82 } 95 83 … … 103 91 { 104 92 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()); 109 94 } 110 95 … … 112 97 { 113 98 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())); 118 100 } 119 101 … … 121 103 { 122 104 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))); 127 106 } 128 107 … … 131 110 WebCore::XPathResult* core(DOMXPathResult *wrapper) 132 111 { 133 return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : 0;112 return wrapper ? reinterpret_cast<WebCore::XPathResult*>(wrapper->_internal) : nullptr; 134 113 } 135 114 -
trunk/Source/WebKit2/ChangeLog
r207530 r207541 1 2016-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 1 22 2016-10-19 Carlos Garcia Campos <cgarcia@igalia.com> 2 23 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp
r205540 r207541 1170 1170 WTF::String convertedExpression = WTF::String::fromUTF8(expression); 1171 1171 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()); 1176 1175 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); 1176 return nullptr; 1177 1177 } 1178 return WebKit::kit( gobjectResult.get());1178 return WebKit::kit(result.releaseReturnValue().ptr()); 1179 1179 } 1180 1180 … … 1204 1204 RefPtr<WebCore::XPathNSResolver> convertedResolver = WebKit::core(resolver); 1205 1205 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()); 1210 1209 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); 1210 return nullptr; 1211 1211 } 1212 return WebKit::kit( gobjectResult.get());1212 return WebKit::kit(result.releaseReturnValue().ptr()); 1213 1213 } 1214 1214 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathExpression.cpp
r205280 r207541 115 115 WebCore::Node* convertedContextNode = WebKit::core(contextNode); 116 116 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()); 121 120 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); 121 return nullptr; 122 122 } 123 return WebKit::kit( gobjectResult.get());123 return WebKit::kit(result.releaseReturnValue().ptr()); 124 124 } 125 125 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMXPathResult.cpp
r205280 r207541 225 225 g_return_val_if_fail(!error || !*error, 0); 226 226 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()); 234 234 } 235 235 … … 240 240 g_return_val_if_fail(!error || !*error, 0); 241 241 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()); 249 249 } 250 250 … … 264 264 g_return_val_if_fail(!error || !*error, 0); 265 265 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(); 273 273 } 274 274 … … 279 279 g_return_val_if_fail(!error || !*error, 0); 280 280 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()); 284 285 } 285 286 … … 290 291 g_return_val_if_fail(!error || !*error, FALSE); 291 292 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(); 299 300 } 300 301 … … 305 306 g_return_val_if_fail(!error || !*error, 0); 306 307 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()); 314 315 } 315 316 … … 329 330 g_return_val_if_fail(!error || !*error, 0); 330 331 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.