Convert more of DOM from ExceptionCode to Exception
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Oct 2016 02:56:39 +0000 (02:56 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Oct 2016 02:56:39 +0000 (02:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164173

Reviewed by Ryosuke Niwa.

Source/WebCore:

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::getUserMedia): Use ExceptionOr.
(WebCore::MediaDevices::enumerateDevices): Ditto.
* Modules/mediastream/MediaDevices.h: Updated for above.
* Modules/mediastream/MediaDevices.idl: Use non-legacy exceptions.

* Modules/mediastream/MediaEndpointSessionDescription.cpp:
Added now-needed include of ExceptionCode.h.

* Modules/mediastream/RTCConfiguration.cpp:
(WebCore::parseIceServer): Use ExceptionOr.
(WebCore::RTCConfiguration::create): Ditto.
(WebCore::RTCConfiguration::initialize): Ditto.
* Modules/mediastream/RTCConfiguration.h: Updated for above.
* Modules/mediastream/RTCConfiguration.idl: Use non-legacy exceptions.

* Modules/mediastream/RTCDTMFSender.cpp:
(WebCore::RTCDTMFSender::create): Use ExceptionOr.
(WebCore::RTCDTMFSender::insertDTMF): Ditto.
* Modules/mediastream/RTCDTMFSender.h: Updated for above.
* Modules/mediastream/RTCDTMFSender.idl: Use non-legacy exceptions.

* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::create): Use ExceptionOr.
(WebCore::RTCDataChannel::setBinaryType): Ditto.
(WebCore::RTCDataChannel::send): Ditto.
(WebCore::RTCDataChannel::didReceiveRawData): Ditto.
* Modules/mediastream/RTCDataChannel.h: Updated for above.
Also fhcanged resturn values to use const AtomicString& and
unsigned instead of unsigned long. Also made more private.
Also changed BinaryType into an enum class.
* Modules/mediastream/RTCDataChannel.idl: Use non-legacy exceptions.

* Modules/mediastream/RTCIceCandidate.cpp:
(WebCore::RTCIceCandidate::create): Use ExceptionOr.
* Modules/mediastream/RTCIceCandidate.h: Updated for above.
* Modules/mediastream/RTCIceCandidate.idl: Use non-legacy exception.

* Modules/mediastream/RTCOfferAnswerOptions.cpp:
(WebCore::RTCOfferOptions::create): Use ExceptionOr.
(WebCore::RTCAnswerOptions::create): Ditto.
* Modules/mediastream/RTCOfferAnswerOptions.h: Updated for above.
Also removed all virtual functions since nothing here is polymorphic
and initalized data members in the header.

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::initializeWith): Use ExceptionOr.
(WebCore::RTCPeerConnection::addTrack): Ditto.
(WebCore::RTCPeerConnection::removeTrack): Ditto.
(WebCore::RTCPeerConnection::addTransceiver): Ditto.
(WebCore::RTCPeerConnection::completeAddTransceiver): Ditto.
(WebCore::RTCPeerConnection::queuedCreateOffer): Ditto.
(WebCore::RTCPeerConnection::queuedCreateAnswer): Ditto.
(WebCore::RTCPeerConnection::setConfiguration): Ditto.
(WebCore::RTCPeerConnection::createDataChannel): Ditto.
* Modules/mediastream/RTCPeerConnection.h: Updated for above.
* Modules/mediastream/RTCPeerConnection.idl: Use non-legacy exceptions.

* Modules/mediastream/RTCRtpSender.cpp:
(WebCore::RTCRtpSender::replaceTrack): Use ExceptionOr.
* Modules/mediastream/RTCRtpSender.h: Updated for above.
* Modules/mediastream/RTCRtpSender.idl: Use non-legacy exception.

* Modules/mediastream/RTCSessionDescription.cpp:
(WebCore::RTCSessionDescription::create): Use ExceptoinOr.
* Modules/mediastream/RTCSessionDescription.h: Updated for above.
(WebCore::RTCSessionDescription::~RTCSessionDescription):
* Modules/mediastream/RTCSessionDescription.idl: Use non-legacy exceptions.

* Modules/navigatorcontentutils/NavigatorContentUtils.cpp:
(WebCore::verifyCustomHandlerURL): Just return a boolean, no exception.
(WebCore::verifyProtocolHandlerScheme): Ditto.
(WebCore::NavigatorContentUtils::registerProtocolHandler): Use ExceptionOr.
(WebCore::NavigatorContentUtils::isProtocolHandlerRegistered): Ditto.
(WebCore::NavigatorContentUtils::unregisterProtocolHandler): Ditto.
* Modules/navigatorcontentutils/NavigatorContentUtils.h: Updated for above.
* Modules/navigatorcontentutils/NavigatorContentUtils.idl: Use non-legacy exceptions.

* bindings/js/JSMediaDevicesCustom.cpp:
(WebCore::JSMediaDevicesGetUserMediaPromiseFunction): Use propagateException.

* bindings/scripts/CodeGeneratorJS.pm:
(NeedsExplicitPropagateExceptionCall): Added. Helper function to decide whether
we need to call propagateException explicitly, if return value processing is not
going to propagate the exception for us.
(GenerateParametersCheck): Moved the code from GenerateReturnParameters inline
because it's almost as short as the function call. Use the newly created
NeedsExplicitPropagateExceptionCall function, which properly handles the case
where the return value is a promise.
(GenerateReturnParameters): Deleted.

* dom/CharacterData.cpp:
(WebCore::CharacterData::substringData): Use ExceptionOr.
(WebCore::CharacterData::insertData): Ditto.
(WebCore::CharacterData::deleteData): Ditto.
(WebCore::CharacterData::replaceData): Ditto.
* dom/CharacterData.h: Updated for above.
* dom/CharacterData.idl: Use non-legacy exceptions.

* dom/DataTransferItemList.h: Tried to use ExceptionOr, but this seems
like dead code that doesn't compile.
* dom/DataTransferItemList.idl: Use non-legacy exceptions.

* dom/MessagePort.idl: Use non-legacy exceptions, except this has
already been converted and was a custom binding.

* dom/MutationObserver.cpp:
(WebCore::MutationObserver::observe): Use ExceptionOr.
* dom/MutationObserver.h: Updated for above.
* dom/MutationObserver.idl: Use non-legacy exception.

* dom/Range.cpp:
(WebCore::deleteCharacterData): Updated use of calls that now use
ExceptionOr.
(WebCore::Range::processContentsBetweenOffsets): Ditto.
(WebCore::Range::insertNode): Ditto.

* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::setInnerHTML): Use ExceptionOr.
* dom/ShadowRoot.h: Updated for above.
* dom/ShadowRoot.idl: Use non-legacy exception.

* dom/Text.cpp:
(WebCore::Text::splitText): Use ExceptionOr.
(WebCore::Text::replaceWholeText): Removed unused ExceptionCode&.
* dom/Text.h: Updated for above.
* dom/Text.idl: Use non-legacy exception.

* editing/ApplyBlockElementCommand.cpp:
(WebCore::isNewLineAtPosition): Rewrote to use data rather than
substringData; more efficient.

* editing/DeleteFromTextNodeCommand.cpp:
(WebCore::DeleteFromTextNodeCommand::doApply): Updated to work with
functions that return ExceptionOr.
(WebCore::DeleteFromTextNodeCommand::doUnapply): Removed IGNORE_EXCEPTION.

* editing/InsertIntoTextNodeCommand.cpp:
(WebCore::InsertIntoTextNodeCommand::InsertIntoTextNodeCommand):
Use WTFMove to avoid a little bit of reference count churn.
(WebCore::InsertIntoTextNodeCommand::doApply): Removed IGNORE_EXCEPTION.
(WebCore::InsertIntoTextNodeCommand::doReapply): Removed ExceptionCode.
(WebCore::InsertIntoTextNodeCommand::doUnapply): Removed IGNORE_EXCEPTION.

* editing/SplitTextNodeCommand.cpp:
(WebCore::SplitTextNodeCommand::doApply): Updated to work with functions
that return ExceptionCode.
(WebCore::SplitTextNodeCommand::doUnapply): Removed ASSERT_NO_EXCEPTION.
(WebCore::SplitTextNodeCommand::insertText1AndTrimText2): Updated to work
with functions that return ExceptionCode.

* html/HTMLTextFormControlElement.cpp:
Added now-needed include of ExceptionCode.h.

* inspector/DOMEditor.cpp: Removed ExceptionCode out argument from calls
to replaceWholeText, which never throws an exception.

Source/WebKit/mac:

* DOM/DOMCharacterData.mm:
(-[DOMCharacterData substringData:length:]): Updated since this
now uses ExceptionOr.
(-[DOMCharacterData insertData:data:]): Ditto.
(-[DOMCharacterData deleteData:length:]): Ditto.
(-[DOMCharacterData replaceData:length:data:]): Ditto.
* DOM/DOMText.mm:
(-[DOMText splitText:]): Ditto.
(-[DOMText replaceWholeText:]): Removed unneeded exception code
handling from function that does not throw an exception.

Source/WebKit2:

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMCharacterData.cpp:
(webkit_dom_character_data_substring_data): Updated since this
now uses ExceptionOr.
(webkit_dom_character_data_insert_data): Ditto.
(webkit_dom_character_data_delete_data): Ditto.
(webkit_dom_character_data_replace_data): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDeprecated.cpp:
(webkit_dom_text_replace_whole_text): Ditto.
* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMText.cpp:
(webkit_dom_text_split_text): Ditto.

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

62 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaDevices.cpp
Source/WebCore/Modules/mediastream/MediaDevices.h
Source/WebCore/Modules/mediastream/MediaDevices.idl
Source/WebCore/Modules/mediastream/MediaEndpointSessionDescription.cpp
Source/WebCore/Modules/mediastream/RTCConfiguration.cpp
Source/WebCore/Modules/mediastream/RTCConfiguration.h
Source/WebCore/Modules/mediastream/RTCConfiguration.idl
Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp
Source/WebCore/Modules/mediastream/RTCDTMFSender.h
Source/WebCore/Modules/mediastream/RTCDTMFSender.idl
Source/WebCore/Modules/mediastream/RTCDataChannel.cpp
Source/WebCore/Modules/mediastream/RTCDataChannel.h
Source/WebCore/Modules/mediastream/RTCDataChannel.idl
Source/WebCore/Modules/mediastream/RTCIceCandidate.cpp
Source/WebCore/Modules/mediastream/RTCIceCandidate.h
Source/WebCore/Modules/mediastream/RTCIceCandidate.idl
Source/WebCore/Modules/mediastream/RTCOfferAnswerOptions.cpp
Source/WebCore/Modules/mediastream/RTCOfferAnswerOptions.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/Modules/mediastream/RTCRtpSender.cpp
Source/WebCore/Modules/mediastream/RTCRtpSender.h
Source/WebCore/Modules/mediastream/RTCRtpSender.idl
Source/WebCore/Modules/mediastream/RTCSessionDescription.cpp
Source/WebCore/Modules/mediastream/RTCSessionDescription.h
Source/WebCore/Modules/mediastream/RTCSessionDescription.idl
Source/WebCore/Modules/navigatorcontentutils/NavigatorContentUtils.cpp
Source/WebCore/Modules/navigatorcontentutils/NavigatorContentUtils.h
Source/WebCore/Modules/navigatorcontentutils/NavigatorContentUtils.idl
Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/dom/CharacterData.cpp
Source/WebCore/dom/CharacterData.h
Source/WebCore/dom/CharacterData.idl
Source/WebCore/dom/DataTransferItemList.h
Source/WebCore/dom/DataTransferItemList.idl
Source/WebCore/dom/MessagePort.idl
Source/WebCore/dom/MutationObserver.cpp
Source/WebCore/dom/MutationObserver.h
Source/WebCore/dom/MutationObserver.idl
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/ShadowRoot.h
Source/WebCore/dom/ShadowRoot.idl
Source/WebCore/dom/Text.cpp
Source/WebCore/dom/Text.h
Source/WebCore/dom/Text.idl
Source/WebCore/editing/ApplyBlockElementCommand.cpp
Source/WebCore/editing/DeleteFromTextNodeCommand.cpp
Source/WebCore/editing/InsertIntoTextNodeCommand.cpp
Source/WebCore/editing/SplitTextNodeCommand.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/inspector/DOMEditor.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOMCharacterData.mm
Source/WebKit/mac/DOM/DOMText.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMCharacterData.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDeprecated.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMText.cpp

