Bug 1161742 - Hoist part of ResolveOrReject into ThenValueBase. r=jww
authorBobby Holley <bobbyholley@gmail.com>
Tue, 05 May 2015 16:24:02 -0700
changeset 273879 e3b6d0d1adeade47d5b22212e4f29092a83b920f
parent 273878 7636ab3485da8d7e275917228932877d217c8e94
child 273880 39a90ea44a699b0eb6bcf6d0d5f3df90ad565a7d
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)
reviewersjww
bugs1161742
milestone40.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 1161742 - Hoist part of ResolveOrReject into ThenValueBase. r=jww
dom/media/MediaPromise.h
--- a/dom/media/MediaPromise.h
+++ b/dom/media/MediaPromise.h
@@ -193,17 +193,28 @@ protected:
     virtual void Disconnect() override
     {
       MOZ_ASSERT(ThenValueBase::mResponseTarget->IsCurrentThreadIn());
       MOZ_DIAGNOSTIC_ASSERT(!Consumer::mComplete);
       Consumer::mDisconnected = true;
     }
 
   protected:
-    virtual void DoResolveOrReject(ResolveOrRejectValue& aValue) = 0;
+    virtual void DoResolveOrRejectInternal(ResolveOrRejectValue& aValue) = 0;
+
+    void DoResolveOrReject(ResolveOrRejectValue& aValue)
+    {
+      Consumer::mComplete = true;
+      if (Consumer::mDisconnected) {
+        PROMISE_LOG("ThenValue::DoResolveOrReject disconnected - bailing out [this=%p]", this);
+        return;
+      }
+
+      DoResolveOrRejectInternal(aValue);
+    }
 
     nsRefPtr<AbstractThread> mResponseTarget; // May be released on any thread.
     const char* mCallSite;
   };
 
   /*
    * We create two overloads for invoking Resolve/Reject Methods so as to
    * make the resolve/reject value argument "optional".
@@ -248,25 +259,18 @@ protected:
 
     // If a Consumer has been disconnected, we don't guarantee that the
     // resolve/reject runnable will be dispatched. Null out our refcounted
     // this-value now so that it's released predictably on the dispatch thread.
     mThisVal = nullptr;
   }
 
   protected:
-    virtual void DoResolveOrReject(ResolveOrRejectValue& aValue) override
+    virtual void DoResolveOrRejectInternal(ResolveOrRejectValue& aValue) override
     {
-      Consumer::mComplete = true;
-      if (Consumer::mDisconnected) {
-        MOZ_ASSERT(!mThisVal);
-        PROMISE_LOG("ThenValue::DoResolveOrReject disconnected - bailing out [this=%p]", this);
-        return;
-      }
-
       if (aValue.IsResolve()) {
         InvokeCallbackMethod(mThisVal.get(), mResolveMethod, aValue.ResolveValue());
       } else {
         InvokeCallbackMethod(mThisVal.get(), mRejectMethod, aValue.RejectValue());
       }
 
       // Null out mThisVal after invoking the callback so that any references are
       // released predictably on the dispatch thread. Otherwise, it would be