Move ChildNode and ParentNode from ExceptionCode to Exception, add support for Except...
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Oct 2016 15:54:51 +0000 (15:54 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Oct 2016 15:54:51 +0000 (15:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164214

Reviewed by Alex Christensen.

Source/WebCore:

* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::initializeOptions): Use FetchHeaders& instead of
Ref<FetchHeaders> for return value.
(WebCore::FetchRequest::initializeWith): Ditto.
* Modules/fetch/FetchRequest.h: Updated for above.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::addSourceBuffer): Use SourceBuffer& instead of
SourceBuffer* for return value.
* Modules/mediasource/MediaSource.h: Updated for above.

* bindings/js/JSDOMBinding.h: Added overloads of checkSecurityForNode so
it works with a function returning a reference.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::getCounterValue): Use Counter& instead of
Counter* for return value.
(WebCore::CSSPrimitiveValue::getRectValue): Use Rect& instead of
Rect* for return value.
* css/CSSPrimitiveValue.h: Updated for above.

* dom/ChildNode.idl: Use non-legacy exceptions.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::querySelector): Use ExceptionOr.
(WebCore::ContainerNode::querySelectorAll): Ditto.
(WebCore::ContainerNode::append): Ditto.
(WebCore::ContainerNode::prepend): Ditto.
* dom/ContainerNode.h: Updated for above.

* dom/Document.cpp:
(WebCore::Document::selectorQueryForString): Use ExceptionOr.
* dom/Document.h: Updated for above.

* dom/Element.cpp:
(WebCore::Element::attachShadow): Return ShadowRoot& instead of
Ref<ShadowRoot> since the shadow root is owned by the element, not
the caller.
(WebCore::Element::matches): Updated for change to make the
selectorQueryForString function use ExceptionOr.
(WebCore::Element::closest): Ditto.
(WebCore::contextNodeForInsertion): Return ContainerNode& instead of
ContainerNode*.
(WebCore::contextElementForInsertion): Updated for above.
* dom/Element.h: Updated for above.
* dom/Element.idl: Changed return type for closest and for
insertAdjacentElement to be nullable since both can return null.

* dom/ExceptionOr.h: Added a specialization for ExceptionOr<T&>.

* dom/Node.cpp:
(WebCore::Node::convertNodesOrStringsIntoNode): Use ExceptionOr.
(WebCore::Node::before): Ditto.
(WebCore::Node::after): Ditto.
(WebCore::Node::replaceWith): Ditto.
* dom/Node.h: Updated for above changes.

* dom/ParentNode.idl: Use non-legacy exceptions.

* dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::queryAll): Changed return type to Ref.
(WebCore::SelectorQueryCache::add): Use ExceptionOr.
* dom/SelectorQuery.h: Updated for above changes.

* html/HTMLFrameOwnerElement.cpp:
(WebCore::HTMLFrameOwnerElement::getSVGDocument): Return
Document& instead of Document*.
* html/HTMLFrameOwnerElement.h: Updated for above change.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::addTextTrack): Return TextTrack&
instead of Ref<TextTrack>.
* html/HTMLMediaElement.h: Updated for above.

* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::partOfSnapshotOverlay):
Updated for new exceptions.
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::querySelector): Ditto.
(WebCore::InspectorDOMAgent::querySelectorAll): Ditto.
(WebCore::InspectorDOMAgent::performSearch): Ditto.
(WebCore::InspectorDOMAgent::highlightSelector): Ditto.

* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::performSearch): Put a null check
here so callers don't have to do it. Pass references to the
individual functions since the pointer can't be null.
(WebCore::InspectorNodeFinder::searchUsingDOMTreeTraversal):
Updated to use reference and streamlined code a bit, using
containsIgnoringASCIICase instead of findIgnoringCase.
(WebCore::InspectorNodeFinder::matchesAttribute): Ditto.
(WebCore::InspectorNodeFinder::matchesElement): Ditto.
(WebCore::InspectorNodeFinder::searchUsingXPath): Ditto.
(WebCore::InspectorNodeFinder::searchUsingCSSSelectors): Ditto.
Also updated  for new exceptions in querySelectorAll.
* inspector/InspectorNodeFinder.h: Updated for above.

* page/Crypto.cpp:
(WebCore::Crypto::webkitSubtle): Return WebKitSubtleCrypto&
insetad of WebKitSubtleCrypto*.
* page/Crypto.h: Updated for above.

* testing/Internals.h: Removed declarations for functions already
removed: ensureShadowRoot and createShadowRoot.

Source/WebKit/mac:

* DOM/DOMCSSPrimitiveValue.mm:
(-[DOMCSSPrimitiveValue getCounterValue]): Updated since return value
is a reference now.
(-[DOMCSSPrimitiveValue getRectValue]): Ditto.

* DOM/DOMDocument.mm:
(-[DOMDocument querySelector:]): Updated exception handling.
(-[DOMDocument querySelectorAll:]): Ditto.
* DOM/DOMDocumentFragment.mm:
(-[DOMDocumentFragment querySelector:]): Ditto.
(-[DOMDocumentFragment querySelectorAll:]): Ditto.
* DOM/DOMElement.mm:
(-[DOMElement querySelector:]): Ditto.
(-[DOMElement querySelectorAll:]): Ditto.

Source/WebKit2:

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp:
(webkit_dom_document_query_selector): Updated exception handling.
(webkit_dom_document_query_selector_all): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentFragment.cpp:
(webkit_dom_document_fragment_query_selector): Ditto.
(webkit_dom_document_fragment_query_selector_all): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp:
(webkit_dom_element_query_selector): Ditto.
(webkit_dom_element_query_selector_all): Ditto.

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

42 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchRequest.cpp
Source/WebCore/Modules/fetch/FetchRequest.h
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/MediaSource.h
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h
Source/WebCore/dom/ChildNode.idl
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNode.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Element.idl
Source/WebCore/dom/ExceptionOr.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ParentNode.idl
Source/WebCore/dom/SelectorQuery.cpp
Source/WebCore/dom/SelectorQuery.h
Source/WebCore/html/HTMLFrameOwnerElement.cpp
Source/WebCore/html/HTMLFrameOwnerElement.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorNodeFinder.cpp
Source/WebCore/inspector/InspectorNodeFinder.h
Source/WebCore/page/Crypto.cpp
Source/WebCore/page/Crypto.h
Source/WebCore/testing/Internals.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOMCSSPrimitiveValue.mm
Source/WebKit/mac/DOM/DOMDocument.mm
Source/WebKit/mac/DOM/DOMDocumentFragment.mm
Source/WebKit/mac/DOM/DOMElement.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentFragment.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp

index c9f53dc..ae059db 100644 (file)
@@ -1,5 +1,117 @@
 2016-10-31  Darin Adler  <darin@apple.com>
 
