WebContent: Protect the switch-to-window endpoint against null BCs

This is one of the few endpoints that does not ensure a top-level BC is
open. It's a bit of an implementation-defined endpoint, so let's protect
against a non-existent BC explicitly.
This commit is contained in:
Timothy Flynn 2024-09-16 17:29:07 -04:00 committed by Tim Ledbetter
commit c7db1204ca
Notes: github-actions[bot] 2024-09-16 23:05:36 +00:00

View file

@ -449,15 +449,17 @@ Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to
// Otherwise, return error with error code no such window.
bool found_matching_context = false;
current_top_level_browsing_context()->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) {
if (handle != context.top_level_traversable()->window_handle())
return Web::TraversalDecision::Continue;
if (auto browsing_context = current_top_level_browsing_context()) {
browsing_context->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) {
if (handle != context.top_level_traversable()->window_handle())
return Web::TraversalDecision::Continue;
m_current_browsing_context = context;
found_matching_context = true;
m_current_browsing_context = context;
found_matching_context = true;
return Web::TraversalDecision::Break;
});
return Web::TraversalDecision::Break;
});
}
if (!found_matching_context)
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");