Throw on out-of-bounds channelCount in AudioNodes

This commit is contained in:
Manish Goregaokar 2018-09-03 20:30:06 +05:30
parent 0ac861ca94
commit 28c21421ca
9 changed files with 44 additions and 38 deletions

View file

@ -44,7 +44,7 @@ impl AudioBufferSourceNode {
window: &Window,
context: &BaseAudioContext,
options: &AudioBufferSourceOptions,
) -> AudioBufferSourceNode {
) -> Fallible<AudioBufferSourceNode> {
let mut node_options = AudioNodeOptions::empty();
node_options.channelCount = Some(2);
node_options.channelCountMode = Some(ChannelCountMode::Max);
@ -55,7 +55,7 @@ impl AudioBufferSourceNode {
&node_options,
0, /* inputs */
1, /* outputs */
);
)?;
let node_id = source_node.node().node_id();
let playback_rate = AudioParam::new(
&window,
@ -77,7 +77,7 @@ impl AudioBufferSourceNode {
f32::MIN,
f32::MAX,
);
AudioBufferSourceNode {
Ok(AudioBufferSourceNode {
source_node,
buffer: Default::default(),
playback_rate: Dom::from_ref(&playback_rate),
@ -85,7 +85,7 @@ impl AudioBufferSourceNode {
loop_enabled: Cell::new(options.loop_),
loop_start: Cell::new(*options.loopStart),
loop_end: Cell::new(*options.loopEnd),
}
})
}
#[allow(unrooted_must_root)]
@ -93,9 +93,9 @@ impl AudioBufferSourceNode {
window: &Window,
context: &BaseAudioContext,
options: &AudioBufferSourceOptions,
) -> DomRoot<AudioBufferSourceNode> {
let node = AudioBufferSourceNode::new_inherited(window, context, options);
reflect_dom_object(Box::new(node), window, AudioBufferSourceNodeBinding::Wrap)
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
let node = AudioBufferSourceNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(Box::new(node), window, AudioBufferSourceNodeBinding::Wrap))
}
pub fn Constructor(
@ -103,7 +103,7 @@ impl AudioBufferSourceNode {
context: &BaseAudioContext,
options: &AudioBufferSourceOptions,
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
Ok(AudioBufferSourceNode::new(window, context, options))
AudioBufferSourceNode::new(window, context, options)
}
}

View file