+        Move ChildNode and ParentNode from ExceptionCode to Exception, add support for ExceptionOr<T&>
+        https://bugs.webkit.org/show_bug.cgi?id=164214
+
+        Reviewed by Alex Christensen.
+
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::FetchRequest::initializeOptions): Use FetchHeaders& instead of
+        Ref<FetchHeaders> for return value.
+        (WebCore::FetchRequest::initializeWith): Ditto.
+        * Modules/fetch/FetchRequest.h: Updated for above.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::addSourceBuffer): Use SourceBuffer& instead of
+        SourceBuffer* for return value.
+        * Modules/mediasource/MediaSource.h: Updated for above.
+
+        * bindings/js/JSDOMBinding.h: Added overloads of checkSecurityForNode so
+        it works with a function returning a reference.
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::getCounterValue): Use Counter& instead of
+        Counter* for return value.
+        (WebCore::CSSPrimitiveValue::getRectValue): Use Rect& instead of
+        Rect* for return value.
+        * css/CSSPrimitiveValue.h: Updated for above.
+
+        * dom/ChildNode.idl: Use non-legacy exceptions.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::querySelector): Use ExceptionOr.
+        (WebCore::ContainerNode::querySelectorAll): Ditto.
+        (WebCore::ContainerNode::append): Ditto.
+        (WebCore::ContainerNode::prepend): Ditto.
+        * dom/ContainerNode.h: Updated for above.
+
+        * dom/Document.cpp:
+        (WebCore::Document::selectorQueryForString): Use ExceptionOr.
+        * dom/Document.h: Updated for above.
+
+        * dom/Element.cpp:
+        (WebCore::Element::attachShadow): Return ShadowRoot& instead of
+        Ref<ShadowRoot> since the shadow root is owned by the element, not
+        the caller.
+        (WebCore::Element::matches): Updated for change to make the
+        selectorQueryForString function use ExceptionOr.
+        (WebCore::Element::closest): Ditto.
+        (WebCore::contextNodeForInsertion): Return ContainerNode& instead of
+        ContainerNode*.
+        (WebCore::contextElementForInsertion): Updated for above.
+        * dom/Element.h: Updated for above.
+        * dom/Element.idl: Changed return type for closest and for
+        insertAdjacentElement to be nullable since both can return null.
+
+        * dom/ExceptionOr.h: Added a specialization for ExceptionOr<T&>.
+
+        * dom/Node.cpp:
+        (WebCore::Node::convertNodesOrStringsIntoNode): Use ExceptionOr.
+        (WebCore::Node::before): Ditto.
+        (WebCore::Node::after): Ditto.
+        (WebCore::Node::replaceWith): Ditto.
+        * dom/Node.h: Updated for above changes.
+
+        * dom/ParentNode.idl: Use non-legacy exceptions.
+
+        * dom/SelectorQuery.cpp:
+        (WebCore::SelectorDataList::queryAll): Changed return type to Ref.
+        (WebCore::SelectorQueryCache::add): Use ExceptionOr.
+        * dom/SelectorQuery.h: Updated for above changes.
+
+        * html/HTMLFrameOwnerElement.cpp:
+        (WebCore::HTMLFrameOwnerElement::getSVGDocument): Return
+        Document& instead of Document*.
+        * html/HTMLFrameOwnerElement.h: Updated for above change.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::addTextTrack): Return TextTrack&
+        instead of Ref<TextTrack>.
+        * html/HTMLMediaElement.h: Updated for above.
+
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::partOfSnapshotOverlay):
+        Updated for new exceptions.
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::querySelector): Ditto.
+        (WebCore::InspectorDOMAgent::querySelectorAll): Ditto.
+        (WebCore::InspectorDOMAgent::performSearch): Ditto.
+        (WebCore::InspectorDOMAgent::highlightSelector): Ditto.
+
+        * inspector/InspectorNodeFinder.cpp:
+        (WebCore::InspectorNodeFinder::performSearch): Put a null check
+        here so callers don't have to do it. Pass references to the
+        individual functions since the pointer can't be null.
+        (WebCore::InspectorNodeFinder::searchUsingDOMTreeTraversal):
+        Updated to use reference and streamlined code a bit, using
+        containsIgnoringASCIICase instead of findIgnoringCase.
+        (WebCore::InspectorNodeFinder::matchesAttribute): Ditto.
+        (WebCore::InspectorNodeFinder::matchesElement): Ditto.
+        (WebCore::InspectorNodeFinder::searchUsingXPath): Ditto.
+        (WebCore::InspectorNodeFinder::searchUsingCSSSelectors): Ditto.
+        Also updated  for new exceptions in querySelectorAll.
+        * inspector/InspectorNodeFinder.h: Updated for above.
+
+        * page/Crypto.cpp:
+        (WebCore::Crypto::webkitSubtle): Return WebKitSubtleCrypto&
+        insetad of WebKitSubtleCrypto*.
+        * page/Crypto.h: Updated for above.
+
+        * testing/Internals.h: Removed declarations for functions already
+        removed: ensureShadowRoot and createShadowRoot.
+
+2016-10-31  Darin Adler  <darin@apple.com>
+
         Convert Document from ExceptionCode to Exception
         https://bugs.webkit.org/show_bug.cgi?id=164212
 
index 9afccb8..5592bd7 100644 (file)
@@ -221,7 +221,7 @@ static bool methodCanHaveBody(const FetchRequest::InternalRequest& internalReque
     return internalRequest.request.httpMethod() != "GET" && internalRequest.request.httpMethod() != "HEAD";
 }
 
