bug 1255618 remove AudioContext from global window at unlink r?ehsan
mDestination is cleared during unlink, which means that after that point the
window can't do much with the AudioContext, nor should need to do so.
MozReview-Commit-ID: E45aCpEfJEu
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -55,16 +55,19 @@ static dom::AudioContext::AudioContextId
NS_IMPL_CYCLE_COLLECTION_CLASS(AudioContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDestination)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListener)
if (!tmp->mIsStarted) {
NS_IMPL_CYCLE_COLLECTION_UNLINK(mActiveNodes)
}
+ // Remove weak reference on the global window as the context is not usable
+ // without mDestination.
+ tmp->DisconnectFromWindow();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AudioContext,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDestination)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListener)
if (!tmp->mIsStarted) {
MOZ_ASSERT(tmp->mIsOffline,
@@ -132,23 +135,28 @@ AudioContext::Init()
return rv;
}
mDestination->SetIsOnlyNodeForContext(true);
}
return NS_OK;
}
-AudioContext::~AudioContext()
+void
+AudioContext::DisconnectFromWindow()
{
nsPIDOMWindowInner* window = GetOwner();
if (window) {
window->RemoveAudioContext(this);
}
+}
+AudioContext::~AudioContext()
+{
+ DisconnectFromWindow();
UnregisterWeakMemoryReporter(this);
}
JSObject*
AudioContext::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
if (mIsOffline) {
return OfflineAudioContextBinding::Wrap(aCx, this, aGivenProto);
--- a/dom/media/webaudio/AudioContext.h
+++ b/dom/media/webaudio/AudioContext.h
@@ -307,16 +307,17 @@ public:
void OnStateChanged(void* aPromise, AudioContextState aNewState);
BasicWaveFormCache* GetBasicWaveFormCache();
IMPL_EVENT_HANDLER(mozinterruptbegin)
IMPL_EVENT_HANDLER(mozinterruptend)
private:
+ void DisconnectFromWindow();
void RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob);
void ShutdownDecoder();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData, bool aAnonymize) override;
friend struct ::mozilla::WebAudioDecodeJob;