1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 11:28:11 +00:00

AK: Port URL::m_fragment from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-08-12 16:52:42 +12:00 committed by Andrew Kaster
parent 5663a2d3b4
commit 9d60f23abc
21 changed files with 68 additions and 76 deletions

View file

@ -1167,7 +1167,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
// and resource's URL's fragment is non-null, then:
if (history_handling != HistoryHandlingBehavior::Reload
&& resource->url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes)
&& !resource->url().fragment().is_null()) {
&& resource->url().fragment().has_value()) {
// 1. Navigate to a fragment given browsingContext, resource's URL, historyHandling, and navigationId.
TRY(navigate_to_a_fragment(resource->url(), history_handling, *navigation_id));
@ -1406,7 +1406,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_ind
}
// 10. If entry's persisted user state is null, and its URL's fragment is non-null, then scroll to the fragment.
if (!entry->url.fragment().is_null())
if (entry->url.fragment().has_value())
active_document()->scroll_to_the_fragment();
// 11. Set the current entry to entry.

View file

@ -378,11 +378,11 @@ DeprecatedString HTMLHyperlinkElementUtils::hash() const
// 2. Let url be this element's url.
// 3. If url is null, or url's fragment is either null or the empty string, return the empty string.
if (!m_url.has_value() || m_url->fragment().is_null() || m_url->fragment().is_empty())
if (!m_url.has_value() || !m_url->fragment().has_value() || m_url->fragment()->is_empty())
return DeprecatedString::empty();
// 4. Return "#", followed by url's fragment.
return DeprecatedString::formatted("#{}", m_url->fragment());
return DeprecatedString::formatted("#{}", *m_url->fragment());
}
void HTMLHyperlinkElementUtils::set_hash(DeprecatedString hash)
@ -406,7 +406,7 @@ void HTMLHyperlinkElementUtils::set_hash(DeprecatedString hash)
// 2. Set url's fragment to the empty string.
auto url_copy = m_url; // We copy the URL here to follow other browser's behavior of reverting the hash change if the parse failed.
url_copy->set_fragment(DeprecatedString::empty());
url_copy->set_fragment(String {});
// 3. Basic URL parse input, with url as url and fragment state as state override.
auto result_url = URLParser::basic_parse(input, {}, move(url_copy), URLParser::State::Fragment);

View file

@ -279,11 +279,11 @@ WebIDL::ExceptionOr<String> Location::hash() const
auto url = this->url();
// 2. If this's url's fragment is either null or the empty string, return the empty string.
if (url.fragment().is_empty())
if (!url.fragment().has_value() || url.fragment()->is_empty())
return String {};
// 3. Return "#", followed by this's url's fragment.
return TRY_OR_THROW_OOM(vm, String::formatted("#{}", url.fragment()));
return TRY_OR_THROW_OOM(vm, String::formatted("#{}", *url.fragment()));
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hash
@ -307,7 +307,7 @@ WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left);
// 5. Set copyURL's fragment to the empty string.
copy_url.set_fragment(""sv);
copy_url.set_fragment(String {});
// 6. Basic URL parse input, with copyURL as url and fragment state as state override.
auto result_url = URLParser::basic_parse(input, {}, copy_url, URLParser::State::Fragment);

View file

@ -543,9 +543,7 @@ static WebIDL::ExceptionOr<Optional<NavigationParams>> create_navigation_params_
response_origin = determine_the_origin(*response->url(), final_sandbox_flags, entry->document_state->initiator_origin(), {});
// 14. Set locationURL to response's location URL given currentURL's fragment.
auto const& fragment = current_url.fragment();
auto fragment_string = fragment.is_null() ? Optional<String> {} : TRY_OR_THROW_OOM(vm, String::from_deprecated_string(fragment));
auto location_url = response->location_url(fragment_string);
auto location_url = response->location_url(current_url.fragment());
VERIFY(!location_url.is_error());
@ -844,7 +842,7 @@ WebIDL::ExceptionOr<void> Navigable::navigate(
if (document_resource.has<Empty>()
&& !response
&& url.equals(active_session_history_entry()->url, AK::URL::ExcludeFragment::Yes)
&& !url.fragment().is_null()) {
&& url.fragment().has_value()) {
// 1. Navigate to a fragment given navigable, url, historyHandling, and navigationId.
TRY(navigate_to_a_fragment(url, history_handling, navigation_id));

View file

@ -123,11 +123,11 @@ WebIDL::ExceptionOr<String> WorkerLocation::hash() const
auto const& fragment = m_global_scope->url().fragment();
// 2. If fragment is either null or the empty string, return the empty string.
if (fragment.is_empty())
if (!fragment.has_value() || fragment->is_empty())
return String {};
// 3. Return "#", followed by fragment.
return TRY_OR_THROW_OOM(vm, String::formatted("#{}", fragment.view()));
return TRY_OR_THROW_OOM(vm, String::formatted("#{}", *fragment));
}
WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope)