Bug 1358697 - Don't capture the Promise raw pointer and make static analysis happy. r=billm
☠☠ backed out by 1b60cc98d34f ☠ ☠
authorKan-Ru Chen <kanru@kanru.info>
Sat, 22 Apr 2017 10:38:52 +0800
changeset 354710 2f0e513820c08f6d1df62f96e435e80de20e38cc
parent 354709 b4bacb062f2191f331facdfce08c5128000e076f
child 354711 4f48f5e12de62bde299f873693f1d19ecdf648eb
push id31711
push usercbook@mozilla.com
push dateTue, 25 Apr 2017 09:24:00 +0000
treeherdermozilla-central@a30dc237c3a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1358697
milestone55.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 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* aPromise,
+                                    const char* aRejectSite) {
+            static_cast<Promise*>(aPromise)->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");