index fd24789..4569962 100644 (file)
@@ -1,3 +1,167 @@
+2016-10-29  Darin Adler  <darin@apple.com>
+
+        Convert more of DOM from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=164173
+
+        Reviewed by Ryosuke Niwa.
+
+        * Modules/mediastream/MediaDevices.cpp:
+        (WebCore::MediaDevices::getUserMedia): Use ExceptionOr.
+        (WebCore::MediaDevices::enumerateDevices): Ditto.
+        * Modules/mediastream/MediaDevices.h: Updated for above.
+        * Modules/mediastream/MediaDevices.idl: Use non-legacy exceptions.
+
+        * Modules/mediastream/MediaEndpointSessionDescription.cpp:
+        Added now-needed include of ExceptionCode.h.
+
+        * Modules/mediastream/RTCConfiguration.cpp:
+        (WebCore::parseIceServer): Use ExceptionOr.
+        (WebCore::RTCConfiguration::create): Ditto.
+        (WebCore::RTCConfiguration::initialize): Ditto.
+        * Modules/mediastream/RTCConfiguration.h: Updated for above.
+        * Modules/mediastream/RTCConfiguration.idl: Use non-legacy exceptions.
+
+        * Modules/mediastream/RTCDTMFSender.cpp:
+        (WebCore::RTCDTMFSender::create): Use ExceptionOr.
+        (WebCore::RTCDTMFSender::insertDTMF): Ditto.
+        * Modules/mediastream/RTCDTMFSender.h: Updated for above.
+        * Modules/mediastream/RTCDTMFSender.idl: Use non-legacy exceptions.
+
+        * Modules/mediastream/RTCDataChannel.cpp:
+        (WebCore::RTCDataChannel::create): Use ExceptionOr.
+        (WebCore::RTCDataChannel::setBinaryType): Ditto.
+        (WebCore::RTCDataChannel::send): Ditto.
+        (WebCore::RTCDataChannel::didReceiveRawData): Ditto.
+        * Modules/mediastream/RTCDataChannel.h: Updated for above.
+        Also fhcanged resturn values to use const AtomicString& and
+        unsigned instead of unsigned long. Also made more private.
+        Also changed BinaryType into an enum class.
+        * Modules/mediastream/RTCDataChannel.idl: Use non-legacy exceptions.
+
+        * Modules/mediastream/RTCIceCandidate.cpp:
+        (WebCore::RTCIceCandidate::create): Use ExceptionOr.
+        * Modules/mediastream/RTCIceCandidate.h: Updated for above.
+        * Modules/mediastream/RTCIceCandidate.idl: Use non-legacy exception.
+
+        * Modules/mediastream/RTCOfferAnswerOptions.cpp:
+        (WebCore::RTCOfferOptions::create): Use ExceptionOr.
+        (WebCore::RTCAnswerOptions::create): Ditto.
+        * Modules/mediastream/RTCOfferAnswerOptions.h: Updated for above.
+        Also removed all virtual functions since nothing here is polymorphic
+        and initalized data members in the header.
+
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::initializeWith): Use ExceptionOr.
+        (WebCore::RTCPeerConnection::addTrack): Ditto.
+        (WebCore::RTCPeerConnection::removeTrack): Ditto.
+        (WebCore::RTCPeerConnection::addTransceiver): Ditto.
+        (WebCore::RTCPeerConnection::completeAddTransceiver): Ditto.
+        (WebCore::RTCPeerConnection::queuedCreateOffer): Ditto.
+        (WebCore::RTCPeerConnection::queuedCreateAnswer): Ditto.
+        (WebCore::RTCPeerConnection::setConfiguration): Ditto.
+        (WebCore::RTCPeerConnection::createDataChannel): Ditto.
+        * Modules/mediastream/RTCPeerConnection.h: Updated for above.
+        * Modules/mediastream/RTCPeerConnection.idl: Use non-legacy exceptions.
+
+        * Modules/mediastream/RTCRtpSender.cpp:
+        (WebCore::RTCRtpSender::replaceTrack): Use ExceptionOr.
+        * Modules/mediastream/RTCRtpSender.h: Updated for above.
+        * Modules/mediastream/RTCRtpSender.idl: Use non-legacy exception.
+
+        * Modules/mediastream/RTCSessionDescription.cpp:
+        (WebCore::RTCSessionDescription::create): Use ExceptoinOr.
+        * Modules/mediastream/RTCSessionDescription.h: Updated for above.
+        (WebCore::RTCSessionDescription::~RTCSessionDescription):
+        * Modules/mediastream/RTCSessionDescription.idl: Use non-legacy exceptions.
+
+        * Modules/navigatorcontentutils/NavigatorContentUtils.cpp:
+        (WebCore::verifyCustomHandlerURL): Just return a boolean, no exception.
+        (WebCore::verifyProtocolHandlerScheme): Ditto.
+        (WebCore::NavigatorContentUtils::registerProtocolHandler): Use ExceptionOr.
+        (WebCore::NavigatorContentUtils::isProtocolHandlerRegistered): Ditto.
+        (WebCore::NavigatorContentUtils::unregisterProtocolHandler): Ditto.
+        * Modules/navigatorcontentutils/NavigatorContentUtils.h: Updated for above.
+        * Modules/navigatorcontentutils/NavigatorContentUtils.idl: Use non-legacy exceptions.
+
+        * bindings/js/JSMediaDevicesCustom.cpp:
+        (WebCore::JSMediaDevicesGetUserMediaPromiseFunction): Use propagateException.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (NeedsExplicitPropagateExceptionCall): Added. Helper function to decide whether
+        we need to call propagateException explicitly, if return value processing is not
+        going to propagate the exception for us.
+        (GenerateParametersCheck): Moved the code from GenerateReturnParameters inline
+        because it's almost as short as the function call. Use the newly created
+        NeedsExplicitPropagateExceptionCall function, which properly handles the case
+        where the return value is a promise.
+        (GenerateReturnParameters): Deleted.
+
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::substringData): Use ExceptionOr.
+        (WebCore::CharacterData::insertData): Ditto.
+        (WebCore::CharacterData::deleteData): Ditto.
+        (WebCore::CharacterData::replaceData): Ditto.
+        * dom/CharacterData.h: Updated for above.
+        * dom/CharacterData.idl: Use non-legacy exceptions.
+
+        * dom/DataTransferItemList.h: Tried to use ExceptionOr, but this seems
+        like dead code that doesn't compile.
+        * dom/DataTransferItemList.idl: Use non-legacy exceptions.
+
+        * dom/MessagePort.idl: Use non-legacy exceptions, except this has
+        already been converted and was a custom binding.
+
+        * dom/MutationObserver.cpp:
+        (WebCore::MutationObserver::observe): Use ExceptionOr.
+        * dom/MutationObserver.h: Updated for above.
+        * dom/MutationObserver.idl: Use non-legacy exception.
+
+        * dom/Range.cpp:
+        (WebCore::deleteCharacterData): Updated use of calls that now use
+        ExceptionOr.
+        (WebCore::Range::processContentsBetweenOffsets): Ditto.
+        (WebCore::Range::insertNode): Ditto.
+
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::setInnerHTML): Use ExceptionOr.
+        * dom/ShadowRoot.h: Updated for above.
+        * dom/ShadowRoot.idl: Use non-legacy exception.
+
+        * dom/Text.cpp:
+        (WebCore::Text::splitText): Use ExceptionOr.
+        (WebCore::Text::replaceWholeText): Removed unused ExceptionCode&.
+        * dom/Text.h: Updated for above.
+        * dom/Text.idl: Use non-legacy exception.
+
+        * editing/ApplyBlockElementCommand.cpp:
+        (WebCore::isNewLineAtPosition): Rewrote to use data rather than
+        substringData; more efficient.
+
+        * editing/DeleteFromTextNodeCommand.cpp:
+        (WebCore::DeleteFromTextNodeCommand::doApply): Updated to work with
+        functions that return ExceptionOr.
+        (WebCore::DeleteFromTextNodeCommand::doUnapply): Removed IGNORE_EXCEPTION.
+
+        * editing/InsertIntoTextNodeCommand.cpp:
+        (WebCore::InsertIntoTextNodeCommand::InsertIntoTextNodeCommand):
+        Use WTFMove to avoid a little bit of reference count churn.
+        (WebCore::InsertIntoTextNodeCommand::doApply): Removed IGNORE_EXCEPTION.
+        (WebCore::InsertIntoTextNodeCommand::doReapply): Removed ExceptionCode.
+        (WebCore::InsertIntoTextNodeCommand::doUnapply): Removed IGNORE_EXCEPTION.
+
+        * editing/SplitTextNodeCommand.cpp:
+        (WebCore::SplitTextNodeCommand::doApply): Updated to work with functions
+        that return ExceptionCode.
+        (WebCore::SplitTextNodeCommand::doUnapply): Removed ASSERT_NO_EXCEPTION.
+        (WebCore::SplitTextNodeCommand::insertText1AndTrimText2): Updated to work
+        with functions that return ExceptionCode.
+
+        * html/HTMLTextFormControlElement.cpp:
+        Added now-needed include of ExceptionCode.h.
+
+        * inspector/DOMEditor.cpp: Removed ExceptionCode out argument from calls
+        to replaceWholeText, which never throws an exception.
+
 2016-10-29  Dean Jackson  <dino@apple.com>
 
         Parse color() function
index 217736f..14a7a72 100644 (file)
@@ -63,16 +63,24 @@ Document* MediaDevices::document() const
     return downcast<Document>(scriptExecutionContext());
 }
 
-void MediaDevices::getUserMedia(Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, Promise&& promise, ExceptionCode& ec) const
+ExceptionOr<void> MediaDevices::getUserMedia(Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, Promise&& promise) const
 {
+    ExceptionCode ec = 0;
     UserMediaRequest::start(document(), WTFMove(audioConstraints), WTFMove(videoConstraints), WTFMove(promise), ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
-void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise, ExceptionCode& ec) const
+ExceptionOr<void> MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise) const
 {
-    RefPtr<MediaDevicesRequest> request = MediaDevicesRequest::create(document(), WTFMove(promise), ec);
+    ExceptionCode ec = 0;
+    auto request = MediaDevicesRequest::create(document(), WTFMove(promise), ec);
+    if (ec)
+        return Exception { ec };
     if (request)
         request->start();
+    return { };
 }
 
 RefPtr<MediaTrackSupportedConstraints> MediaDevices::getSupportedConstraints()
index 592f19b..8ffd77f 100644 (file)
@@ -28,8 +28,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef MediaDevices_h
-#define MediaDevices_h
+#pragma once
 
 #if ENABLE(MEDIA_STREAM)
 
@@ -38,8 +37,6 @@
 #include "MediaDeviceInfo.h"
 #include "ScriptWrappable.h"
 #include <functional>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
@@ -49,8 +46,6 @@ class MediaConstraintsImpl;
 class MediaStream;
 class MediaTrackSupportedConstraints;
 
-typedef int ExceptionCode;
-
 class MediaDevices : public ScriptWrappable, public RefCounted<MediaDevices>, public ContextDestructionObserver {
 public:
     static Ref<MediaDevices> create(ScriptExecutionContext*);
@@ -61,8 +56,8 @@ public:
     typedef DOMPromise<MediaStream> Promise;
     typedef DOMPromise<MediaDeviceInfoVector> EnumerateDevicesPromise;
 
-    void getUserMedia(Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, Promise&&, ExceptionCode&) const;
-    void enumerateDevices(EnumerateDevicesPromise&&, ExceptionCode&) const;
+    ExceptionOr<void> getUserMedia(Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, Promise&&) const;
+    ExceptionOr<void> enumerateDevices(EnumerateDevicesPromise&&) const;
     RefPtr<MediaTrackSupportedConstraints> getSupportedConstraints();
 
 private:
@@ -72,5 +67,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
-
-#endif // MediaDevices_h
index 1657ab9..bd763ba 100644 (file)
@@ -34,6 +34,6 @@
 ] interface MediaDevices {
     MediaTrackSupportedConstraints getSupportedConstraints();
 
-    [Custom, PrivateIdentifier, PublicIdentifier] Promise getUserMedia(Dictionary options);
-    [MayThrowLegacyException] Promise enumerateDevices();
+    [Custom, MayThrowException, PrivateIdentifier, PublicIdentifier] Promise getUserMedia(Dictionary options);
+    [MayThrowException] Promise enumerateDevices();
 };
index 585325f..b3abc5a 100644 (file)
@@ -51,7 +51,7 @@ static bool validateIceServerURL(const String& iceURL)
     return true;
 }
 
-static RefPtr<RTCIceServer> parseIceServer(const Dictionary& iceServer, ExceptionCode& ec)
+static ExceptionOr<Ref<RTCIceServer>> parseIceServer(const Dictionary& iceServer)
 {
     String credential, username;
     iceServer.get("credential", credential);
@@ -67,76 +67,65 @@ static RefPtr<RTCIceServer> parseIceServer(const Dictionary& iceServer, Exceptio
     // So we convert to a string always, which converts a sequence to a string in the format: "foo, bar, ..",
     // then checking for a comma in the string assures that a string was a sequence and then we convert
     // it to a sequence safely.
-    if (urlString.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
-    }
+    if (urlString.isEmpty())
+        return Exception { INVALID_ACCESS_ERR };
 
     if (urlString.find(',') != notFound && iceServer.get("urls", urlsList) && urlsList.size()) {
         for (auto iter = urlsList.begin(); iter != urlsList.end(); ++iter) {
-            if (!validateIceServerURL(*iter)) {
-                ec = INVALID_ACCESS_ERR;
-                return nullptr;
-            }
+            if (!validateIceServerURL(*iter))
+                return Exception { INVALID_ACCESS_ERR };
         }
     } else {
-        if (!validateIceServerURL(urlString)) {
-            ec = INVALID_ACCESS_ERR;
-            return nullptr;
-        }
-
+        if (!validateIceServerURL(urlString))
+            return Exception { INVALID_ACCESS_ERR };
         urlsList.append(urlString);
     }
 
     return RTCIceServer::create(urlsList, credential, username);
 }
 
-RefPtr<RTCConfiguration> RTCConfiguration::create(const Dictionary& configuration, ExceptionCode& ec)
+ExceptionOr<RefPtr<RTCConfiguration>> RTCConfiguration::create(const Dictionary& configuration)
 {
     if (configuration.isUndefinedOrNull())
         return nullptr;
 
-    RefPtr<RTCConfiguration> rtcConfiguration = adoptRef(new RTCConfiguration());
-    rtcConfiguration->initialize(configuration, ec);
-    if (ec)
-        return nullptr;
+    auto result = adoptRef(*new RTCConfiguration);
+    auto initializeResult = result->initialize(configuration);
+    if (initializeResult.hasException())
+        return initializeResult.releaseException();
 
-    return rtcConfiguration;
+    return RefPtr<RTCConfiguration> { WTFMove(result) };
 }
 
 RTCConfiguration::RTCConfiguration()
 {
 }
 
-void RTCConfiguration::initialize(const Dictionary& configuration, ExceptionCode& ec)
+ExceptionOr<void> RTCConfiguration::initialize(const Dictionary& configuration)
 {
     ArrayValue iceServers;
     bool ok = configuration.get("iceServers", iceServers);
-    if (!ok || iceServers.isUndefinedOrNull()) {
-        ec = TYPE_MISMATCH_ERR;
-        return;
-    }
+    if (!ok || iceServers.isUndefinedOrNull())
+        return Exception { TYPE_MISMATCH_ERR };
 
     size_t numberOfServers;
     ok = iceServers.length(numberOfServers);
-    if (!ok || !numberOfServers) {
-        ec = !ok ? TYPE_MISMATCH_ERR : INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!ok)
+        return Exception { TYPE_MISMATCH_ERR };
+    if (!numberOfServers)
+        return Exception { INVALID_ACCESS_ERR };
 
     for (size_t i = 0; i < numberOfServers; ++i) {
         Dictionary iceServerDict;
         ok = iceServers.get(i, iceServerDict);
-        if (!ok) {
-            ec = TYPE_MISMATCH_ERR;
-            return;
-        }
+        if (!ok)
+            return Exception { TYPE_MISMATCH_ERR };
 
-        RefPtr<RTCIceServer> iceServer = parseIceServer(iceServerDict, ec);
-        if (!iceServer)
-            return;
+        auto server = parseIceServer(iceServerDict);
+        if (server.hasException())
+            return server.releaseException();
 
-        m_iceServers.append(WTFMove(iceServer));
+        m_iceServers.append(server.releaseReturnValue());
     }
 
     String iceTransportPolicy;
@@ -145,10 +134,8 @@ void RTCConfiguration::initialize(const Dictionary& configuration, ExceptionCode
             m_iceTransportPolicy = IceTransportPolicy::Relay;
         else if (iceTransportPolicy == "all")
             m_iceTransportPolicy = IceTransportPolicy::All;
-        else {
-            ec = TypeError;
-            return;
-        }
+        else
+            return Exception { TypeError };
     }
 
     String bundlePolicy;
@@ -160,8 +147,10 @@ void RTCConfiguration::initialize(const Dictionary& configuration, ExceptionCode
         else if (bundlePolicy == "max-bundle")
             m_bundlePolicy = BundlePolicy::MaxBundle;
         else
-            ec = TypeError;
+            return Exception { TypeError };
     }
+
+    return { };
 }
 
 } // namespace WebCore
index 5845a43..2dcfc5f 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCConfiguration_h
-#define RTCConfiguration_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
+#include "ExceptionOr.h"
 #include "PeerConnectionStates.h"
 #include "RTCIceServer.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 class Dictionary;
 
