Remove unsafe code to create empty AudioNodeOptions

This commit is contained in:
Fernando Jiménez Moreno 2018-07-09 16:12:58 +02:00
parent b87fc17b4b
commit 911b8ebd79
4 changed files with 11 additions and 27 deletions

View file

@ -7,12 +7,13 @@ use dom::audioparam::{AudioParam, AudioParamImpl};
use dom::audioscheduledsourcenode::AudioScheduledSourceNode; use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
use dom::baseaudiocontext::BaseAudioContext; use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding; 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::AudioBufferSourceNodeMethods;
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceOptions;
use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate; use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions; use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation}; 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::error::{Error, Fallible};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
@ -46,13 +47,12 @@ pub struct AudioBufferSourceNode {
impl AudioBufferSourceNode { impl AudioBufferSourceNode {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
#[allow(unsafe_code)]
fn new_inherited( fn new_inherited(
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &AudioBufferSourceOptions, options: &AudioBufferSourceOptions,
) -> AudioBufferSourceNode { ) -> AudioBufferSourceNode {
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) }; 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);
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers); node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);

View file

@ -86,7 +86,6 @@ pub struct BaseAudioContext {
impl BaseAudioContext { impl BaseAudioContext {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
#[allow(unsafe_code)]
pub fn new_inherited( pub fn new_inherited(
global: &GlobalScope, global: &GlobalScope,
options: BaseAudioContextOptions, options: BaseAudioContextOptions,
@ -109,7 +108,7 @@ impl BaseAudioContext {
state: Cell::new(AudioContextState::Suspended), state: Cell::new(AudioContextState::Suspended),
}; };
let mut options = unsafe { AudioNodeOptions::empty(global.get_cx()) }; let mut options = AudioNodeOptions::empty();
options.channelCount = Some(2); options.channelCount = Some(2);
options.channelCountMode = Some(ChannelCountMode::Explicit); options.channelCountMode = Some(ChannelCountMode::Explicit);
options.channelInterpretation = Some(ChannelInterpretation::Speakers); options.channelInterpretation = Some(ChannelInterpretation::Speakers);
@ -287,21 +286,13 @@ 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
#[allow(unsafe_code)]
fn CreateOscillator(&self) -> DomRoot<OscillatorNode> { fn CreateOscillator(&self) -> DomRoot<OscillatorNode> {
let global = self.global(); OscillatorNode::new(&self.global().as_window(), &self, &OscillatorOptions::empty())
let window = global.as_window();
let options = unsafe { OscillatorOptions::empty(window.get_cx()) };
OscillatorNode::new(&window, &self, &options)
} }
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain /// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain
#[allow(unsafe_code)]
fn CreateGain(&self) -> DomRoot<GainNode> { fn CreateGain(&self) -> DomRoot<GainNode> {
let global = self.global(); GainNode::new(&self.global().as_window(), &self, &GainOptions::empty())
let window = global.as_window();
let options = unsafe { GainOptions::empty(window.get_cx()) };
GainNode::new(&window, &self, &options)
} }
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer /// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
@ -315,16 +306,11 @@ impl BaseAudioContextMethods for BaseAudioContext {
*sample_rate <= 0. { *sample_rate <= 0. {
return Err(Error::NotSupported); return Err(Error::NotSupported);
} }
let global = self.global(); Ok(AudioBuffer::new(&self.global().as_window(), number_of_channels, length, *sample_rate, None))
Ok(AudioBuffer::new(&global.as_window(), number_of_channels, length, *sample_rate, None))
} }
#[allow(unsafe_code)]
fn CreateBufferSource(&self) -> DomRoot<AudioBufferSourceNode> { fn CreateBufferSource(&self) -> DomRoot<AudioBufferSourceNode> {
let global = self.global(); AudioBufferSourceNode::new(&self.global().as_window(), &self, &AudioBufferSourceOptions::empty())
// XXX Can we do this implementing Default?
let options = unsafe { AudioBufferSourceOptions::empty(global.get_cx()) };
AudioBufferSourceNode::new(&global.as_window(), &self, &options)
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]

View file

@ -31,14 +31,13 @@ pub struct GainNode {
} }
impl GainNode { impl GainNode {
#[allow(unsafe_code)]
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new_inherited( pub fn new_inherited(
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
gain_options: &GainOptions, gain_options: &GainOptions,
) -> GainNode { ) -> GainNode {
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) }; 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);
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers); node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);

View file

@ -38,13 +38,12 @@ pub struct OscillatorNode {
impl OscillatorNode { impl OscillatorNode {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
#[allow(unsafe_code)]
pub fn new_inherited( pub fn new_inherited(
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
oscillator_options: &OscillatorOptions, oscillator_options: &OscillatorOptions,
) -> OscillatorNode { ) -> OscillatorNode {
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) }; 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);
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers); node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);