From 3b8cb83e04c74dae9c633c735204acf6305f0de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 30 Jul 2018 18:50:36 +0200 Subject: [PATCH] Make OfflineAudioContextOptions spec compliant --- components/script/dom/offlineaudiocontext.rs | 40 +++++++++---------- .../dom/webidls/OfflineAudioContext.webidl | 6 +-- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/components/script/dom/offlineaudiocontext.rs b/components/script/dom/offlineaudiocontext.rs index 24c4596b8be..4490d5df6f9 100644 --- a/components/script/dom/offlineaudiocontext.rs +++ b/components/script/dom/offlineaudiocontext.rs @@ -41,22 +41,32 @@ pub struct OfflineAudioContext { impl OfflineAudioContext { #[allow(unrooted_must_root)] - fn new_inherited(options: &OfflineAudioContextOptions) -> OfflineAudioContext { + fn new_inherited(channel_count: u32, + length: u32, + sample_rate: f32) -> OfflineAudioContext { + let options = ServoMediaOfflineAudioContextOptions { + channels: channel_count as u8, + length: length as usize, + sample_rate, + }; let context = BaseAudioContext::new_inherited( - BaseAudioContextOptions::OfflineAudioContext(options.into()), + BaseAudioContextOptions::OfflineAudioContext(options), ); OfflineAudioContext { context, - channel_count: options.numberOfChannels, - length: options.length, + channel_count, + length, rendering_started: Cell::new(false), pending_rendering_promise: Default::default(), } } #[allow(unrooted_must_root)] - fn new(window: &Window, options: &OfflineAudioContextOptions) -> DomRoot { - let context = OfflineAudioContext::new_inherited(options); + fn new(window: &Window, + channel_count: u32, + length: u32, + sample_rate: f32) -> DomRoot { + let context = OfflineAudioContext::new_inherited(channel_count, length, sample_rate); reflect_dom_object(Box::new(context), window, OfflineAudioContextBinding::Wrap) } @@ -64,7 +74,7 @@ impl OfflineAudioContext { window: &Window, options: &OfflineAudioContextOptions, ) -> Fallible> { - Ok(OfflineAudioContext::new(window, options)) + Ok(OfflineAudioContext::new(window, options.numberOfChannels, options.length, *options.sampleRate)) } pub fn Constructor_( @@ -82,11 +92,7 @@ impl OfflineAudioContext { return Err(Error::NotSupported); } - let mut options = OfflineAudioContextOptions::empty(); - options.numberOfChannels = number_of_channels; - options.length = length; - options.sampleRate = sample_rate; - Ok(OfflineAudioContext::new(window, &options)) + Ok(OfflineAudioContext::new(window, number_of_channels, length, *sample_rate)) } } @@ -166,13 +172,3 @@ impl OfflineAudioContextMethods for OfflineAudioContext { promise } } - -impl<'a> From<&'a OfflineAudioContextOptions> for ServoMediaOfflineAudioContextOptions { - fn from(options: &OfflineAudioContextOptions) -> Self { - Self { - channels: options.numberOfChannels as u8, - length: options.length as usize, - sample_rate: *options.sampleRate, - } - } -} diff --git a/components/script/dom/webidls/OfflineAudioContext.webidl b/components/script/dom/webidls/OfflineAudioContext.webidl index 688d4ec6f0a..0155f9eb73d 100644 --- a/components/script/dom/webidls/OfflineAudioContext.webidl +++ b/components/script/dom/webidls/OfflineAudioContext.webidl @@ -8,12 +8,12 @@ dictionary OfflineAudioContextOptions { unsigned long numberOfChannels = 1; - unsigned long length = 0; - float sampleRate = 48000.; + required unsigned long length; + required float sampleRate; }; [Exposed=Window, - Constructor (optional OfflineAudioContextOptions contextOptions), + Constructor (OfflineAudioContextOptions contextOptions), Constructor (unsigned long numberOfChannels, unsigned long length, float sampleRate)] interface OfflineAudioContext : BaseAudioContext { readonly attribute unsigned long length;