Bug 1166924 - part 1. r=baku, a=lizzard
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 27 May 2015 14:33:22 -0700
changeset 274926 aac09dd781703fa46548856c6470786f4c968d8e
parent 274925 6ef45122c20ea04036b03b38d456081025045207
child 274927 bde3ab570270dfec981123c01bb52a0d129a7fb4
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, lizzard
bugs1166924
milestone40.0a2
Bug 1166924 - part 1. r=baku, a=lizzard
dom/workers/XMLHttpRequest.cpp
--- a/dom/workers/XMLHttpRequest.cpp
+++ b/dom/workers/XMLHttpRequest.cpp
@@ -134,17 +134,17 @@ public:
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 
   bool
   Init();
 
   void
-  Teardown();
+  Teardown(bool aSendUnpin);
 
   bool
   AddRemoveEventListeners(bool aUpload, bool aAdd);
 
   void
   Reset()
   {
     AssertIsOnMainThread();
@@ -304,17 +304,19 @@ private:
   ~AsyncTeardownRunnable()
   { }
 
   NS_IMETHOD
   Run() override
   {
     AssertIsOnMainThread();
 
-    mProxy->Teardown();
+    // This means the XHR was GC'd, so we can't be pinned, and we don't need to
+    // try to unpin.
+    mProxy->Teardown(/* aSendUnpin */ false);
     mProxy = nullptr;
 
     return NS_OK;
   }
 };
 
 class LoadStartDetectionRunnable final : public nsRunnable,
                                          public nsIDOMEventListener
@@ -564,17 +566,17 @@ public:
 
 private:
   ~SyncTeardownRunnable()
   { }
 
   virtual nsresult
   MainThreadRun() override
   {
-    mProxy->Teardown();
+    mProxy->Teardown(/* aSendUnpin */ true);
     MOZ_ASSERT(!mProxy->mSyncLoopTarget);
     return NS_OK;
   }
 };
 
 class SetBackgroundRequestRunnable final :
   public WorkerThreadProxySyncRunnable
 {
@@ -937,33 +939,35 @@ Proxy::Init()
     mXHR = nullptr;
     return false;
   }
 
   return true;
 }
 
 void
-Proxy::Teardown()
+Proxy::Teardown(bool aSendUnpin)
 {
   AssertIsOnMainThread();
 
   if (mXHR) {
     Reset();
 
     // NB: We are intentionally dropping events coming from xhr.abort on the
     // floor.
     AddRemoveEventListeners(false, false);
     mXHR->Abort();
 
     if (mOutstandingSendCount) {
-      nsRefPtr<XHRUnpinRunnable> runnable =
-        new XHRUnpinRunnable(mWorkerPrivate, mXMLHttpRequestPrivate);
-      if (!runnable->Dispatch(nullptr)) {
-        NS_RUNTIMEABORT("We're going to hang at shutdown anyways.");
+      if (aSendUnpin) {
+        nsRefPtr<XHRUnpinRunnable> runnable =
+          new XHRUnpinRunnable(mWorkerPrivate, mXMLHttpRequestPrivate);
+        if (!runnable->Dispatch(nullptr)) {
+          NS_RUNTIMEABORT("We're going to hang at shutdown anyways.");
+        }
       }
 
       if (mSyncLoopTarget) {
         // We have an unclosed sync loop.  Fix that now.
         nsRefPtr<MainThreadStopSyncLoopRunnable> runnable =
           new MainThreadStopSyncLoopRunnable(mWorkerPrivate,
                                              mSyncLoopTarget.forget(),
                                              false);