mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Remove unsafe code to create empty AudioNodeOptions
This commit is contained in:
parent
b87fc17b4b
commit
911b8ebd79
4 changed files with 11 additions and 27 deletions
|
@ -7,12 +7,13 @@ use dom::audioparam::{AudioParam, AudioParamImpl};
|
|||
use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceNodeMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::
|
||||
AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::num::Finite;
|
||||
|
@ -46,13 +47,12 @@ pub struct AudioBufferSourceNode {
|
|||
|
||||
impl AudioBufferSourceNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
fn new_inherited(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
options: &AudioBufferSourceOptions,
|
||||
) -> AudioBufferSourceNode {
|
||||
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
||||
let mut node_options = AudioNodeOptions::empty();
|
||||
node_options.channelCount = Some(2);
|
||||
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
|
|
|
@ -86,7 +86,6 @@ pub struct BaseAudioContext {
|
|||
|
||||
impl BaseAudioContext {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new_inherited(
|
||||
global: &GlobalScope,
|
||||
options: BaseAudioContextOptions,
|
||||
|
@ -109,7 +108,7 @@ impl BaseAudioContext {
|
|||
state: Cell::new(AudioContextState::Suspended),
|
||||
};
|
||||
|
||||
let mut options = unsafe { AudioNodeOptions::empty(global.get_cx()) };
|
||||
let mut options = AudioNodeOptions::empty();
|
||||
options.channelCount = Some(2);
|
||||
options.channelCountMode = Some(ChannelCountMode::Explicit);
|
||||
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
|
@ -287,21 +286,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
|||
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
|
||||
#[allow(unsafe_code)]
|
||||
fn CreateOscillator(&self) -> DomRoot<OscillatorNode> {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let options = unsafe { OscillatorOptions::empty(window.get_cx()) };
|
||||
OscillatorNode::new(&window, &self, &options)
|
||||
OscillatorNode::new(&self.global().as_window(), &self, &OscillatorOptions::empty())
|
||||
}
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain
|
||||
#[allow(unsafe_code)]
|
||||
fn CreateGain(&self) -> DomRoot<GainNode> {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let options = unsafe { GainOptions::empty(window.get_cx()) };
|
||||
GainNode::new(&window, &self, &options)
|
||||
GainNode::new(&self.global().as_window(), &self, &GainOptions::empty())
|
||||
}
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
|
||||
|
@ -315,16 +306,11 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
|||
*sample_rate <= 0. {
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
let global = self.global();
|
||||
Ok(AudioBuffer::new(&global.as_window(), number_of_channels, length, *sample_rate, None))
|
||||
Ok(AudioBuffer::new(&self.global().as_window(), number_of_channels, length, *sample_rate, None))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn CreateBufferSource(&self) -> DomRoot<AudioBufferSourceNode> {
|
||||
let global = self.global();
|
||||
// XXX Can we do this implementing Default?
|
||||
let options = unsafe { AudioBufferSourceOptions::empty(global.get_cx()) };
|
||||
AudioBufferSourceNode::new(&global.as_window(), &self, &options)
|
||||
AudioBufferSourceNode::new(&self.global().as_window(), &self, &AudioBufferSourceOptions::empty())
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
|
|
|
@ -31,14 +31,13 @@ pub struct GainNode {
|
|||
}
|
||||
|
||||
impl GainNode {
|
||||
#[allow(unsafe_code)]
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
gain_options: &GainOptions,
|
||||
) -> GainNode {
|
||||
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
||||
let mut node_options = AudioNodeOptions::empty();
|
||||
node_options.channelCount = Some(2);
|
||||
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
|
|
|
@ -38,13 +38,12 @@ pub struct OscillatorNode {
|
|||
|
||||
impl OscillatorNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new_inherited(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
oscillator_options: &OscillatorOptions,
|
||||
) -> OscillatorNode {
|
||||
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
||||
let mut node_options = AudioNodeOptions::empty();
|
||||
node_options.channelCount = Some(2);
|
||||
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue