LibWeb: Validate AudioNode::connect() input and output arguments

This commit is contained in:
Tim Ledbetter 2025-01-04 02:21:16 +00:00 committed by Tim Ledbetter
commit 2edd0812ca
Notes: github-actions[bot] 2025-01-09 11:35:56 +00:00
4 changed files with 138 additions and 5 deletions

View file

@ -59,18 +59,35 @@ WebIDL::ExceptionOr<GC::Ref<AudioNode>> AudioNode::connect(GC::Ref<AudioNode> 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<AudioParam> destination_param, WebIDL::UnsignedLong output)
WebIDL::ExceptionOr<void> AudioNode::connect(GC::Ref<AudioParam> 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