From 97576d27b9cb05f123bec6a131c40b0324913606 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 29 Apr 2024 20:03:15 +1200 Subject: [PATCH] LibWeb: Add constructor for OscillatorNode This is still missing a bunch of spec steps to construct the audio node based on the parameters of the OscillatorNode, but it is at least enough to construct an object to be able to add a basic test which can get built upon as more is implemented. --- .../Text/expected/WebAudio/OscillatorNode.txt | 5 +++++ .../Text/input/WebAudio/OscillatorNode.html | 15 +++++++++++++++ Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp | 9 +++++++++ Userland/Libraries/LibWeb/WebAudio/AudioNode.h | 5 +++++ .../LibWeb/WebAudio/AudioScheduledSourceNode.cpp | 5 +++++ .../LibWeb/WebAudio/AudioScheduledSourceNode.h | 2 ++ .../Libraries/LibWeb/WebAudio/OscillatorNode.cpp | 10 ++++++++-- .../Libraries/LibWeb/WebAudio/OscillatorNode.h | 2 ++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt create mode 100644 Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html diff --git a/Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt b/Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt new file mode 100644 index 00000000000..a5005c94af9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt @@ -0,0 +1,5 @@ +OscillatorNode +AudioScheduledSourceNode +AudioNode +EventTarget +Object diff --git a/Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html b/Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html new file mode 100644 index 00000000000..493990015a0 --- /dev/null +++ b/Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html @@ -0,0 +1,15 @@ + + diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp index 7b8e84fe484..2b38985f4f6 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp @@ -6,11 +6,19 @@ #include #include +#include namespace Web::WebAudio { JS_DEFINE_ALLOCATOR(AudioNode); +AudioNode::AudioNode(JS::Realm& realm, JS::NonnullGCPtr context) + : DOM::EventTarget(realm) + , m_context(context) + +{ +} + AudioNode::~AudioNode() = default; // https://webaudio.github.io/web-audio-api/#dom-audionode-connect @@ -91,6 +99,7 @@ void AudioNode::initialize(JS::Realm& realm) void AudioNode::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); + visitor.visit(m_context); } } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h index 0f7572aa5d6..9bde71f4796 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h @@ -42,8 +42,13 @@ public: void disconnect(JS::NonnullGCPtr destination_param, WebIDL::UnsignedLong output); protected: + AudioNode(JS::Realm&, JS::NonnullGCPtr); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; + +private: + JS::NonnullGCPtr m_context; }; } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.cpp index 30c7677d69c..532814aee1c 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.cpp @@ -13,6 +13,11 @@ namespace Web::WebAudio { JS_DEFINE_ALLOCATOR(AudioScheduledSourceNode); +AudioScheduledSourceNode::AudioScheduledSourceNode(JS::Realm& realm, JS::NonnullGCPtr context) + : AudioNode(realm, context) +{ +} + AudioScheduledSourceNode::~AudioScheduledSourceNode() = default; // https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-onended diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.h b/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.h index 8c375c7671c..545398a3dde 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/AudioScheduledSourceNode.h @@ -25,6 +25,8 @@ public: WebIDL::ExceptionOr stop(double when = 0); protected: + AudioScheduledSourceNode(JS::Realm&, JS::NonnullGCPtr); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; }; diff --git a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp index bff58dbcacd..49d3e5e0f89 100644 --- a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp @@ -20,9 +20,15 @@ WebIDL::ExceptionOr> OscillatorNode::create(JS: } // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-oscillatornode -WebIDL::ExceptionOr> OscillatorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr, OscillatorOptions const&) +WebIDL::ExceptionOr> OscillatorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr context, OscillatorOptions const& options) +{ + // FIXME: Invoke "Initialize the AudioNode" steps. + return realm.vm().heap().allocate(realm, realm, context, options); +} + +OscillatorNode::OscillatorNode(JS::Realm& realm, JS::NonnullGCPtr context, OscillatorOptions const&) + : AudioScheduledSourceNode(realm, context) { - return WebIDL::NotSupportedError::create(realm, "FIXME: Implement OscillatorNode::construct_impl"_fly_string); } void OscillatorNode::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h index 9bfedcfd9fd..b254d567bbf 100644 --- a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h @@ -31,6 +31,8 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); protected: + OscillatorNode(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; };