Backed out 8 changesets (bug 1336510) for windows debug mn-e10s failures a=backout
authorWes Kocher <wkocher@mozilla.com>
Thu, 23 Feb 2017 16:07:41 -0800
changeset 373682 3fee518242f68ba6a1b2b107bd475645ecf24622
parent 373681 ea11b190dac4446444d68f0fdf0ae44a38aaa0bc
child 373683 49abbdfdd1ab01a71ee588a171102aefb85baf30
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1336510
milestone54.0a1
backs out419ada2f9e81fdabcd3423381990231bcfb61c0c
19239f566a9332087f637930f14ee7c2bed086e6
c8aeead6fe83a62d86c15decc9445a089ab2b717
422e63b872b5284a2f31cfaf36c1853a8f636a75
21869174dfd3e1548324f590245ea06d215a5d6a
57476b9f342d8872813e701261fad2907738c969
e842cdaaa7e5fb44c713917005b19feed9cf5b6e
bd943b368ff7bce820d381fde4991b9bfb2168ca
Backed out 8 changesets (bug 1336510) for windows debug mn-e10s failures a=backout Backed out changeset 419ada2f9e81 (bug 1336510) Backed out changeset 19239f566a93 (bug 1336510) Backed out changeset c8aeead6fe83 (bug 1336510) Backed out changeset 422e63b872b5 (bug 1336510) Backed out changeset 21869174dfd3 (bug 1336510) Backed out changeset 57476b9f342d (bug 1336510) Backed out changeset e842cdaaa7e5 (bug 1336510) Backed out changeset bd943b368ff7 (bug 1336510) MozReview-Commit-ID: 2z3Wa9QFkX4
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/MediaManager.cpp
dom/media/mediasink/DecodedStream.cpp
dom/media/ogg/OggDemuxer.cpp
dom/media/systemservices/CamerasChild.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
dom/presentation/PresentationConnection.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
ipc/mscom/MainThreadHandoff.cpp
ipc/mscom/WeakRef.cpp
netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp
netwerk/streamconv/converters/nsMultiMixedConv.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1808,24 +1808,23 @@ MediaDecoder::DumpDebugInfo()
     str += readerStr;
   }
 
   if (!GetStateMachine()) {
     DUMP_LOG("%s", str.get());
     return;
   }
 
