WebRTC: Replace RTCPeerConnection custom constructor with a JS built-in constructor
authoradam.bergkvist@ericsson.com <adam.bergkvist@ericsson.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 18:12:46 +0000 (18:12 +0000)
committeradam.bergkvist@ericsson.com <adam.bergkvist@ericsson.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 18:12:46 +0000 (18:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158832

Reviewed by Eric Carlson and Youenn Fablet.

Use a JS built-in constructor instead of a custom constructor. This makes it easier to
initialize private fields for functions implemented as JS built-ins. The constructor
behavior is in need of updating, but that is left to a follow-up change [1].

[1] http://webkit.org/b/158936
No change in behavior.

* CMakeLists.txt:
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::create):
(WebCore::RTCPeerConnection::RTCPeerConnection):
(WebCore::RTCPeerConnection::~RTCPeerConnection):
(WebCore::RTCPeerConnection::initializeWith):
* Modules/mediastream/RTCPeerConnection.h:
* Modules/mediastream/RTCPeerConnection.idl:
* Modules/mediastream/RTCPeerConnection.js:
(initializeRTCPeerConnection):
Add JS built-in constructor function.
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSRTCPeerConnectionCustom.cpp: Removed.
(WebCore::constructJSRTCPeerConnection): Deleted.

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/Modules/mediastream/RTCPeerConnection.js
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSRTCPeerConnectionCustom.cpp [deleted file]

index ed2bcf8..56965f2 100644 (file)
@@ -1201,7 +1201,6 @@ set(WebCore_SOURCES
     bindings/js/JSPopStateEventCustom.cpp
     bindings/js/JSReadableStreamPrivateConstructors.cpp
     bindings/js/JSReadableStreamSourceCustom.cpp
-    bindings/js/JSRTCPeerConnectionCustom.cpp
     bindings/js/JSRTCStatsResponseCustom.cpp
     bindings/js/JSSQLResultSetRowListCustom.cpp
     bindings/js/JSSQLTransactionCustom.cpp
index 24422c7..f56a05c 100644 (file)
@@ -1,3 +1,32 @@
+2016-06-22  Adam Bergkvist  <adam.bergkvist@ericsson.com>
+
+        WebRTC: Replace RTCPeerConnection custom constructor with a JS built-in constructor
+        https://bugs.webkit.org/show_bug.cgi?id=158832
+
+        Reviewed by Eric Carlson and Youenn Fablet.
+
+        Use a JS built-in constructor instead of a custom constructor. This makes it easier to
+        initialize private fields for functions implemented as JS built-ins. The constructor
+        behavior is in need of updating, but that is left to a follow-up change [1].
+
+        [1] http://webkit.org/b/158936
+        No change in behavior.
+
+        * CMakeLists.txt:
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::create):
+        (WebCore::RTCPeerConnection::RTCPeerConnection):
+        (WebCore::RTCPeerConnection::~RTCPeerConnection):
+        (WebCore::RTCPeerConnection::initializeWith):
+        * Modules/mediastream/RTCPeerConnection.h:
+        * Modules/mediastream/RTCPeerConnection.idl:
+        * Modules/mediastream/RTCPeerConnection.js:
+        (initializeRTCPeerConnection):
+        Add JS built-in constructor function.
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSRTCPeerConnectionCustom.cpp: Removed.
+        (WebCore::constructJSRTCPeerConnection): Deleted.
+
 2016-06-22  Youenn Fablet  <youenn@apple.com>
 
         CrossOriginPreflightChecker should call DocumentThreadableLoader preflightFailure instead of didFailLoading
index 3c52971..62736c9 100644 (file)
@@ -59,46 +59,38 @@ namespace WebCore {
 using namespace PeerConnection;
 using namespace PeerConnectionStates;
 
-RefPtr<RTCPeerConnection> RTCPeerConnection::create(ScriptExecutionContext& context, const Dictionary& rtcConfiguration, ExceptionCode& ec)
+Ref<RTCPeerConnection> RTCPeerConnection::create(ScriptExecutionContext& context)
 {
-    RefPtr<RTCConfiguration> configuration = RTCConfiguration::create(rtcConfiguration, ec);
-    if (ec)
-        return nullptr;
-
-    RefPtr<RTCPeerConnection> peerConnection = adoptRef(new RTCPeerConnection(context, WTFMove(configuration), ec));
+    Ref<RTCPeerConnection> peerConnection = adoptRef(*new RTCPeerConnection(context));
     peerConnection->suspendIfNeeded();
-    if (ec)
-        return nullptr;
 
     return peerConnection;
 }
 
-RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext& context, RefPtr<RTCConfiguration>&& configuration, ExceptionCode& ec)
+RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext& context)
     : ActiveDOMObject(&context)
-    , m_signalingState(SignalingState::Stable)
-    , m_iceGatheringState(IceGatheringState::New)
-    , m_iceConnectionState(IceConnectionState::New)
-    , m_configuration(WTFMove(configuration))
+    , m_backend(PeerConnectionBackend::create(this))
+{
+}
+
+RTCPeerConnection::~RTCPeerConnection()
 {
-    Document& document = downcast<Document>(context);
+    stop();
+}
 