-typedef int ExceptionCode;
-
+// FIXME: Why reference count this?
 class RTCConfiguration : public RefCounted<RTCConfiguration> {
 public:
-    static RefPtr<RTCConfiguration> create(const Dictionary& configuration, ExceptionCode&);
-    virtual ~RTCConfiguration() { }
+    static ExceptionOr<RefPtr<RTCConfiguration>> create(const Dictionary& configuration);
 
     using IceTransportPolicy = PeerConnectionStates::IceTransportPolicy;
     IceTransportPolicy iceTransportPolicy() const { return m_iceTransportPolicy; }
@@ -62,7 +57,7 @@ public:
 private:
     RTCConfiguration();
 
-    void initialize(const Dictionary& configuration, ExceptionCode&);
+    ExceptionOr<void> initialize(const Dictionary& configuration);
 
     Vector<RefPtr<RTCIceServer>> m_iceServers;
     IceTransportPolicy m_iceTransportPolicy { IceTransportPolicy::All };
@@ -72,5 +67,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCConfiguration_h
index 0b07b30..234a225 100644 (file)
@@ -28,6 +28,7 @@ enum RTCBundlePolicy { "balanced", "max-compat", "max-bundle" };
 
 [
     Conditional=WEB_RTC,
+    ImplementationLacksVTable,
     NoInterfaceObject,
 ] interface RTCConfiguration {
     readonly attribute sequence<RTCIceServer> iceServers;
index d28a562..f7bc7d3 100644 (file)
@@ -44,21 +44,19 @@ static const long maxToneDurationMs = 6000;
 static const long minInterToneGapMs = 30;
 static const long defaultInterToneGapMs = 70;
 
-RefPtr<RTCDTMFSender> RTCDTMFSender::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, RefPtr<MediaStreamTrack>&& track, ExceptionCode& ec)
+ExceptionOr<Ref<RTCDTMFSender>> RTCDTMFSender::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, RefPtr<MediaStreamTrack>&& track)
 {
-    std::unique_ptr<RTCDTMFSenderHandler> handler = peerConnectionHandler->createDTMFSender(&track->source());
-    if (!handler) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
-
-    RefPtr<RTCDTMFSender> dtmfSender = adoptRef(new RTCDTMFSender(context, WTFMove(track), WTFMove(handler)));
-    dtmfSender->suspendIfNeeded();
-    return dtmfSender;
+    auto handler = peerConnectionHandler->createDTMFSender(&track->source());
+    if (!handler)
+        return Exception { NOT_SUPPORTED_ERR };
+
+    auto sender = adoptRef(*new RTCDTMFSender(*context, WTFMove(track), WTFMove(handler)));
+    sender->suspendIfNeeded();
+    return WTFMove(sender);
 }
 
-RTCDTMFSender::RTCDTMFSender(ScriptExecutionContext* context, RefPtr<MediaStreamTrack>&& track, std::unique_ptr<RTCDTMFSenderHandler> handler)
-    : ActiveDOMObject(context)
+RTCDTMFSender::RTCDTMFSender(ScriptExecutionContext& context, RefPtr<MediaStreamTrack>&& track, std::unique_ptr<RTCDTMFSenderHandler> handler)
+    : ActiveDOMObject(&context)
     , m_track(WTFMove(track))
     , m_duration(defaultToneDurationMs)
     , m_interToneGap(defaultInterToneGapMs)
@@ -88,28 +86,24 @@ String RTCDTMFSender::toneBuffer() const
     return m_handler->currentToneBuffer();
 }
 
-void RTCDTMFSender::insertDTMF(const String& tones, Optional<int> duration, Optional<int> interToneGap, ExceptionCode& ec)
+ExceptionOr<void> RTCDTMFSender::insertDTMF(const String& tones, Optional<int> duration, Optional<int> interToneGap)
 {
-    if (!canInsertDTMF()) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
+    if (!canInsertDTMF())
+        return Exception { NOT_SUPPORTED_ERR };
 
-    if (duration && (duration.value() > maxToneDurationMs || duration.value() < minToneDurationMs)) {
-        ec = SYNTAX_ERR;
-        return;
-    }
+    if (duration && (duration.value() > maxToneDurationMs || duration.value() < minToneDurationMs))
+        return Exception { SYNTAX_ERR };
 
-    if (interToneGap && interToneGap.value() < minInterToneGapMs) {
-        ec = SYNTAX_ERR;
-        return;
-    }
+    if (interToneGap && interToneGap.value() < minInterToneGapMs)
+        return Exception { SYNTAX_ERR };
 
     m_duration = duration.valueOr(defaultToneDurationMs);
     m_interToneGap = interToneGap.valueOr(defaultInterToneGapMs);
 
     if (!m_handler->insertDTMF(tones, m_duration, m_interToneGap))
-        ec = SYNTAX_ERR;
+        return Exception { SYNTAX_ERR };
+
+    return { };
 }
 
 void RTCDTMFSender::didPlayTone(const String& tone)
index 75b19ee..fca4253 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCDTMFSender_h
-#define RTCDTMFSender_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
 #include "ActiveDOMObject.h"
 #include "EventTarget.h"
+#include "ExceptionOr.h"
 #include "RTCDTMFSenderHandlerClient.h"
 #include "ScriptWrappable.h"
 #include "Timer.h"
-#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
@@ -41,10 +40,10 @@ class MediaStreamTrack;
 class RTCPeerConnectionHandler;
 class RTCDTMFSenderHandler;
 
-class RTCDTMFSender final : public RefCounted<RTCDTMFSender>, public EventTargetWithInlineData, public RTCDTMFSenderHandlerClient, public ActiveDOMObject {
+class RTCDTMFSender final : public RefCounted<RTCDTMFSender>, public EventTargetWithInlineData, private RTCDTMFSenderHandlerClient, public ActiveDOMObject {
 public:
-    static RefPtr<RTCDTMFSender> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, RefPtr<MediaStreamTrack>&&, ExceptionCode&);
-    ~RTCDTMFSender();
+    static ExceptionOr<Ref<RTCDTMFSender>> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, RefPtr<MediaStreamTrack>&&);
+    virtual ~RTCDTMFSender();
 
     bool canInsertDTMF() const;
     MediaStreamTrack* track() const;
@@ -52,32 +51,28 @@ public:
     long duration() const { return m_duration; }
     long interToneGap() const { return m_interToneGap; }
 
-    void insertDTMF(const String& tones, Optional<int> duration, Optional<int> interToneGap, ExceptionCode&);
+    ExceptionOr<void> insertDTMF(const String& tones, Optional<int> duration, Optional<int> interToneGap);
 
-    // EventTarget
-    EventTargetInterface eventTargetInterface() const override { return RTCDTMFSenderEventTargetInterfaceType; }
-    ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
-
-    using RefCounted<RTCDTMFSender>::ref;
-    using RefCounted<RTCDTMFSender>::deref;
+    using RefCounted::ref;
+    using RefCounted::deref;
 
 private:
-    RTCDTMFSender(ScriptExecutionContext*, RefPtr<MediaStreamTrack>&&, std::unique_ptr<RTCDTMFSenderHandler>);
+    RTCDTMFSender(ScriptExecutionContext&, RefPtr<MediaStreamTrack>&&, std::unique_ptr<RTCDTMFSenderHandler>);
 
-    // ActiveDOMObject
-    void stop() override;
-    const char* activeDOMObjectName() const override;
-    bool canSuspendForDocumentSuspension() const override;
+    void stop() final;
+    const char* activeDOMObjectName() const final;
+    bool canSuspendForDocumentSuspension() const final;
 
-    void scheduleDispatchEvent(Ref<Event>&&);
-    void scheduledEventTimerFired();
+    EventTargetInterface eventTargetInterface() const final { return RTCDTMFSenderEventTargetInterfaceType; }
+    ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
 
-    // EventTarget
-    void refEventTarget() override { ref(); }
-    void derefEventTarget() override { deref(); }
+    void refEventTarget() final { ref(); }
+    void derefEventTarget() final { deref(); }
 
-    // RTCDTMFSenderHandlerClient
-    void didPlayTone(const String&) override;
+    void didPlayTone(const String&) final;
+
+    void scheduleDispatchEvent(Ref<Event>&&);
+    void scheduledEventTimerFired();
 
     RefPtr<MediaStreamTrack> m_track;
     long m_duration;
@@ -94,5 +89,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCDTMFSender_h
index 795b939..fea23bd 100644 (file)
@@ -24,9 +24,9 @@
  */
 
 [
-    NoInterfaceObject,
-    Conditional=WEB_RTC,
     ActiveDOMObject,
+    Conditional=WEB_RTC,
+    NoInterfaceObject,
 ] interface RTCDTMFSender : EventTarget {
     readonly attribute boolean canInsertDTMF;
     readonly attribute MediaStreamTrack track;
@@ -34,7 +34,7 @@
     readonly attribute long duration;
     readonly attribute long interToneGap;
 
-    [MayThrowLegacyException] void insertDTMF(DOMString tones, optional long duration, optional long interToneGap);
+    [MayThrowException] void insertDTMF(DOMString tones, optional long duration, optional long interToneGap);
 
     attribute EventHandler ontonechange;
 };
index 34ca9a8..104c1cc 100644 (file)
@@ -55,7 +55,7 @@ static const AtomicString& arraybufferKeyword()
     return arraybuffer;
 }
 
-RefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, const Dictionary& options, ExceptionCode& ec)
+ExceptionOr<Ref<RTCDataChannel>> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, const Dictionary& options)
 {
     RTCDataChannelInit initData;
     String maxRetransmitsStr;
@@ -71,31 +71,25 @@ RefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, R
     bool maxRetransmitTimeConversion;
     initData.maxRetransmits = maxRetransmitsStr.toUIntStrict(&maxRetransmitsConversion);
     initData.maxRetransmitTime = maxRetransmitTimeStr.toUIntStrict(&maxRetransmitTimeConversion);
-    if (maxRetransmitsConversion && maxRetransmitTimeConversion) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
+    if (maxRetransmitsConversion && maxRetransmitTimeConversion)
+        return Exception { SYNTAX_ERR };
 
-    std::unique_ptr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataChannel(label, initData);
-    if (!handler) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
-    return adoptRef(*new RTCDataChannel(context, WTFMove(handler)));
+    auto handler = peerConnectionHandler->createDataChannel(label, initData);
+    if (!handler)
+        return Exception { NOT_SUPPORTED_ERR };
+
+    return adoptRef(*new RTCDataChannel(*context, WTFMove(handler)));
 }
 
-Ref<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, std::unique_ptr<RTCDataChannelHandler> handler)
+Ref<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, std::unique_ptr<RTCDataChannelHandler>&& handler)
 {
     ASSERT(handler);
-    return adoptRef(*new RTCDataChannel(context, WTFMove(handler)));
+    return adoptRef(*new RTCDataChannel(*context, WTFMove(handler)));
 }
 
-RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, std::unique_ptr<RTCDataChannelHandler> handler)
-    : m_scriptExecutionContext(context)
+RTCDataChannel::RTCDataChannel(ScriptExecutionContext& context, std::unique_ptr<RTCDataChannelHandler>&& handler)
+    : m_scriptExecutionContext(&context)
     , m_handler(WTFMove(handler))
-    , m_stopped(false)
-    , m_readyState(ReadyStateConnecting)
-    , m_binaryType(BinaryTypeArrayBuffer)
     , m_scheduledEventTimer(*this, &RTCDataChannel::scheduledEventTimerFired)
 {
     m_handler->setClient(this);
@@ -122,7 +116,7 @@ unsigned short RTCDataChannel::maxRetransmitTime() const
 
 unsigned short RTCDataChannel::maxRetransmits() const
 {
-return m_handler->maxRetransmits();
+    return m_handler->maxRetransmits();
 }
 
 String RTCDataChannel::protocol() const
@@ -140,13 +134,13 @@ unsigned short RTCDataChannel::id() const
     return m_handler->id();
 }
 
-AtomicString RTCDataChannel::readyState() const
+const AtomicString& RTCDataChannel::readyState() const
 {
     static NeverDestroyed<AtomicString> connectingState("connecting", AtomicString::ConstructFromLiteral);
     static NeverDestroyed<AtomicString> openState("open", AtomicString::ConstructFromLiteral);
     static NeverDestroyed<AtomicString> closingState("closing", AtomicString::ConstructFromLiteral);
     static NeverDestroyed<AtomicString> closedState("closed", AtomicString::ConstructFromLiteral);
-    
+
     switch (m_readyState) {
     case ReadyStateConnecting:
         return connectingState;
@@ -162,17 +156,17 @@ AtomicString RTCDataChannel::readyState() const
     return emptyAtom;
 }
 
-unsigned long RTCDataChannel::bufferedAmount() const
+unsigned RTCDataChannel::bufferedAmount() const
 {
     return m_handler->bufferedAmount();
 }
 
-AtomicString RTCDataChannel::binaryType() const
+const AtomicString& RTCDataChannel::binaryType() const
 {
     switch (m_binaryType) {
-    case BinaryTypeBlob:
+    case BinaryType::Blob:
         return blobKeyword();
-    case BinaryTypeArrayBuffer:
+    case BinaryType::ArrayBuffer:
         return arraybufferKeyword();
     }
 
@@ -180,57 +174,58 @@ AtomicString RTCDataChannel::binaryType() const
     return emptyAtom;
 }
 
-void RTCDataChannel::setBinaryType(const AtomicString& binaryType, ExceptionCode& ec)
+ExceptionOr<void> RTCDataChannel::setBinaryType(const AtomicString& binaryType)
 {
     if (binaryType == blobKeyword())
-        ec = NOT_SUPPORTED_ERR;
-    else if (binaryType == arraybufferKeyword())
-        m_binaryType = BinaryTypeArrayBuffer;
-    else
-        ec = TYPE_MISMATCH_ERR;
+        return Exception { NOT_SUPPORTED_ERR };
+    if (binaryType == arraybufferKeyword()) {
+        m_binaryType = BinaryType::ArrayBuffer;
+        return { };
+    }
+    return Exception { TYPE_MISMATCH_ERR };
 }
 
-void RTCDataChannel::send(const String& data, ExceptionCode& ec)
+ExceptionOr<void> RTCDataChannel::send(const String& data)
 {
-    if (m_readyState != ReadyStateOpen) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
+    if (m_readyState != ReadyStateOpen)
+        return Exception { INVALID_STATE_ERR };
 
     if (!m_handler->sendStringData(data)) {
         // FIXME: Decide what the right exception here is.
-        ec = SYNTAX_ERR;
+        return Exception { SYNTAX_ERR };
     }
+
+    return { };
 }
 
-void RTCDataChannel::send(ArrayBuffer& data, ExceptionCode& ec)
+ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
 {
-    if (m_readyState != ReadyStateOpen) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
+    if (m_readyState != ReadyStateOpen)
+        return Exception { INVALID_STATE_ERR };
 
     size_t dataLength = data.byteLength();
     if (!dataLength)
-        return;
+        return { };
 
     const char* dataPointer = static_cast<const char*>(data.data());
 
     if (!m_handler->sendRawData(dataPointer, dataLength)) {
         // FIXME: Decide what the right exception here is.
-        ec = SYNTAX_ERR;
+        return Exception { SYNTAX_ERR };
     }
+
+    return { };
 }
 
-void RTCDataChannel::send(ArrayBufferView& data, ExceptionCode& ec)
+ExceptionOr<void> RTCDataChannel::send(ArrayBufferView& data)
 {
-    send(*data.buffer(), ec);
+    return send(*data.buffer());
 }
 
-void RTCDataChannel::send(Blob&, ExceptionCode& ec)
+ExceptionOr<void> RTCDataChannel::send(Blob&)
 {
-    // FIXME: implement
-    ec = NOT_SUPPORTED_ERR;
+    // FIXME: Implement.
+    return Exception { NOT_SUPPORTED_ERR };
 }
 
 void RTCDataChannel::close()
@@ -273,12 +268,12 @@ void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength)
     if (m_stopped)
         return;
 
