diff --git a/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp b/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp index b694cf8cece..3980ebab55a 100644 --- a/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp +++ b/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp @@ -31,7 +31,22 @@ AudioBufferSourceNode::~AudioBufferSourceNode() = default; // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer WebIDL::ExceptionOr AudioBufferSourceNode::set_buffer(GC::Ptr buffer) { - m_buffer = buffer; + // 1. Let new buffer be the AudioBuffer or null value to be assigned to buffer. + auto new_buffer = buffer; + + // 2. If new buffer is not null and [[buffer set]] is true, throw an InvalidStateError and abort these steps. + if (new_buffer && m_buffer_set) + return WebIDL::InvalidStateError::create(realm(), "Buffer has already been set"_string); + + // 3. If new buffer is not null, set [[buffer set]] to true. + if (new_buffer) + m_buffer_set = true; + + // 4. Assign new buffer to the buffer attribute. + m_buffer = new_buffer; + + // FIXME: 5. If start() has previously been called on this node, perform the operation acquire the content on buffer. + return {}; } diff --git a/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h b/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h index 69517bf5d7b..e0fb0782fe5 100644 --- a/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h +++ b/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h @@ -60,6 +60,8 @@ private: GC::Ref m_playback_rate; GC::Ref m_detune; bool m_loop { false }; + // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer-set-slot + bool m_buffer_set { false }; double m_loop_start { 0.0 }; double m_loop_end { 0.0 }; }; diff --git a/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.txt b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.txt new file mode 100644 index 00000000000..d21f0791922 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.txt @@ -0,0 +1,27 @@ +Harness status: OK + +Found 22 tests + +22 Pass +Pass # AUDIT TASK RUNNER STARTED. +Pass Executing "validate .buffer" +Pass Audit report +Pass > [validate .buffer] Validatation of AudioBuffer in .buffer attribute setter +Pass source.buffer = 57 threw TypeError: "Not an object of type AudioBuffer". +Pass source.buffer = null did not throw an exception. +Pass source.buffer = buffer did not throw an exception. +Pass source.buffer = new buffer threw InvalidStateError: "Buffer has already been set". +Pass source.buffer = null again did not throw an exception. +Pass source.buffer = buffer again threw InvalidStateError: "Buffer has already been set". +Pass source.buffer = null after setting to null did not throw an exception. +Pass Setting source with mono buffer did not throw an exception. +Pass Setting source with stereo buffer did not throw an exception. +Pass Setting source with 3 channels buffer did not throw an exception. +Pass Setting source with 4 channels buffer did not throw an exception. +Pass Setting source with 5 channels buffer did not throw an exception. +Pass Setting source with 6 channels buffer did not throw an exception. +Pass Setting source with 7 channels buffer did not throw an exception. +Pass Setting source with 8 channels buffer did not throw an exception. +Pass Setting source with 9 channels buffer did not throw an exception. +Pass < [validate .buffer] All assertions passed. (total 16 assertions) +Pass # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.html b/Tests/LibWeb/Text/input/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.html new file mode 100644 index 00000000000..e37f932c6eb --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels.html @@ -0,0 +1,97 @@ + + + + + audiobuffersource-channels.html + + + + + + + + + +