LibWeb: Return OptionalNone from DOMURL::parse on failure

This ports one more function away from needing to use the awkward
valid state of the URL class.
This commit is contained in:
Shannon Booth 2025-01-22 17:35:52 +13:00 committed by Sam Atkins
commit fd27eef0d1
Notes: github-actions[bot] 2025-01-22 12:34:57 +00:00
18 changed files with 63 additions and 65 deletions

View file

@ -487,20 +487,20 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
auto parsed_url = DOMURL::parse(url, api_base_url, api_url_character_encoding);
// 6. If parsedURL is failure, then throw a "SyntaxError" DOMException.
if (!parsed_url.is_valid())
if (!parsed_url.has_value())
return WebIDL::SyntaxError::create(realm(), "Invalid URL"_string);
// 7. If the async argument is omitted, set async to true, and set username and password to null.
// NOTE: This is handled in the overload lacking the async argument.
// 8. If parsedURLs host is non-null, then:
if (parsed_url.host().has_value()) {
if (parsed_url->host().has_value()) {
// 1. If the username argument is not null, set the username given parsedURL and username.
if (username.has_value())
parsed_url.set_username(username.value());
parsed_url->set_username(username.value());
// 2. If the password argument is not null, set the password given parsedURL and password.
if (password.has_value())
parsed_url.set_password(password.value());
parsed_url->set_password(password.value());
}
// 9. If async is false, the current global object is a Window object, and either thiss timeout is
@ -523,7 +523,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
// Set thiss request method to method.
m_request_method = normalized_method.span();
// Set thiss request URL to parsedURL.
m_request_url = parsed_url;
m_request_url = parsed_url.release_value();
// Set thiss synchronous flag if async is false; otherwise unset thiss synchronous flag.
m_synchronous = !async;
// Empty thiss author request headers.