Bug 1497149 - Avoid nulling mSeekDOMPromise on OOM, and use IgnoreErrors(). r=jya
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 08 Oct 2018 19:39:41 +0000
changeset 488439 3ded0ccdc4a548190faf633dca587cd11744b6f4
parent 488438 7355fb2908e5087eddab422ac838697284c25d82
child 488440 1bbb6f80f5d9b3275ca9986a276fa1ae510da710
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersjya
bugs1497149
milestone64.0a1
Bug 1497149 - Avoid nulling mSeekDOMPromise on OOM, and use IgnoreErrors(). r=jya Differential Revision: https://phabricator.services.mozilla.com/D8021
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2694,18 +2694,18 @@ HTMLMediaElement::CurrentTime() const
 }
 
 void
 HTMLMediaElement::FastSeek(double aTime, ErrorResult& aRv)
 {
   LOG(LogLevel::Debug, ("%p FastSeek(%f) called by JS", this, aTime));
   LOG(LogLevel::Debug, ("Reporting telemetry VIDEO_FASTSEEK_USED"));
   Telemetry::Accumulate(Telemetry::VIDEO_FASTSEEK_USED, 1);
-  RefPtr<Promise> tobeDropped = Seek(aTime, SeekTarget::PrevSyncPoint, aRv);
-  aRv.SuppressException();
+  RefPtr<Promise> tobeDropped = Seek(aTime, SeekTarget::PrevSyncPoint,
+                                     IgnoreErrors());
 }
 
 already_AddRefed<Promise>
 HTMLMediaElement::SeekToNextFrame(ErrorResult& aRv)
 {
   /* This will cause JIT code to be kept around longer, to help performance
    * when using SeekToNextFrame to iterate through every frame of a video.
    */
@@ -2720,18 +2720,18 @@ HTMLMediaElement::SeekToNextFrame(ErrorR
   return Seek(CurrentTime(), SeekTarget::NextFrame, aRv);
 }
 
 void
 HTMLMediaElement::SetCurrentTime(double aCurrentTime, ErrorResult& aRv)
 {
   LOG(LogLevel::Debug,
       ("%p SetCurrentTime(%f) called by JS", this, aCurrentTime));
-  RefPtr<Promise> tobeDropped = Seek(aCurrentTime, SeekTarget::Accurate, aRv);
-  aRv.SuppressException();
+  RefPtr<Promise> tobeDropped = Seek(aCurrentTime, SeekTarget::Accurate,
+                                     IgnoreErrors());
 }
 
 /**
  * Check if aValue is inside a range of aRanges, and if so returns true
  * and puts the range index in aIntervalIndex. If aValue is not
  * inside a range, returns false, and aIntervalIndex
  * is set to the index of the range which starts immediately after aValue
  * (and can be aRanges.Length() if aValue is after the last range).
@@ -2764,16 +2764,17 @@ HTMLMediaElement::Seek(double aTime,
 {
   // Note: Seek is called both by synchronous code that expects errors thrown in
   // aRv, as well as asynchronous code that expects a promise. Make sure all
   // synchronous errors are returned using aRv, not promise rejections.
 
   // aTime should be non-NaN.
   MOZ_ASSERT(!mozilla::IsNaN(aTime));
 
+  RefPtr<Promise> promise = CreateDOMPromise(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   // Detect if user has interacted with element by seeking so that
   // play will not be blocked when initiated by a script.
   if (EventStateManager::IsHandlingUserInput()) {
     mIsBlessed = true;
@@ -2885,17 +2886,19 @@ HTMLMediaElement::Seek(double aTime,
   // event if it changes the playback position as a result of the seek.
   LOG(LogLevel::Debug, ("%p SetCurrentTime(%f) starting seek", this, aTime));
   mDecoder->Seek(aTime, aSeekType);
 
   // We changed whether we're seeking so we need to AddRemoveSelfReference.
   AddRemoveSelfReference();
 
   // Keep the DOM promise.
-  return do_AddRef(mSeekDOMPromise = CreateDOMPromise(aRv));
+  mSeekDOMPromise = promise;
+
+  return promise.forget();
 }
 
 double
 HTMLMediaElement::Duration() const
 {
   if (mSrcStream) {
     return std::numeric_limits<double>::infinity();
   }