Bug 1343550 - Prevent creating AudioNodes on an AudioContext that has been disconnected from its owner. r=baku

Spec (being written): https://github.com/WebAudio/web-audio-api/issues/1139

Bug 1343550 - Prevent touching promises when shutting down an AudioContext, when the global is going away soon. r=baku

MozReview-Commit-ID: F6en9KEbNNf

--HG--
extra : rebase_source : 04076caa38bba980cdff776b5997f33e24516d9e
extra : intermediate-source : 4f2cd3f715a218dc3bca55e89720b6aa1040d35c
extra : source : 69cd9c72bd4ed419e3f7f7b5ab64ee0fa8bd89a2
This commit is contained in:
Paul Adenot 2017-03-15 17:36:40 +01:00
Родитель cdd567b0c8
Коммит 838b5a8cad
2 изменённых файлов: 25 добавлений и 9 удалений

Просмотреть файл

@ -140,6 +140,7 @@ AudioContext::AudioContext(nsPIDOMWindowInner* aWindow,
, mIsShutDown(false)
, mCloseCalled(false)
, mSuspendCalled(false)
, mIsDisconnecting(false)
{
bool mute = aWindow->AddAudioContext(this);
@ -260,7 +261,9 @@ AudioContext::Constructor(const GlobalObject& aGlobal,
bool AudioContext::CheckClosed(ErrorResult& aRv)
{
if (mAudioContextState == AudioContextState::Closed) {
if (mAudioContextState == AudioContextState::Closed ||
mIsShutDown ||
mIsDisconnecting) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return true;
}
@ -640,21 +643,31 @@ AudioContext::CurrentTime() const
return stream->StreamTimeToSeconds(stream->GetCurrentTime());
}
void AudioContext::DisconnectFromOwner()
{
mIsDisconnecting = true;
Shutdown();
DOMEventTargetHelper::DisconnectFromOwner();
}
void
AudioContext::Shutdown()
{
mIsShutDown = true;
if (!mIsOffline) {
ErrorResult dummy;
RefPtr<Promise> ignored = Close(dummy);
}
// We don't want to touch promises if the global is going away soon.
if (!mIsDisconnecting) {
if (!mIsOffline) {
IgnoredErrorResult dummy;
RefPtr<Promise> ignored = Close(dummy);
}
for (auto p : mPromiseGripArray) {
p->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
}
for (auto p : mPromiseGripArray) {
p->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
}
mPromiseGripArray.Clear();
mPromiseGripArray.Clear();
}
// Release references to active nodes.
// Active AudioNodes don't unregister in destructors, at which point the

Просмотреть файл

@ -142,6 +142,8 @@ public:
return GetOwner();
}
virtual void DisconnectFromOwner() override;
void Shutdown(); // idempotent
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -372,6 +374,7 @@ private:
bool mCloseCalled;
// Suspend has been called with no following resume.
bool mSuspendCalled;
bool mIsDisconnecting;
};
static const dom::AudioContext::AudioContextId NO_AUDIO_CONTEXT = 0;