aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/audioparam.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-04-26 03:32:48 -0400
committerGitHub <noreply@github.com>2019-04-26 03:32:48 -0400
commit56c2e85cab5b01ad31be3c69f0fcc2c992960e5c (patch)
tree09234476267a9c0c2829a32c0a6dabfde5fb6b79 /components/script/dom/audioparam.rs
parent9b2018779347dcd404b955e3773dfed3c3b45c92 (diff)
parent8a8a9f7135d76daafac07a010c3feb6787dc3532 (diff)
downloadservo-56c2e85cab5b01ad31be3c69f0fcc2c992960e5c.tar.gz
servo-56c2e85cab5b01ad31be3c69f0fcc2c992960e5c.zip
Auto merge of #23270 - Manishearth:audioparam-validation, r=ferjm
Add input validation for AudioParam methods Waiting on a build to make WPT updates Spec requires us to validate inputs, we aren't doing this here. We don't need to check for things being finite since we already get the arguments as `Finite` values <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23270) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/audioparam.rs')
-rw-r--r--components/script/dom/audioparam.rs77
1 files changed, 65 insertions, 12 deletions
diff --git a/components/script/dom/audioparam.rs b/components/script/dom/audioparam.rs
index c024b88bae3..08ab6f32d10 100644
--- a/components/script/dom/audioparam.rs
+++ b/components/script/dom/audioparam.rs
@@ -7,6 +7,7 @@ use crate::dom::bindings::codegen::Bindings::AudioParamBinding;
use crate::dom::bindings::codegen::Bindings::AudioParamBinding::{
AudioParamMethods, AutomationRate,
};
+use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
@@ -142,12 +143,22 @@ impl AudioParamMethods for AudioParam {
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-setvalueattime
- fn SetValueAtTime(&self, value: Finite<f32>, start_time: Finite<f64>) -> DomRoot<AudioParam> {
+ fn SetValueAtTime(
+ &self,
+ value: Finite<f32>,
+ start_time: Finite<f64>,
+ ) -> Fallible<DomRoot<AudioParam>> {
+ if *start_time < 0. {
+ return Err(Error::Range(format!(
+ "start time {} should not be negative",
+ *start_time
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::SetValueAtTime(*value, *start_time),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-linearramptovalueattime
@@ -155,12 +166,18 @@ impl AudioParamMethods for AudioParam {
&self,
value: Finite<f32>,
end_time: Finite<f64>,
- ) -> DomRoot<AudioParam> {
+ ) -> Fallible<DomRoot<AudioParam>> {
+ if *end_time < 0. {
+ return Err(Error::Range(format!(
+ "end time {} should not be negative",
+ *end_time
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::RampToValueAtTime(RampKind::Linear, *value, *end_time),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-exponentialramptovalueattime
@@ -168,12 +185,24 @@ impl AudioParamMethods for AudioParam {
&self,
value: Finite<f32>,
end_time: Finite<f64>,
- ) -> DomRoot<AudioParam> {
+ ) -> Fallible<DomRoot<AudioParam>> {
+ if *end_time < 0. {
+ return Err(Error::Range(format!(
+ "end time {} should not be negative",
+ *end_time
+ )));
+ }
+ if *value == 0. {
+ return Err(Error::Range(format!(
+ "target value {} should not be 0",
+ *value
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::RampToValueAtTime(RampKind::Exponential, *value, *end_time),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-settargetattime
@@ -182,30 +211,54 @@ impl AudioParamMethods for AudioParam {
target: Finite<f32>,
start_time: Finite<f64>,
time_constant: Finite<f32>,
- ) -> DomRoot<AudioParam> {
+ ) -> Fallible<DomRoot<AudioParam>> {
+ if *start_time < 0. {
+ return Err(Error::Range(format!(
+ "start time {} should not be negative",
+ *start_time
+ )));
+ }
+ if *time_constant < 0. {
+ return Err(Error::Range(format!(
+ "time constant {} should not be negative",
+ *time_constant
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::SetTargetAtTime(*target, *start_time, (*time_constant).into()),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelscheduledvalues
- fn CancelScheduledValues(&self, cancel_time: Finite<f64>) -> DomRoot<AudioParam> {
+ fn CancelScheduledValues(&self, cancel_time: Finite<f64>) -> Fallible<DomRoot<AudioParam>> {
+ if *cancel_time < 0. {
+ return Err(Error::Range(format!(
+ "cancel time {} should not be negative",
+ *cancel_time
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::CancelScheduledValues(*cancel_time),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelandholdattime
- fn CancelAndHoldAtTime(&self, cancel_time: Finite<f64>) -> DomRoot<AudioParam> {
+ fn CancelAndHoldAtTime(&self, cancel_time: Finite<f64>) -> Fallible<DomRoot<AudioParam>> {
+ if *cancel_time < 0. {
+ return Err(Error::Range(format!(
+ "cancel time {} should not be negative",
+ *cancel_time
+ )));
+ }
self.message_node(AudioNodeMessage::SetParam(
self.param,
UserAutomationEvent::CancelAndHoldAtTime(*cancel_time),
));
- DomRoot::from_ref(self)
+ Ok(DomRoot::from_ref(self))
}
}