-ExceptionOr<Ref<FetchHeaders>> FetchRequest::initializeOptions(const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeOptions(const Dictionary& init)
 {
     ASSERT(scriptExecutionContext());
 
@@ -237,10 +237,10 @@ ExceptionOr<Ref<FetchHeaders>> FetchRequest::initializeOptions(const Dictionary&
             return Exception { TypeError, ASCIILiteral("There cannot be an integrity in no-cors mode.") };
         m_headers->setGuard(FetchHeaders::Guard::RequestNoCors);
     }
-    return m_headers.copyRef();
+    return m_headers.get();
 }
 
-ExceptionOr<Ref<FetchHeaders>> FetchRequest::initializeWith(const String& url, const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(const String& url, const Dictionary& init)
 {
     ASSERT(scriptExecutionContext());
     // FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser.
@@ -256,7 +256,7 @@ ExceptionOr<Ref<FetchHeaders>> FetchRequest::initializeWith(const String& url, c
     return initializeOptions(init);
 }
 
-ExceptionOr<Ref<FetchHeaders>> FetchRequest::initializeWith(FetchRequest& input, const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(FetchRequest& input, const Dictionary& init)
 {
     if (input.isDisturbedOrLocked())
         return Exception {TypeError, ASCIILiteral("Request input is disturbed or locked.") };
index 0b6cb68..b76265a 100644 (file)
@@ -45,8 +45,8 @@ class FetchRequest final : public FetchBodyOwner {
 public:
     static Ref<FetchRequest> create(ScriptExecutionContext& context) { return adoptRef(*new FetchRequest(context, Nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { })); }
 
-    ExceptionOr<Ref<FetchHeaders>> initializeWith(FetchRequest&, const Dictionary&);
-    ExceptionOr<Ref<FetchHeaders>> initializeWith(const String&, const Dictionary&);
+    ExceptionOr<FetchHeaders&> initializeWith(FetchRequest&, const Dictionary&);
+    ExceptionOr<FetchHeaders&> initializeWith(const String&, const Dictionary&);
     ExceptionOr<void> setBody(JSC::ExecState&, JSC::JSValue, FetchRequest*);
 
     const String& method() const { return m_internalRequest.request.httpMethod(); }
@@ -95,7 +95,7 @@ public:
 private:
     FetchRequest(ScriptExecutionContext&, Optional<FetchBody>&&, Ref<FetchHeaders>&&, InternalRequest&&);
 
-    ExceptionOr<Ref<FetchHeaders>> initializeOptions(const Dictionary&);
+    ExceptionOr<FetchHeaders&> initializeOptions(const Dictionary&);
 
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
index 80e7284..af13e42 100644 (file)
@@ -622,7 +622,7 @@ void MediaSource::streamEndedWithError(Optional<EndOfStreamError> error)
     }
 }
 
-ExceptionOr<SourceBuffer*> MediaSource::addSourceBuffer(const String& type)
+ExceptionOr<SourceBuffer&> MediaSource::addSourceBuffer(const String& type)
 {
     LOG(MediaSource, "MediaSource::addSourceBuffer(%s) %p", type.ascii().data(), this);
 
@@ -668,14 +668,14 @@ ExceptionOr<SourceBuffer*> MediaSource::addSourceBuffer(const String& type)
     // ↳ Set the mode attribute on the new object to "segments".
     buffer->setMode(shouldGenerateTimestamps ? SourceBuffer::AppendMode::Sequence : SourceBuffer::AppendMode::Segments);
 
-    SourceBuffer* result = buffer.ptr();
+    auto& result = buffer.get();
 
     // 8. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(WTFMove(buffer));
     regenerateActiveSourceBuffers();
 
     // 9. Return the new object to the caller.
-    return WTFMove(result);
+    return result;
 }
 
 ExceptionOr<void> MediaSource::removeSourceBuffer(SourceBuffer& buffer)
index 37f113c..5a5320b 100644 (file)
@@ -89,7 +89,7 @@ public:
 
     SourceBufferList* sourceBuffers() { return m_sourceBuffers.get(); }
     SourceBufferList* activeSourceBuffers() { return m_activeSourceBuffers.get(); }
-    ExceptionOr<SourceBuffer*> addSourceBuffer(const String& type);
+    ExceptionOr<SourceBuffer&> addSourceBuffer(const String& type);
     ExceptionOr<void> removeSourceBuffer(SourceBuffer&);
     static bool isTypeSupported(const String& type);
 
index a15e864..18ab3c1 100644 (file)
@@ -285,8 +285,10 @@ WEBCORE_EXPORT bool hasIteratorMethod(JSC::ExecState&, JSC::JSValue);
 
 enum SecurityReportingOption { DoNotReportSecurityError, LogSecurityError, ThrowSecurityError };
 namespace BindingSecurity {
+    template<typename T> T* checkSecurityForNode(JSC::ExecState&, T&);
     template<typename T> T* checkSecurityForNode(JSC::ExecState&, T*);
     template<typename T> ExceptionOr<T*> checkSecurityForNode(JSC::ExecState&, ExceptionOr<T*>&&);
+    template<typename T> ExceptionOr<T*> checkSecurityForNode(JSC::ExecState&, ExceptionOr<T&>&&);
     bool shouldAllowAccessToDOMWindow(JSC::ExecState*, DOMWindow&, SecurityReportingOption = LogSecurityError);
     bool shouldAllowAccessToDOMWindow(JSC::ExecState&, DOMWindow&, String& message);
     bool shouldAllowAccessToFrame(JSC::ExecState*, Frame*, SecurityReportingOption = LogSecurityError);
@@ -774,6 +776,11 @@ template<typename T> inline JSC::JSValue toJSNewlyCreated(JSC::ExecState& state,
     return toJSNewlyCreated(&state, &globalObject, value.releaseReturnValue());
 }
 
+template<typename T> inline T* BindingSecurity::checkSecurityForNode(JSC::ExecState& state, T& node)
+{
+    return shouldAllowAccessToNode(state, &node) ? &node : nullptr;
+}
+
 template<typename T> inline T* BindingSecurity::checkSecurityForNode(JSC::ExecState& state, T* node)
 {
     return shouldAllowAccessToNode(state, node) ? node : nullptr;
@@ -782,7 +789,14 @@ template<typename T> inline T* BindingSecurity::checkSecurityForNode(JSC::ExecSt
 template<typename T> inline ExceptionOr<T*> BindingSecurity::checkSecurityForNode(JSC::ExecState& state, ExceptionOr<T*>&& value)
 {
     if (value.hasException())
-        return WTFMove(value);
+        return value.releaseException();
+    return checkSecurityForNode(state, value.releaseReturnValue());
+}
+
+template<typename T> inline ExceptionOr<T*> BindingSecurity::checkSecurityForNode(JSC::ExecState& state, ExceptionOr<T&>&& value)
+{
+    if (value.hasException())
+        return value.releaseException();
     return checkSecurityForNode(state, value.releaseReturnValue());
 }
 
index 492c754..621fce8 100644 (file)
@@ -962,18 +962,18 @@ String CSSPrimitiveValue::stringValue() const
     }
 }
 
-ExceptionOr<Counter*> CSSPrimitiveValue::getCounterValue() const
+ExceptionOr<Counter&> CSSPrimitiveValue::getCounterValue() const
 {
     if (m_primitiveUnitType != CSS_COUNTER)
         return Exception { INVALID_ACCESS_ERR };
-    return m_value.counter;
+    return *m_value.counter;
 }
 
-ExceptionOr<Rect*> CSSPrimitiveValue::getRectValue() const
+ExceptionOr<Rect&> CSSPrimitiveValue::getRectValue() const
 {
     if (m_primitiveUnitType != CSS_RECT)
         return Exception { INVALID_ACCESS_ERR };
-    return m_value.rect;
+    return *m_value.rect;
 }
 
 ExceptionOr<Ref<RGBColor>> CSSPrimitiveValue::getRGBColorValue() const
index e655a1b..f1c8aea 100644 (file)
@@ -251,8 +251,8 @@ public:
     WEBCORE_EXPORT ExceptionOr<float> getFloatValue(unsigned short unitType) const;
     WEBCORE_EXPORT ExceptionOr<void> setStringValue(unsigned short stringType, const String& stringValue);
     WEBCORE_EXPORT ExceptionOr<String> getStringValue() const;
-    WEBCORE_EXPORT ExceptionOr<Counter*> getCounterValue() const;
-    WEBCORE_EXPORT ExceptionOr<Rect*> getRectValue() const;
+    WEBCORE_EXPORT ExceptionOr<Counter&> getCounterValue() const;
+    WEBCORE_EXPORT ExceptionOr<Rect&> getRectValue() const;
     WEBCORE_EXPORT ExceptionOr<Ref<RGBColor>> getRGBColorValue() const;
 
     double computeDegrees() const;
index fc5d85e..54f70a3 100644 (file)
@@ -22,8 +22,8 @@
 [
     NoInterfaceObject,
 ] interface ChildNode {
-    [CEReactions, Unscopable, MayThrowLegacyException] void before((Node or DOMString)... nodes);
-    [CEReactions, Unscopable, MayThrowLegacyException] void after((Node or DOMString)... nodes);
-    [CEReactions, Unscopable, MayThrowLegacyException] void replaceWith((Node or DOMString)... nodes);
+    [CEReactions, Unscopable, MayThrowException] void before((Node or DOMString)... nodes);
+    [CEReactions, Unscopable, MayThrowException] void after((Node or DOMString)... nodes);
+    [CEReactions, Unscopable, MayThrowException] void replaceWith((Node or DOMString)... nodes);
     [CEReactions, Unscopable, MayThrowException] void remove();
 };
index 3514971..85c594d 100644 (file)
@@ -809,18 +809,20 @@ void ContainerNode::updateTreeAfterInsertion(Node& child)
     dispatchChildInsertionEvents(child);
 }
 
-Element* ContainerNode::querySelector(const String& selectors, ExceptionCode& ec)
+ExceptionOr<Element*> ContainerNode::querySelector(const String& selectors)
 {
-    if (SelectorQuery* selectorQuery = document().selectorQueryForString(selectors, ec))
-        return selectorQuery->queryFirst(*this);
-    return nullptr;
+    auto query = document().selectorQueryForString(selectors);
+    if (query.hasException())
+        return query.releaseException();
+    return query.releaseReturnValue().queryFirst(*this);
 }
 
-RefPtr<NodeList> ContainerNode::querySelectorAll(const String& selectors, ExceptionCode& ec)
+ExceptionOr<Ref<NodeList>> ContainerNode::querySelectorAll(const String& selectors)
 {
-    if (SelectorQuery* selectorQuery = document().selectorQueryForString(selectors, ec))
-        return selectorQuery->queryAll(*this);
-    return nullptr;
+    auto query = document().selectorQueryForString(selectors);
+    if (query.hasException())
+        return query.releaseException();
+    return query.releaseReturnValue().queryAll(*this);
 }
 
 Ref<HTMLCollection> ContainerNode::getElementsByTagName(const AtomicString& qualifiedName)
@@ -878,22 +880,38 @@ unsigned ContainerNode::childElementCount() const
     return std::distance(children.begin(), children.end());
 }
 
-void ContainerNode::append(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<void> ContainerNode::append(Vector<NodeOrString>&& vector)
 {
-    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
-    if (ec || !node)
-        return;
+    auto result = convertNodesOrStringsIntoNode(WTFMove(vector));
+    if (result.hasException())
+        return result.releaseException();
+
+    auto node = result.releaseReturnValue();
+    if (!node)
+        return { };
 
+    ExceptionCode ec = 0;
     appendChild(*node, ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
-void ContainerNode::prepend(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<void> ContainerNode::prepend(Vector<NodeOrString>&& vector)
 {
-    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
-    if (ec || !node)
-        return;
+    auto result = convertNodesOrStringsIntoNode(WTFMove(vector));
+    if (result.hasException())
+        return result.releaseException();
+
+    auto node = result.releaseReturnValue();
+    if (!node)
+        return { };
 
+    ExceptionCode ec = 0;
     insertBefore(*node, firstChild(), ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
 HTMLCollection* ContainerNode::cachedHTMLCollection(CollectionType type)
index a65f64a..55eeecb 100644 (file)
@@ -86,8 +86,8 @@ public:
     // This gives the area within which events may get handled by a hander registered on this node.
     virtual LayoutRect absoluteEventHandlerBounds(bool& /* includesFixedPositionElements */) { return LayoutRect(); }
 
-    WEBCORE_EXPORT Element* querySelector(const String& selectors, ExceptionCode&);
-    WEBCORE_EXPORT RefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<Element*> querySelector(const String& selectors);
+    WEBCORE_EXPORT ExceptionOr<Ref<NodeList>> querySelectorAll(const String& selectors);
 
     WEBCORE_EXPORT Ref<HTMLCollection> getElementsByTagName(const AtomicString&);
     WEBCORE_EXPORT Ref<HTMLCollection> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
@@ -100,8 +100,8 @@ public:
     WEBCORE_EXPORT Element* firstElementChild() const;
     WEBCORE_EXPORT Element* lastElementChild() const;
     WEBCORE_EXPORT unsigned childElementCount() const;
-    void append(Vector<NodeOrString>&&, ExceptionCode&);
-    void prepend(Vector<NodeOrString>&&, ExceptionCode&);
+    ExceptionOr<void> append(Vector<NodeOrString>&&);
+    ExceptionOr<void> prepend(Vector<NodeOrString>&&);
 
     bool ensurePreInsertionValidity(Node& newChild, Node* refChild, ExceptionCode&);
 
index dfe640e..e4ae07f 100644 (file)
@@ -762,16 +762,13 @@ HTMLImageElement* Document::imageElementByCaseFoldedUsemap(const AtomicStringImp
     return m_imagesByUsemap.getElementByCaseFoldedUsemap(name, *this);
 }
 
-SelectorQuery* Document::selectorQueryForString(const String& selectorString, ExceptionCode& ec)
+ExceptionOr<SelectorQuery&> Document::selectorQueryForString(const String& selectorString)
 {
-    if (selectorString.isEmpty()) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
-
+    if (selectorString.isEmpty())
+        return Exception { SYNTAX_ERR };
     if (!m_selectorQueryCache)
         m_selectorQueryCache = std::make_unique<SelectorQueryCache>();
-    return m_selectorQueryCache->add(selectorString, *this, ec);
+    return m_selectorQueryCache->add(selectorString, *this);
 }
 
 void Document::clearSelectorQueryCache()
index 4241ec4..bd1daf3 100644 (file)
@@ -347,7 +347,7 @@ public:
     void removeImageElementByCaseFoldedUsemap(const AtomicStringImpl&, HTMLImageElement&);
     HTMLImageElement* imageElementByCaseFoldedUsemap(const AtomicStringImpl&) const;
 
-    SelectorQuery* selectorQueryForString(const String&, ExceptionCode&);
+    ExceptionOr<SelectorQuery&> selectorQueryForString(const String&);
     void clearSelectorQueryCache();
 
     // DOM methods & attributes for Document
index 2b495ad..5f7a258 100644 (file)
@@ -1832,7 +1832,7 @@ static bool canAttachAuthorShadowRoot(const Element& element)
     return tagNames.get().contains(localName) || Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid;
 }
 
-ExceptionOr<Ref<ShadowRoot>> Element::attachShadow(const ShadowRootInit& init)
+ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
 {
     if (!canAttachAuthorShadowRoot(*this))
         return Exception { NOT_SUPPORTED_ERR };
@@ -1841,8 +1841,9 @@ ExceptionOr<Ref<ShadowRoot>> Element::attachShadow(const ShadowRootInit& init)
     if (init.mode == ShadowRootMode::UserAgent)
         return Exception { TypeError };
     auto shadow = ShadowRoot::create(document(), init.mode);
-    addShadowRoot(shadow.copyRef());
-    return WTFMove(shadow);
+    auto& result = shadow.get();
+    addShadowRoot(WTFMove(shadow));
+    return result;
 }
 
 ShadowRoot* Element::shadowRootForBindings(JSC::ExecState& state) const
@@ -2952,22 +2953,18 @@ bool Element::matchesDefaultPseudoClass() const
 
 ExceptionOr<bool> Element::matches(const String& selector)
 {
-    ExceptionCode ec = 0;
-    auto* query = document().selectorQueryForString(selector, ec);
-    if (ec)
-        return Exception { ec };
-    return query && query->matches(*this);
+    auto query = document().selectorQueryForString(selector);
+    if (query.hasException())
+        return query.releaseException();
+    return query.releaseReturnValue().matches(*this);
 }
 
 ExceptionOr<Element*> Element::closest(const String& selector)
 {
-    ExceptionCode ec = 0;
-    auto* query = document().selectorQueryForString(selector, ec);
-    if (ec)
-        return Exception { ec };
-    if (!query)
-        return nullptr;
-    return query->closest(*this);
+    auto query = document().selectorQueryForString(selector);
+    if (query.hasException())
+        return query.releaseException();
+    return query.releaseReturnValue().closest(*this);
 }
 
 bool Element::shouldAppearIndeterminate() const
@@ -3707,16 +3704,16 @@ ExceptionOr<Element*> Element::insertAdjacentElement(const String& where, Elemen
 }
 
 // Step 1 of https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml.
-static ExceptionOr<ContainerNode*> contextNodeForInsertion(const String& where, Element& element)
+static ExceptionOr<ContainerNode&> contextNodeForInsertion(const String& where, Element& element)
 {
     if (equalLettersIgnoringASCIICase(where, "beforebegin") || equalLettersIgnoringASCIICase(where, "afterend")) {
         auto* parent = element.parentNode();
         if (!parent || is<Document>(*parent))
             return Exception { NO_MODIFICATION_ALLOWED_ERR };
-        return parent;
+        return *parent;
     }
     if (equalLettersIgnoringASCIICase(where, "afterbegin") || equalLettersIgnoringASCIICase(where, "beforeend"))
-        return &element;
+        return element;
     return Exception { SYNTAX_ERR };
 }
 
@@ -3726,7 +3723,7 @@ static ExceptionOr<Ref<Element>> contextElementForInsertion(const String& where,
     auto contextNodeResult = contextNodeForInsertion(where, element);
     if (contextNodeResult.hasException())
         return contextNodeResult.releaseException();
-    auto& contextNode = *contextNodeResult.releaseReturnValue();
+    auto& contextNode = contextNodeResult.releaseReturnValue();
     if (!is<Element>(contextNode) || (contextNode.document().isHTMLDocument() && is<HTMLHtmlElement>(contextNode)))
         return Ref<Element> { HTMLBodyElement::create(contextNode.document()) };
     return Ref<Element> { downcast<Element>(contextNode) };
index 7dcb2f8..dda8bda 100644 (file)
@@ -273,7 +273,7 @@ public:
     struct ShadowRootInit {
         ShadowRootMode mode;
     };
-    ExceptionOr<Ref<ShadowRoot>> attachShadow(const ShadowRootInit&);
+    ExceptionOr<ShadowRoot&> attachShadow(const ShadowRootInit&);
 
     ShadowRoot* userAgentShadowRoot() const;
     WEBCORE_EXPORT ShadowRoot& ensureUserAgentShadowRoot();
index e42d2d4..7056173 100644 (file)
     [PutForwards=value] readonly attribute DOMTokenList classList;
 
     [MayThrowException] boolean matches(DOMString selectors);
-    [MayThrowException] Element closest(DOMString selectors);
+    [MayThrowException] Element? closest(DOMString selectors);
     [ImplementedAs=matches, MayThrowException] boolean webkitMatchesSelector(DOMString selectors);
 
     // CSSOM View Module API
     [CEReactions, Reflect] attribute DOMString uiactions;
 #endif
 
-    [CEReactions, MayThrowException] Element insertAdjacentElement(DOMString where, Element element);
+    [CEReactions, MayThrowException] Element? insertAdjacentElement(DOMString where, Element element);
     [CEReactions, MayThrowException] void insertAdjacentHTML(DOMString where, DOMString html);
     [MayThrowException] void insertAdjacentText(DOMString where, DOMString text);
 
index 2d1419f..757a845 100644 (file)
@@ -46,6 +46,19 @@ private:
     Variant<Exception, ReturnType> m_value;
 };
 
+template<typename ReturnReferenceType> class ExceptionOr<ReturnReferenceType&> {
+public:
+    ExceptionOr(Exception&&);
+    ExceptionOr(ReturnReferenceType&);
+
+    bool hasException() const;
+    Exception&& releaseException();
+    ReturnReferenceType& releaseReturnValue();
+
+private:
+    ExceptionOr<ReturnReferenceType*> m_value;
+};
+
 template<> class ExceptionOr<void> {
 public:
     ExceptionOr(Exception&&);
@@ -88,6 +101,31 @@ template<typename ReturnType> inline ReturnType&& ExceptionOr<ReturnType>::relea
     return WTF::get<ReturnType>(WTFMove(m_value));
 }
 
+template<typename ReturnReferenceType> inline ExceptionOr<ReturnReferenceType&>::ExceptionOr(Exception&& exception)
+    : m_value(WTFMove(exception))
+{
+}
+
+template<typename ReturnReferenceType> inline ExceptionOr<ReturnReferenceType&>::ExceptionOr(ReturnReferenceType& returnValue)
+    : m_value(&returnValue)
+{
+}
+
+template<typename ReturnReferenceType> inline bool ExceptionOr<ReturnReferenceType&>::hasException() const
+{
+    return m_value.hasException();
+}
+
+template<typename ReturnReferenceType> inline Exception&& ExceptionOr<ReturnReferenceType&>::releaseException()
+{
+    return m_value.releaseException();
+}
+
+template<typename ReturnReferenceType> inline ReturnReferenceType& ExceptionOr<ReturnReferenceType&>::releaseReturnValue()
+{
+    return *m_value.releaseReturnValue();
+}
+
 inline ExceptionOr<void>::ExceptionOr(Exception&& exception)
     : m_exception(WTFMove(exception))
 {
index 14701b4..9ac9e8b 100644 (file)
@@ -466,7 +466,7 @@ static RefPtr<Node> firstFollowingSiblingNotInNodeSet(Node& context, const HashS
     return nullptr;
 }
 
-RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<RefPtr<Node>> Node::convertNodesOrStringsIntoNode(Vector<NodeOrString>&& nodeOrStringVector)
 {
     if (nodeOrStringVector.isEmpty())
         return nullptr;
@@ -481,73 +481,98 @@ RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<NodeOrString>&& nodeOrSt
     }
 
     if (nodes.size() == 1)
-        return WTFMove(nodes.first());
+        return RefPtr<Node> { WTFMove(nodes.first()) };
 
     auto nodeToReturn = DocumentFragment::create(document());
     for (auto& node : nodes) {
-        if (!nodeToReturn->appendChild(node, ec))
-            return nullptr;
+        ExceptionCode ec = 0;
+        nodeToReturn->appendChild(node, ec);
+        if (ec)
+            return Exception { ec };
     }
-    return WTFMove(nodeToReturn);
+    return RefPtr<Node> { WTFMove(nodeToReturn) };
 }
 
-void Node::before(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<void> Node::before(Vector<NodeOrString>&& nodeOrStringVector)
 {
     RefPtr<ContainerNode> parent = parentNode();
     if (!parent)
-        return;
+        return { };
 
     auto nodeSet = nodeSetPreTransformedFromNodeOrStringVector(nodeOrStringVector);
     auto viablePreviousSibling = firstPrecedingSiblingNotInNodeSet(*this, nodeSet);
 
-    auto node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
-    if (ec || !node)
-        return;
+    auto result = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector));
+    if (result.hasException())
+        return result.releaseException();
+    auto node = result.releaseReturnValue();
+    if (!node)
+        return { };
 
     if (viablePreviousSibling)
         viablePreviousSibling = viablePreviousSibling->nextSibling();
     else
         viablePreviousSibling = parent->firstChild();
 
+    ExceptionCode ec = 0;
     parent->insertBefore(*node, viablePreviousSibling.get(), ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
-void Node::after(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<void> Node::after(Vector<NodeOrString>&& nodeOrStringVector)
 {
     RefPtr<ContainerNode> parent = parentNode();
     if (!parent)
-        return;
+        return { };
 
     auto nodeSet = nodeSetPreTransformedFromNodeOrStringVector(nodeOrStringVector);
     auto viableNextSibling = firstFollowingSiblingNotInNodeSet(*this, nodeSet);
 
-    auto node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
-    if (ec || !node)
-        return;
+    auto result = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector));
+    if (result.hasException())
+        return result.releaseException();
+    auto node = result.releaseReturnValue();
+    if (!node)
+        return { };
 
+    ExceptionCode ec = 0;
     parent->insertBefore(*node, viableNextSibling.get(), ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
-void Node::replaceWith(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
+ExceptionOr<void> Node::replaceWith(Vector<NodeOrString>&& nodeOrStringVector)
 {
     RefPtr<ContainerNode> parent = parentNode();
     if (!parent)
-        return;
+        return { };
 
     auto nodeSet = nodeSetPreTransformedFromNodeOrStringVector(nodeOrStringVector);
     auto viableNextSibling = firstFollowingSiblingNotInNodeSet(*this, nodeSet);
 
-    auto node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
-    if (ec)
-        return;
+    auto result = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector));
+    if (result.hasException())
+        return result.releaseException();
+    auto node = result.releaseReturnValue();
 
     if (parentNode() == parent) {
-        if (node)
+        if (node) {
+            ExceptionCode ec = 0;
             parent->replaceChild(*node, *this, ec);
-        else
+            if (ec)
+                return Exception { ec };
+        } else
             parent->removeChild(*this);
-    } else if (node)
+    } else if (node) {
+        ExceptionCode ec = 0;
         parent->insertBefore(*node, viableNextSibling.get(), ec);
+        if (ec)
+            return Exception { ec };
+    }
+    return { };
 }
 
 ExceptionOr<void> Node::remove()
index ec85e0b..ffd009d 100644 (file)
@@ -193,9 +193,9 @@ public:
     WEBCORE_EXPORT Element* nextElementSibling() const;
 
     // From the ChildNode - https://dom.spec.whatwg.org/#childnode
-    void before(Vector<NodeOrString>&&, ExceptionCode&);
-    void after(Vector<NodeOrString>&&, ExceptionCode&);
-    void replaceWith(Vector<NodeOrString>&&, ExceptionCode&);
+    ExceptionOr<void> before(Vector<NodeOrString>&&);
+    ExceptionOr<void> after(Vector<NodeOrString>&&);
+    ExceptionOr<void> replaceWith(Vector<NodeOrString>&&);
     WEBCORE_EXPORT ExceptionOr<void> remove();
 
     // Other methods (not part of DOM)
@@ -652,7 +652,7 @@ protected:
     void invalidateStyle(Style::Validity, Style::InvalidationMode = Style::InvalidationMode::Normal);
     void updateAncestorsForStyleRecalc();
 
-    RefPtr<Node> convertNodesOrStringsIntoNode(Vector<NodeOrString>&&, ExceptionCode&);
+    ExceptionOr<RefPtr<Node>> convertNodesOrStringsIntoNode(Vector<NodeOrString>&&);
 
 private:
     virtual PseudoId customPseudoId() const
index 3aa494e..eaf11dd 100644 (file)
     readonly attribute Element lastElementChild;
     readonly attribute unsigned long childElementCount;
 
-    [CEReactions, Unscopable, MayThrowLegacyException] void prepend((Node or DOMString)... nodes);
-    [CEReactions, Unscopable, MayThrowLegacyException] void append((Node or DOMString)... nodes);
+    [CEReactions, Unscopable, MayThrowException] void prepend((Node or DOMString)... nodes);
+    [CEReactions, Unscopable, MayThrowException] void append((Node or DOMString)... nodes);
 
     // [Unscopable] Element? query(DOMString relativeSelectors);
     // [NewObject, Unscopable] Elements queryAll(DOMString relativeSelectors);
-    [MayThrowLegacyException] Element querySelector(DOMString selectors);
-    [MayThrowLegacyException, NewObject] NodeList querySelectorAll(DOMString selectors);
+    [MayThrowException] Element querySelector(DOMString selectors);
+    [MayThrowException, NewObject] NodeList querySelectorAll(DOMString selectors);
 };
index 859c6b2..1d8735d 100644 (file)
@@ -169,7 +169,7 @@ struct AllElementExtractorSelectorQueryTrait {
     ALWAYS_INLINE static void appendOutputForElement(OutputType& output, Element* element) { ASSERT(element); output.append(*element); }
 };
 
-RefPtr<NodeList> SelectorDataList::queryAll(ContainerNode& rootNode) const
+Ref<NodeList> SelectorDataList::queryAll(ContainerNode& rootNode) const
 {
     Vector<Ref<Element>> result;
     execute<AllElementExtractorSelectorQueryTrait>(rootNode, result);
@@ -616,31 +616,27 @@ SelectorQuery::SelectorQuery(CSSSelectorList&& selectorList)
 {
 }
 
-SelectorQuery* SelectorQueryCache::add(const String& selectors, Document& document, ExceptionCode& ec)
+ExceptionOr<SelectorQuery&> SelectorQueryCache::add(const String& selectors, Document& document)
 {
     auto it = m_entries.find(selectors);
     if (it != m_entries.end())
-        return it->value.get();
+        return *it->value;
 
     CSSParser parser(document);
     CSSSelectorList selectorList;
     parser.parseSelector(selectors, selectorList);
 
-    if (!selectorList.first() || selectorList.hasInvalidSelector()) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
+    if (!selectorList.first() || selectorList.hasInvalidSelector())
+        return Exception { SYNTAX_ERR };
 
-    if (selectorList.selectorsNeedNamespaceResolution()) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
+    if (selectorList.selectorsNeedNamespaceResolution())
+        return Exception { SYNTAX_ERR };
 
     const int maximumSelectorQueryCacheSize = 256;
     if (m_entries.size() == maximumSelectorQueryCacheSize)
         m_entries.remove(m_entries.begin());
 
-    return m_entries.add(selectors, std::make_unique<SelectorQuery>(WTFMove(selectorList))).iterator->value.get();
+    return *m_entries.add(selectors, std::make_unique<SelectorQuery>(WTFMove(selectorList))).iterator->value;
 }
 
 }
index 58ab670..601addf 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef SelectorQuery_h
-#define SelectorQuery_h
+#pragma once
 
 #include "CSSSelectorList.h"
+#include "ExceptionOr.h"
 #include "NodeList.h"
 #include "SelectorCompiler.h"
 #include <wtf/HashMap.h>
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-    
 class CSSSelector;
 class ContainerNode;
 class Document;
 class Element;
-class Node;
-class NodeList;
 
 class SelectorDataList {
 public:
     explicit SelectorDataList(const CSSSelectorList&);
     bool matches(Element&) const;
     Element* closest(Element&) const;
-    RefPtr<NodeList> queryAll(ContainerNode& rootNode) const;
+    Ref<NodeList> queryAll(ContainerNode& rootNode) const;
     Element* queryFirst(ContainerNode& rootNode) const;
 
 private:
@@ -120,7 +116,7 @@ public:
     explicit SelectorQuery(CSSSelectorList&&);
     bool matches(Element&) const;
     Element* closest(Element&) const;
-    RefPtr<NodeList> queryAll(ContainerNode& rootNode) const;
+    Ref<NodeList> queryAll(ContainerNode& rootNode) const;
     Element* queryFirst(ContainerNode& rootNode) const;
 
 private:
@@ -130,10 +126,8 @@ private:
 
 class SelectorQueryCache {
     WTF_MAKE_FAST_ALLOCATED;
-
 public:
-    SelectorQuery* add(const String&, Document&, ExceptionCode&);
-
+    ExceptionOr<SelectorQuery&> add(const String&, Document&);
 private:
     HashMap<String, std::unique_ptr<SelectorQuery>> m_entries;
 };
@@ -148,7 +142,7 @@ inline Element* SelectorQuery::closest(Element& element) const
     return m_selectors.closest(element);
 }
 
-inline RefPtr<NodeList> SelectorQuery::queryAll(ContainerNode& rootNode) const
+inline Ref<NodeList> SelectorQuery::queryAll(ContainerNode& rootNode) const
 {
     return m_selectors.queryAll(rootNode);
 }
@@ -159,5 +153,3 @@ inline Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const
 }
 
 }
-
-#endif
index 1f6fd7f..71b6221 100644 (file)
@@ -112,11 +112,11 @@ bool HTMLFrameOwnerElement::isKeyboardFocusable(KeyboardEvent& event) const
     return m_contentFrame && HTMLElement::isKeyboardFocusable(event);
 }
 
-ExceptionOr<Document*> HTMLFrameOwnerElement::getSVGDocument() const
+ExceptionOr<Document&> HTMLFrameOwnerElement::getSVGDocument() const
 {
     auto* document = contentDocument();
     if (is<SVGDocument>(document))
-        return document;
+        return *document;
     // Spec: http://www.w3.org/TR/SVG/struct.html#InterfaceGetSVGDocument
     return Exception { NOT_SUPPORTED_ERR };
 }
index bfcc0ee..d852efa 100644 (file)
@@ -49,7 +49,7 @@ public:
     // RenderElement when using fallback content.
     RenderWidget* renderWidget() const;
 
-    ExceptionOr<Document*> getSVGDocument() const;
+    ExceptionOr<Document&> getSVGDocument() const;
 
     virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
 
index 05b9f60..e2e1d41 100644 (file)
@@ -3594,7 +3594,7 @@ void HTMLMediaElement::forgetResourceSpecificTracks()
         removeVideoTrack(*m_videoTracks->lastItem());
 }
 
-ExceptionOr<Ref<TextTrack>> HTMLMediaElement::addTextTrack(const String& kind, const String& label, const String& language)
+ExceptionOr<TextTrack&> HTMLMediaElement::addTextTrack(const String& kind, const String& label, const String& language)
 {
     // 4.8.10.12.4 Text track API
     // The addTextTrack(kind, label, language) method of media elements, when invoked, must run the following steps:
@@ -3609,21 +3609,22 @@ ExceptionOr<Ref<TextTrack>> HTMLMediaElement::addTextTrack(const String& kind, c
 
     // 5. Create a new text track corresponding to the new object, and set its text track kind to kind, its text 
     // track label to label, its text track language to language...
-    auto textTrack = TextTrack::create(ActiveDOMObject::scriptExecutionContext(), this, kind, emptyString(), label, language);
+    auto track = TextTrack::create(ActiveDOMObject::scriptExecutionContext(), this, kind, emptyString(), label, language);
+    auto& trackReference = track.get();
 
     // Note, due to side effects when changing track parameters, we have to
     // first append the track to the text track list.
 
     // 6. Add the new text track to the media element's list of text tracks.
-    addTextTrack(textTrack.copyRef());
+    addTextTrack(WTFMove(track));
 
     // ... its text track readiness state to the text track loaded state ...
-    textTrack->setReadinessState(TextTrack::Loaded);
+    trackReference.setReadinessState(TextTrack::Loaded);
 
     // ... its text track mode to the text track hidden mode, and its text track list of cues to an empty list ...
-    textTrack->setMode(TextTrack::Mode::Hidden);
+    trackReference.setMode(TextTrack::Mode::Hidden);
 
-    return WTFMove(textTrack);
+    return trackReference;
 }
 
 AudioTrackList& HTMLMediaElement::audioTracks()
index 5aa95b9..35b233d 100644 (file)
@@ -277,7 +277,7 @@ public:
     double percentLoaded() const;
 
 #if ENABLE(VIDEO_TRACK)
-    ExceptionOr<Ref<TextTrack>> addTextTrack(const String& kind, const String& label, const String& language);
+    ExceptionOr<TextTrack&> addTextTrack(const String& kind, const String& label, const String& language);
 
     AudioTrackList& audioTracks();
     TextTrackList& textTracks();
index 1968700..3523509 100644 (file)
@@ -429,8 +429,13 @@ bool HTMLPlugInImageElement::partOfSnapshotOverlay(const Node* node) const
     ShadowRoot* shadow = userAgentShadowRoot();
     if (!shadow)
         return false;
-    RefPtr<Element> snapshotLabel = shadow->querySelector(selector.get(), ASSERT_NO_EXCEPTION);
-    return node && snapshotLabel && (node == snapshotLabel.get() || node->isDescendantOf(snapshotLabel.get()));
+    if (!node)
+        return false;
+    auto queryResult = shadow->querySelector(selector.get());
+    if (queryResult.hasException())
+        return false;
+    auto* snapshotLabel = queryResult.releaseReturnValue();
+    return snapshotLabel && snapshotLabel->contains(node);
 }
 
 void HTMLPlugInImageElement::removeSnapshotTimerFired()
index 2070b4c..29eac97 100644 (file)
@@ -533,15 +533,14 @@ void InspectorDOMAgent::querySelector(ErrorString& errorString, int nodeId, cons
         return;
     }
 
-    ExceptionCode ec = 0;
-    RefPtr<Element> element = downcast<ContainerNode>(*node).querySelector(selectors, ec);
-    if (ec) {
+    auto queryResult = downcast<ContainerNode>(*node).querySelector(selectors);
+    if (queryResult.hasException()) {
         errorString = ASCIILiteral("DOM Error while querying");
         return;
     }
 
-    if (element)
-        *elementId = pushNodePathToFrontend(element.get());
+    if (auto* element = queryResult.releaseReturnValue())
+        *elementId = pushNodePathToFrontend(element);
 }
 
 void InspectorDOMAgent::querySelectorAll(ErrorString& errorString, int nodeId, const String& selectors, RefPtr<Inspector::Protocol::Array<int>>& result)
@@ -554,15 +553,14 @@ void InspectorDOMAgent::querySelectorAll(ErrorString& errorString, int nodeId, c
         return;
     }
 
-    ExceptionCode ec = 0;
-    RefPtr<NodeList> nodes = downcast<ContainerNode>(*node).querySelectorAll(selectors, ec);
-    if (ec) {
+    auto queryResult = downcast<ContainerNode>(*node).querySelectorAll(selectors);
+    if (queryResult.hasException()) {
         errorString = ASCIILiteral("DOM Error while querying");
         return;
     }
 
+    auto nodes = queryResult.releaseReturnValue();
     result = Inspector::Protocol::Array<int>::create();
-
     for (unsigned i = 0; i < nodes->length(); ++i)
         result->addItem(pushNodePathToFrontend(nodes->item(i)));
 }
@@ -905,7 +903,7 @@ void InspectorDOMAgent::performSearch(ErrorString& errorString, const String& wh
             }
             finder.performSearch(node);
         }
-    } else if (m_document) {
+    } else {
         // There's no need to iterate the frames tree because
         // the search helper will go inside the frame owner elements.
         finder.performSearch(m_document.get());
@@ -1115,19 +1113,18 @@ void InspectorDOMAgent::highlightSelector(ErrorString& errorString, const Inspec
         return;
     }
 
-    ExceptionCode ec = 0;
-    RefPtr<NodeList> nodes = document->querySelectorAll(selectorString, ec);
+    auto queryResult = document->querySelectorAll(selectorString);
     // FIXME: <https://webkit.org/b/146161> Web Inspector: DOM.highlightSelector should work for "a:visited"
-    if (ec) {
+    if (queryResult.hasException()) {
         errorString = ASCIILiteral("DOM Error while querying");
         return;
     }
 
-    std::unique_ptr<HighlightConfig> highlightConfig = highlightConfigFromInspectorObject(errorString, &highlightInspectorObject);
+    auto highlightConfig = highlightConfigFromInspectorObject(errorString, &highlightInspectorObject);
     if (!highlightConfig)
         return;
 
-    m_overlay->highlightNodeList(WTFMove(nodes), *highlightConfig);
+    m_overlay->highlightNodeList(queryResult.releaseReturnValue(), *highlightConfig);
 }
 
 void InspectorDOMAgent::highlightNode(ErrorString& errorString, const InspectorObject& highlightInspectorObject, const int* nodeId, const String* objectId)
index 55b2c28..59583a9 100644 (file)
@@ -65,38 +65,33 @@ InspectorNodeFinder::InspectorNodeFinder(const String& whitespaceTrimmedQuery)
 
 void InspectorNodeFinder::performSearch(Node* parentNode)
 {
-    searchUsingXPath(parentNode);
-    searchUsingCSSSelectors(parentNode);
+    if (!parentNode)
+        return;
+
+    searchUsingXPath(*parentNode);
+    searchUsingCSSSelectors(*parentNode);
 
     // Keep the DOM tree traversal last. This way iframe content will come after their parents.
-    searchUsingDOMTreeTraversal(parentNode);
+    searchUsingDOMTreeTraversal(*parentNode);
 }
 
-void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node* parentNode)
+void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node& parentNode)
 {
     // Manual plain text search.
-    for (auto* node = parentNode; node; node = NodeTraversal::next(*node, parentNode)) {
+    for (auto* node = &parentNode; node; node = NodeTraversal::next(*node, &parentNode)) {
         switch (node->nodeType()) {
         case Node::TEXT_NODE:
         case Node::COMMENT_NODE:
-        case Node::CDATA_SECTION_NODE: {
-            if (node->nodeValue().findIgnoringCase(m_whitespaceTrimmedQuery) != notFound)
+        case Node::CDATA_SECTION_NODE:
+            if (node->nodeValue().containsIgnoringASCIICase(m_whitespaceTrimmedQuery))
                 m_results.add(node);
             break;
-        }
-        case Node::ELEMENT_NODE: {
+        case Node::ELEMENT_NODE:
             if (matchesElement(downcast<Element>(*node)))
                 m_results.add(node);
-
-            // Search inside frame elements.
-            if (is<HTMLFrameOwnerElement>(*node)) {
-                HTMLFrameOwnerElement& frameOwner = downcast<HTMLFrameOwnerElement>(*node);
-                if (Document* document = frameOwner.contentDocument())
-                    performSearch(document);
-            }
-
+            if (is<HTMLFrameOwnerElement>(downcast<Element>(*node)))
+                performSearch(downcast<HTMLFrameOwnerElement>(*node).contentDocument());
             break;
-        }
         default:
             break;
         }
@@ -105,15 +100,15 @@ void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node* parentNode)
 
 bool InspectorNodeFinder::matchesAttribute(const Attribute& attribute)
 {
-    if (attribute.localName().string().findIgnoringCase(m_whitespaceTrimmedQuery) != notFound)
+    if (attribute.localName().string().containsIgnoringASCIICase(m_whitespaceTrimmedQuery))
         return true;
-    return m_exactAttributeMatch ? attribute.value() == m_attributeQuery : attribute.value().string().findIgnoringCase(m_attributeQuery) != notFound;
+    return m_exactAttributeMatch ? attribute.value() == m_attributeQuery : attribute.value().string().containsIgnoringASCIICase(m_attributeQuery);
 }
 
 bool InspectorNodeFinder::matchesElement(const Element& element)
 {
     String nodeName = element.nodeName();
-    if ((!m_startTagFound && !m_endTagFound && (nodeName.findIgnoringCase(m_tagNameQuery) != notFound))
+    if ((!m_startTagFound && !m_endTagFound && nodeName.containsIgnoringASCIICase(m_tagNameQuery))
         || (m_startTagFound && m_endTagFound && equalIgnoringASCIICase(nodeName, m_tagNameQuery))
         || (m_startTagFound && !m_endTagFound && nodeName.startsWith(m_tagNameQuery, false))
         || (!m_startTagFound && m_endTagFound && nodeName.endsWith(m_tagNameQuery, false)))
@@ -130,9 +125,9 @@ bool InspectorNodeFinder::matchesElement(const Element& element)
     return false;
 }
 
-void InspectorNodeFinder::searchUsingXPath(Node* parentNode)
+void InspectorNodeFinder::searchUsingXPath(Node& parentNode)
 {
-    auto evaluateResult = parentNode->document().evaluate(m_whitespaceTrimmedQuery, parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr);
+    auto evaluateResult = parentNode.document().evaluate(m_whitespaceTrimmedQuery, &parentNode, nullptr, XPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nullptr);
     if (evaluateResult.hasException())
         return;
     auto result = evaluateResult.releaseReturnValue();
@@ -152,22 +147,21 @@ void InspectorNodeFinder::searchUsingXPath(Node* parentNode)
             node = downcast<Attr>(*node).ownerElement();
 
         // XPath can get out of the context node that we pass as the starting point to evaluate, so we need to filter for just the nodes we care about.
-        if (node == parentNode || node->isDescendantOf(parentNode))
+        if (parentNode.contains(node))
             m_results.add(node);
     }
 }
 
-void InspectorNodeFinder::searchUsingCSSSelectors(Node* parentNode)
+void InspectorNodeFinder::searchUsingCSSSelectors(Node& parentNode)
 {
-    ASSERT(parentNode);
-    if (!is<ContainerNode>(*parentNode))
+    if (!is<ContainerNode>(parentNode))
         return;
 
-    ExceptionCode ec = 0;
-    RefPtr<NodeList> nodeList = downcast<ContainerNode>(*parentNode).querySelectorAll(m_whitespaceTrimmedQuery, ec);
-    if (ec || !nodeList)
+    auto queryResult = downcast<ContainerNode>(parentNode).querySelectorAll(m_whitespaceTrimmedQuery);
+    if (queryResult.hasException())
         return;
 
+    auto nodeList = queryResult.releaseReturnValue();
     unsigned size = nodeList->length();
     for (unsigned i = 0; i < size; ++i)
         m_results.add(nodeList->item(i));
index c6761c6..5d55dd3 100644 (file)
@@ -49,9 +49,9 @@ private:
     bool matchesAttribute(const Attribute&);
     bool matchesElement(const Element&);
 
-    void searchUsingDOMTreeTraversal(Node*);
-    void searchUsingXPath(Node*);
-    void searchUsingCSSSelectors(Node*);
+    void searchUsingDOMTreeTraversal(Node&);
+    void searchUsingXPath(Node&);
+    void searchUsingCSSSelectors(Node&);
 
     bool m_startTagFound;
     bool m_endTagFound;
index be3872f..08cc431 100644 (file)
@@ -69,7 +69,7 @@ SubtleCrypto& Crypto::subtle()
     return m_subtle;
 }
 
-ExceptionOr<WebKitSubtleCrypto*> Crypto::webkitSubtle()
+ExceptionOr<WebKitSubtleCrypto&> Crypto::webkitSubtle()
 {
     if (!isMainThread())
         return Exception { NOT_SUPPORTED_ERR };
@@ -77,7 +77,7 @@ ExceptionOr<WebKitSubtleCrypto*> Crypto::webkitSubtle()
     if (!m_webkitSubtle)
         m_webkitSubtle = WebKitSubtleCrypto::create(*downcast<Document>(scriptExecutionContext()));
 
-    return m_webkitSubtle.get();
+    return *m_webkitSubtle;
 }
 
 #endif
index 9034e61..9b480e0 100644 (file)
@@ -52,7 +52,7 @@ public:
     SubtleCrypto& subtle();
 
     // Will be deprecated.
-    ExceptionOr<WebKitSubtleCrypto*> webkitSubtle();
+    ExceptionOr<WebKitSubtleCrypto&> webkitSubtle();
 #endif
 
 private:
index 2a49aaa..36f220e 100644 (file)
@@ -109,9 +109,7 @@ public:
 
     RefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
 
-    ExceptionOr<Node*> ensureShadowRoot(Element& host);
     Node* ensureUserAgentShadowRoot(Element& host);
-    ExceptionOr<Node*> createShadowRoot(Element& host);
     Node* shadowRoot(Element& host);
     ExceptionOr<String> shadowRootType(const Node&) const;
     String shadowPseudoId(Element&);
index b8cfb5f..c6e488e 100644 (file)
@@ -1,5 +1,27 @@
 2016-10-31  Darin Adler  <darin@apple.com>
 
+        Move ChildNode and ParentNode from ExceptionCode to Exception, add support for ExceptionOr<T&>
+        https://bugs.webkit.org/show_bug.cgi?id=164214
+
+        Reviewed by Alex Christensen.
+
+        * DOM/DOMCSSPrimitiveValue.mm:
+        (-[DOMCSSPrimitiveValue getCounterValue]): Updated since return value
+        is a reference now.
+        (-[DOMCSSPrimitiveValue getRectValue]): Ditto.
+
+        * DOM/DOMDocument.mm:
+        (-[DOMDocument querySelector:]): Updated exception handling.
+        (-[DOMDocument querySelectorAll:]): Ditto.
+        * DOM/DOMDocumentFragment.mm:
+        (-[DOMDocumentFragment querySelector:]): Ditto.
+        (-[DOMDocumentFragment querySelectorAll:]): Ditto.
+        * DOM/DOMElement.mm:
+        (-[DOMElement querySelector:]): Ditto.
+        (-[DOMElement querySelectorAll:]): Ditto.
+
+2016-10-31  Darin Adler  <darin@apple.com>
+
         Convert Document from ExceptionCode to Exception
         https://bugs.webkit.org/show_bug.cgi?id=164212
 
index 2290fbd..42a7a02 100644 (file)
 - (DOMCounter *)getCounterValue
 {
     WebCore::JSMainThreadNullState state;
-    return kit(raiseOnDOMError(IMPL->getCounterValue()));
+    return kit(&raiseOnDOMError(IMPL->getCounterValue()));
 }
 
 - (DOMRect *)getRectValue
 {
     WebCore::JSMainThreadNullState state;
-    return kit(raiseOnDOMError(IMPL->getRectValue()));
+    return kit(&raiseOnDOMError(IMPL->getRectValue()));
 }
 
 - (DOMRGBColor *)getRGBColorValue
index 3a5a2f7..926777e 100644 (file)
@@ -744,19 +744,13 @@ static RefPtr<WebCore::XPathNSResolver> wrap(id <DOMXPathNSResolver> resolver)
 - (DOMElement *)querySelector:(NSString *)selectors
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMElement *result = kit(WTF::getPtr(IMPL->querySelector(selectors, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->querySelector(selectors)));
 }
 
 - (DOMNodeList *)querySelectorAll:(NSString *)selectors
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMNodeList *result = kit(WTF::getPtr(IMPL->querySelectorAll(selectors, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->querySelectorAll(selectors)).ptr());
 }
 
 @end
index 5ee6558..1fd7ea9 100644 (file)
 - (DOMElement *)querySelector:(NSString *)selectors
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMElement *result = kit(WTF::getPtr(IMPL->querySelector(selectors, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->querySelector(selectors)));
 }
 
 - (DOMNodeList *)querySelectorAll:(NSString *)selectors
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMNodeList *result = kit(WTF::getPtr(IMPL->querySelectorAll(selectors, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->querySelectorAll(selectors)).ptr());
 }
 
 @end
index 33a8c25..c0aa8f7 100644 (file)
@@ -472,19 +472,13 @@ DOMElement *kit(Element* value)
 - (DOMElement *)querySelector:(NSString *)selectors
 {
     JSMainThreadNullState state;
-    ExceptionCode ec = 0;
-    DOMElement *result = kit(unwrap(*self).querySelector(selectors, ec));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(unwrap(*self).querySelector(selectors)));
 }
 
 - (DOMNodeList *)querySelectorAll:(NSString *)selectors
 {
     JSMainThreadNullState state;
-    ExceptionCode ec = 0;
-    DOMNodeList *result = kit(unwrap(*self).querySelectorAll(selectors, ec).get());
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(unwrap(*self).querySelectorAll(selectors)).ptr());
 }
 
 @end
