Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 3 - WebSocket, r=asuth
☠☠ backed out by 73615fe67ab6 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 17 Apr 2018 20:51:03 +0200
changeset 414178 246fb3ee14cd82024354f82cac6c97f48139c3d1
parent 414177 629e499c0f754bc3cce971bd1a90310ce04114ab
child 414179 0d2088370d0c8bad625758d8c1cc49761293501b
push id33861
push userccoroiu@mozilla.com
push dateWed, 18 Apr 2018 10:50:38 +0000
treeherdermozilla-central@4af4ae0aee55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1450644
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 3 - WebSocket, r=asuth
dom/websocket/WebSocket.cpp
--- a/dom/websocket/WebSocket.cpp
+++ b/dom/websocket/WebSocket.cpp
@@ -567,17 +567,17 @@ WebSocketImpl::FailConnection(uint16_t a
 }
 
 namespace {
 
 class DisconnectInternalRunnable final : public WorkerMainThreadRunnable
 {
 public:
   explicit DisconnectInternalRunnable(WebSocketImpl* aImpl)
-    : WorkerMainThreadRunnable(aImpl->mWorkerRef->Private(),
+    : WorkerMainThreadRunnable(GetCurrentThreadWorkerPrivate(),
                                NS_LITERAL_CSTRING("WebSocket :: disconnect"))
     , mImpl(aImpl)
   { }
 
   bool MainThreadRun() override
   {
     mImpl->DisconnectInternal();
     return true;
@@ -615,17 +615,17 @@ WebSocketImpl::Disconnect()
   if (NS_IsMainThread()) {
     DisconnectInternal();
 
     // If we haven't called WebSocket::DisconnectFromOwner yet, update
     // web socket count here.
     if (mWebSocket->GetOwner()) {
       mWebSocket->GetOwner()->UpdateWebSocketCount(-1);
     }
-  } else if (mWorkerRef) {
+  } else {
     RefPtr<DisconnectInternalRunnable> runnable =
       new DisconnectInternalRunnable(this);
     ErrorResult rv;
     runnable->Dispatch(Killing, rv);
     // XXXbz this seems totally broken.  We should be propagating this out, but
     // where to, exactly?
     rv.SuppressException();
   }
@@ -1398,28 +1398,24 @@ WebSocket::ConstructorCommon(const Globa
     }
 
     aRv = runnable->ErrorCode();
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
 
     if (NS_WARN_IF(!webSocketImpl->RegisterWorkerRef(workerPrivate))) {
-      // The worker is shutting down. We cannot proceed but we return a
-      // 'connecting' object.
-      webSocketImpl->mWorkerShuttingDown = true;
-      webSocketImpl->Disconnect();
-      return webSocket.forget();
+      // The worker is shutting down.
+      aRv.Throw(NS_ERROR_FAILURE);
+      return nullptr;
     }
 
     RefPtr<ConnectRunnable> connectRunnable =
       new ConnectRunnable(workerPrivate, webSocketImpl);
-    // We can use Closing because we have a WorkerRef and that is enough to be
-    // sure that the worker is up and running.
-    connectRunnable->Dispatch(Closing, aRv);
+    connectRunnable->Dispatch(Canceling, aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
 
     connectionFailed = connectRunnable->ConnectionFailed();
   }
 
   // It can be that we have been already disconnected because the WebSocket is