diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index 7a456fa8a047..7888ce506621 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -60,6 +60,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioContext) 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, @@ -137,13 +140,18 @@ AudioContext::Init() return NS_OK; } -AudioContext::~AudioContext() +void +AudioContext::DisconnectFromWindow() { nsPIDOMWindowInner* window = GetOwner(); if (window) { window->RemoveAudioContext(this); } +} +AudioContext::~AudioContext() +{ + DisconnectFromWindow(); UnregisterWeakMemoryReporter(this); } diff --git a/dom/media/webaudio/AudioContext.h b/dom/media/webaudio/AudioContext.h index 58f559c75bb8..a1d317963977 100644 --- a/dom/media/webaudio/AudioContext.h +++ b/dom/media/webaudio/AudioContext.h @@ -311,6 +311,7 @@ public: IMPL_EVENT_HANDLER(mozinterruptend) private: + void DisconnectFromWindow(); void RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob); void ShutdownDecoder();