-    if (m_binaryType == BinaryTypeBlob) {
+    if (m_binaryType == BinaryType::Blob) {
         // FIXME: Implement.
         return;
     }
 
-    if (m_binaryType == BinaryTypeArrayBuffer) {
+    if (m_binaryType == BinaryType::ArrayBuffer) {
         scheduleDispatchEvent(MessageEvent::create(ArrayBuffer::create(data, dataLength)));
         return;
     }
index c919dea..dae5d24 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCDataChannel_h
-#define RTCDataChannel_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
 #include "EventTarget.h"
+#include "ExceptionOr.h"
 #include "RTCDataChannelHandlerClient.h"
 #include "ScriptWrappable.h"
 #include "Timer.h"
-#include <wtf/RefCounted.h>
 
 namespace JSC {
     class ArrayBuffer;
@@ -47,8 +46,8 @@ class RTCPeerConnectionHandler;
 
 class RTCDataChannel final : public RefCounted<RTCDataChannel>, public EventTargetWithInlineData, public RTCDataChannelHandlerClient {
 public:
-    static Ref<RTCDataChannel> create(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>);
-    static RefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& label, const Dictionary& options, ExceptionCode&);
+    static Ref<RTCDataChannel> create(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>&&);
+    static ExceptionOr<Ref<RTCDataChannel>> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& label, const Dictionary& options);
     ~RTCDataChannel();
 
     String label() const;
@@ -58,56 +57,51 @@ public:
     String protocol() const;
     bool negotiated() const;
     unsigned short id() const;
-    AtomicString readyState() const;
-    unsigned long bufferedAmount() const;
+    const AtomicString& readyState() const;
+    unsigned bufferedAmount() const;
 
-    AtomicString binaryType() const;
-    void setBinaryType(const AtomicString&, ExceptionCode&);
+    const AtomicString& binaryType() const;
+    ExceptionOr<void> setBinaryType(const AtomicString&);
 
-    void send(const String&, ExceptionCode&);
-    void send(JSC::ArrayBuffer&, ExceptionCode&);
-    void send(JSC::ArrayBufferView&, ExceptionCode&);
-    void send(Blob&, ExceptionCode&);
+    ExceptionOr<void> send(const String&);
+    ExceptionOr<void> send(JSC::ArrayBuffer&);
+    ExceptionOr<void> send(JSC::ArrayBufferView&);
+    ExceptionOr<void> send(Blob&);
 
     void close();
 
     void stop();
 
-    // EventTarget
-    EventTargetInterface eventTargetInterface() const override { return RTCDataChannelEventTargetInterfaceType; }
-    ScriptExecutionContext* scriptExecutionContext() const override { return m_scriptExecutionContext; }
-
-    using RefCounted<RTCDataChannel>::ref;
-    using RefCounted<RTCDataChannel>::deref;
+    using RefCounted::ref;
+    using RefCounted::deref;
 
 private:
-    RTCDataChannel(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>);
+    RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&);
 
     void scheduleDispatchEvent(Ref<Event>&&);
     void scheduledEventTimerFired();
 
-    // EventTarget
-    void refEventTarget() override { ref(); }
-    void derefEventTarget() override { deref(); }
+    EventTargetInterface eventTargetInterface() const final { return RTCDataChannelEventTargetInterfaceType; }
+    ScriptExecutionContext* scriptExecutionContext() const final { return m_scriptExecutionContext; }
+
+    void refEventTarget() final { ref(); }
+    void derefEventTarget() final { deref(); }
 
     ScriptExecutionContext* m_scriptExecutionContext;
 
-    // RTCDataChannelHandlerClient
-    void didChangeReadyState(ReadyState) override;
-    void didReceiveStringData(const String&) override;
-    void didReceiveRawData(const char*, size_t) override;
-    void didDetectError() override;
+    void didChangeReadyState(ReadyState) final;
+    void didReceiveStringData(const String&) final;
+    void didReceiveRawData(const char*, size_t) final;
+    void didDetectError() final;
 
     std::unique_ptr<RTCDataChannelHandler> m_handler;
 
-    bool m_stopped;
+    bool m_stopped { false };
 
-    ReadyState m_readyState;
-    enum BinaryType {
-        BinaryTypeBlob,
-        BinaryTypeArrayBuffer
-    };
-    BinaryType m_binaryType;
+    ReadyState m_readyState { ReadyStateConnecting };
+
+    enum class BinaryType { Blob, ArrayBuffer };
+    BinaryType m_binaryType { BinaryType::ArrayBuffer };
 
     Timer m_scheduledEventTimer;
     Vector<Ref<Event>> m_scheduledEvents;
@@ -116,5 +110,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCDataChannel_h
index 5fe6ded..e778c0f 100644 (file)
     readonly attribute DOMString readyState;
     readonly attribute unsigned long bufferedAmount;
 
-    [SetterMayThrowLegacyException] attribute DOMString binaryType;
+    [SetterMayThrowException] attribute DOMString binaryType;
 
-    [MayThrowLegacyException] void send(ArrayBuffer data);
-    [MayThrowLegacyException] void send(ArrayBufferView data);
-    [MayThrowLegacyException] void send(Blob data);
-    [MayThrowLegacyException] void send(DOMString data);
+    [MayThrowException] void send(ArrayBuffer data);
+    [MayThrowException] void send(ArrayBufferView data);
+    [MayThrowException] void send(Blob data);
+    [MayThrowException] void send(DOMString data);
 
     void close();
 
index 5556782..6bffe2c 100644 (file)
 
 namespace WebCore {
 
-RefPtr<RTCIceCandidate> RTCIceCandidate::create(const Dictionary& dictionary, ExceptionCode& ec)
+ExceptionOr<Ref<RTCIceCandidate>> RTCIceCandidate::create(const Dictionary& dictionary)
 {
     String candidate;
-    if (!dictionary.get("candidate", candidate)) {
-        ec = TypeError;
-        return nullptr;
-    }
+    if (!dictionary.get("candidate", candidate))
+        return Exception { TypeError };
 
     String sdpMid;
     dictionary.getWithUndefinedOrNullCheck("sdpMid", sdpMid);
@@ -58,19 +56,15 @@ RefPtr<RTCIceCandidate> RTCIceCandidate::create(const Dictionary& dictionary, Ex
     if (dictionary.getWithUndefinedOrNullCheck("sdpMLineIndex", sdpMLineIndexString)) {
         bool intConversionOk;
         unsigned result = sdpMLineIndexString.toUIntStrict(&intConversionOk);
-        if (!intConversionOk || result > USHRT_MAX) {
-            ec = TypeError;
-            return nullptr;
-        }
+        if (!intConversionOk || result > USHRT_MAX)
+            return Exception { TypeError };
         sdpMLineIndex = result;
     }
 
-    if (sdpMid.isNull() && !sdpMLineIndex) {
-        ec = TypeError;
-        return nullptr;
-    }
+    if (sdpMid.isNull() && !sdpMLineIndex)
+        return Exception { TypeError };
 
-    return adoptRef(new RTCIceCandidate(candidate, sdpMid, sdpMLineIndex));
+    return adoptRef(*new RTCIceCandidate(candidate, sdpMid, sdpMLineIndex));
 }
 
 Ref<RTCIceCandidate> RTCIceCandidate::create(const String& candidate, const String& sdpMid, Optional<unsigned short> sdpMLineIndex)
index 930cbbd..d789f3d 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCIceCandidate_h
-#define RTCIceCandidate_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
-#include "ExceptionBase.h"
+#include "ExceptionOr.h"
 #include "ScriptWrappable.h"
 #include <wtf/Optional.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -47,9 +43,8 @@ class RTCIceCandidateDescriptor;
 
 class RTCIceCandidate : public RefCounted<RTCIceCandidate>, public ScriptWrappable {
 public:
-    static RefPtr<RTCIceCandidate> create(const Dictionary&, ExceptionCode&);
+    static ExceptionOr<Ref<RTCIceCandidate>> create(const Dictionary&);
     static Ref<RTCIceCandidate> create(const String& candidate, const String& sdpMid, Optional<unsigned short> sdpMLineIndex);
-    virtual ~RTCIceCandidate() { }
 
     const String& candidate() const { return m_candidate; }
     const String& sdpMid() const { return m_sdpMid; }
@@ -66,5 +61,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCIceCandidate_h
index ac4fdc4..658d682 100644 (file)
@@ -32,7 +32,8 @@
 [
     Conditional=WEB_RTC,
     Constructor(Dictionary dictionary),
-    ConstructorMayThrowLegacyException,
+    ConstructorMayThrowException,
+    ImplementationLacksVTable,
     PrivateIdentifier,
     PublicIdentifier
 ] interface RTCIceCandidate {
@@ -42,4 +43,3 @@
 
     serializer = {candidate, sdpMid, sdpMLineIndex};
 };
-
index 9c42a84..721ec4b 100644 (file)
 
 namespace WebCore {
 
-RTCOfferAnswerOptions::RTCOfferAnswerOptions()
-    : m_voiceActivityDetection(true)
-{
-}
-
 bool RTCOfferAnswerOptions::initialize(const Dictionary& options)
 {
     bool voiceActivityDetection;
@@ -47,24 +42,15 @@ bool RTCOfferAnswerOptions::initialize(const Dictionary& options)
     return true;
 }
 
-RefPtr<RTCOfferOptions> RTCOfferOptions::create(const Dictionary& options, ExceptionCode& ec)
+ExceptionOr<Ref<RTCOfferOptions>> RTCOfferOptions::create(const Dictionary& options)
 {
-    RefPtr<RTCOfferOptions> offerOptions = adoptRef(new RTCOfferOptions());
-    if (!offerOptions->initialize(options)) {
+    auto result = adoptRef(*new RTCOfferOptions);
+    if (!result->initialize(options)) {
         // FIXME: https://webkit.org/b/129800
         // According to the spec, the error is going to be defined yet, so let's use TYPE_MISMATCH_ERR for now.
-        ec = TYPE_MISMATCH_ERR;
-        return nullptr;
+        return Exception { TYPE_MISMATCH_ERR };
     }
-
-    return offerOptions;
-}
-
-RTCOfferOptions::RTCOfferOptions()
-    : m_offerToReceiveVideo(0)
-    , m_offerToReceiveAudio(0)
-    , m_iceRestart(false)
-{
+    return WTFMove(result);
 }
 
 bool RTCOfferOptions::initialize(const Dictionary& options)
@@ -99,17 +85,15 @@ bool RTCOfferOptions::initialize(const Dictionary& options)
     return RTCOfferAnswerOptions::initialize(options);
 }
 
-RefPtr<RTCAnswerOptions> RTCAnswerOptions::create(const Dictionary& options, ExceptionCode& ec)
+ExceptionOr<Ref<RTCAnswerOptions>> RTCAnswerOptions::create(const Dictionary& options)
 {
-    RefPtr<RTCAnswerOptions> offerOptions = adoptRef(new RTCAnswerOptions());
-    if (!offerOptions->initialize(options)) {
+    auto result = adoptRef(*new RTCAnswerOptions);
+    if (!result->initialize(options)) {
         // FIXME: https://webkit.org/b/129800
         // According to the spec, the error is going to be defined yet, so let's use TYPE_MISMATCH_ERR for now.
-        ec = TYPE_MISMATCH_ERR;
-        return nullptr;
+        return Exception { TYPE_MISMATCH_ERR };
     }
-
-    return offerOptions;
+    return WTFMove(result);
 }
 
 bool RTCAnswerOptions::initialize(const Dictionary& options)
index 7fc5743..b33d141 100644 (file)
@@ -24,8 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCOfferAnswerOptions_h
-#define RTCOfferAnswerOptions_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
@@ -38,47 +37,46 @@ namespace WebCore {
 
 class Dictionary;
 
-class RTCOfferAnswerOptions : public RefCounted<RTCOfferAnswerOptions> {
+class RTCOfferAnswerOptions {
 public:
-    virtual ~RTCOfferAnswerOptions() { }
-
     bool voiceActivityDetection() const { return m_voiceActivityDetection; }
 
 protected:
-    virtual bool initialize(const Dictionary&);
-    RTCOfferAnswerOptions();
+    RTCOfferAnswerOptions() = default;
+    bool initialize(const Dictionary&);
 
-    bool m_voiceActivityDetection;
+private:
+    bool m_voiceActivityDetection { true };
 };
 
-class RTCOfferOptions : public RTCOfferAnswerOptions {
+// FIXME: Why is this reference counted?
+class RTCOfferOptions : public RefCounted<RTCOfferOptions>, public RTCOfferAnswerOptions {
 public:
-    static RefPtr<RTCOfferOptions> create(const Dictionary&, ExceptionCode&);
+    static ExceptionOr<Ref<RTCOfferOptions>> create(const Dictionary&);
 
     int64_t offerToReceiveVideo() const { return m_offerToReceiveVideo; }
     int64_t offerToReceiveAudio() const { return m_offerToReceiveAudio; }
     bool iceRestart() const { return m_iceRestart; }
 
 private:
-    bool initialize(const Dictionary&) override;
-    RTCOfferOptions();
+    RTCOfferOptions() = default;
+    bool initialize(const Dictionary&);
 
-    int64_t m_offerToReceiveVideo;
-    int64_t m_offerToReceiveAudio;
-    bool m_iceRestart;
+    int64_t m_offerToReceiveVideo { 0 };
+    int64_t m_offerToReceiveAudio { 0 };
+    bool m_iceRestart { false };
 };
 
-class RTCAnswerOptions : public RTCOfferAnswerOptions {
+// FIXME: Why is this reference counted?
+class RTCAnswerOptions : public RefCounted<RTCAnswerOptions>, public RTCOfferAnswerOptions {
 public:
-    static RefPtr<RTCAnswerOptions> create(const Dictionary&, ExceptionCode&);
+    static ExceptionOr<Ref<RTCAnswerOptions>> create(const Dictionary&);
 
 private:
-    bool initialize(const Dictionary&) override;
-    RTCAnswerOptions() { }
+    RTCAnswerOptions() = default;
+    bool initialize(const Dictionary&);
 };
 
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCOfferAnswerOptions_h
index 9d1a626..e8f911a 100644 (file)
@@ -78,39 +78,29 @@ RTCPeerConnection::~RTCPeerConnection()
     stop();
 }
 
-void RTCPeerConnection::initializeWith(Document& document, const Dictionary& rtcConfiguration, ExceptionCode& ec)
+ExceptionOr<void> RTCPeerConnection::initializeWith(Document& document, const Dictionary& rtcConfiguration)
 {
-    if (!document.frame()) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
+    if (!document.frame())
+        return Exception { NOT_SUPPORTED_ERR };
 
-    if (!m_backend) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
+    if (!m_backend)
+        return Exception { NOT_SUPPORTED_ERR };
 
-    setConfiguration(rtcConfiguration, ec);
+    return setConfiguration(rtcConfiguration);
 }
 
-RefPtr<RTCRtpSender> RTCPeerConnection::addTrack(Ref<MediaStreamTrack>&& track, const Vector<std::reference_wrapper<MediaStream>>& streams, ExceptionCode& ec)
+ExceptionOr<Ref<RTCRtpSender>> RTCPeerConnection::addTrack(Ref<MediaStreamTrack>&& track, const Vector<std::reference_wrapper<MediaStream>>& streams)
 {
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return nullptr;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
     // Require at least one stream until https://github.com/w3c/webrtc-pc/issues/288 is resolved
-    if (!streams.size()) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
+    if (!streams.size())
+        return Exception { NOT_SUPPORTED_ERR };
 
     for (auto& sender : m_transceiverSet->getSenders()) {
-        if (sender->trackId() == track->id()) {
-            ec = INVALID_ACCESS_ERR;
-            return nullptr;
-        }
+        if (sender->trackId() == track->id())
+            return Exception { INVALID_ACCESS_ERR };
     }
 
     Vector<String> mediaStreamIds;
@@ -150,30 +140,27 @@ RefPtr<RTCRtpSender> RTCPeerConnection::addTrack(Ref<MediaStreamTrack>&& track,
 
     m_backend->markAsNeedingNegotiation();
 
-    return sender;
+    return Ref<RTCRtpSender> { *sender };
 }
 
-void RTCPeerConnection::removeTrack(RTCRtpSender& sender, ExceptionCode& ec)
+ExceptionOr<void> RTCPeerConnection::removeTrack(RTCRtpSender& sender)
 {
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
     if (!m_transceiverSet->getSenders().contains(&sender))
-        return;
+        return { };
 
     sender.stop();
 
     m_backend->markAsNeedingNegotiation();
+    return { };
 }
 
-RefPtr<RTCRtpTransceiver> RTCPeerConnection::addTransceiver(Ref<MediaStreamTrack>&& track, const RtpTransceiverInit& init, ExceptionCode& ec)
+ExceptionOr<Ref<RTCRtpTransceiver>> RTCPeerConnection::addTransceiver(Ref<MediaStreamTrack>&& track, const RtpTransceiverInit& init)
 {
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return nullptr;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
     String transceiverMid = RTCRtpTransceiver::getNextMid();
     const String& trackKind = track->kind();
@@ -184,20 +171,17 @@ RefPtr<RTCRtpTransceiver> RTCPeerConnection::addTransceiver(Ref<MediaStreamTrack
     auto transceiver = RTCRtpTransceiver::create(WTFMove(sender), WTFMove(receiver));
     transceiver->setProvisionalMid(transceiverMid);
 
-    return completeAddTransceiver(WTFMove(transceiver), init);
+    completeAddTransceiver(transceiver, init);
+    return WTFMove(transceiver);
 }
 
-RefPtr<RTCRtpTransceiver> RTCPeerConnection::addTransceiver(const String& kind, const RtpTransceiverInit& init, ExceptionCode& ec)
+ExceptionOr<Ref<RTCRtpTransceiver>> RTCPeerConnection::addTransceiver(const String& kind, const RtpTransceiverInit& init)
 {
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return nullptr;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
-    if (kind != "audio" && kind != "video") {
-        ec = TypeError;
-        return nullptr;
-    }
+    if (kind != "audio" && kind != "video")
+        return Exception { TypeError };
 
     String transceiverMid = RTCRtpTransceiver::getNextMid();
     String trackId = createCanonicalUUIDString();
@@ -207,17 +191,16 @@ RefPtr<RTCRtpTransceiver> RTCPeerConnection::addTransceiver(const String& kind,
     auto transceiver = RTCRtpTransceiver::create(WTFMove(sender), WTFMove(receiver));
     transceiver->setProvisionalMid(transceiverMid);
 
-    return completeAddTransceiver(WTFMove(transceiver), init);
+    completeAddTransceiver(transceiver, init);
+    return WTFMove(transceiver);
 }
 
-RefPtr<RTCRtpTransceiver> RTCPeerConnection::completeAddTransceiver(Ref<RTCRtpTransceiver>&& transceiver, const RtpTransceiverInit& init)
+void RTCPeerConnection::completeAddTransceiver(RTCRtpTransceiver& transceiver, const RtpTransceiverInit& init)
 {
-    transceiver->setDirection(static_cast<RTCRtpTransceiver::Direction>(init.direction));
+    transceiver.setDirection(static_cast<RTCRtpTransceiver::Direction>(init.direction));
 
-    m_transceiverSet->append(transceiver.copyRef());
+    m_transceiverSet->append(&transceiver);
     m_backend->markAsNeedingNegotiation();
-
-    return WTFMove(transceiver);
 }
 
 void RTCPeerConnection::queuedCreateOffer(const Dictionary& offerOptions, SessionDescriptionPromise&& promise)
@@ -227,15 +210,13 @@ void RTCPeerConnection::queuedCreateOffer(const Dictionary& offerOptions, Sessio
         return;
     }
 
-    ExceptionCode ec = 0;
-    RefPtr<RTCOfferOptions> options = RTCOfferOptions::create(offerOptions, ec);
-    if (ec) {
+    auto options = RTCOfferOptions::create(offerOptions);
+    if (options.hasException()) {
         promise.reject(OperationError, "Invalid createOffer argument");
         return;
     }
-    ASSERT(options);
 
-    m_backend->createOffer(*options, WTFMove(promise));
+    m_backend->createOffer(options.releaseReturnValue(), WTFMove(promise));
 }
 
 void RTCPeerConnection::queuedCreateAnswer(const Dictionary& answerOptions, SessionDescriptionPromise&& promise)
@@ -245,14 +226,13 @@ void RTCPeerConnection::queuedCreateAnswer(const Dictionary& answerOptions, Sess
         return;
     }
 
-    ExceptionCode ec = 0;
-    RefPtr<RTCAnswerOptions> options = RTCAnswerOptions::create(answerOptions, ec);
-    if (ec) {
+    auto options = RTCAnswerOptions::create(answerOptions);
+    if (options.hasException()) {
         promise.reject(OperationError, "Invalid createAnswer argument");
         return;
     }
 
-    m_backend->createAnswer(*options, WTFMove(promise));
+    m_backend->createAnswer(options.releaseReturnValue(), WTFMove(promise));
 }
 
 void RTCPeerConnection::queuedSetLocalDescription(RTCSessionDescription& description, PeerConnection::VoidPromise&& promise)
@@ -379,24 +359,21 @@ RTCConfiguration* RTCPeerConnection::getConfiguration() const
     return m_configuration.get();
 }
 
-void RTCPeerConnection::setConfiguration(const Dictionary& configuration, ExceptionCode& ec)
+ExceptionOr<void> RTCPeerConnection::setConfiguration(const Dictionary& configuration)
 {
-    if (configuration.isUndefinedOrNull()) {
-        ec = TypeError;
-        return;
-    }
+    if (configuration.isUndefinedOrNull())
+        return Exception { TypeError };
 
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
-    RefPtr<RTCConfiguration> newConfiguration = RTCConfiguration::create(configuration, ec);
-    if (ec)
-        return;
+    auto newConfiguration = RTCConfiguration::create(configuration);
+    if (newConfiguration.hasException())
+        return newConfiguration.releaseException();
 
-    m_configuration = WTFMove(newConfiguration);
+    m_configuration = newConfiguration.releaseReturnValue();
     m_backend->setConfiguration(*m_configuration);
+    return { };
 }
 
 void RTCPeerConnection::privateGetStats(MediaStreamTrack* selector, PeerConnection::StatsPromise&& promise)
@@ -404,12 +381,10 @@ void RTCPeerConnection::privateGetStats(MediaStreamTrack* selector, PeerConnecti
     m_backend->getStats(selector, WTFMove(promise));
 }
 
-RefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String, const Dictionary&, ExceptionCode& ec)
+ExceptionOr<RefPtr<RTCDataChannel>> RTCPeerConnection::createDataChannel(const String&, const Dictionary&)
 {
-    if (m_signalingState == SignalingState::Closed) {
-        ec = INVALID_STATE_ERR;
-        return nullptr;
-    }
+    if (m_signalingState == SignalingState::Closed)
+        return Exception { INVALID_STATE_ERR };
 
     return nullptr;
 }
index e0afba0..0a7a13b 100644 (file)
@@ -60,7 +60,7 @@ public:
     static Ref<RTCPeerConnection> create(ScriptExecutionContext&);
     ~RTCPeerConnection();
 
-    void initializeWith(Document&, const Dictionary&, ExceptionCode&);
+    ExceptionOr<void> initializeWith(Document&, const Dictionary&);
 
     const Vector<RefPtr<RTCRtpSender>>& getSenders() const { return m_transceiverSet->getSenders(); }
     const Vector<RefPtr<RTCRtpReceiver>>& getReceivers() const { return m_transceiverSet->getReceivers(); }
@@ -69,8 +69,8 @@ public:
     // Part of legacy MediaStream-based API (mostly implemented as JS built-ins)
     Vector<RefPtr<MediaStream>> getRemoteStreams() const { return m_backend->getRemoteStreams(); }
 
-    RefPtr<RTCRtpSender> addTrack(Ref<MediaStreamTrack>&&, const Vector<std::reference_wrapper<MediaStream>>&, ExceptionCode&);
-    void removeTrack(RTCRtpSender&, ExceptionCode&);
+    ExceptionOr<Ref<RTCRtpSender>> addTrack(Ref<MediaStreamTrack>&&, const Vector<std::reference_wrapper<MediaStream>>&);
+    ExceptionOr<void> removeTrack(RTCRtpSender&);
 
     // This enum is mirrored in RTCRtpTransceiver.h
     enum class RtpTransceiverDirection { Sendrecv, Sendonly, Recvonly, Inactive };
@@ -79,8 +79,8 @@ public:
         RtpTransceiverDirection direction;
     };
 
-    RefPtr<RTCRtpTransceiver> addTransceiver(Ref<MediaStreamTrack>&&, const RtpTransceiverInit&, ExceptionCode&);
-    RefPtr<RTCRtpTransceiver> addTransceiver(const String& kind, const RtpTransceiverInit&, ExceptionCode&);
+    ExceptionOr<Ref<RTCRtpTransceiver>> addTransceiver(Ref<MediaStreamTrack>&&, const RtpTransceiverInit&);
+    ExceptionOr<Ref<RTCRtpTransceiver>> addTransceiver(const String& kind, const RtpTransceiverInit&);
 
     void queuedCreateOffer(const Dictionary& offerOptions, PeerConnection::SessionDescriptionPromise&&);
     void queuedCreateAnswer(const Dictionary& answerOptions, PeerConnection::SessionDescriptionPromise&&);
@@ -103,11 +103,11 @@ public:
     String iceConnectionState() const;
 
     RTCConfiguration* getConfiguration() const;
-    void setConfiguration(const Dictionary& configuration, ExceptionCode&);
+    ExceptionOr<void> setConfiguration(const Dictionary&);
 
     void privateGetStats(MediaStreamTrack*, PeerConnection::StatsPromise&&);
 
-    RefPtr<RTCDataChannel> createDataChannel(String label, const Dictionary& dataChannelDict, ExceptionCode&);
+    ExceptionOr<RefPtr<RTCDataChannel>> createDataChannel(const String& label, const Dictionary& dataChannelDict);
 
     void close();
 
@@ -124,7 +124,7 @@ public:
 private:
     RTCPeerConnection(ScriptExecutionContext&);
 
-    RefPtr<RTCRtpTransceiver> completeAddTransceiver(Ref<RTCRtpTransceiver>&&, const RtpTransceiverInit&);
+    void completeAddTransceiver(RTCRtpTransceiver&, const RtpTransceiverInit&);
 
     // EventTarget implementation.
     void refEventTarget() final { ref(); }
index 093d3cf..3ddc6f4 100644 (file)
     JSBuiltinConstructor,
 ] interface RTCPeerConnection : EventTarget {
     // Private initializer
-    [PrivateIdentifier, CallWith=Document, MayThrowLegacyException] void initializeWith(Dictionary parameters);
+    [PrivateIdentifier, CallWith=Document, MayThrowException] void initializeWith(Dictionary parameters);
 
     // RTP Media API extensions
     [PrivateIdentifier, PublicIdentifier] sequence<RTCRtpSender> getSenders();
     sequence<RTCRtpReceiver> getReceivers();
     sequence<RTCRtpTransceiver> getTransceivers();
 
-    [PrivateIdentifier, PublicIdentifier, MayThrowLegacyException] RTCRtpSender addTrack(MediaStreamTrack track, MediaStream... streams);
-    [PrivateIdentifier, PublicIdentifier, MayThrowLegacyException] void removeTrack(RTCRtpSender sender);
+    [PrivateIdentifier, PublicIdentifier, MayThrowException] RTCRtpSender addTrack(MediaStreamTrack track, MediaStream... streams);
+    [PrivateIdentifier, PublicIdentifier, MayThrowException] void removeTrack(RTCRtpSender sender);
 
-    [MayThrowLegacyException] RTCRtpTransceiver addTransceiver(MediaStreamTrack track, optional RTCRtpTransceiverInit init);
-    [MayThrowLegacyException] RTCRtpTransceiver addTransceiver(DOMString kind, optional RTCRtpTransceiverInit init);
+    [MayThrowException] RTCRtpTransceiver addTransceiver(MediaStreamTrack track, optional RTCRtpTransceiverInit init);
+    [MayThrowException] RTCRtpTransceiver addTransceiver(DOMString kind, optional RTCRtpTransceiverInit init);
 
     // Legacy MediaSream-based API (implemented on top of the RTP Media API)
     [JSBuiltin] sequence<MediaStream> getLocalStreams();
@@ -98,7 +98,7 @@
     readonly attribute DOMString iceConnectionState;
 
     RTCConfiguration getConfiguration();
-    [MayThrowLegacyException] void setConfiguration(Dictionary configuration);
+    [MayThrowException] void setConfiguration(Dictionary configuration);
 
     [JSBuiltin] Promise getStats(optional MediaStreamTrack? selector = null);
     // Legacy signature: Promise getStats(MediaStreamTrack? selector
     [PrivateIdentifier] Promise queuedAddIceCandidate(RTCIceCandidate candidate);
     [PrivateIdentifier] Promise privateGetStats(MediaStreamTrack? selector);
 
-    [MayThrowLegacyException] RTCDataChannel createDataChannel([TreatNullAs=EmptyString] DOMString label, optional Dictionary options);
+    [MayThrowException] RTCDataChannel createDataChannel([TreatNullAs=EmptyString] DOMString label, optional Dictionary options);
 
     void close();
 
index 1aaedef..8850bbf 100644 (file)
@@ -67,19 +67,19 @@ void RTCRtpSender::setTrack(RefPtr<MediaStreamTrack>&& track)
     m_track = WTFMove(track);
 }
 
-void RTCRtpSender::replaceTrack(Ref<MediaStreamTrack>&& withTrack, PeerConnection::VoidPromise&& promise, ExceptionCode& ec)
+ExceptionOr<void> RTCRtpSender::replaceTrack(Ref<MediaStreamTrack>&& withTrack, PeerConnection::VoidPromise&& promise)
 {
     if (isStopped()) {
         promise.reject(INVALID_STATE_ERR);
-        return;
+        return { };
     }
 
-    if (m_trackKind != withTrack->kind()) {
-        ec = TypeError;
-        return;
-    }
+    if (m_trackKind != withTrack->kind())
+        return Exception { TypeError };
 
     m_client->replaceTrack(*this, WTFMove(withTrack), WTFMove(promise));
+
+    return { };
 }
 
 } // namespace WebCore
index f35501c..de63e66 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCRtpSender_h
-#define RTCRtpSender_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
 #include "PeerConnectionBackend.h"
 #include "RTCRtpSenderReceiverBase.h"
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -61,7 +59,7 @@ public:
     void stop() { m_client = nullptr; }
     void setTrack(RefPtr<MediaStreamTrack>&&);
 
-    void replaceTrack(Ref<MediaStreamTrack>&&, PeerConnection::VoidPromise&&, ExceptionCode&);
+    ExceptionOr<void> replaceTrack(Ref<MediaStreamTrack>&&, PeerConnection::VoidPromise&&);
 
 private:
     RTCRtpSender(RefPtr<MediaStreamTrack>&&, const String& trackKind, Vector<String>&& mediaStreamIds, RTCRtpSenderClient&);
@@ -75,4 +73,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-#endif // RTCRtpSender_h
index 0db5a90..d8d2cc9 100644 (file)
@@ -33,5 +33,5 @@
 ] interface RTCRtpSender {
     readonly attribute MediaStreamTrack? track;
 
-    [MayThrowLegacyException] Promise replaceTrack(MediaStreamTrack withTrack);
+    [MayThrowException] Promise replaceTrack(MediaStreamTrack withTrack);
 };
index 1d439cb..07f2d8e 100644 (file)
  */
 
 #include "config.h"
+#include "RTCSessionDescription.h"
 
 #if ENABLE(WEB_RTC)
 
-#include "RTCSessionDescription.h"
-
 #include "Dictionary.h"
+#include "ExceptionCode.h"
 
 namespace WebCore {
 
@@ -55,25 +55,21 @@ static bool parseTypeString(const String& string, RTCSessionDescription::SdpType
     return true;
 }
 
-RefPtr<RTCSessionDescription> RTCSessionDescription::create(const Dictionary& dictionary, ExceptionCode& ec)
+ExceptionOr<Ref<RTCSessionDescription>> RTCSessionDescription::create(const Dictionary& dictionary)
 {
     String typeString;
     // Dictionary member type is required.
-    if (!dictionary.get("type", typeString)) {
-        ec = TypeError;
-        return nullptr;
-    }
+    if (!dictionary.get("type", typeString))
+        return Exception { TypeError };
 
     SdpType type;
-    if (!parseTypeString(typeString, type)) {
-        ec = TypeError;
-        return nullptr;
-    }
+    if (!parseTypeString(typeString, type))
+        return Exception { TypeError };
 
     String sdp;
     dictionary.get("sdp", sdp);
 
-    return adoptRef(new RTCSessionDescription(type, sdp));
+    return adoptRef(*new RTCSessionDescription(type, sdp));
 }
 
 Ref<RTCSessionDescription> RTCSessionDescription::create(SdpType type, const String& sdp)
index d270dca..aabec84 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RTCSessionDescription_h
-#define RTCSessionDescription_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
-#include "ExceptionCode.h"
+#include "ExceptionOr.h"
 #include "ScriptWrappable.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -52,9 +48,8 @@ public:
         Rollback
     };
 
-    static RefPtr<RTCSessionDescription> create(const Dictionary&, ExceptionCode&);
+    static ExceptionOr<Ref<RTCSessionDescription>> create(const Dictionary&);
     static Ref<RTCSessionDescription> create(SdpType, const String& sdp);
-    virtual ~RTCSessionDescription() { }
 
     SdpType type() const { return m_type; }
 
@@ -71,5 +66,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // RTCSessionDescription_h
index 3a028d7..9305ae4 100644 (file)
 [
     Conditional=WEB_RTC,
     Constructor(Dictionary dictionary),
-    ConstructorMayThrowLegacyException,
+    ConstructorMayThrowException,
+    ImplementationLacksVTable,
     PrivateIdentifier,
-    PublicIdentifier
+    PublicIdentifier,
 ] interface RTCSessionDescription {
-    [SetterMayThrowLegacyException] readonly attribute RTCSdpType type;
+    [SetterMayThrowException] readonly attribute RTCSdpType type;
     readonly attribute DOMString sdp;
 
     serializer = {type, sdp};
index ffe022a..010efb7 100644 (file)
 
 namespace WebCore {
 
-static bool verifyCustomHandlerURL(const URL& baseURL, const String& url, ExceptionCode& ec)
+static bool verifyCustomHandlerURL(const URL& baseURL, const String& url)
 {
     // The specification requires that it is a SYNTAX_ERR if the "%s" token is
     // not present.
     static const char token[] = "%s";
     int index = url.find(token);
-    if (-1 == index) {
-        ec = SYNTAX_ERR;
+    if (-1 == index)
         return false;
-    }
 
     // It is also a SYNTAX_ERR if the custom handler URL, as created by removing
     // the "%s" token and prepending the base url, does not resolve.
@@ -57,10 +55,8 @@ static bool verifyCustomHandlerURL(const URL& baseURL, const String& url, Except
 
     URL kurl(baseURL, newURL);
 
-    if (kurl.isEmpty() || !kurl.isValid()) {
-        ec = SYNTAX_ERR;
+    if (kurl.isEmpty() || !kurl.isValid())
         return false;
-    }
 
     return true;
 }
@@ -76,7 +72,7 @@ static inline bool isProtocolWhitelisted(const String& scheme)
     return protocolWhitelist.get().contains(scheme);
 }
 
-static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
+static bool verifyProtocolHandlerScheme(const String& scheme)
 {
     if (isProtocolWhitelisted(scheme))
         return true;
@@ -88,7 +84,6 @@ static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
             return true;
     }
 
-    ec = SECURITY_ERR;
     return false;
 }
 
@@ -101,23 +96,25 @@ NavigatorContentUtils::~NavigatorContentUtils()
 {
 }
 
-void NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title, ExceptionCode& ec)
+ExceptionOr<void> NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title)
 {
     if (!navigator.frame())
-        return;
+        return { };
 
     URL baseURL = navigator.frame()->document()->baseURL();
 
-    if (!verifyCustomHandlerURL(baseURL, url, ec))
-        return;
+    if (!verifyCustomHandlerURL(baseURL, url))
+        return Exception { SYNTAX_ERR };
 
-    if (!verifyProtocolHandlerScheme(scheme, ec))
-        return;
+    if (!verifyProtocolHandlerScheme(scheme))
+        return Exception { SECURITY_ERR };
 
     NavigatorContentUtils::from(navigator.frame()->page())->client()->registerProtocolHandler(scheme, baseURL, URL(ParsedURLString, url), navigator.frame()->displayStringModifiedByEncoding(title));
+    return { };
 }
 
 #if ENABLE(CUSTOM_SCHEME_HANDLER)
+
 static String customHandlersStateString(const NavigatorContentUtilsClient::CustomHandlersState state)
 {
     static NeverDestroyed<String> newHandler(ASCIILiteral("new"));
@@ -137,39 +134,41 @@ static String customHandlersStateString(const NavigatorContentUtilsClient::Custo
     return String();
 }
 
-String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator& navigator, const String& scheme, const String& url, ExceptionCode& ec)
+ExceptionOr<String> NavigatorContentUtils::isProtocolHandlerRegistered(Navigator& navigator, const String& scheme, const String& url)
 {
     static NeverDestroyed<String> declined(ASCIILiteral("declined"));
 
     if (!navigator.frame())
-        return declined;
+        return String { declined };
 
     URL baseURL = navigator.frame()->document()->baseURL();
 
-    if (!verifyCustomHandlerURL(baseURL, url, ec))
-        return declined;
+    if (!verifyCustomHandlerURL(baseURL, url))
+        return Exception { SYNTAX_ERR };
 
-    if (!verifyProtocolHandlerScheme(scheme, ec))
-        return declined;
+    if (!verifyProtocolHandlerScheme(scheme))
+        return Exception { SECURITY_ERR };
 
     return customHandlersStateString(NavigatorContentUtils::from(navigator.frame()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, URL(ParsedURLString, url)));
 }
 
-void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, const String& scheme, const String& url, ExceptionCode& ec)
+ExceptionOr<void> NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, const String& scheme, const String& url)
 {
     if (!navigator.frame())
-        return;
+        return { };
 
     URL baseURL = navigator.frame()->document()->baseURL();
 
-    if (!verifyCustomHandlerURL(baseURL, url, ec))
-        return;
+    if (!verifyCustomHandlerURL(baseURL, url))
+        return Exception { SYNTAX_ERR };
 
-    if (!verifyProtocolHandlerScheme(scheme, ec))
-        return;
+    if (!verifyProtocolHandlerScheme(scheme))
+        return Exception { SECURITY_ERR };
 
     NavigatorContentUtils::from(navigator.frame()->page())->client()->unregisterProtocolHandler(scheme, baseURL, URL(ParsedURLString, url));
+    return { };
 }
+
 #endif
 
 const char* NavigatorContentUtils::supplementName()
@@ -185,4 +184,3 @@ void provideNavigatorContentUtilsTo(Page* page, std::unique_ptr<NavigatorContent
 } // namespace WebCore
 
 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS)
-
index 86b9564..bf26477 100644 (file)
  * DAMAGE.
  */
 
-#ifndef NavigatorContentUtils_h
-#define NavigatorContentUtils_h
+#pragma once
 
 #if ENABLE(NAVIGATOR_CONTENT_UTILS)
 
+#include "ExceptionOr.h"
 #include "NavigatorContentUtilsClient.h"
 #include "Supplementable.h"
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -51,11 +50,11 @@ public:
     static const char* supplementName();
     static NavigatorContentUtils* from(Page*);
 
-    static void registerProtocolHandler(Navigator&, const String& scheme, const String& url, const String& title, ExceptionCode&);
+    static ExceptionOr<void> registerProtocolHandler(Navigator&, const String& scheme, const String& url, const String& title);
 
 #if ENABLE(CUSTOM_SCHEME_HANDLER)
-    static String isProtocolHandlerRegistered(Navigator&, const String& scheme, const String& url, ExceptionCode&);
-    static void unregisterProtocolHandler(Navigator&, const String& scheme, const String& url, ExceptionCode&);
+    static ExceptionOr<String> isProtocolHandlerRegistered(Navigator&, const String& scheme, const String& url);
+    static ExceptionOr<void> unregisterProtocolHandler(Navigator&, const String& scheme, const String& url);
 #endif
 
 private:
@@ -67,5 +66,3 @@ private:
 } // namespace WebCore
 
 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS)
