Bug 1458971 - Make ClientSourceOpPromise hold the operation promise alive. r=baku, a=RyanVM
authorBen Kelly <ben@wanderview.com>
Wed, 09 May 2018 08:48:01 -0700
changeset 473257 1304c1c433d324a3bd38700c370d576a6123a4ae
parent 473256 19a17750a0999c56d9f40845aa78865686ea5b84
child 473258 d2b96fb1faa49334a156fa8e0df5ebed633dca9f
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, RyanVM
bugs1458971
milestone61.0
Bug 1458971 - Make ClientSourceOpPromise hold the operation promise alive. r=baku, a=RyanVM
dom/clients/manager/ClientSourceOpChild.cpp
--- a/dom/clients/manager/ClientSourceOpChild.cpp
+++ b/dom/clients/manager/ClientSourceOpChild.cpp
@@ -48,22 +48,27 @@ ClientSourceOpChild::DoSourceOp(Method a
   // The ClientSource methods are required to always return a promise.  If
   // they encounter an error they should just immediately resolve or reject
   // the promise as appropriate.
   MOZ_DIAGNOSTIC_ASSERT(promise);
 
   // Capture 'this' is safe here because we disconnect the promise
   // ActorDestroy() which ensures nethier lambda is called if the
   // actor is destroyed before the source operation completes.
+  //
+  // Also capture the promise to ensure it lives until we get a reaction
+  // or the actor starts shutting down and we disconnect our Thenable.
+  // If the ClientSource is doing something async it may throw away the
+  // promise on its side if the global is closed.
   promise->Then(target, __func__,
-    [this] (const mozilla::dom::ClientOpResult& aResult) {
+    [this, promise] (const mozilla::dom::ClientOpResult& aResult) {
       mPromiseRequestHolder.Complete();
       Unused << PClientSourceOpChild::Send__delete__(this, aResult);
     },
-    [this] (nsresult aRv) {
+    [this, promise] (nsresult aRv) {
       mPromiseRequestHolder.Complete();
       Unused << PClientSourceOpChild::Send__delete__(this, aRv);
     })->Track(mPromiseRequestHolder);
 }
 
 void
 ClientSourceOpChild::ActorDestroy(ActorDestroyReason aReason)
 {