index b731b31..fa66f8d 100644 (file)
@@ -1,5 +1,22 @@
 2016-10-31  Darin Adler  <darin@apple.com>
 
+        Move ChildNode and ParentNode from ExceptionCode to Exception, add support for ExceptionOr<T&>
+        https://bugs.webkit.org/show_bug.cgi?id=164214
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocument.cpp:
+        (webkit_dom_document_query_selector): Updated exception handling.
+        (webkit_dom_document_query_selector_all): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentFragment.cpp:
+        (webkit_dom_document_fragment_query_selector): Ditto.
+        (webkit_dom_document_fragment_query_selector_all): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp:
+        (webkit_dom_element_query_selector): Ditto.
+        (webkit_dom_element_query_selector_all): Ditto.
+
+2016-10-31  Darin Adler  <darin@apple.com>
+
         Convert Document from ExceptionCode to Exception
         https://bugs.webkit.org/show_bug.cgi?id=164212
 
index 669fcad..5a79faf 100644 (file)
@@ -1386,13 +1386,13 @@ WebKitDOMElement* webkit_dom_document_query_selector(WebKitDOMDocument* self, co
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::Document* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->querySelector(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelector(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 WebKitDOMNodeList* webkit_dom_document_query_selector_all(WebKitDOMDocument* self, const gchar* selectors, GError** error)
@@ -1403,13 +1403,13 @@ WebKitDOMNodeList* webkit_dom_document_query_selector_all(WebKitDOMDocument* sel
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::Document* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::NodeList> gobjectResult = WTF::getPtr(item->querySelectorAll(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelectorAll(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
 WebKitDOMDocumentType* webkit_dom_document_get_doctype(WebKitDOMDocument* self)
index 1cc4e24..58eb52d 100644 (file)
@@ -199,13 +199,13 @@ WebKitDOMElement* webkit_dom_document_fragment_query_selector(WebKitDOMDocumentF
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::DocumentFragment* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->querySelector(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelector(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 WebKitDOMNodeList* webkit_dom_document_fragment_query_selector_all(WebKitDOMDocumentFragment* self, const gchar* selectors, GError** error)
@@ -216,13 +216,13 @@ WebKitDOMNodeList* webkit_dom_document_fragment_query_selector_all(WebKitDOMDocu
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::DocumentFragment* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::NodeList> gobjectResult = WTF::getPtr(item->querySelectorAll(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelectorAll(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
 WebKitDOMHTMLCollection* webkit_dom_document_fragment_get_children(WebKitDOMDocumentFragment* self)
index 3e3d66b..a9216a8 100644 (file)
@@ -998,13 +998,13 @@ WebKitDOMElement* webkit_dom_element_query_selector(WebKitDOMElement* self, cons
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::Element* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->querySelector(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelector(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue());
 }
 
 WebKitDOMNodeList* webkit_dom_element_query_selector_all(WebKitDOMElement* self, const gchar* selectors, GError** error)
@@ -1015,13 +1015,13 @@ WebKitDOMNodeList* webkit_dom_element_query_selector_all(WebKitDOMElement* self,
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::Element* item = WebKit::core(self);
     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::NodeList> gobjectResult = WTF::getPtr(item->querySelectorAll(convertedSelectors, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->querySelectorAll(convertedSelectors);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
+        return nullptr;
     }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(result.releaseReturnValue().ptr());
 }
 
 gchar* webkit_dom_element_get_tag_name(WebKitDOMElement* self)