-
-#endif // NavigatorContentUtils_h
index 313a0ee..f3eca86 100644 (file)
@@ -20,8 +20,7 @@
 
 // http://www.w3.org/TR/html5/system-state-and-capabilities.html#custom-handlers
 partial interface Navigator {
-    [Conditional=NAVIGATOR_CONTENT_UTILS, MayThrowLegacyException] void registerProtocolHandler(DOMString scheme, DOMString url, DOMString title);
-    [Conditional=NAVIGATOR_CONTENT_UTILS&CUSTOM_SCHEME_HANDLER, MayThrowLegacyException] DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url);
-    [Conditional=NAVIGATOR_CONTENT_UTILS&CUSTOM_SCHEME_HANDLER, MayThrowLegacyException] void unregisterProtocolHandler(DOMString scheme, DOMString url);
+    [Conditional=NAVIGATOR_CONTENT_UTILS, MayThrowException] void registerProtocolHandler(DOMString scheme, DOMString url, DOMString title);
+    [Conditional=NAVIGATOR_CONTENT_UTILS&CUSTOM_SCHEME_HANDLER, MayThrowException] DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url);
+    [Conditional=NAVIGATOR_CONTENT_UTILS&CUSTOM_SCHEME_HANDLER, MayThrowException] void unregisterProtocolHandler(DOMString scheme, DOMString url);
 };
