Bug 849230 - Limit the range of sample rates accepted by AudioContext.createBuffer according to the spec; r=padenot

This commit is contained in:
Ehsan Akhgari 2013-03-08 12:29:00 -05:00
parent 1d74004842
commit 422eb58946
3 changed files with 16 additions and 1 deletions

View File

@ -79,6 +79,11 @@ AudioContext::CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels,
uint32_t aLength, float aSampleRate,
ErrorResult& aRv)
{
if (aSampleRate < 8000 || aSampleRate > 96000) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
}
if (aLength > INT32_MAX) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;

View File

@ -7,6 +7,7 @@
</head>
<body>
<pre id="test">
<script src="webaudio.js" type="text/javascript"></script>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
@ -34,6 +35,14 @@ addLoadEvent(function() {
}
ok(!foundNonZero, "Buffer " + i + " should be initialized to 0");
}
expectException(function() {
context.createBuffer(2, 2048, 7999);
}, DOMException.DOM_SYNTAX_ERR);
expectException(function() {
context.createBuffer(2, 2048, 96001);
}, DOMException.DOM_SYNTAX_ERR);
context.createBuffer(2, 2048, 8000); // no exception
context.createBuffer(2, 2048, 96000); // no exception
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
});

View File

@ -10,7 +10,8 @@
<script class="testbody" type="text/javascript">
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
AudioContext().createBuffer(0, 0, 0);
var ctx = new AudioContext();
ctx.createBuffer(0, 0, ctx.sampleRate);
ok(true, "The test should not crash during CC");
SpecialPowers.clearUserPref("media.webaudio.enabled");