mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
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:
parent
c8821cf8e0
commit
97576d27b9
5
Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt
Normal file
5
Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
OscillatorNode
|
||||
AudioScheduledSourceNode
|
||||
AudioNode
|
||||
EventTarget
|
||||
Object
|
15
Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html
Normal file
15
Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html
Normal 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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue