diff --git a/components/script/dom/oscillatornode.rs b/components/script/dom/oscillatornode.rs index 8038b06237b..e2b33f4639e 100644 --- a/components/script/dom/oscillatornode.rs +++ b/components/script/dom/oscillatornode.rs @@ -13,23 +13,25 @@ use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorNo use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::{ self, OscillatorOptions, OscillatorType, }; -use crate::dom::bindings::error::Fallible; +use crate::dom::bindings::error::{Error, ErrorResult, Fallible}; use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::window::Window; use dom_struct::dom_struct; -use servo_media::audio::node::AudioNodeInit; +use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage}; +use servo_media::audio::oscillator_node::OscillatorNodeMessage; use servo_media::audio::oscillator_node::OscillatorNodeOptions as ServoMediaOscillatorOptions; use servo_media::audio::oscillator_node::OscillatorType as ServoMediaOscillatorType; use servo_media::audio::param::ParamType; +use std::cell::Cell; use std::f32; #[dom_struct] pub struct OscillatorNode { source_node: AudioScheduledSourceNode, - oscillator_type: OscillatorType, - frequency: Dom, detune: Dom, + frequency: Dom, + oscillator_type: Cell, } impl OscillatorNode { @@ -71,10 +73,9 @@ impl OscillatorNode { -440. / 2., 440. / 2., ); - Ok(OscillatorNode { source_node, - oscillator_type: options.type_, + oscillator_type: Cell::new(options.type_), frequency: Dom::from_ref(&frequency), detune: Dom::from_ref(&detune), }) @@ -113,6 +114,25 @@ impl OscillatorNodeMethods for OscillatorNode { fn Detune(&self) -> DomRoot { DomRoot::from_ref(&self.detune) } + + // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type + fn Type(&self) -> OscillatorType { + self.oscillator_type.get() + } + + // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type + fn SetType(&self, type_: OscillatorType) -> ErrorResult { + if type_ == OscillatorType::Custom { + return Err(Error::InvalidState); + } + self.oscillator_type.set(type_); + self.source_node + .node() + .message(AudioNodeMessage::OscillatorNode( + OscillatorNodeMessage::SetOscillatorType(type_.into()), + )); + return Ok(()); + } } impl<'a> From<&'a OscillatorOptions> for ServoMediaOscillatorOptions { diff --git a/components/script/dom/webidls/OscillatorNode.webidl b/components/script/dom/webidls/OscillatorNode.webidl index 263b8c29bae..510b87880a7 100644 --- a/components/script/dom/webidls/OscillatorNode.webidl +++ b/components/script/dom/webidls/OscillatorNode.webidl @@ -24,8 +24,8 @@ dictionary OscillatorOptions : AudioNodeOptions { [Exposed=Window, Constructor (BaseAudioContext context, optional OscillatorOptions options)] interface OscillatorNode : AudioScheduledSourceNode { -// [SetterThrows] -// attribute OscillatorType type; + [SetterThrows] + attribute OscillatorType type; readonly attribute AudioParam frequency; readonly attribute AudioParam detune; diff --git a/tests/wpt/metadata/webaudio/idlharness.https.window.js.ini b/tests/wpt/metadata/webaudio/idlharness.https.window.js.ini index 19c39cdb633..2557846cc75 100644 --- a/tests/wpt/metadata/webaudio/idlharness.https.window.js.ini +++ b/tests/wpt/metadata/webaudio/idlharness.https.window.js.ini @@ -41,9 +41,6 @@ [AudioWorkletNode interface: worklet_node must inherit property "port" with the proper type] expected: FAIL - [OscillatorNode interface: attribute type] - expected: FAIL - [AudioContext interface: operation suspend()] expected: FAIL @@ -140,9 +137,6 @@ [AudioNode interface: calling connect(AudioParam, unsigned long) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError] expected: FAIL - [OscillatorNode interface: new OscillatorNode(context) must inherit property "type" with the proper type] - expected: FAIL - [MediaStreamAudioDestinationNode interface: attribute stream] expected: FAIL