Backed out changeset 29c306545aa5 (bug 1539528) for mochitest failure at /builds/worker/workspace/build/src/xpcom/threads/nsThreadManager.cpp:69. On a CLOSED TREE
authorDaniel Varga <dvarga@mozilla.com>
Fri, 29 Mar 2019 11:18:33 +0200
changeset 466725 bd16a067d3b83e0f855df857ce7037c44bb862d9
parent 466724 447f58b42b72d5f54f09d301ec1fe5ff03d3fd43
child 466726 09dab984c603ffc486e81d542a674babb4516fb4
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1539528
milestone68.0a1
backs out29c306545aa5c14a1f2bbe911770b39d09ab5938
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
Backed out changeset 29c306545aa5 (bug 1539528) for mochitest failure at /builds/worker/workspace/build/src/xpcom/threads/nsThreadManager.cpp:69. On a CLOSED TREE
dom/websocket/WebSocket.cpp
dom/websocket/WebSocket.h
--- a/dom/websocket/WebSocket.cpp
+++ b/dom/websocket/WebSocket.cpp
@@ -865,27 +865,25 @@ WebSocketImpl::GetInterface(const nsIID&
 
   return QueryInterface(aIID, aResult);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // WebSocket
 ////////////////////////////////////////////////////////////////////////////////
 
-WebSocket::WebSocket(nsIGlobalObject* aGlobal)
-    : DOMEventTargetHelper(aGlobal),
+WebSocket::WebSocket(nsPIDOMWindowInner* aOwnerWindow)
+    : DOMEventTargetHelper(aOwnerWindow),
       mIsMainThread(true),
       mKeepingAlive(false),
       mCheckMustKeepAlive(true),
       mOutgoingBufferedAmount(0),
       mBinaryType(dom::BinaryType::Blob),
       mMutex("WebSocket::mMutex"),
       mReadyState(CONNECTING) {
-  MOZ_ASSERT(aGlobal);
-
   mImpl = new WebSocketImpl(this);
   mIsMainThread = mImpl->mIsMainThread;
 }
 
 WebSocket::~WebSocket() {}
 
 JSObject* WebSocket::WrapObject(JSContext* cx,
                                 JS::Handle<JSObject*> aGivenProto) {
@@ -1177,22 +1175,17 @@ class AsyncOpenRunnable final : public W
 
 already_AddRefed<WebSocket> WebSocket::ConstructorCommon(
     const GlobalObject& aGlobal, const nsAString& aUrl,
     const Sequence<nsString>& aProtocols,
     nsITransportProvider* aTransportProvider,
     const nsACString& aNegotiatedExtensions, ErrorResult& aRv) {
   MOZ_ASSERT_IF(!aTransportProvider, aNegotiatedExtensions.IsEmpty());
   nsCOMPtr<nsIPrincipal> principal;
-
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
-  if (NS_WARN_IF(!global)) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
+  nsCOMPtr<nsPIDOMWindowInner> ownerWindow;
 
   if (NS_IsMainThread()) {
     nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal =
         do_QueryInterface(aGlobal.GetAsSupports());
     if (!scriptPrincipal) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
@@ -1204,16 +1197,22 @@ already_AddRefed<WebSocket> WebSocket::C
     }
 
     nsCOMPtr<nsIScriptGlobalObject> sgo =
         do_QueryInterface(aGlobal.GetAsSupports());
     if (!sgo) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
+
+    ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
+    if (!ownerWindow) {
+      aRv.Throw(NS_ERROR_FAILURE);
+      return nullptr;
+    }
   }
 
   nsTArray<nsString> protocolArray;
 
   for (uint32_t index = 0, len = aProtocols.Length(); index < len; ++index) {
     const nsString& protocolElement = aProtocols[index];
 
     if (protocolElement.IsEmpty()) {
@@ -1227,17 +1226,17 @@ already_AddRefed<WebSocket> WebSocket::C
     if (protocolElement.FindChar(',') != -1) /* interferes w/list */ {
       aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
       return nullptr;
     }
 
     protocolArray.AppendElement(protocolElement);
   }
 
-  RefPtr<WebSocket> webSocket = new WebSocket(global);
+  RefPtr<WebSocket> webSocket = new WebSocket(ownerWindow);
   RefPtr<WebSocketImpl> webSocketImpl = webSocket->mImpl;
 
   bool connectionFailed = true;
 
   if (NS_IsMainThread()) {
     // We're keeping track of all main thread web sockets to be able to
     // avoid throttling timeouts when we have active web sockets.
     webSocket->GetOwner()->UpdateWebSocketCount(1);
@@ -1345,17 +1344,16 @@ already_AddRefed<WebSocket> WebSocket::C
   aRv = webSocket->mImpl->mChannel->SetNotificationCallbacks(webSocket->mImpl);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   if (NS_IsMainThread()) {
     MOZ_ASSERT(principal);
 
-    nsCOMPtr<nsPIDOMWindowInner> ownerWindow = do_QueryInterface(global);
     nsPIDOMWindowOuter* outerWindow = ownerWindow->GetOuterWindow();
 
     uint64_t windowID = 0;
     nsCOMPtr<nsPIDOMWindowOuter> topWindow = outerWindow->GetScriptableTop();
     nsCOMPtr<nsPIDOMWindowInner> topInner;
     if (topWindow) {
       topInner = topWindow->GetCurrentInnerWindow();
     }
@@ -1797,18 +1795,27 @@ nsresult WebSocket::CreateAndDispatchSim
 }
 
 nsresult WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
                                                   bool aIsBinary) {
   MOZ_ASSERT(mImpl);
   AssertIsOnTargetThread();
 
   AutoJSAPI jsapi;
-  if (NS_WARN_IF(!jsapi.Init(GetOwnerGlobal()))) {
-    return NS_ERROR_FAILURE;
+
+  if (NS_IsMainThread()) {
+    if (NS_WARN_IF(!jsapi.Init(GetOwner()))) {
+      return NS_ERROR_FAILURE;
+    }
+  } else {
+    MOZ_ASSERT(!mIsMainThread);
+    MOZ_ASSERT(mImpl->mWorkerRef);
+    if (NS_WARN_IF(!jsapi.Init(mImpl->mWorkerRef->Private()->GlobalScope()))) {
+      return NS_ERROR_FAILURE;
+    }
   }
 
   JSContext* cx = jsapi.cx();
 
   nsresult rv = CheckInnerWindowCorrectness();
   if (NS_FAILED(rv)) {
     return NS_OK;
   }
@@ -1817,17 +1824,17 @@ nsresult WebSocket::CreateAndDispatchMes
 
   // Create appropriate JS object for message
   JS::Rooted<JS::Value> jsData(cx);
   if (aIsBinary) {
     if (mBinaryType == dom::BinaryType::Blob) {
       messageType = nsIWebSocketEventListener::TYPE_BLOB;
 
       RefPtr<Blob> blob =
-          Blob::CreateStringBlob(GetOwnerGlobal(), aData, EmptyString());
+          Blob::CreateStringBlob(GetOwner(), aData, EmptyString());
       MOZ_ASSERT(blob);
 
       if (!ToJSValue(cx, blob, &jsData)) {
         return NS_ERROR_FAILURE;
       }
 
     } else if (mBinaryType == dom::BinaryType::Arraybuffer) {
       messageType = nsIWebSocketEventListener::TYPE_ARRAYBUFFER;
--- a/dom/websocket/WebSocket.h
+++ b/dom/websocket/WebSocket.h
@@ -50,16 +50,18 @@ class WebSocket final : public DOMEventT
   virtual void EventListenerAdded(nsAtom* aType) override;
 
   using EventTarget::EventListenerRemoved;
   virtual void EventListenerRemoved(nsAtom* aType) override;
 
   virtual void DisconnectFromOwner() override;
 
   // nsWrapperCache
+  nsPIDOMWindowInner* GetParentObject() { return GetOwner(); }
+
   virtual JSObject* WrapObject(JSContext* cx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
   // DOMEventTargetHelper
   void BindToOwner(nsIGlobalObject* aNew) override;
 
  public:  // static helpers:
   // Determine if preferences allow WebSocket
@@ -131,17 +133,17 @@ class WebSocket final : public DOMEventT
 
   // webIDL: void send(DOMString|Blob|ArrayBufferView data);
   void Send(const nsAString& aData, ErrorResult& aRv);
   void Send(Blob& aData, ErrorResult& aRv);
   void Send(const ArrayBuffer& aData, ErrorResult& aRv);
   void Send(const ArrayBufferView& aData, ErrorResult& aRv);
 
  private:  // constructor && destructor
-  explicit WebSocket(nsIGlobalObject* aGlobal);
+  explicit WebSocket(nsPIDOMWindowInner* aOwnerWindow);
   virtual ~WebSocket();
 
   void SetReadyState(uint16_t aReadyState);
 
   // These methods actually do the dispatch for various events.
   nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);
   nsresult CreateAndDispatchMessageEvent(const nsACString& aData,
                                          bool aIsBinary);