mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Throw on out-of-bounds channelCount in AudioNodes
This commit is contained in:
parent
0ac861ca94
commit
28c21421ca
9 changed files with 44 additions and 38 deletions
|
@ -44,7 +44,7 @@ impl AudioBufferSourceNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &AudioBufferSourceOptions,
|
options: &AudioBufferSourceOptions,
|
||||||
) -> AudioBufferSourceNode {
|
) -> Fallible<AudioBufferSourceNode> {
|
||||||
let mut node_options = AudioNodeOptions::empty();
|
let mut node_options = AudioNodeOptions::empty();
|
||||||
node_options.channelCount = Some(2);
|
node_options.channelCount = Some(2);
|
||||||
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||||
|
@ -55,7 +55,7 @@ impl AudioBufferSourceNode {
|
||||||
&node_options,
|
&node_options,
|
||||||
0, /* inputs */
|
0, /* inputs */
|
||||||
1, /* outputs */
|
1, /* outputs */
|
||||||
);
|
)?;
|
||||||
let node_id = source_node.node().node_id();
|
let node_id = source_node.node().node_id();
|
||||||
let playback_rate = AudioParam::new(
|
let playback_rate = AudioParam::new(
|
||||||
&window,
|
&window,
|
||||||
|
@ -77,7 +77,7 @@ impl AudioBufferSourceNode {
|
||||||
f32::MIN,
|
f32::MIN,
|
||||||
f32::MAX,
|
f32::MAX,
|
||||||
);
|
);
|
||||||
AudioBufferSourceNode {
|
Ok(AudioBufferSourceNode {
|
||||||
source_node,
|
source_node,
|
||||||
buffer: Default::default(),
|
buffer: Default::default(),
|
||||||
playback_rate: Dom::from_ref(&playback_rate),
|
playback_rate: Dom::from_ref(&playback_rate),
|
||||||
|
@ -85,7 +85,7 @@ impl AudioBufferSourceNode {
|
||||||
loop_enabled: Cell::new(options.loop_),
|
loop_enabled: Cell::new(options.loop_),
|
||||||
loop_start: Cell::new(*options.loopStart),
|
loop_start: Cell::new(*options.loopStart),
|
||||||
loop_end: Cell::new(*options.loopEnd),
|
loop_end: Cell::new(*options.loopEnd),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
@ -93,9 +93,9 @@ impl AudioBufferSourceNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &AudioBufferSourceOptions,
|
options: &AudioBufferSourceOptions,
|
||||||
) -> DomRoot<AudioBufferSourceNode> {
|
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
|
||||||
let node = AudioBufferSourceNode::new_inherited(window, context, options);
|
let node = AudioBufferSourceNode::new_inherited(window, context, options)?;
|
||||||
reflect_dom_object(Box::new(node), window, AudioBufferSourceNodeBinding::Wrap)
|
Ok(reflect_dom_object(Box::new(node), window, AudioBufferSourceNodeBinding::Wrap))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Constructor(
|
pub fn Constructor(
|
||||||
|
@ -103,7 +103,7 @@ impl AudioBufferSourceNode {
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &AudioBufferSourceOptions,
|
options: &AudioBufferSourceOptions,
|
||||||
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
|
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
|
||||||
Ok(AudioBufferSourceNode::new(window, context, options))
|
AudioBufferSourceNode::new(window, context, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,14 @@ impl AudioNode {
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
number_of_inputs: u32,
|
number_of_inputs: u32,
|
||||||
number_of_outputs: 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);
|
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(
|
pub fn new_inherited_for_id(
|
||||||
|
|
|
@ -24,24 +24,25 @@ pub struct AudioScheduledSourceNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioScheduledSourceNode {
|
impl AudioScheduledSourceNode {
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
node_type: AudioNodeInit,
|
node_type: AudioNodeInit,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
number_of_inputs: u32,
|
number_of_inputs: u32,
|
||||||
number_of_outputs: u32,
|
number_of_outputs: u32,
|
||||||
) -> AudioScheduledSourceNode {
|
) -> Fallible<AudioScheduledSourceNode> {
|
||||||
AudioScheduledSourceNode {
|
Ok(AudioScheduledSourceNode {
|
||||||
node: AudioNode::new_inherited(
|
node: AudioNode::new_inherited(
|
||||||
node_type,
|
node_type,
|
||||||
context,
|
context,
|
||||||
options,
|
options,
|
||||||
number_of_inputs,
|
number_of_inputs,
|
||||||
number_of_outputs,
|
number_of_outputs,
|
||||||
),
|
)?,
|
||||||
started: Cell::new(false),
|
started: Cell::new(false),
|
||||||
stopped: Cell::new(false),
|
stopped: Cell::new(false),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node(&self) -> &AudioNode {
|
pub fn node(&self) -> &AudioNode {
|
||||||
|
|
|
@ -317,7 +317,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
||||||
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
|
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
|
||||||
|
|
||||||
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
|
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
|
||||||
fn CreateOscillator(&self) -> DomRoot<OscillatorNode> {
|
fn CreateOscillator(&self) -> Fallible<DomRoot<OscillatorNode>> {
|
||||||
OscillatorNode::new(
|
OscillatorNode::new(
|
||||||
&self.global().as_window(),
|
&self.global().as_window(),
|
||||||
&self,
|
&self,
|
||||||
|
@ -326,7 +326,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain
|
/// 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())
|
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
|
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource
|
||||||
fn CreateBufferSource(&self) -> DomRoot<AudioBufferSourceNode> {
|
fn CreateBufferSource(&self) -> Fallible<DomRoot<AudioBufferSourceNode>> {
|
||||||
AudioBufferSourceNode::new(
|
AudioBufferSourceNode::new(
|
||||||
&self.global().as_window(),
|
&self.global().as_window(),
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl ChannelMergerNode {
|
||||||
&node_options,
|
&node_options,
|
||||||
options.numberOfInputs, // inputs
|
options.numberOfInputs, // inputs
|
||||||
1, // outputs
|
1, // outputs
|
||||||
);
|
)?;
|
||||||
Ok(ChannelMergerNode {
|
Ok(ChannelMergerNode {
|
||||||
node,
|
node,
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl GainNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &GainOptions,
|
options: &GainOptions,
|
||||||
) -> GainNode {
|
) -> Fallible<GainNode> {
|
||||||
let mut node_options = AudioNodeOptions::empty();
|
let mut node_options = AudioNodeOptions::empty();
|
||||||
let count = options.parent.channelCount.unwrap_or(2);
|
let count = options.parent.channelCount.unwrap_or(2);
|
||||||
let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Max);
|
let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Max);
|
||||||
|
@ -45,7 +45,7 @@ impl GainNode {
|
||||||
&node_options,
|
&node_options,
|
||||||
1, // inputs
|
1, // inputs
|
||||||
1, // outputs
|
1, // outputs
|
||||||
);
|
)?;
|
||||||
let gain = AudioParam::new(
|
let gain = AudioParam::new(
|
||||||
window,
|
window,
|
||||||
context,
|
context,
|
||||||
|
@ -56,10 +56,10 @@ impl GainNode {
|
||||||
f32::MIN, // min value
|
f32::MIN, // min value
|
||||||
f32::MAX, // max value
|
f32::MAX, // max value
|
||||||
);
|
);
|
||||||
GainNode {
|
Ok(GainNode {
|
||||||
node,
|
node,
|
||||||
gain: Dom::from_ref(&gain),
|
gain: Dom::from_ref(&gain),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
@ -67,9 +67,9 @@ impl GainNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &GainOptions,
|
options: &GainOptions,
|
||||||
) -> DomRoot<GainNode> {
|
) -> Fallible<DomRoot<GainNode>> {
|
||||||
let node = GainNode::new_inherited(window, context, options);
|
let node = GainNode::new_inherited(window, context, options)?;
|
||||||
reflect_dom_object(Box::new(node), window, GainNodeBinding::Wrap)
|
Ok(reflect_dom_object(Box::new(node), window, GainNodeBinding::Wrap))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Constructor(
|
pub fn Constructor(
|
||||||
|
@ -77,7 +77,7 @@ impl GainNode {
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &GainOptions,
|
options: &GainOptions,
|
||||||
) -> Fallible<DomRoot<GainNode>> {
|
) -> Fallible<DomRoot<GainNode>> {
|
||||||
Ok(GainNode::new(window, context, options))
|
GainNode::new(window, context, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl OscillatorNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
oscillator_options: &OscillatorOptions,
|
oscillator_options: &OscillatorOptions,
|
||||||
) -> OscillatorNode {
|
) -> Fallible<OscillatorNode> {
|
||||||
let mut node_options = AudioNodeOptions::empty();
|
let mut node_options = AudioNodeOptions::empty();
|
||||||
node_options.channelCount = Some(2);
|
node_options.channelCount = Some(2);
|
||||||
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||||
|
@ -46,7 +46,7 @@ impl OscillatorNode {
|
||||||
&node_options,
|
&node_options,
|
||||||
0, /* inputs */
|
0, /* inputs */
|
||||||
1, /* outputs */
|
1, /* outputs */
|
||||||
);
|
)?;
|
||||||
let node_id = source_node.node().node_id();
|
let node_id = source_node.node().node_id();
|
||||||
let frequency = AudioParam::new(
|
let frequency = AudioParam::new(
|
||||||
window,
|
window,
|
||||||
|
@ -69,12 +69,12 @@ impl OscillatorNode {
|
||||||
440. / 2.,
|
440. / 2.,
|
||||||
);
|
);
|
||||||
|
|
||||||
OscillatorNode {
|
Ok(OscillatorNode {
|
||||||
source_node,
|
source_node,
|
||||||
oscillator_type: oscillator_options.type_,
|
oscillator_type: oscillator_options.type_,
|
||||||
frequency: Dom::from_ref(&frequency),
|
frequency: Dom::from_ref(&frequency),
|
||||||
detune: Dom::from_ref(&detune),
|
detune: Dom::from_ref(&detune),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
@ -82,9 +82,9 @@ impl OscillatorNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &OscillatorOptions,
|
options: &OscillatorOptions,
|
||||||
) -> DomRoot<OscillatorNode> {
|
) -> Fallible<DomRoot<OscillatorNode>> {
|
||||||
let node = OscillatorNode::new_inherited(window, context, options);
|
let node = OscillatorNode::new_inherited(window, context, options)?;
|
||||||
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
|
Ok(reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Constructor(
|
pub fn Constructor(
|
||||||
|
@ -92,7 +92,7 @@ impl OscillatorNode {
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
options: &OscillatorOptions,
|
options: &OscillatorOptions,
|
||||||
) -> Fallible<DomRoot<OscillatorNode>> {
|
) -> Fallible<DomRoot<OscillatorNode>> {
|
||||||
Ok(OscillatorNode::new(window, context, options))
|
OscillatorNode::new(window, context, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl PannerNode {
|
||||||
&node_options,
|
&node_options,
|
||||||
1, // inputs
|
1, // inputs
|
||||||
1, // outputs
|
1, // outputs
|
||||||
);
|
)?;
|
||||||
let id = node.node_id();
|
let id = node.node_id();
|
||||||
let position_x = AudioParam::new(
|
let position_x = AudioParam::new(
|
||||||
window,
|
window,
|
||||||
|
|
|
@ -30,13 +30,13 @@ interface BaseAudioContext : EventTarget {
|
||||||
Promise<AudioBuffer> decodeAudioData(ArrayBuffer audioData,
|
Promise<AudioBuffer> decodeAudioData(ArrayBuffer audioData,
|
||||||
optional DecodeSuccessCallback successCallback,
|
optional DecodeSuccessCallback successCallback,
|
||||||
optional DecodeErrorCallback errorCallback);
|
optional DecodeErrorCallback errorCallback);
|
||||||
AudioBufferSourceNode createBufferSource();
|
[Throws] AudioBufferSourceNode createBufferSource();
|
||||||
// ConstantSourceNode createConstantSource();
|
// ConstantSourceNode createConstantSource();
|
||||||
// ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
|
// ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
|
||||||
// optional unsigned long numberOfInputChannels = 2,
|
// optional unsigned long numberOfInputChannels = 2,
|
||||||
// optional unsigned long numberOfOutputChannels = 2);
|
// optional unsigned long numberOfOutputChannels = 2);
|
||||||
// AnalyserNode createAnalyser();
|
// AnalyserNode createAnalyser();
|
||||||
GainNode createGain();
|
[Throws] GainNode createGain();
|
||||||
// DelayNode createDelay(optional double maxDelayTime = 1);
|
// DelayNode createDelay(optional double maxDelayTime = 1);
|
||||||
// BiquadFilterNode createBiquadFilter();
|
// BiquadFilterNode createBiquadFilter();
|
||||||
// IIRFilterNode createIIRFilter(sequence<double> feedforward,
|
// IIRFilterNode createIIRFilter(sequence<double> feedforward,
|
||||||
|
@ -48,7 +48,7 @@ interface BaseAudioContext : EventTarget {
|
||||||
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
|
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
|
||||||
// ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
|
// ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
|
||||||
// DynamicsCompressorNode createDynamicsCompressor();
|
// DynamicsCompressorNode createDynamicsCompressor();
|
||||||
OscillatorNode createOscillator();
|
[Throws] OscillatorNode createOscillator();
|
||||||
// PeriodicWave createPeriodicWave(sequence<float> real,
|
// PeriodicWave createPeriodicWave(sequence<float> real,
|
||||||
// sequence<float> imag,
|
// sequence<float> imag,
|
||||||
// optional PeriodicWaveConstraints constraints);
|
// optional PeriodicWaveConstraints constraints);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue