Bug 1358697 - Don't capture the Promise raw pointer and make static analysis happy. r?billm draft
authorKan-Ru Chen <kanru@kanru.info>
Sat, 22 Apr 2017 10:38:52 +0800
changeset 567518 d285bc85660497cca15066651f126e1dd3a956d4
parent 566378 dd530a59750adcaa0d48fa4f69b0cdb52715852a
child 625676 b4ca8f56503ad3d44b343739399dd90d2225c349
push id55602
push userbmo:kchen@mozilla.com
push dateTue, 25 Apr 2017 05:29:44 +0000
reviewersbillm
bugs1358697
milestone55.0a1
Bug 1358697 - Don't capture the Promise raw pointer and make static analysis happy. r?billm MozReview-Commit-ID: 7lMVMcNBDHJ
ipc/glue/MessageChannel.cpp
ipc/glue/MessageChannel.h
ipc/ipdl/test/cxx/TestAsyncReturns.cpp
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -712,17 +712,17 @@ MessageChannel::Clear()
     }
 
     if (mWorkerLoop) {
         mWorkerLoop->RemoveDestructionObserver(this);
     }
 
     gUnresolvedPromises -= mPendingPromises.size();
     for (auto& pair : mPendingPromises) {
-        pair.second.mRejectFunction(__func__);
+        pair.second.mRejectFunction(pair.second.mPromise, __func__);
     }
     mPendingPromises.clear();
 
     mWorkerLoop = nullptr;
     delete mLink;
     mLink = nullptr;
 
     mOnChannelConnectedTask->Cancel();
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -93,17 +93,17 @@ class MessageChannel : HasResultCodes, M
     class CxxStackFrame;
     class InterruptFrame;
 
     typedef mozilla::Monitor Monitor;
 
     struct PromiseHolder
     {
         RefPtr<MozPromiseRefcountable> mPromise;
-        std::function<void(const char*)> mRejectFunction;
+        std::function<void(MozPromiseRefcountable*, const char*)> mRejectFunction;
     };
     static Atomic<size_t> gUnresolvedPromises;
     friend class PromiseReporter;
 
   public:
     static const int32_t kNoTimeout;
 
     typedef IPC::Message Message;
@@ -181,18 +181,20 @@ class MessageChannel : HasResultCodes, M
     bool Send(Message* aMsg, Promise* aPromise) {
         int32_t seqno = NextSeqno();
         aMsg->set_seqno(seqno);
         if (!Send(aMsg)) {
             return false;
         }
         PromiseHolder holder;
         holder.mPromise = aPromise;
-        holder.mRejectFunction = [aPromise](const char* aRejectSite) {
-            aPromise->Reject(PromiseRejectReason::ChannelClosed, aRejectSite);
+        holder.mRejectFunction = [](MozPromiseRefcountable* aRejectPromise,
+                                    const char* aRejectSite) {
+            static_cast<Promise*>(aRejectPromise)->Reject(
+                PromiseRejectReason::ChannelClosed, aRejectSite);
         };
         mPendingPromises.insert(std::make_pair(seqno, Move(holder)));
         gUnresolvedPromises++;
         return true;
     }
 
     void SendBuildID();
 
--- a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp
+++ b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp
@@ -1,12 +1,14 @@
 #include "TestAsyncReturns.h"
 
 #include "IPDLUnitTests.h"      // fail etc.
 
+#include "mozilla/Unused.h"
+
 namespace mozilla {
 namespace _ipdltest {
 
 static uint32_t sMagic1 = 0x105b59fb;
 static uint32_t sMagic2 = 0x09b6f5e3;
 
 //-----------------------------------------------------------------------------
 // parent
@@ -74,17 +76,17 @@ TestAsyncReturnsChild::~TestAsyncReturns
 {
   MOZ_COUNT_DTOR(TestAsyncReturnsChild);
 }
 
 mozilla::ipc::IPCResult
 TestAsyncReturnsChild::RecvNoReturn(RefPtr<NoReturnPromise>&& aPromise)
 {
   // Leak the promise intentionally
-  aPromise->AddRef();
+  Unused << do_AddRef(aPromise);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 TestAsyncReturnsChild::RecvPing(RefPtr<PingPromise>&& aPromise)
 {
   if (!AbstractThread::GetCurrent()) {
     fail("AbstractThread not initalized");