+void RTCPeerConnection::initializeWith(Document& document, const Dictionary& rtcConfiguration, ExceptionCode& ec)
+{
     if (!document.frame()) {
         ec = NOT_SUPPORTED_ERR;
         return;
     }
 
-    m_backend = PeerConnectionBackend::create(this);
     if (!m_backend) {
         ec = NOT_SUPPORTED_ERR;
         return;
     }
 
-    m_backend->setConfiguration(*m_configuration);
-}
-
-RTCPeerConnection::~RTCPeerConnection()
-{
-    stop();
+    setConfiguration(rtcConfiguration, ec);
 }
 
 RefPtr<RTCRtpSender> RTCPeerConnection::addTrack(Ref<MediaStreamTrack>&& track, const Vector<MediaStream*>& streams, ExceptionCode& ec)
index f85ec64..59e8180 100644 (file)
@@ -60,9 +60,11 @@ class RTCStatsCallback;
 
 class RTCPeerConnection final : public RefCounted<RTCPeerConnection>, public PeerConnectionBackendClient, public RTCRtpSenderClient, public EventTargetWithInlineData, public ActiveDOMObject {
 public:
-    static RefPtr<RTCPeerConnection> create(ScriptExecutionContext&, const Dictionary& rtcConfiguration, ExceptionCode&);
+    static Ref<RTCPeerConnection> create(ScriptExecutionContext&);
     ~RTCPeerConnection();
 
+    void initializeWith(Document&, const Dictionary&, ExceptionCode&);
+
     const Vector<RefPtr<RTCRtpSender>>& getSenders() const { return m_transceiverSet->getSenders(); }
     const Vector<RefPtr<RTCRtpReceiver>>& getReceivers() const { return m_transceiverSet->getReceivers(); }
     const Vector<RefPtr<RTCRtpTransceiver>>& getTransceivers() const override { return m_transceiverSet->list(); }
@@ -117,7 +119,7 @@ public:
     using RefCounted<RTCPeerConnection>::deref;
 
 private:
-    RTCPeerConnection(ScriptExecutionContext&, RefPtr<RTCConfiguration>&&, ExceptionCode&);
+    RTCPeerConnection(ScriptExecutionContext&);
 
     RefPtr<RTCRtpTransceiver> completeAddTransceiver(Ref<RTCRtpTransceiver>&&, const RtpTransceiverInit&);
 
@@ -147,9 +149,9 @@ private:
     // RTCRtpSenderClient
     void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, PeerConnection::VoidPromise&&) override;
 
-    PeerConnectionStates::SignalingState m_signalingState;
-    PeerConnectionStates::IceGatheringState m_iceGatheringState;
-    PeerConnectionStates::IceConnectionState m_iceConnectionState;
+    PeerConnectionStates::SignalingState m_signalingState { PeerConnectionStates::SignalingState::Stable };
+    PeerConnectionStates::IceGatheringState m_iceGatheringState { PeerConnectionStates::IceGatheringState::New };
+    PeerConnectionStates::IceConnectionState m_iceConnectionState { PeerConnectionStates::IceConnectionState::New };
 
     std::unique_ptr<RtpTransceiverSet> m_transceiverSet { std::unique_ptr<RtpTransceiverSet>(new RtpTransceiverSet()) };
 
index abbb1e6..40ac877 100644 (file)
     ActiveDOMObject,
     Conditional=WEB_RTC,
     ConstructorCallWith=ScriptExecutionContext,
-    ConstructorRaisesException,
-    CustomConstructor(Dictionary rtcConfiguration),
+    JSBuiltinConstructor,
     InterfaceName=webkitRTCPeerConnection,
 ] interface RTCPeerConnection : EventTarget {
+    // Private initializer
+    [PrivateIdentifier, CallWith=Document, RaisesException] void initializeWith(Dictionary parameters);
+
     // RTP Media API extensions
     sequence<RTCRtpSender> getSenders();
     sequence<RTCRtpReceiver> getReceivers();
index 9b788f6..91e7ecf 100644 (file)
 
 // @conditional=ENABLE(WEB_RTC)
 
+function initializeRTCPeerConnection(configuration)
+{
+    "use strict";
+
+    if (arguments.length < 1)
+        throw new @TypeError("Not enough arguments");
+
+    if (!@isObject(configuration))
+        throw new @TypeError("RTCPeerConnection argument must be a valid Dictionary");
+
+    // FIXME: Handle errors in a better way than catching and re-throwing (http://webkit.org/b/158936)
+    try {
+        this.@initializeWith(configuration);
+    } catch (e) {
+        const message = e.name === "TypeMismatchError" ? "Invalid RTCPeerConnection constructor arguments"
+            : "Error creating RTCPeerConnection";
+        throw new @TypeError(message);
+    }
+    return this;
+}
+
 function createOffer()
 {
     "use strict";
index 8ffd10d..cd644cd 100644 (file)
                07C59B6817F784BA000FBCBB /* MediaSourceSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07C59B6517F784BA000FBCBB /* MediaSourceSettings.cpp */; };
                07C59B6917F784BA000FBCBB /* MediaSourceSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C59B6617F784BA000FBCBB /* MediaSourceSettings.h */; };
                07C59B6E17F794F6000FBCBB /* JSMediaStreamTrackCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07C59B6D17F794F6000FBCBB /* JSMediaStreamTrackCustom.cpp */; };