-
index f7ae349..df7e184 100644 (file)
@@ -359,7 +359,6 @@ static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState& state, Ref<Defe
         return;
     }
 
-    ExceptionCode ec = 0;
     auto constraintsDictionary = Dictionary(&state, state.uncheckedArgument(0));
 
     MediaTrackConstraintSetMap mandatoryAudioConstraints;
@@ -386,8 +385,7 @@ static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState& state, Ref<Defe
 
     auto audioConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryAudioConstraints), WTFMove(advancedAudioConstraints), areAudioConstraintsValid);
     auto videoConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryVideoConstraints), WTFMove(advancedVideoConstraints), areVideoConstraintsValid);
-    castThisValue<JSMediaDevices>(state).wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), WTFMove(promise), ec);
-    setDOMException(&state, ec);
+    propagateException(state, scope, castThisValue<JSMediaDevices>(state).wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), WTFMove(promise)));
 }
 
 JSValue JSMediaDevices::getUserMedia(ExecState& state)
index 0476e16..896919c 100644 (file)
@@ -4261,6 +4261,18 @@ sub WillConvertUndefinedToDefaultParameterValue
     return 0;
 }
 
+sub NeedsExplicitPropagateExceptionCall
+{
+    my ($function) = @_;
+
+    return 0 unless $function->signature->extendedAttributes->{MayThrowException};
+
+    return 1 if $function->signature->type && $function->signature->type->name eq "void";
+    return 1 if IsReturningPromise($function);
+
+    return 0;
+}
+
 sub GenerateParametersCheck
 {
     my ($outputArray, $function, $interface, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType) = @_;
@@ -4486,23 +4498,15 @@ sub GenerateParametersCheck
         $argumentIndex++;
     }
 
-    push @arguments, GenerateReturnParameters($function);
+    push(@arguments, "WTFMove(promise)") if IsReturningPromise($function);
+    push(@arguments, "ec") if $function->signature->extendedAttributes->{MayThrowLegacyException};
+
     my $functionString = "$functionName(" . join(", ", @arguments) . ")";
-    $functionString = "propagateException(*state, throwScope, $functionString)" if $function->signature->type && $function->signature->type->name eq "void" && $function->signature->extendedAttributes->{MayThrowException};
+    $functionString = "propagateException(*state, throwScope, $functionString)" if NeedsExplicitPropagateExceptionCall($function);
 
     return ($functionString, scalar @arguments);
 }
 
-sub GenerateReturnParameters
-{
-    my $function = shift;
-
-    my @arguments;
-    push(@arguments, "WTFMove(promise)") if IsReturningPromise($function);
-    push(@arguments, "ec") if $function->signature->extendedAttributes->{MayThrowLegacyException};
-    return @arguments;
-}
-
 sub GenerateDictionaryHeader
 {
     my ($object, $dictionary, $className, $enumerations) = @_;
index 3434529..ac83cb4 100644 (file)
@@ -63,11 +63,10 @@ void CharacterData::setData(const String& data)
     document().textRemoved(this, 0, oldLength);
 }
 
-String CharacterData::substringData(unsigned offset, unsigned count, ExceptionCode& ec)
+ExceptionOr<String> CharacterData::substringData(unsigned offset, unsigned count)
 {
-    checkCharDataOperation(offset, ec);
-    if (ec)
-        return String();
+    if (offset > length())
+        return Exception { INDEX_SIZE_ERR };
 
     return m_data.substring(offset, count);
 }
@@ -118,11 +117,10 @@ void CharacterData::appendData(const String& data)
     // FIXME: Should we call textInserted here?
 }
 
-void CharacterData::insertData(unsigned offset, const String& data, ExceptionCode& ec)
+ExceptionOr<void> CharacterData::insertData(unsigned offset, const String& data)
 {
-    checkCharDataOperation(offset, ec);
-    if (ec)
-        return;
+    if (offset > length())
+        return Exception { INDEX_SIZE_ERR };
 
     String newStr = m_data;
     newStr.insert(data, offset);
@@ -130,13 +128,14 @@ void CharacterData::insertData(unsigned offset, const String& data, ExceptionCod
     setDataAndUpdate(newStr, offset, 0, data.length());
 
     document().textInserted(this, offset, data.length());
+
+    return { };
 }
 
-void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& ec)
+ExceptionOr<void> CharacterData::deleteData(unsigned offset, unsigned count)
 {
-    checkCharDataOperation(offset, ec);
-    if (ec)
-        return;
+    if (offset > length())
+        return Exception { INDEX_SIZE_ERR };
 
     count = std::min(count, length() - offset);
 
@@ -146,13 +145,14 @@ void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& e
     setDataAndUpdate(newStr, offset, count, 0);
 
     document().textRemoved(this, offset, count);
+
+    return { };
 }
 
