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.
This commit is contained in:
Shannon Booth 2024-04-29 20:03:15 +12:00 committed by Andreas Kling
parent c8821cf8e0
commit 97576d27b9
Notes: sideshowbarker 2024-07-17 08:37:36 +09:00
8 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,5 @@
OscillatorNode
AudioScheduledSourceNode
AudioNode
EventTarget
Object

View File

@ -0,0 +1,15 @@
<script src="../include.js"></script>
<script>
test(() => {
const audioContext = new OfflineAudioContext(1, 5000, 44100);
const oscillator = audioContext.createOscillator();
let prototype = Object.getPrototypeOf(oscillator);
while (prototype) {
println(prototype.constructor.name);
prototype = Object.getPrototypeOf(prototype);
}
});
</script>

View File

@ -6,11 +6,19 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/WebAudio/AudioNode.h>
#include <LibWeb/WebAudio/BaseAudioContext.h>
namespace Web::WebAudio {
JS_DEFINE_ALLOCATOR(AudioNode);
AudioNode::AudioNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> 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);
}
}

View File

@ -42,8 +42,13 @@ public:
void disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output);
protected:
AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
private:
JS::NonnullGCPtr<BaseAudioContext> m_context;
};
}

View File

@ -13,6 +13,11 @@ namespace Web::WebAudio {
JS_DEFINE_ALLOCATOR(AudioScheduledSourceNode);
AudioScheduledSourceNode::AudioScheduledSourceNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context)
: AudioNode(realm, context)
{
}
AudioScheduledSourceNode::~AudioScheduledSourceNode() = default;
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-onended

View File

@ -25,6 +25,8 @@ public:
WebIDL::ExceptionOr<void> stop(double when = 0);
protected:
AudioScheduledSourceNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
};

View File

@ -20,9 +20,15 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> OscillatorNode::create(JS:
}
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-oscillatornode
WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> OscillatorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const&)
WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> OscillatorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, OscillatorOptions const& options)
{
// FIXME: Invoke "Initialize the AudioNode" steps.
return realm.vm().heap().allocate<OscillatorNode>(realm, realm, context, options);
}
OscillatorNode::OscillatorNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, OscillatorOptions const&)
: AudioScheduledSourceNode(realm, context)
{
return WebIDL::NotSupportedError::create(realm, "FIXME: Implement OscillatorNode::construct_impl"_fly_string);
}
void OscillatorNode::initialize(JS::Realm& realm)

View File

@ -31,6 +31,8 @@ public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
protected:
OscillatorNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
};