-               07CA120E182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07CA120D182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp */; };
                07CE77D516712A6A00C55A47 /* InbandTextTrackPrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 07CE77D416712A6A00C55A47 /* InbandTextTrackPrivateClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                07D637401BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */; };
                07D637411BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm */; };
                07C59B6D17F794F6000FBCBB /* JSMediaStreamTrackCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaStreamTrackCustom.cpp; sourceTree = "<group>"; };
                07C8AD111D073D630087C5CE /* AVFoundationMIMETypeCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AVFoundationMIMETypeCache.mm; sourceTree = "<group>"; };
                07C8AD121D073D630087C5CE /* AVFoundationMIMETypeCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVFoundationMIMETypeCache.h; sourceTree = "<group>"; };
-               07CA120D182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRTCPeerConnectionCustom.cpp; sourceTree = "<group>"; };
                07CE77D416712A6A00C55A47 /* InbandTextTrackPrivateClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InbandTextTrackPrivateClient.h; sourceTree = "<group>"; };
                07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProviderAVFObjC.h; sourceTree = "<group>"; };
                07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAudioSourceProviderAVFObjC.mm; sourceTree = "<group>"; };
                                FDBD1DFB167FE27D0051A11E /* JSOscillatorNodeCustom.cpp */,
                                FD8AA63D169514A700D2EA68 /* JSPannerNodeCustom.cpp */,
                                A85F22081430377D007CC884 /* JSPopStateEventCustom.cpp */,
-                               07CA120D182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp */,
                                07DC5FD317D3EEE90099F890 /* JSRTCStatsResponseCustom.cpp */,
                                51DCE8010CAC9F1C00488358 /* JSSQLResultSetRowListCustom.cpp */,
                                1AD2316D0CD269E700C1F194 /* JSSQLTransactionCustom.cpp */,
                                07969DB717D14151007FF842 /* JSRTCIceCandidateEvent.cpp in Sources */,
                                073794EB19EE341E00E5A045 /* JSRTCIceServer.cpp in Sources */,
                                07969DB917D14151007FF842 /* JSRTCPeerConnection.cpp in Sources */,
-                               07CA120E182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp in Sources */,
                                5E2C43711BCF0D750001E2BC /* JSRTCRtpReceiver.cpp in Sources */,
                                5E2C43731BCF0D750001E2BC /* JSRTCRtpSender.cpp in Sources */,
                                07969DBB17D14151007FF842 /* JSRTCSessionDescription.cpp in Sources */,
diff --git a/Source/WebCore/bindings/js/JSRTCPeerConnectionCustom.cpp b/Source/WebCore/bindings/js/JSRTCPeerConnectionCustom.cpp
deleted file mode 100644 (file)
index 03d8dc4..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(WEB_RTC)
-
-#include "JSRTCPeerConnection.h"
-
-#include "ExceptionCode.h"
-#include "JSDOMBinding.h"
-
-using namespace JSC;
-
-namespace WebCore {
-
-EncodedJSValue JSC_HOST_CALL constructJSRTCPeerConnection(ExecState* exec)
-{
-    // Spec says that we must have at least one arument, the RTCConfiguration.
-    if (exec->argumentCount() < 1)
-        return throwVMError(exec, createNotEnoughArgumentsError(exec));
-
-    ExceptionCode ec = 0;
-    Dictionary rtcConfiguration(exec, exec->argument(0));
-    if (exec->hadException())
-        return JSValue::encode(jsUndefined());
-
-    if (!rtcConfiguration.isObject())
-        return throwVMError(exec, createTypeError(exec, "RTCPeerConnection argument must be a valid Dictionary"));
-
-    DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
-    ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext();
-    if (!scriptExecutionContext)
-        return throwVMError(exec, createReferenceError(exec, "RTCPeerConnection constructor associated document is unavailable"));
-
-    auto peerConnection = RTCPeerConnection::create(*scriptExecutionContext, rtcConfiguration, ec);
-    if (ec == TYPE_MISMATCH_ERR) {
-        setDOMException(exec, ec);
-        return throwVMError(exec, createTypeError(exec, "Invalid RTCPeerConnection constructor arguments"));
-    }
-
-    if (ec) {
-        setDOMException(exec, ec);
-        return throwVMError(exec, createTypeError(exec, "Error creating RTCPeerConnection"));
-    }
-
-    return JSValue::encode(CREATE_DOM_WRAPPER(jsConstructor->globalObject(), RTCPeerConnection, peerConnection.releaseNonNull()));
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(WEB_RTC)