mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 17:19:13 +00:00
LibWeb: Implement OscillatorNode.type
This is a simple getter and setter of the OscillatorType enum, with error checking to not allow 'custom', as that should only be changed through 'setPeriodicWave()'.
This commit is contained in:
parent
b48ba823b9
commit
099c9e4a7e
Notes:
sideshowbarker
2024-07-16 20:08:14 +09:00
Author: https://github.com/shannonbooth
Commit: 099c9e4a7e
Pull-request: https://github.com/SerenityOS/serenity/pull/24195
5 changed files with 61 additions and 2 deletions
|
@ -23,7 +23,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> OscillatorNode::create(JS:
|
|||
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);
|
||||
TRY(verify_valid_type(realm, options.type));
|
||||
auto node = realm.vm().heap().allocate<OscillatorNode>(realm, realm, context, options);
|
||||
return node;
|
||||
}
|
||||
|
||||
OscillatorNode::OscillatorNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, OscillatorOptions const&)
|
||||
|
@ -31,6 +33,33 @@ OscillatorNode::OscillatorNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioConte
|
|||
{
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
|
||||
Bindings::OscillatorType OscillatorNode::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
|
||||
WebIDL::ExceptionOr<void> OscillatorNode::verify_valid_type(JS::Realm& realm, Bindings::OscillatorType type)
|
||||
{
|
||||
// The shape of the periodic waveform. It may directly be set to any of the type constant values except
|
||||
// for "custom". ⌛ Doing so MUST throw an InvalidStateError exception. The setPeriodicWave() method can
|
||||
// be used to set a custom waveform, which results in this attribute being set to "custom". The default
|
||||
// value is "sine". When this attribute is set, the phase of the oscillator MUST be conserved.
|
||||
if (type == Bindings::OscillatorType::Custom)
|
||||
return WebIDL::InvalidStateError::create(realm, "Oscillator node type cannot be set to 'custom'"_fly_string);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
|
||||
WebIDL::ExceptionOr<void> OscillatorNode::set_type(Bindings::OscillatorType type)
|
||||
{
|
||||
TRY(verify_valid_type(realm(), type));
|
||||
m_type = type;
|
||||
return {};
|
||||
}
|
||||
|
||||
void OscillatorNode::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue