aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-08-31 01:18:25 -0700
committerManish Goregaokar <manishsmail@gmail.com>2018-08-31 05:27:59 -0700
commit303b62ae8d0c101d5e3ef716bef5f889821f0923 (patch)
tree5ed1e47e83262a130324ee143f054bcc22999562
parent1ee3deea274eeda9a31af3ccd3a9bacf19603ce8 (diff)
downloadservo-303b62ae8d0c101d5e3ef716bef5f889821f0923.tar.gz
servo-303b62ae8d0c101d5e3ef716bef5f889821f0923.zip
Throw errors for invalid values in panner node constructor
-rw-r--r--components/script/dom/pannernode.rs31
-rw-r--r--components/script/dom/webidls/PannerNode.webidl2
2 files changed, 25 insertions, 8 deletions
diff --git a/components/script/dom/pannernode.rs b/components/script/dom/pannernode.rs
index 7f1909cdb50..ab1fea05db9 100644
--- a/components/script/dom/pannernode.rs
+++ b/components/script/dom/pannernode.rs
@@ -54,16 +54,29 @@ impl PannerNode {
) -> Fallible<PannerNode> {
let count = options.parent.channelCount.unwrap_or(2);
let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Clamped_max);
+ let interpretation = options.parent.channelInterpretation.unwrap_or(ChannelInterpretation::Speakers);
if mode == ChannelCountMode::Max {
return Err(Error::NotSupported)
}
- if count > 2 {
+ if count > 2 || count == 0 {
return Err(Error::NotSupported)
}
+ if *options.maxDistance <= 0. {
+ return Err(Error::Range("maxDistance should be positive".into()))
+ }
+ if *options.refDistance < 0. {
+ return Err(Error::Range("refDistance should be non-negative".into()))
+ }
+ if *options.rolloffFactor < 0. {
+ return Err(Error::Range("rolloffFactor should be non-negative".into()))
+ }
+ if *options.coneOuterGain < 0. || *options.coneOuterGain > 1. {
+ return Err(Error::InvalidState)
+ }
let mut node_options = AudioNodeOptions::empty();
node_options.channelCount = Some(count);
node_options.channelCountMode = Some(mode);
- node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
+ node_options.channelInterpretation = Some(interpretation);
let options = options.into();
let node = AudioNode::new_inherited(
AudioNodeInit::PannerNode(options),
@@ -230,10 +243,14 @@ impl PannerNodeMethods for PannerNode {
Finite::wrap(self.ref_distance.get())
}
// https://webaudio.github.io/web-audio-api/#dom-pannernode-refdistance
- fn SetRefDistance(&self, val: Finite<f64>) {
+ fn SetRefDistance(&self, val: Finite<f64>) -> Fallible<()> {
+ if *val < 0. {
+ return Err(Error::Range("value should be non-negative".into()))
+ }
self.ref_distance.set(*val);
let msg = PannerNodeMessage::SetRefDistance(self.ref_distance.get());
self.upcast::<AudioNode>().message(AudioNodeMessage::PannerNode(msg));
+ Ok(())
}
// https://webaudio.github.io/web-audio-api/#dom-pannernode-maxdistance
fn MaxDistance(&self) -> Finite<f64> {
@@ -241,8 +258,8 @@ impl PannerNodeMethods for PannerNode {
}
// https://webaudio.github.io/web-audio-api/#dom-pannernode-maxdistance
fn SetMaxDistance(&self, val: Finite<f64>) -> Fallible<()> {
- if *val < 0. {
- return Err(Error::NotSupported)
+ if *val <= 0. {
+ return Err(Error::Range("value should be positive".into()))
}
self.max_distance.set(*val);
let msg = PannerNodeMessage::SetMaxDistance(self.max_distance.get());
@@ -256,7 +273,7 @@ impl PannerNodeMethods for PannerNode {
// https://webaudio.github.io/web-audio-api/#dom-pannernode-rollofffactor
fn SetRolloffFactor(&self, val: Finite<f64>) -> Fallible<()> {
if *val < 0. {
- return Err(Error::Range("value should be positive".into()))
+ return Err(Error::Range("value should be non-negative".into()))
}
self.rolloff_factor.set(*val);
let msg = PannerNodeMessage::SetRolloff(self.rolloff_factor.get());
@@ -289,7 +306,7 @@ impl PannerNodeMethods for PannerNode {
}
// https://webaudio.github.io/web-audio-api/#dom-pannernode-coneoutergain
fn SetConeOuterGain(&self, val: Finite<f64>) -> Fallible<()> {
- if *val < 0. || *val > 360. {
+ if *val < 0. || *val > 1. {
return Err(Error::InvalidState)
}
self.cone_outer_gain.set(*val);
diff --git a/components/script/dom/webidls/PannerNode.webidl b/components/script/dom/webidls/PannerNode.webidl
index 18d01f52b11..b1c1cdfb68f 100644
--- a/components/script/dom/webidls/PannerNode.webidl
+++ b/components/script/dom/webidls/PannerNode.webidl
@@ -45,7 +45,7 @@ interface PannerNode : AudioNode {
readonly attribute AudioParam orientationY;
readonly attribute AudioParam orientationZ;
attribute DistanceModelType distanceModel;
- attribute double refDistance;
+ [SetterThrows] attribute double refDistance;
[SetterThrows] attribute double maxDistance;
[SetterThrows] attribute double rolloffFactor;
attribute double coneInnerAngle;