Bug 1358697 - Don't capture the Promise raw pointer and make static analysis happy. r?billm
MozReview-Commit-ID: 7lMVMcNBDHJ
--- 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");