mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-15 23:01:52 +00:00
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:
parent
b81d6945dc
commit
fd27eef0d1
Notes:
github-actions[bot]
2025-01-22 12:34:57 +00:00
Author: https://github.com/shannonbooth
Commit: fd27eef0d1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3339
Reviewed-by: https://github.com/AtkinsSJ ✅
18 changed files with 63 additions and 65 deletions
|
@ -205,7 +205,7 @@ URL::URL EnvironmentSettingsObject::parse_url(StringView url)
|
|||
auto base_url = api_base_url();
|
||||
|
||||
// 2. Return the result of applying the URL parser to url, with baseURL.
|
||||
return DOMURL::parse(url, base_url);
|
||||
return DOMURL::parse(url, base_url).value_or(URL::URL {});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url
|
||||
|
@ -225,7 +225,7 @@ URL::URL EnvironmentSettingsObject::encoding_parse_url(StringView url)
|
|||
auto base_url = api_base_url();
|
||||
|
||||
// 5. Return the result of applying the URL parser to url, with baseURL and encoding.
|
||||
return DOMURL::parse(url, base_url, encoding);
|
||||
return DOMURL::parse(url, base_url, encoding).value_or(URL::URL {});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-and-serializing-a-url
|
||||
|
|
|
@ -221,15 +221,15 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
|
|||
|
||||
// 6. If url is failure, then throw a TypeError indicating that resolution of normalizedSpecifier was blocked since the afterPrefix portion
|
||||
// could not be URL-parsed relative to the resolutionResult mapped to by the specifierKey prefix.
|
||||
if (!url.is_valid())
|
||||
if (!url.has_value())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as the after prefix portion could not be URL-parsed.", normalized_specifier).release_value_but_fixme_should_propagate_errors() };
|
||||
|
||||
// 7. Assert: url is a URL.
|
||||
VERIFY(url.is_valid());
|
||||
VERIFY(url.has_value());
|
||||
|
||||
// 8. If the serialization of resolutionResult is not a code unit prefix of the serialization of url, then throw a TypeError indicating
|
||||
// that the resolution of normalizedSpecifier was blocked due to it backtracking above its prefix specifierKey.
|
||||
if (!Infra::is_code_unit_prefix(resolution_result->serialize(), url.serialize()))
|
||||
if (!Infra::is_code_unit_prefix(resolution_result->serialize(), url->serialize()))
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as it backtracks above its prefix specifierKey.", normalized_specifier).release_value_but_fixme_should_propagate_errors() };
|
||||
|
||||
// 9. Return url.
|
||||
|
@ -250,7 +250,7 @@ Optional<URL::URL> resolve_url_like_module_specifier(ByteString const& specifier
|
|||
auto url = DOMURL::parse(specifier, base_url);
|
||||
|
||||
// 2. If url is failure, then return null.
|
||||
if (!url.is_valid())
|
||||
if (!url.has_value())
|
||||
return {};
|
||||
|
||||
// 3. Return url.
|
||||
|
@ -261,7 +261,7 @@ Optional<URL::URL> resolve_url_like_module_specifier(ByteString const& specifier
|
|||
auto url = DOMURL::parse(specifier);
|
||||
|
||||
// 3. If url is failure, then return null.
|
||||
if (!url.is_valid())
|
||||
if (!url.has_value())
|
||||
return {};
|
||||
|
||||
// 4. Return url.
|
||||
|
|
|
@ -202,7 +202,7 @@ WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_sc
|
|||
auto scope_prefix_url = DOMURL::parse(scope_prefix.as_string(), base_url);
|
||||
|
||||
// 3. If scopePrefixURL is failure, then:
|
||||
if (!scope_prefix_url.is_valid()) {
|
||||
if (!scope_prefix_url.has_value()) {
|
||||
// 1. The user agent may report a warning to the console that the scope prefix URL was not parseable.
|
||||
auto& console = realm.intrinsics().console_object()->console();
|
||||
console.output_debug_message(JS::Console::LogLevel::Warn,
|
||||
|
@ -213,7 +213,7 @@ WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_sc
|
|||
}
|
||||
|
||||
// 4. Let normalizedScopePrefix be the serialization of scopePrefixURL.
|
||||
auto normalised_scope_prefix = scope_prefix_url.serialize();
|
||||
auto normalised_scope_prefix = scope_prefix_url->serialize();
|
||||
|
||||
// 5. Set normalized[normalizedScopePrefix] to the result of sorting and normalizing a module specifier map given potentialSpecifierMap and baseURL.
|
||||
normalised.set(normalised_scope_prefix, TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue