LibWeb: Port Document encoding_parse_url and parse_url to Optional<URL>

This ports two more APIs away from URL::is_valid.
This commit is contained in:
Shannon Booth 2025-01-23 19:40:57 +13:00 committed by Tim Ledbetter
parent cfe9b7a82b
commit 22a7cd9700
Notes: github-actions[bot] 2025-01-27 00:04:07 +00:00
26 changed files with 135 additions and 107 deletions

View file

@ -625,14 +625,14 @@ public:
// would have resulted from parsing the URL specified by candidate's src attribute's value relative to the
// candidate's node document when the src attribute was last changed.
auto url_record = m_candidate->document().parse_url(candiate_src);
auto url_string = url_record.to_string();
// 4. ⌛ If urlString was not obtained successfully, then end the synchronous section, and jump down to the failed
// with elements step below.
if (!url_record.is_valid()) {
if (!url_record.has_value()) {
TRY(failed_with_elements());
return {};
}
auto url_string = url_record->to_string();
// FIXME: 5. ⌛ If candidate has a type attribute whose value, when parsed as a MIME type (including any codecs described
// by the codecs parameter, for types that define that parameter), represents a type that the user agent knows
@ -645,7 +645,7 @@ public:
// 8. Run the resource fetch algorithm with urlRecord. If that algorithm returns without aborting this one, then
// the load failed.
TRY(m_media_element->fetch_resource(url_record, [this](auto) {
TRY(m_media_element->fetch_resource(*url_record, [this](auto) {
failed_with_elements().release_value_but_fixme_should_propagate_errors();
}));
@ -871,15 +871,15 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::select_resource()
auto url_record = document().parse_url(source);
// 3. ⌛ If urlString was obtained successfully, set the currentSrc attribute to urlString.
if (url_record.is_valid())
m_current_src = url_record.to_string();
if (url_record.has_value())
m_current_src = url_record->to_string();
// 4. End the synchronous section, continuing the remaining steps in parallel.
// 5. If urlRecord was obtained successfully, run the resource fetch algorithm with urlRecord. If that algorithm returns without aborting this one,
// then the load failed.
if (url_record.is_valid()) {
TRY(fetch_resource(url_record, move(failed_with_attribute)));
if (url_record.has_value()) {
TRY(fetch_resource(*url_record, move(failed_with_attribute)));
return {};
}