-  RefPtr<MediaDecoder> self = this;
   GetStateMachine()->RequestDebugInfo()->Then(
     AbstractThread::MainThread(), __func__,
-    [this, self, str] (const nsACString& aString) {
+    [this, str] (const nsACString& aString) {
       DUMP_LOG("%s", str.get());
       DUMP_LOG("%s", aString.Data());
     },
-    [this, self, str] () {
+    [this, str] () {
       DUMP_LOG("%s", str.get());
     });
 }
 
 RefPtr<MediaDecoder::DebugInfoPromise>
 MediaDecoder::RequestDebugInfo()
 {
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2800,21 +2800,16 @@ MediaDecoderStateMachine::IsVideoDecodin
 }
 
 bool MediaDecoderStateMachine::IsPlaying() const
 {
   MOZ_ASSERT(OnTaskQueue());
   return mMediaSink->IsPlaying();
 }
 
-void MediaDecoderStateMachine::SetMediaNotSeekable()
-{
-  mMediaSeekable = false;
-}
-
 nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Dispatch initialization that needs to happen on that task queue.
   nsCOMPtr<nsIRunnable> r = NewRunnableMethod<RefPtr<MediaDecoder>>(
     this, &MediaDecoderStateMachine::InitializationTask, aDecoder);
   mTaskQueue->Dispatch(r.forget());
@@ -2822,17 +2817,19 @@ nsresult MediaDecoderStateMachine::Init(
   mAudioQueueListener = AudioQueue().PopEvent().Connect(
     mTaskQueue, this, &MediaDecoderStateMachine::OnAudioPopped);
   mVideoQueueListener = VideoQueue().PopEvent().Connect(
     mTaskQueue, this, &MediaDecoderStateMachine::OnVideoPopped);
 
   mMetadataManager.Connect(mReader->TimedMetadataEvent(), OwnerThread());
 
   mOnMediaNotSeekable = mReader->OnMediaNotSeekable().Connect(
-    OwnerThread(), this, &MediaDecoderStateMachine::SetMediaNotSeekable);
+    OwnerThread(), [this] () {
+      mMediaSeekable = false;
+    });
 
   mMediaSink = CreateMediaSink(mAudioCaptured);
 
   aDecoder->RequestCDMProxy()->Then(
     OwnerThread(), __func__, this,
     &MediaDecoderStateMachine::OnCDMProxyReady,
     &MediaDecoderStateMachine::OnCDMProxyNotReady)
   ->Track(mCDMProxyPromise);
@@ -3110,30 +3107,29 @@ MediaDecoderStateMachine::RequestAudioDa
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(IsAudioDecoding());
   MOZ_ASSERT(!IsRequestingAudioData());
   MOZ_ASSERT(!IsWaitingAudioData());
   SAMPLE_LOG("Queueing audio task - queued=%" PRIuSIZE ", decoder-queued=%" PRIuSIZE,
              AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames());
 
-  RefPtr<MediaDecoderStateMachine> self = this;
   mReader->RequestAudioData()->Then(
     OwnerThread(), __func__,
-    [this, self] (MediaData* aAudio) {
+    [this] (MediaData* aAudio) {
       MOZ_ASSERT(aAudio);
       mAudioDataRequest.Complete();
       // audio->GetEndTime() is not always mono-increasing in chained ogg.
       mDecodedAudioEndTime =
         std::max(aAudio->GetEndTime(), mDecodedAudioEndTime);
       SAMPLE_LOG("OnAudioDecoded [%" PRId64 ",%" PRId64 "]", aAudio->mTime,
                  aAudio->GetEndTime());
       mStateObj->HandleAudioDecoded(aAudio);
     },
-    [this, self] (const MediaResult& aError) {
+    [this] (const MediaResult& aError) {
       SAMPLE_LOG("OnAudioNotDecoded aError=%" PRIu32, static_cast<uint32_t>(aError.Code()));
       mAudioDataRequest.Complete();
       switch (aError.Code()) {
         case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
           mStateObj->HandleWaitingForAudio();
           break;
         case NS_ERROR_DOM_MEDIA_CANCELED:
           mStateObj->HandleAudioCanceled();
@@ -3157,30 +3153,29 @@ MediaDecoderStateMachine::RequestVideoDa
   MOZ_ASSERT(!IsWaitingVideoData());
   SAMPLE_LOG(
     "Queueing video task - queued=%" PRIuSIZE ", decoder-queued=%" PRIoSIZE
     ", skip=%i, time=%" PRId64,
     VideoQueue().GetSize(), mReader->SizeOfVideoQueueInFrames(),
     aSkipToNextKeyframe, aCurrentTime.ToMicroseconds());
 
   TimeStamp videoDecodeStartTime = TimeStamp::Now();
-  RefPtr<MediaDecoderStateMachine> self = this;
   mReader->RequestVideoData(aSkipToNextKeyframe, aCurrentTime)->Then(
     OwnerThread(), __func__,
-    [this, self, videoDecodeStartTime] (MediaData* aVideo) {
+    [this, videoDecodeStartTime] (MediaData* aVideo) {
       MOZ_ASSERT(aVideo);
       mVideoDataRequest.Complete();
       // Handle abnormal or negative timestamps.
       mDecodedVideoEndTime =
         std::max(mDecodedVideoEndTime, aVideo->GetEndTime());
       SAMPLE_LOG("OnVideoDecoded [%" PRId64 ",%" PRId64 "]", aVideo->mTime,
                  aVideo->GetEndTime());
       mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime);
     },
-    [this, self] (const MediaResult& aError) {
+    [this] (const MediaResult& aError) {
       SAMPLE_LOG("OnVideoNotDecoded aError=%" PRIu32 , static_cast<uint32_t>(aError.Code()));
       mVideoDataRequest.Complete();
       switch (aError.Code()) {
         case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
           mStateObj->HandleWaitingForVideo();
           break;
         case NS_ERROR_DOM_MEDIA_CANCELED:
           mStateObj->HandleVideoCanceled();
@@ -3194,40 +3189,39 @@ MediaDecoderStateMachine::RequestVideoDa
     })->Track(mVideoDataRequest);
 }
 
 void
 MediaDecoderStateMachine::WaitForData(MediaData::Type aType)
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(aType == MediaData::AUDIO_DATA || aType == MediaData::VIDEO_DATA);
-  RefPtr<MediaDecoderStateMachine> self = this;
   if (aType == MediaData::AUDIO_DATA) {
     mReader->WaitForData(MediaData::AUDIO_DATA)->Then(
       OwnerThread(), __func__,
-      [self] (MediaData::Type aType) {
-        self->mAudioWaitRequest.Complete();
+      [this] (MediaData::Type aType) {
+        mAudioWaitRequest.Complete();
         MOZ_ASSERT(aType == MediaData::AUDIO_DATA);
-        self->mStateObj->HandleAudioWaited(aType);
+        mStateObj->HandleAudioWaited(aType);
       },
-      [self] (const WaitForDataRejectValue& aRejection) {
-        self->mAudioWaitRequest.Complete();
-        self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA);
+      [this] (const WaitForDataRejectValue& aRejection) {
+        mAudioWaitRequest.Complete();
+        DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA);
       })->Track(mAudioWaitRequest);
   } else {
     mReader->WaitForData(MediaData::VIDEO_DATA)->Then(
       OwnerThread(), __func__,
-      [self] (MediaData::Type aType) {
-        self->mVideoWaitRequest.Complete();
+      [this] (MediaData::Type aType) {
+        mVideoWaitRequest.Complete();
         MOZ_ASSERT(aType == MediaData::VIDEO_DATA);
-        self->mStateObj->HandleVideoWaited(aType);
+        mStateObj->HandleVideoWaited(aType);
       },
-      [self] (const WaitForDataRejectValue& aRejection) {
-        self->mVideoWaitRequest.Complete();
-        self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA);
+      [this] (const WaitForDataRejectValue& aRejection) {
+        mVideoWaitRequest.Complete();
+        DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA);
       })->Track(mVideoWaitRequest);
   }
 }
 
 void
 MediaDecoderStateMachine::StartMediaSink()
 {
   MOZ_ASSERT(OnTaskQueue());
@@ -3578,20 +3572,19 @@ MediaDecoderStateMachine::ScheduleStateM
     return;
   }
 
   TimeStamp now = TimeStamp::Now();
   TimeStamp target = now + TimeDuration::FromMicroseconds(aMicroseconds);
 
   // It is OK to capture 'this' without causing UAF because the callback
   // always happens before shutdown.
-  RefPtr<MediaDecoderStateMachine> self = this;
-  mDelayedScheduler.Ensure(target, [self] () {
-    self->mDelayedScheduler.CompleteRequest();
-    self->RunStateMachine();
+  mDelayedScheduler.Ensure(target, [this] () {
+    mDelayedScheduler.CompleteRequest();
+    RunStateMachine();
   }, [] () {
     MOZ_DIAGNOSTIC_ASSERT(false);
   });
 }
 
 bool MediaDecoderStateMachine::OnTaskQueue() const
 {
   return OwnerThread()->IsCurrentThreadIn();
@@ -3798,19 +3791,18 @@ MediaDecoderStateMachine::GetDebugInfo()
          + mMediaSink->GetDebugInfo();
 }
 
 RefPtr<MediaDecoder::DebugInfoPromise>
 MediaDecoderStateMachine::RequestDebugInfo()
 {
   using PromiseType = MediaDecoder::DebugInfoPromise;
   RefPtr<PromiseType::Private> p = new PromiseType::Private(__func__);
-  RefPtr<MediaDecoderStateMachine> self = this;
-  OwnerThread()->Dispatch(NS_NewRunnableFunction([self, p] () {
-    p->Resolve(self->GetDebugInfo(), __func__);
+  OwnerThread()->Dispatch(NS_NewRunnableFunction([this, p] () {
+    p->Resolve(GetDebugInfo(), __func__);
   }), AbstractThread::AssertDispatchSuccess, AbstractThread::TailDispatch);
   return p.forget();
 }
 
 void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
                                                bool aFinishWhenEnded)
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -292,19 +292,16 @@ private:
 
   // True if shutdown process has begun.
   bool IsShutdown() const;
 
   // Returns true if we're currently playing. The decoder monitor must
   // be held.
   bool IsPlaying() const;
 
-  // Sets mMediaSeekable to false.
-  void SetMediaNotSeekable();
-
   // Resets all states related to decoding and aborts all pending requests
   // to the decoders.
   void ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
                                                TrackInfo::kVideoTrack));
 
 protected:
   virtual ~MediaDecoderStateMachine();
 
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2290,33 +2290,33 @@ if (privileged) {
       Preferences::GetBool("media.navigator.streams.fake");
 
   bool askPermission =
       (!privileged || Preferences::GetBool("media.navigator.permission.force")) &&
       (!fake || Preferences::GetBool("media.navigator.permission.fake"));
 
   RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowID, videoType,
                                                    audioType, fake);
-  RefPtr<MediaManager> self = this;
-  p->Then([self, onSuccess, onFailure, windowID, c, listener, askPermission,
+  p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission,
            prefs, isHTTPS, callID, principalInfo,
            isChrome](SourceSet*& aDevices) mutable {
 
     RefPtr<Refcountable<UniquePtr<SourceSet>>> devices(
          new Refcountable<UniquePtr<SourceSet>>(aDevices)); // grab result
 
-    // Ensure that our windowID is still good.
-    if (!nsGlobalWindow::GetInnerWindowWithId(windowID)) {
+    // Ensure that the captured 'this' pointer and our windowID are still good.
+    if (!MediaManager::Exists() ||
+        !nsGlobalWindow::GetInnerWindowWithId(windowID)) {
       return;
     }
 
     // Apply any constraints. This modifies the passed-in list.
-    RefPtr<PledgeChar> p2 = self->SelectSettings(c, isChrome, devices);
-
-    p2->Then([self, onSuccess, onFailure, windowID, c,
+    RefPtr<PledgeChar> p2 = SelectSettings(c, isChrome, devices);
+
+    p2->Then([this, onSuccess, onFailure, windowID, c,
               listener, askPermission, prefs, isHTTPS, callID, principalInfo,
               isChrome, devices](const char*& badConstraint) mutable {
 
       // Ensure that the captured 'this' pointer and our windowID are still good.
       auto* globalWindow = nsGlobalWindow::GetInnerWindowWithId(windowID);
       RefPtr<nsPIDOMWindowInner> window = globalWindow ? globalWindow->AsInner()
                                                        : nullptr;
       if (!MediaManager::Exists() || !window) {
@@ -2354,23 +2354,23 @@ if (privileged) {
       // Pass callbacks and MediaStreamListener along to GetUserMediaTask.
       RefPtr<GetUserMediaTask> task (new GetUserMediaTask(c, onSuccess.forget(),
                                                           onFailure.forget(),
                                                           windowID, listener,
                                                           prefs, principalInfo,
                                                           isChrome,
                                                           devices->release()));
       // Store the task w/callbacks.
-      self->mActiveCallbacks.Put(callID, task.forget());
+      mActiveCallbacks.Put(callID, task.forget());
 
       // Add a WindowID cross-reference so OnNavigation can tear things down
       nsTArray<nsString>* array;
-      if (!self->mCallIds.Get(windowID, &array)) {
+      if (!mCallIds.Get(windowID, &array)) {
         array = new nsTArray<nsString>();
-        self->mCallIds.Put(windowID, array);
+        mCallIds.Put(windowID, array);
       }
       array->AppendElement(callID);
 
       nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
       if (!askPermission) {
         obs->NotifyObservers(devicesCopy, "getUserMedia:privileged:allow",
                              callID.BeginReading());
       } else {
@@ -2997,19 +2997,17 @@ MediaManager::Shutdown()
   // Post ShutdownTask to execute on mMediaThread and pass in a lambda
   // callback to be executed back on this thread once it is done.
   //
   // The lambda callback "captures" the 'this' pointer for member access.
   // This is safe since this is guaranteed to be here since sSingleton isn't
   // cleared until the lambda function clears it.
 
   // note that this == sSingleton
-  MOZ_ASSERT(this == sSingleton);
-  RefPtr<MediaManager> that = this;
-
+  RefPtr<MediaManager> that(sSingleton);
   // Release the backend (and call Shutdown()) from within the MediaManager thread
   // Don't use MediaManager::PostTask() because we're sInShutdown=true here!
   RefPtr<ShutdownTask> shutdown = new ShutdownTask(this,
       media::NewRunnableFrom([this, that]() mutable {
     LOG(("MediaManager shutdown lambda running, releasing MediaManager singleton and thread"));
     if (mMediaThread) {
       mMediaThread->Stop();
     }
--- a/dom/media/mediasink/DecodedStream.cpp
+++ b/dom/media/mediasink/DecodedStream.cpp
@@ -65,20 +65,19 @@ public:
   void DoNotifyFinished()
   {
     MOZ_ASSERT(NS_IsMainThread());
     mFinishPromise.ResolveIfExists(true, __func__);
   }
 
   void Forget()
   {
-    RefPtr<DecodedStreamGraphListener> self = this;
-    mAbstractMainThread->Dispatch(NS_NewRunnableFunction([self] () {
+    mAbstractMainThread->Dispatch(NS_NewRunnableFunction([this] () {
       MOZ_ASSERT(NS_IsMainThread());
-      self->mFinishPromise.ResolveIfExists(true, __func__);
+      mFinishPromise.ResolveIfExists(true, __func__);
     }));
     MutexAutoLock lock(mMutex);
     mStream = nullptr;
   }
 
   MediaEventSource<int64_t>& OnOutput()
   {
     return mOnOutput;
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -123,23 +123,18 @@ OggDemuxer::~OggDemuxer()
 {
   MOZ_COUNT_DTOR(OggDemuxer);
   Reset(TrackInfo::kAudioTrack);
   Reset(TrackInfo::kVideoTrack);
   if (HasAudio() || HasVideo()) {
     // If we were able to initialize our decoders, report whether we encountered
     // a chained stream or not.
     bool isChained = mIsChained;
-    void* ptr = this;
-    nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([ptr, isChained]() -> void {
-      // We can't use OGG_DEBUG here because it implicitly refers to `this`,
-      // which we can't capture in this runnable.
-      MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug,
-              ("OggDemuxer(%p)::%s: Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d",
-               ptr, __func__, isChained));
+    nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([=]() -> void {
+      OGG_DEBUG("Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", isChained);
       Telemetry::Accumulate(Telemetry::HistogramID::MEDIA_OGG_LOADED_IS_CHAINED, isChained);
     });
     // Non-DocGroup version of AbstractThread::MainThread is fine for Telemetry.
     AbstractThread::MainThread()->Dispatch(task.forget());
   }
 }
 
 void
--- a/dom/media/systemservices/CamerasChild.cpp
+++ b/dom/media/systemservices/CamerasChild.cpp
@@ -280,30 +280,38 @@ CamerasChild::DispatchToParent(nsIRunnab
 int
 CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine,
                                    const char* deviceUniqueIdUTF8)
 {
   LOG((__PRETTY_FUNCTION__));
   LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8));
   nsCString unique_id(deviceUniqueIdUTF8);
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString>
-    (this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id);
+    media::NewRunnableFrom([this, aCapEngine, unique_id]() -> nsresult {
+      if (this->SendNumberOfCapabilities(aCapEngine, unique_id)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger);
   LOG(("Capture capability count: %d", dispatcher.ReturnValue()));
   return dispatcher.ReturnValue();
 }
 
 int
 CamerasChild::NumberOfCaptureDevices(CaptureEngine aCapEngine)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine>
-    (this, &CamerasChild::SendNumberOfCaptureDevices, aCapEngine);
+    media::NewRunnableFrom([this, aCapEngine]() -> nsresult {
+      if (this->SendNumberOfCaptureDevices(aCapEngine)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger);
   LOG(("Capture Devices: %d", dispatcher.ReturnValue()));
   return dispatcher.ReturnValue();
 }
 
 mozilla::ipc::IPCResult
 CamerasChild::RecvReplyNumberOfCaptureDevices(const int& numdev)
 {
@@ -316,34 +324,42 @@ CamerasChild::RecvReplyNumberOfCaptureDe
   return IPC_OK();
 }
 
 int
 CamerasChild::EnsureInitialized(CaptureEngine aCapEngine)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine>
-    (this, &CamerasChild::SendEnsureInitialized, aCapEngine);
+    media::NewRunnableFrom([this, aCapEngine]() -> nsresult {
+      if (this->SendEnsureInitialized(aCapEngine)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger);
   LOG(("Capture Devices: %d", dispatcher.ReturnValue()));
   return dispatcher.ReturnValue();
 }
 
 int
 CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine,
                                    const char* unique_idUTF8,
                                    const unsigned int capability_number,
                                    webrtc::VideoCaptureCapability& capability)
 {
   LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number));
   nsCString unique_id(unique_idUTF8);
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString, unsigned int>
-    (this, &CamerasChild::SendGetCaptureCapability, aCapEngine, unique_id, capability_number);
+    media::NewRunnableFrom([this, aCapEngine, unique_id, capability_number]() -> nsresult {
+      if (this->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   if (dispatcher.Success()) {
     capability = mReplyCapability;
   }
   return dispatcher.ReturnValue();
 }
 
 mozilla::ipc::IPCResult
@@ -369,18 +385,22 @@ CamerasChild::GetCaptureDevice(CaptureEn
                                unsigned int list_number, char* device_nameUTF8,
                                const unsigned int device_nameUTF8Length,
                                char* unique_idUTF8,
                                const unsigned int unique_idUTF8Length,
                                bool* scary)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, unsigned int>
-    (this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number);
+    media::NewRunnableFrom([this, aCapEngine, list_number]() -> nsresult {
+      if (this->SendGetCaptureDevice(aCapEngine, list_number)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   if (dispatcher.Success()) {
     base::strlcpy(device_nameUTF8, mReplyDeviceName.get(), device_nameUTF8Length);
     base::strlcpy(unique_idUTF8, mReplyDeviceID.get(), unique_idUTF8Length);
     if (scary) {
       *scary = mReplyScary;
     }
     LOG(("Got %s name %s id", device_nameUTF8, unique_idUTF8));
@@ -409,18 +429,22 @@ CamerasChild::AllocateCaptureDevice(Capt
                                     const char* unique_idUTF8,
                                     const unsigned int unique_idUTF8Length,
                                     int& aStreamId,
                                     const mozilla::ipc::PrincipalInfo& aPrincipalInfo)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCString unique_id(unique_idUTF8);
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString, const mozilla::ipc::PrincipalInfo&>
-    (this, &CamerasChild::SendAllocateCaptureDevice, aCapEngine, unique_id, aPrincipalInfo);
+    media::NewRunnableFrom([this, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult {
+      if (this->SendAllocateCaptureDevice(aCapEngine, unique_id, aPrincipalInfo)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   if (dispatcher.Success()) {
     LOG(("Capture Device allocated: %d", mReplyInteger));
     aStreamId = mReplyInteger;
   }
   return dispatcher.ReturnValue();
 }
 
@@ -438,18 +462,22 @@ CamerasChild::RecvReplyAllocateCaptureDe
 }
 
 int
 CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine,
                                    const int capture_id)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
-    (this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id);
+    media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult {
+      if (this->SendReleaseCaptureDevice(aCapEngine, capture_id)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   return dispatcher.ReturnValue();
 }
 
 void
 CamerasChild::AddCallback(const CaptureEngine aCapEngine, const int capture_id,
                           FrameRelay* render)
 {
@@ -485,29 +513,37 @@ CamerasChild::StartCapture(CaptureEngine
   VideoCaptureCapability capCap(webrtcCaps.width,
                            webrtcCaps.height,
                            webrtcCaps.maxFPS,
                            webrtcCaps.expectedCaptureDelay,
                            webrtcCaps.rawType,
                            webrtcCaps.codecType,
                            webrtcCaps.interlaced);
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, int, VideoCaptureCapability>
-    (this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap);
+    media::NewRunnableFrom([this, aCapEngine, capture_id, capCap]() -> nsresult {
+      if (this->SendStartCapture(aCapEngine, capture_id, capCap)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   return dispatcher.ReturnValue();
 }
 
 int
 CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
-    mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
-    (this, &CamerasChild::SendStopCapture, aCapEngine, capture_id);
+    media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult {
+      if (this->SendStopCapture(aCapEngine, capture_id)) {
+        return NS_OK;
+      }
+      return NS_ERROR_FAILURE;
+    });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   if (dispatcher.Success()) {
     RemoveCallback(aCapEngine, capture_id);
   }
   return dispatcher.ReturnValue();
 }
 
 void
@@ -558,20 +594,23 @@ CamerasChild::ShutdownParent()
   {
     MonitorAutoLock monitor(mReplyMonitor);
     mIPCIsAlive = false;
     monitor.NotifyAll();
   }
   if (CamerasSingleton::Thread()) {
     LOG(("Dispatching actor deletion"));
     // Delete the parent actor.
-    // CamerasChild (this) will remain alive and is only deleted by the
-    // IPC layer when SendAllDone returns.
-    nsCOMPtr<nsIRunnable> deleteRunnable =
-      mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone);
+    RefPtr<Runnable> deleteRunnable =
+      // CamerasChild (this) will remain alive and is only deleted by the
+      // IPC layer when SendAllDone returns.
+      media::NewRunnableFrom([this]() -> nsresult {
+        Unused << this->SendAllDone();
+        return NS_OK;
+      });
     CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL);
   } else {
     LOG(("ShutdownParent called without PBackground thread"));
   }
 }
 
 void
 CamerasChild::ShutdownChild()
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -311,20 +311,20 @@ void
 MediaEngineRemoteVideoSource::SetLastCapability(
     const webrtc::CaptureCapability& aCapability)
 {
   mLastCapability = mCapability;
 
   webrtc::CaptureCapability cap = aCapability;
   RefPtr<MediaEngineRemoteVideoSource> that = this;
 
-  NS_DispatchToMainThread(media::NewRunnableFrom([that, cap]() mutable {
-    that->mSettings.mWidth.Value() = cap.width;
-    that->mSettings.mHeight.Value() = cap.height;
-    that->mSettings.mFrameRate.Value() = cap.maxFPS;
+  NS_DispatchToMainThread(media::NewRunnableFrom([this, that, cap]() mutable {
+    mSettings.mWidth.Value() = cap.width;
+    mSettings.mHeight.Value() = cap.height;
+    mSettings.mFrameRate.Value() = cap.maxFPS;
     return NS_OK;
   }));
 }
 
 void
 MediaEngineRemoteVideoSource::NotifyPull(MediaStreamGraph* aGraph,
                                          SourceMediaStream* aSource,
                                          TrackID aID, StreamTime aDesiredTime,
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -368,20 +368,20 @@ MediaEngineWebRTCMicrophoneSource::Updat
 void
 MediaEngineWebRTCMicrophoneSource::SetLastPrefs(
     const MediaEnginePrefs& aPrefs)
 {
   mLastPrefs = aPrefs;
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
 
-  NS_DispatchToMainThread(media::NewRunnableFrom([that, aPrefs]() mutable {
-    that->mSettings.mEchoCancellation.Value() = aPrefs.mAecOn;
-    that->mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn;
-    that->mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn;
+  NS_DispatchToMainThread(media::NewRunnableFrom([this, that, aPrefs]() mutable {
+    mSettings.mEchoCancellation.Value() = aPrefs.mAecOn;
+    mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn;
+    mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn;
     return NS_OK;
   }));
 }
 
 
 nsresult
 MediaEngineWebRTCMicrophoneSource::Deallocate(AllocationHandle* aHandle)
 {
--- a/dom/presentation/PresentationConnection.cpp
+++ b/dom/presentation/PresentationConnection.cpp
@@ -730,36 +730,35 @@ PresentationConnection::RemoveFromLoadGr
 void
 PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessage)
 {
   if (mState == PresentationConnectionState::Terminated) {
     return;
   }
 
   nsString message = nsString(aMessage);
-  RefPtr<PresentationConnection> self = this;
   nsCOMPtr<nsIRunnable> r =
-    NS_NewRunnableFunction([self, message]() -> void {
+    NS_NewRunnableFunction([this, message]() -> void {
       // Set |mState| to |PresentationConnectionState::Closed| here to avoid
       // calling |ProcessStateChanged|.
-      self->mState = PresentationConnectionState::Closed;
+      mState = PresentationConnectionState::Closed;
 
       // Make sure dispatching the event and closing the connection are invoked
       // at the same time by setting |aDispatchNow| to true.
       Unused << NS_WARN_IF(NS_FAILED(
-        self->DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error,
-                                           message,
-                                           true)));
+        DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error,
+                                      message,
+                                      true)));
 
       nsCOMPtr<nsIPresentationService> service =
         do_GetService(PRESENTATION_SERVICE_CONTRACTID);
       if(NS_WARN_IF(!service)) {
         return;
       }
 
       Unused << NS_WARN_IF(NS_FAILED(
-        service->CloseSession(self->mId,
-                              self->mRole,
+        service->CloseSession(mId,
+                              mRole,
                               nsIPresentationService::CLOSED_REASON_ERROR)));
     });
 
   Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(r)));
 }
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -1311,19 +1311,18 @@ CompositorBridgeParent::FlushApzRepaints
 {
   MOZ_ASSERT(mApzcTreeManager);
   uint64_t layersId = aLayerTree->GetId();
   if (layersId == 0) {
     // The request is coming from the parent-process layer tree, so we should
     // use the compositor's root layer tree id.
     layersId = mRootLayerTreeID;
   }
-  RefPtr<CompositorBridgeParent> self = this;
   APZThreadUtils::RunOnControllerThread(NS_NewRunnableFunction([=] () {
-    self->mApzcTreeManager->FlushApzRepaints(layersId);
+    mApzcTreeManager->FlushApzRepaints(layersId);
   }));
 }
 
 void
 CompositorBridgeParent::GetAPZTestData(const LayerTransactionParent* aLayerTree,
                                        APZTestData* aOutData)
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
--- a/ipc/mscom/MainThreadHandoff.cpp
+++ b/ipc/mscom/MainThreadHandoff.cpp
@@ -8,17 +8,16 @@
 
 #include "mozilla/Move.h"
 #include "mozilla/mscom/InterceptorLog.h"
 #include "mozilla/mscom/Registration.h"
 #include "mozilla/mscom/Utils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "nsThreadUtils.h"
-#include "nsProxyRelease.h"
 
 using mozilla::DebugOnly;
 
 namespace {
 
 class HandoffRunnable : public mozilla::Runnable
 {
 public:
@@ -103,21 +102,22 @@ MainThreadHandoff::Release()
 {
   ULONG newRefCnt = (ULONG) InterlockedDecrement((LONG*)&mRefCnt);
   if (newRefCnt == 0) {
     // It is possible for the last Release() call to happen off-main-thread.
     // If so, we need to dispatch an event to delete ourselves.
     if (NS_IsMainThread()) {
       delete this;
     } else {
-      // We need to delete this object on the main thread, but we aren't on the
-      // main thread right now, so we send a reference to ourselves to the main
-      // thread to be re-released there.
-      RefPtr<MainThreadHandoff> self = this;
-      NS_ReleaseOnMainThread(self.forget());
+      mozilla::DebugOnly<nsresult> rv =
+        NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void
+        {
+          delete this;
+        }));
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
   }
   return newRefCnt;
 }
 
 HRESULT
 MainThreadHandoff::OnCall(ICallFrame* aFrame)
 {
--- a/ipc/mscom/WeakRef.cpp
+++ b/ipc/mscom/WeakRef.cpp
@@ -6,17 +6,16 @@
 
 #define INITGUID
 #include "mozilla/mscom/WeakRef.h"
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Mutex.h"
 #include "nsThreadUtils.h"
 #include "nsWindowsHelpers.h"
-#include "nsProxyRelease.h"
 
 static void
 InitializeCS(CRITICAL_SECTION& aCS)
 {
   DWORD flags = 0;
 #if defined(RELEASE_OR_BETA)
   flags |= CRITICAL_SECTION_NO_DEBUG_INFO;
 #endif
@@ -143,21 +142,24 @@ WeakReferenceSupport::Release()
       mSharedRef->Clear();
     }
   }
   NS_LOG_RELEASE(this, newRefCnt, "mscom::WeakReferenceSupport");
   if (newRefCnt == 0) {
     if (mFlags != Flags::eDestroyOnMainThread || NS_IsMainThread()) {
       delete this;
     } else {
-      // We need to delete this object on the main thread, but we aren't on the
-      // main thread right now, so we send a reference to ourselves to the main
-      // thread to be re-released there.
-      RefPtr<WeakReferenceSupport> self = this;
-      NS_ReleaseOnMainThread(self.forget());
+      // It is possible for the last Release() call to happen off-main-thread.
+      // If so, we need to dispatch an event to delete ourselves.
+      mozilla::DebugOnly<nsresult> rv =
+        NS_DispatchToMainThread(NS_NewRunnableFunction([this]() -> void
+        {
+          delete this;
+        }));
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
   }
   return newRefCnt;
 }
 
 HRESULT
 WeakReferenceSupport::GetWeakReference(IWeakReference** aOutWeakRef)
 {
--- a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp
+++ b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp
@@ -616,17 +616,17 @@ ResolveOperator::Reply(DNSServiceRef aSd
                        const nsACString& aFullName,
                        const nsACString& aHostTarget,
                        uint16_t aPort,
                        uint16_t aTxtLen,
                        const unsigned char* aTxtRecord)
 {
   MOZ_ASSERT(GetThread() == NS_GetCurrentThread());
 
-  auto guard = MakeScopeExit([&] {
+  auto guard = MakeScopeExit([this] {
     Unused << NS_WARN_IF(NS_FAILED(Stop()));
   });
 
   if (NS_WARN_IF(kDNSServiceErr_NoError != aErrorCode)) {
     LOG_E("ResolveOperator::Reply (%d)", aErrorCode);
     return;
   }
 
@@ -735,17 +735,17 @@ GetAddrInfoOperator::Reply(DNSServiceRef
                            uint32_t aInterfaceIndex,
                            DNSServiceErrorType aErrorCode,
                            const nsACString& aHostName,
                            const NetAddr& aAddress,
                            uint32_t aTTL)
 {
   MOZ_ASSERT(GetThread() == NS_GetCurrentThread());
 
-  auto guard = MakeScopeExit([&] {
+  auto guard = MakeScopeExit([this] {
     Unused << NS_WARN_IF(NS_FAILED(Stop()));
   });
 
   if (NS_WARN_IF(kDNSServiceErr_NoError != aErrorCode)) {
     LOG_E("GetAddrInfoOperator::Reply (%d)", aErrorCode);
     return;
   }
 
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -802,24 +802,19 @@ nsMultiMixedConv::SwitchToControlParsing
     mTokenizer.EnableCustomToken(mBoundaryTokenWithDashes, false);
     mTokenizer.EnableCustomToken(mBoundaryToken, false);
 }
 
 // nsMultiMixedConv methods
 nsMultiMixedConv::nsMultiMixedConv() :
     mCurrentPartID(0),
     mInOnDataAvailable(false),
-    // XXX: This is a hack to bypass the raw pointer to refcounted object in
-    // lambda analysis. It should be removed and replaced when the
-    // IncrementalTokenizer API is improved to avoid the need for such
-    // workarounds.
-    //
-    // This is safe because `mTokenizer` will not outlive `this`, meaning that
-    // this std::bind object will be destroyed before `this` dies.
-    mTokenizer(std::bind(&nsMultiMixedConv::ConsumeToken, this, std::placeholders::_1))
+    mTokenizer([this](Token const& token, mozilla::IncrementalTokenizer&) -> nsresult {
+        return this->ConsumeToken(token);
+    })
 {
     mContentLength      = UINT64_MAX;
     mByteRangeStart     = 0;
     mByteRangeEnd       = 0;
     mTotalSent          = 0;
     mIsByteRangeRequest = false;
     mParserState        = INIT;
     mRawData            = nullptr;