Bug 812390 - Protect against NaN in AudioContext.createDelay; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 15 Nov 2012 17:48:04 -0800
changeset 113460 a1683ba4319d76ba84ba4aead8052f074bf8305b
parent 113459 b68af28e3ef213ffba364265325648023effddc4
child 113461 a0cd4bcb321795f59a9c05a934b6aa02cd9918b3
push id18160
push usereakhgari@mozilla.com
push dateFri, 16 Nov 2012 01:56:59 +0000
treeherdermozilla-inbound@a1683ba4319d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs812390
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 812390 - Protect against NaN in AudioContext.createDelay; r=bzbarsky
content/media/webaudio/AudioContext.cpp
content/media/webaudio/test/test_delayNode.html
dom/webidl/AudioContext.webidl
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -101,22 +101,22 @@ AudioContext::CreateGain()
 {
   nsRefPtr<GainNode> gainNode = new GainNode(this);
   return gainNode.forget();
 }
 
 already_AddRefed<DelayNode>
 AudioContext::CreateDelay(float aMaxDelayTime, ErrorResult& aRv)
 {
-  if (aMaxDelayTime <= 0.f || aMaxDelayTime >= 3.f) {
-    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return nullptr;
+  if (aMaxDelayTime > 0.f && aMaxDelayTime < 3.f) {
+    nsRefPtr<DelayNode> delayNode = new DelayNode(this, aMaxDelayTime);
+    return delayNode.forget();
   }
-  nsRefPtr<DelayNode> delayNode = new DelayNode(this, aMaxDelayTime);
-  return delayNode.forget();
+  aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+  return nullptr;
 }
 
 already_AddRefed<PannerNode>
 AudioContext::CreatePanner()
 {
   nsRefPtr<PannerNode> pannerNode = new PannerNode(this);
   return pannerNode.forget();
 }
--- a/content/media/webaudio/test/test_delayNode.html
+++ b/content/media/webaudio/test/test_delayNode.html
@@ -55,16 +55,19 @@ addLoadEvent(function() {
 
   expectException(function() {
     context.createDelay(0);
   }, DOMException.NOT_SUPPORTED_ERR);
   expectException(function() {
     context.createDelay(3);
   }, DOMException.NOT_SUPPORTED_ERR);
   expectException(function() {
+    context.createDelay(NaN);
+  }, DOMException.NOT_SUPPORTED_ERR);
+  expectException(function() {
     context.createDelay(-1);
   }, DOMException.NOT_SUPPORTED_ERR);
   context.createDelay(1); // should not throw
 
   source.start(0);
   SimpleTest.executeSoon(function() {
     source.stop(0);
     source.disconnect();
--- a/dom/webidl/AudioContext.webidl
+++ b/dom/webidl/AudioContext.webidl
@@ -23,16 +23,18 @@ interface mozAudioContext {
     // AudioBuffer createBuffer(ArrayBuffer buffer, boolean mixToMono);
 
     // AudioNode creation 
     [Creator]
     AudioBufferSourceNode createBufferSource();
 
     [Creator]
     GainNode createGain();
+    // maxDelayTime should ideally be a restricted float to protect against
+    // things such as NaNs.
     [Creator, Throws]
     DelayNode createDelay(optional float maxDelayTime = 1);
     [Creator]
     BiquadFilterNode createBiquadFilter();
     [Creator]
     PannerNode createPanner();
 
     [Creator]