-void CharacterData::replaceData(unsigned offset, unsigned count, const String& data, ExceptionCode& ec)
+ExceptionOr<void> CharacterData::replaceData(unsigned offset, unsigned count, const String& data)
 {
-    checkCharDataOperation(offset, ec);
-    if (ec)
-        return;
+    if (offset > length())
+        return Exception { INDEX_SIZE_ERR };
 
     count = std::min(count, length() - offset);
 
@@ -165,6 +165,8 @@ void CharacterData::replaceData(unsigned offset, unsigned count, const String& d
     // update the markers for spell checking and grammar checking
     document().textRemoved(this, offset, count);
     document().textInserted(this, offset, data.length());
+
+    return { };
 }
 
 String CharacterData::nodeValue() const
@@ -232,18 +234,6 @@ void CharacterData::dispatchModifiedEvent(const String& oldData)
     InspectorInstrumentation::characterDataModified(document(), *this);
 }
 
-void CharacterData::checkCharDataOperation(unsigned offset, ExceptionCode& ec)
-{
-    ec = 0;
-
-    // INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit
-    // units in data.
-    if (offset > length()) {
-        ec = INDEX_SIZE_ERR;
-        return;
-    }
-}
-
 int CharacterData::maxCharacterOffset() const
 {
     return static_cast<int>(length());
index 7e70877..c0b2147 100644 (file)
@@ -23,7 +23,6 @@
 #pragma once
 
 #include "ContainerNode.h"
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -34,11 +33,11 @@ public:
 
     WEBCORE_EXPORT void setData(const String&);
     unsigned length() const { return m_data.length(); }
-    WEBCORE_EXPORT String substringData(unsigned offset, unsigned count, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<String> substringData(unsigned offset, unsigned count);
     WEBCORE_EXPORT void appendData(const String&);
-    WEBCORE_EXPORT void insertData(unsigned offset, const String&, ExceptionCode&);
-    WEBCORE_EXPORT void deleteData(unsigned offset, unsigned count, ExceptionCode&);
-    WEBCORE_EXPORT void replaceData(unsigned offset, unsigned count, const String&, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<void> insertData(unsigned offset, const String&);
+    WEBCORE_EXPORT ExceptionOr<void> deleteData(unsigned offset, unsigned count);
+    WEBCORE_EXPORT ExceptionOr<void> replaceData(unsigned offset, unsigned count, const String&);
 
     bool containsOnlyWhitespace() const;
 
@@ -68,7 +67,6 @@ private:
     int maxCharacterOffset() const final;
     bool offsetInCharacters() const final;
     void setDataAndUpdate(const String&, unsigned offsetOfReplacedData, unsigned oldLength, unsigned newLength);
-    void checkCharDataOperation(unsigned offset, ExceptionCode&);
     void notifyParentAfterChange(ContainerNode::ChildChangeSource);
 
     String m_data;
index 48142a0..366081b 100644 (file)
@@ -21,12 +21,12 @@ interface CharacterData : Node {
     [CEReactions, TreatNullAs=EmptyString] attribute DOMString data;
     readonly attribute unsigned long length;
 
-    [MayThrowLegacyException] DOMString? substringData(unsigned long offset, unsigned long length);
+    [MayThrowException] DOMString? substringData(unsigned long offset, unsigned long length);
 
     [CEReactions] void appendData(DOMString data);
-    [CEReactions, MayThrowLegacyException] void insertData(unsigned long offset, DOMString data);
-    [CEReactions, MayThrowLegacyException] void deleteData(unsigned long offset, unsigned long length);
-    [CEReactions, MayThrowLegacyException] void replaceData(unsigned long offset, unsigned long length, DOMString data);
+    [CEReactions, MayThrowException] void insertData(unsigned long offset, DOMString data);
+    [CEReactions, MayThrowException] void deleteData(unsigned long offset, unsigned long length);
+    [CEReactions, MayThrowException] void replaceData(unsigned long offset, unsigned long length, DOMString data);
 };
 
 CharacterData implements ChildNode;
index 0a0cff5..172a9b3 100644 (file)
@@ -28,8 +28,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef DataTransferItemList_h
-#define DataTransferItemList_h
+#pragma once
 
 #if ENABLE(DATA_TRANSFER_ITEMS)
 
@@ -41,22 +40,19 @@ namespace WebCore {
 
 class File;
 
-typedef int ExceptionCode;
-
+// FIXME: Unclear why this need to be an abstract base class.
 class DataTransferItemList : public RefCounted<DataTransferItemList> {
 public:
     virtual ~DataTransferItemList() { }
 
-    virtual size_t length() const = 0;
-    virtual PassRefPtr<DataTransferItem> item(unsigned long index) = 0;
-    virtual void deleteItem(unsigned long index, ExceptionCode&) = 0;
+    virtual unsigned length() const = 0;
+    virtual DataTransferItem* item(unsigned index) = 0;
+    virtual ExceptionOr<void> deleteItem(unsigned index) = 0;
     virtual void clear() = 0;
-    virtual void add(const String& data, const String& type, ExceptionCode&) = 0;
-    virtual void add(PassRefPtr<File>) = 0;
+    virtual ExceptionOr<void> add(const String& data, const String& type) = 0;
+    virtual void add(RefPtr<File>&&) = 0;
 };
 
 } // namespace WebCore
 
 #endif // ENABLE(DATA_TRANSFER_ITEMS)
-
-#endif // DataTransferItemList_h
index dd549e6..bdf2a87 100644 (file)
@@ -40,7 +40,5 @@
     void clear();
     void add(File? file);
 
-    // FIXME: Using "undefined" as default parameter value is wrong.
-    [MayThrowLegacyException] void add(optional DOMString data = "undefined", optional DOMString type = "undefined");
+    [MayThrowException] void add(optional DOMString data = "undefined", optional DOMString type = "undefined");
 };
-
index ca47a33..9a6589a 100644 (file)
@@ -31,7 +31,7 @@
     GenerateIsReachable=Impl,
     JSCustomMarkFunction,
 ] interface MessagePort : EventTarget {
-    [Custom, MayThrowLegacyException] void postMessage(any message, optional Array messagePorts);
+    [Custom, MayThrowException] void postMessage(any message, optional Array messagePorts);
 
     void start();
     void close();
index 75b8798..f17001f 100644 (file)
@@ -72,7 +72,7 @@ bool MutationObserver::validateOptions(MutationObserverOptions options)
         && ((options & CharacterData) || !(options & CharacterDataOldValue));
 }
 
-void MutationObserver::observe(Node& node, const Init& init, ExceptionCode& ec)
+ExceptionOr<void> MutationObserver::observe(Node& node, const Init& init)
 {
     MutationObserverOptions options = 0;
 
@@ -98,12 +98,12 @@ void MutationObserver::observe(Node& node, const Init& init, ExceptionCode& ec)
     if (init.characterData ? init.characterData.value() : (options & CharacterDataOldValue))
         options |= CharacterData;
 
-    if (!validateOptions(options)) {
-        ec = TypeError;
-        return;
-    }
+    if (!validateOptions(options))
+        return Exception { TypeError };
 
     node.registerMutationObserver(this, options, attributeFilter);
+
+    return { };
 }
 
 Vector<Ref<MutationRecord>> MutationObserver::takeRecords()
index 2bc7dd5..7244b9c 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef MutationObserver_h
-#define MutationObserver_h
+#pragma once
 
+#include "ExceptionOr.h"
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
-#include <wtf/Optional.h>
-#include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -45,10 +43,8 @@ class MutationObserverRegistration;
 class MutationRecord;
 class Node;
 
-typedef int ExceptionCode;
-
-typedef unsigned char MutationObserverOptions;
-typedef unsigned char MutationRecordDeliveryOptions;
+using MutationObserverOptions = unsigned char;
+using MutationRecordDeliveryOptions = unsigned char;
 
 class MutationObserver : public RefCounted<MutationObserver> {
     friend class MutationObserverMicrotask;
@@ -85,7 +81,7 @@ public:
         Optional<Vector<String>> attributeFilter;
     };
 
-    void observe(Node&, const Init&, ExceptionCode&);
+    ExceptionOr<void> observe(Node&, const Init&);
     Vector<Ref<MutationRecord>> takeRecords();
     void disconnect();
 
@@ -113,5 +109,3 @@ private:
 };
 
 }
-
-#endif // MutationObserver_h
index 99c4b9b..f7a2c0f 100644 (file)
@@ -33,7 +33,7 @@
     CustomIsReachable,
     ImplementationLacksVTable,
 ] interface MutationObserver {
-    [MayThrowLegacyException] void observe(Node target, optional MutationObserverInit options);
+    [MayThrowException] void observe(Node target, optional MutationObserverInit options);
     sequence<MutationRecord> takeRecords();
     void disconnect();
 };
index b0135cc..df795a2 100644 (file)
@@ -652,10 +652,16 @@ RefPtr<DocumentFragment> Range::processContents(ActionType action, ExceptionCode
 
 static inline void deleteCharacterData(CharacterData& data, unsigned startOffset, unsigned endOffset, ExceptionCode& ec)
 {
-    if (data.length() - endOffset)
-        data.deleteData(endOffset, data.length() - endOffset, ec);
-    if (startOffset)
-        data.deleteData(0, startOffset, ec);
+    if (data.length() - endOffset) {
+        auto result = data.deleteData(endOffset, data.length() - endOffset);
+        if (result.hasException())
+            ec = result.releaseException().code();
+    }
+    if (startOffset) {
+        auto result = data.deleteData(0, startOffset);
+        if (result.hasException())
+            ec = result.releaseException().code();
+    }
 }
 
 RefPtr<Node> Range::processContentsBetweenOffsets(ActionType action, PassRefPtr<DocumentFragment> fragment, Node* container, unsigned startOffset, unsigned endOffset, ExceptionCode& ec)
@@ -680,8 +686,11 @@ RefPtr<Node> Range::processContentsBetweenOffsets(ActionType action, PassRefPtr<
             } else
                 result = WTFMove(characters);
         }
-        if (action == Extract || action == Delete)
-            downcast<CharacterData>(*container).deleteData(startOffset, endOffset - startOffset, ec);
+        if (action == Extract || action == Delete) {
+            auto result = downcast<CharacterData>(*container).deleteData(startOffset, endOffset - startOffset);
+            if (result.hasException())
+                ec = result.releaseException().code();
+        }
         break;
     case Node::PROCESSING_INSTRUCTION_NODE:
         endOffset = std::min(endOffset, static_cast<ProcessingInstruction*>(container)->data().length());
@@ -845,9 +854,12 @@ void Range::insertNode(Ref<Node>&& node, ExceptionCode& ec)
 
     EventQueueScope scope;
     if (startIsText) {
-        referenceNode = downcast<Text>(startContainer()).splitText(startOffset(), ec);
-        if (ec)
+        auto result = downcast<Text>(startContainer()).splitText(startOffset());
+        if (result.hasException()) {
+            ec = result.releaseException().code();
             return;
+        }
+        referenceNode = result.releaseReturnValue();
     }
 
     if (referenceNode == node.ptr())
index 399a787..5a096f4 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "CSSStyleSheet.h"
 #include "ElementTraversal.h"
+#include "ExceptionCode.h"
 #include "RenderElement.h"
 #include "RuntimeEnabledFeatures.h"
 #include "SlotAssignment.h"
@@ -106,21 +107,14 @@ String ShadowRoot::innerHTML() const
     return createMarkup(*this, ChildrenOnly);
 }
 
-void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
+ExceptionOr<void> ShadowRoot::setInnerHTML(const String& markup)
 {
-    if (isOrphan()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
+    if (isOrphan())
+        return Exception { INVALID_ACCESS_ERR };
     auto fragment = createFragmentForInnerOuterHTML(*host(), markup, AllowScriptingContent);
-    if (fragment.hasException()) {
-        ec = fragment.releaseException().code();
-        return;
-    }
-    auto result = replaceChildrenWithFragment(*this, fragment.releaseReturnValue());
-    if (result.hasException())
-        ec = result.releaseException().code();
+    if (fragment.hasException())
+        return fragment.releaseException();
+    return replaceChildrenWithFragment(*this, fragment.releaseReturnValue());
 }
 
 bool ShadowRoot::childTypeAllowed(NodeType type) const
index ae27f73..d4e5e54 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ShadowRoot_h
-#define ShadowRoot_h
+#pragma once
 
-#include "ContainerNode.h"
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "Element.h"
-#include "ExceptionCode.h"
 #include "ShadowRootMode.h"
-#include "TreeScope.h"
 
 namespace WebCore {
 
@@ -65,7 +61,7 @@ public:
     void setHost(Element* host) { m_host = host; }
 
     String innerHTML() const;
-    void setInnerHTML(const String&, ExceptionCode&);
+    ExceptionOr<void> setInnerHTML(const String&);
 
     Element* activeElement() const;
 
@@ -142,5 +138,3 @@ inline bool hasShadowRootParent(const Node& node)
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ShadowRoot)
     static bool isType(const WebCore::Node& node) { return node.isShadowRoot(); }
 SPECIALIZE_TYPE_TRAITS_END()
-
-#endif
index a23ebd0..a6d4a77 100644 (file)
     EnabledAtRuntime=ShadowDOM,
     JSGenerateToJSObject
 ] interface ShadowRoot : DocumentFragment {
-    readonly attribute ShadowRootMode   mode;
-    readonly attribute Element          host;
+    readonly attribute ShadowRootMode mode;
+    readonly attribute Element host;
 
-    [CEReactions, SetterMayThrowLegacyException, TreatNullAs=EmptyString] attribute DOMString innerHTML;
+    [CEReactions, SetterMayThrowException, TreatNullAs=EmptyString] attribute DOMString innerHTML;
 };
 
 ShadowRoot implements DocumentOrShadowRoot;
index 367cfe8..0e4c97a 100644 (file)
@@ -56,33 +56,29 @@ Text::~Text()
     ASSERT(!renderer());
 }
 
-RefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec)
+ExceptionOr<Ref<Text>> Text::splitText(unsigned offset)
 {
-    ec = 0;
-
-    // INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than
-    // the number of 16-bit units in data.
-    if (offset > length()) {
-        ec = INDEX_SIZE_ERR;
-        return 0;
-    }
+    if (offset > length())
+        return Exception { INDEX_SIZE_ERR };
 
     EventQueueScope scope;
-    String oldStr = data();
-    Ref<Text> newText = virtualCreate(oldStr.substring(offset));
-    setDataWithoutUpdate(oldStr.substring(0, offset));
+    auto oldData = data();
+    auto newText = virtualCreate(oldData.substring(offset));
+    setDataWithoutUpdate(oldData.substring(0, offset));
 
-    dispatchModifiedEvent(oldStr);
+    dispatchModifiedEvent(oldData);
 
-    if (parentNode())
+    if (parentNode()) {
+        ExceptionCode ec = 0;
         parentNode()->insertBefore(newText, nextSibling(), ec);
-    if (ec)
-        return 0;
+        if (ec)
+            return Exception { ec };
+    }
 
     document().textNodeSplit(this);
 
     if (renderer())
-        renderer()->setTextWithOffset(data(), 0, oldStr.length());
+        renderer()->setTextWithOffset(data(), 0, oldData.length());
 
     return WTFMove(newText);
 }