@ -44,9 +44,14 @@ impl AudioNode {
options: &AudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32,
) -> AudioNode {
) -> Fallible<AudioNode> {
if let Some(c) = options.channelCount {
if c == 0 || c > MAX_CHANNEL_COUNT {
return Err(Error::NotSupported);
}
}
let node_id = context.audio_context_impl().create_node(node_type);
AudioNode::new_inherited_for_id(node_id, context, options, number_of_inputs, number_of_outputs)
Ok(AudioNode::new_inherited_for_id(node_id, context, options, number_of_inputs, number_of_outputs))
}
pub fn new_inherited_for_id(

View file

@ -24,24 +24,25 @@ pub struct AudioScheduledSourceNode {
}
impl AudioScheduledSourceNode {
#[allow(unrooted_must_root)]
pub fn new_inherited(
node_type: AudioNodeInit,
context: &BaseAudioContext,
options: &AudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32,
) -> AudioScheduledSourceNode {
AudioScheduledSourceNode {
) -> Fallible<AudioScheduledSourceNode> {
Ok(AudioScheduledSourceNode {
node: AudioNode::new_inherited(
node_type,
context,
options,
number_of_inputs,
number_of_outputs,
),
)?,
started: Cell::new(false),
stopped: Cell::new(false),
}
})
}
pub fn node(&self) -> &AudioNode {

View file

@ -317,7 +317,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
fn CreateOscillator(&self) -> DomRoot<OscillatorNode> {
fn CreateOscillator(&self) -> Fallible<DomRoot<OscillatorNode>> {
OscillatorNode::new(
&self.global().as_window(),
&self,
@ -326,7 +326,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain
fn CreateGain(&self) -> DomRoot<GainNode> {
fn CreateGain(&self) -> Fallible<DomRoot<GainNode>> {
GainNode::new(&self.global().as_window(), &self, &GainOptions::empty())
}
@ -360,7 +360,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource
fn CreateBufferSource(&self) -> DomRoot<AudioBufferSourceNode> {
fn CreateBufferSource(&self) -> Fallible<DomRoot<AudioBufferSourceNode>> {
AudioBufferSourceNode::new(
&self.global().as_window(),
&self,

View file

@ -49,7 +49,7 @@ impl ChannelMergerNode {
&node_options,
options.numberOfInputs, // inputs
1, // outputs
);
)?;
Ok(ChannelMergerNode {
node,
})

View file

@ -31,7 +31,7 @@ impl GainNode {
window: &Window,
context: &BaseAudioContext,
options: &GainOptions,
) -> GainNode {
) -> Fallible<GainNode> {
let mut node_options = AudioNodeOptions::empty();
let count = options.parent.channelCount.unwrap_or(2);
let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Max);
@ -45,7 +45,7 @@ impl GainNode {
&node_options,
1, // inputs
1, // outputs
);
)?;
let gain = AudioParam::new(
window,
context,
@ -56,10 +56,10 @@ impl GainNode {
f32::MIN, // min value
f32::MAX, // max value
);
GainNode {
Ok(GainNode {
node,
gain: Dom::from_ref(&gain),
}
})
}
#[allow(unrooted_must_root)]
@ -67,9 +67,9 @@ impl GainNode {
window: &Window,
context: &BaseAudioContext,
options: &GainOptions,
) -> DomRoot<GainNode> {
let node = GainNode::new_inherited(window, context, options);
reflect_dom_object(Box::new(node), window, GainNodeBinding::Wrap)
) -> Fallible<DomRoot<GainNode>> {
let node = GainNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(Box::new(node), window, GainNodeBinding::Wrap))
}
pub fn Constructor(
@ -77,7 +77,7 @@ impl GainNode {
context: &BaseAudioContext,
options: &GainOptions,
) -> Fallible<DomRoot<GainNode>> {
Ok(GainNode::new(window, context, options))
GainNode::new(window, context, options)
}
}

View file

@ -35,7 +35,7 @@ impl OscillatorNode {
window: &Window,
context: &BaseAudioContext,
oscillator_options: &OscillatorOptions,
) -> OscillatorNode {
) -> Fallible<OscillatorNode> {
let mut node_options = AudioNodeOptions::empty();
node_options.channelCount = Some(2);
node_options.channelCountMode = Some(ChannelCountMode::Max);
@ -46,7 +46,7 @@ impl OscillatorNode {
&node_options,
0, /* inputs */
1, /* outputs */
);
)?;
let node_id = source_node.node().node_id();
let frequency = AudioParam::new(
window,
@ -69,12 +69,12 @@ impl OscillatorNode {
440. / 2.,
);
OscillatorNode {
Ok(OscillatorNode {
source_node,
oscillator_type: oscillator_options.type_,
frequency: Dom::from_ref(&frequency),
detune: Dom::from_ref(&detune),
}
})
}
#[allow(unrooted_must_root)]
@ -82,9 +82,9 @@ impl OscillatorNode {
window: &Window,
context: &BaseAudioContext,
options: &OscillatorOptions,
) -> DomRoot<OscillatorNode> {
let node = OscillatorNode::new_inherited(window, context, options);
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
) -> Fallible<DomRoot<OscillatorNode>> {
let node = OscillatorNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap))
}
pub fn Constructor(
@ -92,7 +92,7 @@ impl OscillatorNode {
context: &BaseAudioContext,
options: &OscillatorOptions,
) -> Fallible<DomRoot<OscillatorNode>> {
Ok(OscillatorNode::new(window, context, options))
OscillatorNode::new(window, context, options)
}
}

View file

@ -84,7 +84,7 @@ impl PannerNode {
&node_options,
1, // inputs
1, // outputs
);
)?;
let id = node.node_id();
let position_x = AudioParam::new(
window,

View file

@ -30,13 +30,13 @@ interface BaseAudioContext : EventTarget {
Promise<AudioBuffer> decodeAudioData(ArrayBuffer audioData,
optional DecodeSuccessCallback successCallback,
optional DecodeErrorCallback errorCallback);
AudioBufferSourceNode createBufferSource();
[Throws] AudioBufferSourceNode createBufferSource();
// ConstantSourceNode createConstantSource();
// ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
// optional unsigned long numberOfInputChannels = 2,
// optional unsigned long numberOfOutputChannels = 2);
// AnalyserNode createAnalyser();
GainNode createGain();
[Throws] GainNode createGain();
// DelayNode createDelay(optional double maxDelayTime = 1);
// BiquadFilterNode createBiquadFilter();
// IIRFilterNode createIIRFilter(sequence<double> feedforward,
@ -48,7 +48,7 @@ interface BaseAudioContext : EventTarget {
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
// ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
// DynamicsCompressorNode createDynamicsCompressor();
OscillatorNode createOscillator();
[Throws] OscillatorNode createOscillator();
// PeriodicWave createPeriodicWave(sequence<float> real,
// sequence<float> imag,
// optional PeriodicWaveConstraints constraints);