Bug 1344357 P1 - move the MediaDecoder::mSeekDOMPromise to HTMLMediaElement; r=jwwang

There was a cycle amoung a window object -> a HTMLMediaElement -> a MediaDecoder -> a Promise (-> back to the window object).
And we have no way to break the cycle since the MediaDecoder does not participate into the collection.

By moving the Promise form MediaDecoder to HTMLMediaElement, we will be able to break the cycle since the HTMLMediaElement is in the collection.

We'll implement the cycle collection in the next patch.

MozReview-Commit-ID: CyVXBl6IMI3
This commit is contained in:
Kaku Kuo
2017-04-17 18:25:26 +08:00
parent 51e8453104
commit c3d28c22e8
6 changed files with 58 additions and 43 deletions

View File

@@ -2731,6 +2731,9 @@ HTMLMediaElement::Seek(double aTime,
// We changed whether we're seeking so we need to AddRemoveSelfReference.
AddRemoveSelfReference();
// Keep the DOM promise.
mSeekDOMPromise = promise;
return promise.forget();
}
@@ -7490,5 +7493,33 @@ bool HasDebuggerPrivilege(JSContext* aCx, JSObject* aObj)
NS_LITERAL_STRING("debugger"));
}
void
HTMLMediaElement::AsyncResolveSeekDOMPromiseIfExists()
{
MOZ_ASSERT(NS_IsMainThread());
if (mSeekDOMPromise) {
RefPtr<dom::Promise> promise = mSeekDOMPromise.forget();
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
promise->MaybeResolveWithUndefined();
});
mAbstractMainThread->Dispatch(r.forget());
mSeekDOMPromise = nullptr;
}
}
void
HTMLMediaElement::AsyncRejectSeekDOMPromiseIfExists()
{
MOZ_ASSERT(NS_IsMainThread());
if (mSeekDOMPromise) {
RefPtr<dom::Promise> promise = mSeekDOMPromise.forget();
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
});
mAbstractMainThread->Dispatch(r.forget());
mSeekDOMPromise = nullptr;
}
}
} // namespace dom
} // namespace mozilla