@@ -122,7 +118,7 @@ String Text::wholeText() const
     return result.toString();
 }
 
-RefPtr<Text> Text::replaceWholeText(const String& newText, ExceptionCode&)
+RefPtr<Text> Text::replaceWholeText(const String& newText)
 {
     // Remove all adjacent text nodes, and replace the contents of this one.
 
index b11a43d..187b56f 100644 (file)
@@ -39,12 +39,12 @@ public:
 
     virtual ~Text();
 
-    WEBCORE_EXPORT RefPtr<Text> splitText(unsigned offset, ExceptionCode&);
+    WEBCORE_EXPORT ExceptionOr<Ref<Text>> splitText(unsigned offset);
 
     // DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772
 
     WEBCORE_EXPORT String wholeText() const;
-    WEBCORE_EXPORT RefPtr<Text> replaceWholeText(const String&, ExceptionCode&);
+    WEBCORE_EXPORT RefPtr<Text> replaceWholeText(const String&);
     
     RenderPtr<RenderText> createTextRenderer(const RenderStyle&);
     
index a4afd13..831224d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Apple Inc.
+ * Copyright (C) 2006 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */
+
 [
     Constructor(optional DOMString data),
     ConstructorCallWith=Document,
     CustomToJSObject,
 ] interface Text : CharacterData {
+    [MayThrowException] Text splitText(unsigned long offset);
 
-    // DOM Level 1
-
-    [MayThrowLegacyException] Text splitText(unsigned long offset);
-
-    // Introduced in DOM Level 3:
     readonly attribute DOMString wholeText;
 };
 
index df61ae3..e578b41 100644 (file)
@@ -175,13 +175,7 @@ static bool isNewLineAtPosition(const Position& position)
     int offset = position.offsetInContainerNode();
     if (!is<Text>(textNode) || offset < 0 || offset >= textNode->maxCharacterOffset())
         return false;
-
-    ExceptionCode ec = 0;
-    String textAtPosition = downcast<Text>(*textNode).substringData(offset, 1, ec);
-    if (ec)
-        return false;
-
-    return textAtPosition[0] == '\n';
+    return downcast<Text>(*textNode).data()[offset] == '\n';
 }
 
 const RenderStyle* ApplyBlockElementCommand::renderStyleOfEnclosingTextNode(const Position& position)
index cd3be85..6718484 100644 (file)
@@ -51,12 +51,11 @@ void DeleteFromTextNodeCommand::doApply()
     if (!isEditableNode(*m_node))
         return;
 
-    ExceptionCode ec = 0;
-    m_text = m_node->substringData(m_offset, m_count, ec);
-    if (ec)
+    auto result = m_node->substringData(m_offset, m_count);
+    if (result.hasException())
         return;
-
-    m_node->deleteData(m_offset, m_count, ec);
+    m_text = result.releaseReturnValue();
+    m_node->deleteData(m_offset, m_count);
 }
 
 void DeleteFromTextNodeCommand::doUnapply()
@@ -66,7 +65,7 @@ void DeleteFromTextNodeCommand::doUnapply()
     if (!m_node->hasEditableStyle())
         return;
 
-    m_node->insertData(m_offset, m_text, IGNORE_EXCEPTION);
+    m_node->insertData(m_offset, m_text);
 }
 
 #ifndef NDEBUG
index 79a81ce..9d2894e 100644 (file)
 #include "InsertIntoTextNodeCommand.h"
 
 #include "Document.h"
-#include "ExceptionCodePlaceholder.h"
 #include "Frame.h"
 #include "RenderText.h"
 #include "Settings.h"
 #include "Text.h"
+
 #if PLATFORM(IOS)
 #include "RenderText.h"
 #endif
@@ -40,7 +40,7 @@ namespace WebCore {
 
 InsertIntoTextNodeCommand::InsertIntoTextNodeCommand(RefPtr<Text>&& node, unsigned offset, const String& text, EditAction editingAction)
     : SimpleEditCommand(node->document(), editingAction)
-    , m_node(node)
+    , m_node(WTFMove(node))
     , m_offset(offset)
     , m_text(text)
 {
@@ -63,15 +63,19 @@ void InsertIntoTextNodeCommand::doApply()
             renderText->momentarilyRevealLastTypedCharacter(m_offset + m_text.length());
     }
 
-    m_node->insertData(m_offset, m_text, IGNORE_EXCEPTION);
+    m_node->insertData(m_offset, m_text);
 }
 
 #if PLATFORM(IOS)
+
+// FIXME: Why would reapply be iOS-specific?
 void InsertIntoTextNodeCommand::doReapply()
 {
-    ExceptionCode ec;
-    m_node->insertData(m_offset, m_text, ec);
+    // FIXME: Shouldn't this have a hasEditableStyle check?
+
+    m_node->insertData(m_offset, m_text);
 }
+
 #endif
     
 void InsertIntoTextNodeCommand::doUnapply()
@@ -79,14 +83,16 @@ void InsertIntoTextNodeCommand::doUnapply()
     if (!m_node->hasEditableStyle())
         return;
 
-    m_node->deleteData(m_offset, m_text.length(), IGNORE_EXCEPTION);
+    m_node->deleteData(m_offset, m_text.length());
 }
 
 #ifndef NDEBUG
+
 void InsertIntoTextNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
 {
     addNodeAndDescendants(m_node.get(), nodes);
 }
+
 #endif
 
 } // namespace WebCore
index a0b9c44..7419be9 100644 (file)
@@ -54,11 +54,14 @@ void SplitTextNodeCommand::doApply()
     if (!parent || !parent->hasEditableStyle())
         return;
 
-    String prefixText = m_text2->substringData(0, m_offset, IGNORE_EXCEPTION);
+    auto result = m_text2->substringData(0, m_offset);
+    if (result.hasException())
+        return;
+    auto prefixText = result.releaseReturnValue();
     if (prefixText.isEmpty())
         return;
 
-    m_text1 = Text::create(document(), prefixText);
+    m_text1 = Text::create(document(), WTFMove(prefixText));
     ASSERT(m_text1);
     document().markers().copyMarkers(m_text2.get(), 0, m_offset, m_text1.get(), 0);
 
@@ -74,7 +77,7 @@ void SplitTextNodeCommand::doUnapply()
 
     String prefixText = m_text1->data();
 
-    m_text2->insertData(0, prefixText, ASSERT_NO_EXCEPTION);
+    m_text2->insertData(0, prefixText);
 
     document().markers().copyMarkers(m_text1.get(), 0, prefixText.length(), m_text2.get(), 0);
     m_text1->remove();
@@ -98,15 +101,17 @@ void SplitTextNodeCommand::insertText1AndTrimText2()
     m_text2->parentNode()->insertBefore(*m_text1, m_text2.get(), ec);
     if (ec)
         return;
-    m_text2->deleteData(0, m_offset, ec);
+    m_text2->deleteData(0, m_offset);
 }
 
 #ifndef NDEBUG
+
 void SplitTextNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
 {
     addNodeAndDescendants(m_text1.get(), nodes);
     addNodeAndDescendants(m_text2.get(), nodes);
 }
+
 #endif
     
 } // namespace WebCore
index 8378f91..f37416d 100644 (file)
@@ -31,6 +31,7 @@
 #include "Document.h"
 #include "Event.h"
 #include "EventNames.h"
+#include "ExceptionCode.h"
 #include "Frame.h"
 #include "FrameSelection.h"
 #include "HTMLBRElement.h"
index e69ab1f..e9b85a9 100644 (file)
@@ -260,15 +260,15 @@ public:
         return redo(ec);
     }
 
-    bool undo(ExceptionCode& ec) override
+    bool undo(ExceptionCode&) override
     {
-        m_textNode->replaceWholeText(m_oldText, ec);
+        m_textNode->replaceWholeText(m_oldText);
         return true;
     }
 
-    bool redo(ExceptionCode& ec) override
+    bool redo(ExceptionCode&) override
     {
-        m_textNode->replaceWholeText(m_text, ec);
+        m_textNode->replaceWholeText(m_text);
         return true;
     }
 
index 8d399e1..9c1ff50 100644 (file)
@@ -1,3 +1,21 @@
+2016-10-29  Darin Adler  <darin@apple.com>
+
+        Convert more of DOM from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=164173
+
+        Reviewed by Ryosuke Niwa.
+
+        * DOM/DOMCharacterData.mm:
+        (-[DOMCharacterData substringData:length:]): Updated since this
+        now uses ExceptionOr.
+        (-[DOMCharacterData insertData:data:]): Ditto.
+        (-[DOMCharacterData deleteData:length:]): Ditto.
+        (-[DOMCharacterData replaceData:length:data:]): Ditto.
+        * DOM/DOMText.mm:
+        (-[DOMText splitText:]): Ditto.
+        (-[DOMText replaceWholeText:]): Removed unneeded exception code
+        handling from function that does not throw an exception.
+
 2016-10-28  Darin Adler  <darin@apple.com>
 
         Move all classes in the HTML directory from ExceptionCode to Exception
index 9319641..704aab9 100644 (file)
 - (NSString *)substringData:(unsigned)offset length:(unsigned)inLength
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    NSString *result = IMPL->substringData(offset, inLength, ec);
-    raiseOnDOMError(ec);
-    return result;
+    return raiseOnDOMError(IMPL->substringData(offset, inLength));
 }
 
 - (void)appendData:(NSString *)inData
 - (void)insertData:(unsigned)offset data:(NSString *)inData
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    IMPL->insertData(offset, inData, ec);
-    raiseOnDOMError(ec);
+    raiseOnDOMError(IMPL->insertData(offset, inData));
 }
 
 - (void)deleteData:(unsigned)offset length:(unsigned)inLength
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    IMPL->deleteData(offset, inLength, ec);
-    raiseOnDOMError(ec);
+    raiseOnDOMError(IMPL->deleteData(offset, inLength));
 }
 
 - (void)replaceData:(unsigned)offset length:(unsigned)inLength data:(NSString *)inData
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    IMPL->replaceData(offset, inLength, inData, ec);
-    raiseOnDOMError(ec);
+    raiseOnDOMError(IMPL->replaceData(offset, inLength, inData));
 }
 
 - (void)remove
index 50f85d2..404a8a4 100644 (file)
 - (DOMText *)splitText:(unsigned)offset
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMText *result = kit(WTF::getPtr(IMPL->splitText(offset, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(raiseOnDOMError(IMPL->splitText(offset)).ptr());
 }
 
 - (DOMText *)replaceWholeText:(NSString *)content
 {
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    DOMText *result = kit(WTF::getPtr(IMPL->replaceWholeText(content, ec)));
-    raiseOnDOMError(ec);
-    return result;
+    return kit(IMPL->replaceWholeText(content).get());
 }
 
 @end
index 43549d3..927be4c 100644 (file)
@@ -1,3 +1,21 @@
+2016-10-29  Darin Adler  <darin@apple.com>
+
+        Convert more of DOM from ExceptionCode to Exception
+        https://bugs.webkit.org/show_bug.cgi?id=164173
+
+        Reviewed by Ryosuke Niwa.
+
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMCharacterData.cpp:
+        (webkit_dom_character_data_substring_data): Updated since this
+        now uses ExceptionOr.
+        (webkit_dom_character_data_insert_data): Ditto.
+        (webkit_dom_character_data_delete_data): Ditto.
+        (webkit_dom_character_data_replace_data): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDeprecated.cpp:
+        (webkit_dom_text_replace_whole_text): Ditto.
+        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMText.cpp:
+        (webkit_dom_text_split_text): Ditto.
+
 2016-10-28  Darin Adler  <darin@apple.com>
 
         Move all classes in the HTML directory from ExceptionCode to Exception
index 9f3c8f8..378c345 100644 (file)
@@ -169,9 +169,10 @@ gchar* webkit_dom_character_data_substring_data(WebKitDOMCharacterData* self, gu
     g_return_val_if_fail(WEBKIT_DOM_IS_CHARACTER_DATA(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::CharacterData* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    gchar* result = convertToUTF8String(item->substringData(offset, length, ec));
-    return result;
+    auto result = item->substringData(offset, length);
+    if (result.hasException())
+        return nullptr;
+    return convertToUTF8String(result.releaseReturnValue());
 }
 
 void webkit_dom_character_data_append_data(WebKitDOMCharacterData* self, const gchar* data, GError** error)
@@ -193,10 +194,9 @@ void webkit_dom_character_data_insert_data(WebKitDOMCharacterData* self, gulong
     g_return_if_fail(!error || !*error);
     WebCore::CharacterData* item = WebKit::core(self);
     WTF::String convertedData = WTF::String::fromUTF8(data);
-    WebCore::ExceptionCode ec = 0;
-    item->insertData(offset, convertedData, ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->insertData(offset, convertedData);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     }
 }
@@ -207,10 +207,9 @@ void webkit_dom_character_data_delete_data(WebKitDOMCharacterData* self, gulong
     g_return_if_fail(WEBKIT_DOM_IS_CHARACTER_DATA(self));
     g_return_if_fail(!error || !*error);
     WebCore::CharacterData* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    item->deleteData(offset, length, ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->deleteData(offset, length);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     }
 }
@@ -223,10 +222,9 @@ void webkit_dom_character_data_replace_data(WebKitDOMCharacterData* self, gulong
     g_return_if_fail(!error || !*error);
     WebCore::CharacterData* item = WebKit::core(self);
     WTF::String convertedData = WTF::String::fromUTF8(data);
-    WebCore::ExceptionCode ec = 0;
-    item->replaceData(offset, length, convertedData, ec);
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->replaceData(offset, length, convertedData);
+    if (result.hasException()) {
+        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     }
 }
index 87756f4..b95b641 100644 (file)
@@ -155,13 +155,7 @@ WebKitDOMText* webkit_dom_text_replace_whole_text(WebKitDOMText* self, const gch
     g_return_val_if_fail(!error || !*error, nullptr);
 
     WebCore::JSMainThreadNullState state;
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Text> gobjectResult = WTF::getPtr(WebKit::core(self)->replaceWholeText(WTF::String::fromUTF8(content), ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
-        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
-    }
-    return WebKit::kit(gobjectResult.get());
+    return WebKit::kit(WebKit::core(self)->replaceWholeText(WTF::String::fromUTF8(content)).get());
 }
 
 gboolean webkit_dom_html_input_element_get_capture(WebKitDOMHTMLInputElement* self)
index bda6313..f9f2672 100644 (file)
@@ -140,13 +140,13 @@ WebKitDOMText* webkit_dom_text_split_text(WebKitDOMText* self, gulong offset, GE
     g_return_val_if_fail(WEBKIT_DOM_IS_TEXT(self), 0);
     g_return_val_if_fail(!error || !*error, 0);
     WebCore::Text* item = WebKit::core(self);
-    WebCore::ExceptionCode ec = 0;
-    RefPtr<WebCore::Text> gobjectResult = WTF::getPtr(item->splitText(offset, ec));
-    if (ec) {
-        WebCore::ExceptionCodeDescription ecdesc(ec);
+    auto result = item->splitText(offset);
+    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_text_get_whole_text(WebKitDOMText* self)