diff --git a/Libraries/LibWeb/WebAudio/AudioNode.cpp b/Libraries/LibWeb/WebAudio/AudioNode.cpp index 6ce11238bb9..8a5cf702cc8 100644 --- a/Libraries/LibWeb/WebAudio/AudioNode.cpp +++ b/Libraries/LibWeb/WebAudio/AudioNode.cpp @@ -59,18 +59,35 @@ WebIDL::ExceptionOr> AudioNode::connect(GC::Ref de return WebIDL::InvalidAccessError::create(realm(), "Cannot connect to an AudioNode in a different AudioContext"_string); } - (void)output; - (void)input; + // The output parameter is an index describing which output of the AudioNode from which to connect. + // If this parameter is out-of-bounds, an IndexSizeError exception MUST be thrown. + if (output >= number_of_outputs()) { + return WebIDL::IndexSizeError::create(realm(), MUST(String::formatted("Output index {} exceeds number of outputs", output))); + } + + // The input parameter is an index describing which input of the destination AudioNode to connect to. + // If this parameter is out-of-bounds, an IndexSizeError exception MUST be thrown. + if (input >= destination_node->number_of_inputs()) { + return WebIDL::IndexSizeError::create(realm(), MUST(String::formatted("Input index '{}' exceeds number of inputs", input))); + } + dbgln("FIXME: Implement Audio::connect(AudioNode)"); return destination_node; } // https://webaudio.github.io/web-audio-api/#dom-audionode-connect-destinationparam-output -void AudioNode::connect(GC::Ref destination_param, WebIDL::UnsignedLong output) +WebIDL::ExceptionOr AudioNode::connect(GC::Ref destination_param, WebIDL::UnsignedLong output) { (void)destination_param; - (void)output; + + // The output parameter is an index describing which output of the AudioNode from which to connect. + // If the parameter is out-of-bounds, an IndexSizeError exception MUST be thrown. + if (output >= number_of_outputs()) { + return WebIDL::IndexSizeError::create(realm(), MUST(String::formatted("Output index {} exceeds number of outputs", output))); + } + dbgln("FIXME: Implement AudioNode::connect(AudioParam)"); + return {}; } // https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect diff --git a/Libraries/LibWeb/WebAudio/AudioNode.h b/Libraries/LibWeb/WebAudio/AudioNode.h index 4509c87bd69..d854f5a88f5 100644 --- a/Libraries/LibWeb/WebAudio/AudioNode.h +++ b/Libraries/LibWeb/WebAudio/AudioNode.h @@ -37,7 +37,7 @@ public: virtual ~AudioNode() override; WebIDL::ExceptionOr> connect(GC::Ref destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0); - void connect(GC::Ref destination_param, WebIDL::UnsignedLong output = 0); + WebIDL::ExceptionOr connect(GC::Ref destination_param, WebIDL::UnsignedLong output = 0); void disconnect(); void disconnect(WebIDL::UnsignedLong output); diff --git a/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audionode-interface/audionode.txt b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audionode-interface/audionode.txt new file mode 100644 index 00000000000..9dec24c66f9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audionode-interface/audionode.txt @@ -0,0 +1,23 @@ +Harness status: OK + +Found 18 tests + +18 Pass +Pass # AUDIT TASK RUNNER STARTED. +Pass Executing "test" +Pass Audit report +Pass > [test] Basic tests for AudioNode API. +Pass AudioBufferSource.numberOfInputs is equal to 0. +Pass AudioBufferSource.numberOfOutputs is equal to 1. +Pass AudioContext.destination.numberOfInputs is equal to 1. +Pass AudioContext.destination.numberOfOutputs is equal to 1. +Pass audioNode.connect(0, 0, 0) threw TypeError: "Not an object of type AudioNode". +Pass audioNode.connect(null, 0, 0) threw TypeError: "Not an object of type AudioNode". +Pass audioNode.connect(context.destination, 5, 0) threw IndexSizeError: "Output index 5 exceeds number of outputs". +Pass audioNode.connect(context.destination, 0, 5) threw IndexSizeError: "Input index '5' exceeds number of inputs". +Pass audioNode.connect(context.destination, 0, 0) did not throw an exception. +Pass Connecting a node to a different context threw InvalidAccessError: "Cannot connect to an AudioNode in a different AudioContext". +Pass context3 = new AudioContext(1, 44100, 44100) threw TypeError: "Not an object of type AudioContextOptions". +Pass AudioNode is an EventTarget is true. +Pass < [test] All assertions passed. (total 12 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-audionode-interface/audionode.html b/Tests/LibWeb/Text/input/wpt-import/webaudio/the-audio-api/the-audionode-interface/audionode.html new file mode 100644 index 00000000000..b75ff06b4d8 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/webaudio/the-audio-api/the-audionode-interface/audionode.html @@ -0,0 +1,93 @@ + + + + + audionode.html + + + + + + + +
+
+ + +