Browse Source

LibWeb: Implement BaseAudioContext.createOscillator

Which currently will always throw an exception as it is unimplemented
under the hood - but this gives all of the plumbing we need in order to
create a oscillator node as used in the reduced turnstyle testcase.
Shannon Booth 1 year ago
parent
commit
1678f43c38

+ 8 - 0
Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp

@@ -9,6 +9,7 @@
 #include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/HTML/EventNames.h>
 #include <LibWeb/WebAudio/BaseAudioContext.h>
+#include <LibWeb/WebAudio/OscillatorNode.h>
 
 namespace Web::WebAudio {
 
@@ -35,6 +36,13 @@ WebIDL::CallbackType* BaseAudioContext::onstatechange()
     return event_handler_attribute(HTML::EventNames::statechange);
 }
 
+// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
+WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> BaseAudioContext::create_oscillator()
+{
+    // Factory method for an OscillatorNode.
+    return OscillatorNode::create(realm(), *this);
+}
+
 // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
 WebIDL::ExceptionOr<void> BaseAudioContext::verify_audio_options_inside_nominal_range(JS::Realm& realm, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate)
 {

+ 2 - 0
Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h

@@ -44,6 +44,8 @@ public:
 
     static WebIDL::ExceptionOr<void> verify_audio_options_inside_nominal_range(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
 
+    WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> create_oscillator();
+
 protected:
     explicit BaseAudioContext(JS::Realm&);
 

+ 2 - 1
Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl

@@ -1,5 +1,6 @@
 #import <DOM/EventTarget.idl>
 #import <DOM/EventHandler.idl>
+#import <WebAudio/OscillatorNode.idl>
 
 // https://www.w3.org/TR/webaudio/#enumdef-audiocontextstate
 enum AudioContextState { "suspended", "running", "closed" };
@@ -32,7 +33,7 @@ interface BaseAudioContext : EventTarget {
     // FIXME: DynamicsCompressorNode createDynamicsCompressor ();
     // FIXME: GainNode createGain ();
     // FIXME: IIRFilterNode createIIRFilter (sequence<double> feedforward, sequence<double> feedback);
-    // FIXME: OscillatorNode createOscillator ();
+    OscillatorNode createOscillator();
     // FIXME: PannerNode createPanner ();
     // FIXME: PeriodicWave createPeriodicWave (sequence<float> real, sequence<float> imag, optional PeriodicWaveConstraints constraints = {});
     // FIXME: ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);