Skip to content

Commit

Permalink
Bug 1646601 throw InvalidStateError on (Offline)AudioContext construc…
Browse files Browse the repository at this point in the history
  • Loading branch information
karlt committed Sep 15, 2020
1 parent 9e13b21 commit 8b05bea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions dom/media/webaudio/AudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ JSObject* AudioContext::WrapObject(JSContext* aCx,
}
}

static bool CheckFullyActive(nsPIDOMWindowInner* aWindow, ErrorResult& aRv) {
if (!aWindow->IsFullyActive()) {
aRv.ThrowInvalidStateError("The document is not fully active.");
return false;
}
return true;
}

/* static */
already_AddRefed<AudioContext> AudioContext::Constructor(
const GlobalObject& aGlobal, const AudioContextOptions& aOptions,
Expand All @@ -261,6 +269,14 @@ already_AddRefed<AudioContext> AudioContext::Constructor(
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
/**
* If the current settings object’s responsible document is NOT fully
* active, throw an InvalidStateError and abort these steps.
*/
if (!CheckFullyActive(window, aRv)) {
return nullptr;
}

if (aOptions.mSampleRate.WasPassed() &&
(aOptions.mSampleRate.Value() < WebAudioUtils::MinSampleRate ||
aOptions.mSampleRate.Value() > WebAudioUtils::MaxSampleRate)) {
Expand Down Expand Up @@ -304,6 +320,13 @@ already_AddRefed<AudioContext> AudioContext::Constructor(
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
/**
* If the current settings object’s responsible document is NOT fully
* active, throw an InvalidStateError and abort these steps.
*/
if (!CheckFullyActive(window, aRv)) {
return nullptr;
}

if (aNumberOfChannels == 0 ||
aNumberOfChannels > WebAudioUtils::MaxChannelCount) {
Expand Down
6 changes: 4 additions & 2 deletions dom/media/webaudio/test/test_bug827541.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Tell the cycle collector about the audio contexts owned by nsGlobalWindow</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Expand All @@ -13,9 +14,10 @@
var frameWin = iframe.contentWindow;
new frameWin.AudioContext();
document.body.removeChild(iframe);
new frameWin.AudioContext();
expectException(() => new frameWin.AudioContext(),
DOMException.INVALID_STATE_ERR);

ok(true, "This test should not leak");
// This test should not leak.
</script>
</pre>
</body>
Expand Down

0 comments on commit 8b05bea

Please sign in to comment.