mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
AK: Port URL::m_fragment from DeprecatedString to String
This commit is contained in:
parent
5663a2d3b4
commit
9d60f23abc
21 changed files with 68 additions and 76 deletions
|
@ -1737,14 +1737,16 @@ Document::IndicatedPart Document::determine_the_indicated_part() const
|
|||
// For an HTML document document, the following processing model must be followed to determine its indicated part:
|
||||
|
||||
// 1. Let fragment be document's URL's fragment.
|
||||
auto fragment = url().fragment();
|
||||
VERIFY(url().fragment().has_value());
|
||||
|
||||
auto fragment = url().fragment().value();
|
||||
|
||||
// 2. If fragment is the empty string, then return the special value top of the document.
|
||||
if (fragment.is_empty())
|
||||
return Document::TopOfTheDocument {};
|
||||
|
||||
// 3. Let potentialIndicatedElement be the result of finding a potential indicated element given document and fragment.
|
||||
auto potential_indicated_element = find_a_potential_indicated_element(fragment);
|
||||
auto* potential_indicated_element = find_a_potential_indicated_element(fragment.to_deprecated_string());
|
||||
|
||||
// 4. If potentialIndicatedElement is not null, then return potentialIndicatedElement.
|
||||
if (potential_indicated_element)
|
||||
|
|
|
@ -1077,9 +1077,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> http_redirect_f
|
|||
: static_cast<Infrastructure::FilteredResponse const&>(response).internal_response();
|
||||
|
||||
// 3. Let locationURL be actualResponse’s location URL given request’s current URL’s fragment.
|
||||
auto const& fragment = request->current_url().fragment();
|
||||
auto fragment_string = fragment.is_null() ? Optional<String> {} : TRY_OR_THROW_OOM(vm, String::from_deprecated_string(fragment));
|
||||
auto location_url_or_error = actual_response->location_url(fragment_string);
|
||||
auto location_url_or_error = actual_response->location_url(request->current_url().fragment());
|
||||
|
||||
// 4. If locationURL is null, then return response.
|
||||
if (!location_url_or_error.is_error() && !location_url_or_error.value().has_value())
|
||||
|
|
|
@ -118,8 +118,8 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<String> const& reques
|
|||
return Error::from_string_view("Invalid 'Location' header URL"sv);
|
||||
|
||||
// 4. If location is a URL whose fragment is null, then set location’s fragment to requestFragment.
|
||||
if (location.fragment().is_null())
|
||||
location.set_fragment(request_fragment.has_value() ? request_fragment->to_deprecated_string() : DeprecatedString {});
|
||||
if (!location.fragment().has_value())
|
||||
location.set_fragment(request_fragment);
|
||||
|
||||
// 5. Return location.
|
||||
return location;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -302,8 +302,8 @@ void FrameLoader::resource_did_load()
|
|||
return;
|
||||
}
|
||||
|
||||
if (!url.fragment().is_empty())
|
||||
browsing_context().scroll_to_anchor(url.fragment());
|
||||
if (url.fragment().has_value() && !url.fragment()->is_empty())
|
||||
browsing_context().scroll_to_anchor(url.fragment()->to_deprecated_string());
|
||||
else
|
||||
browsing_context().scroll_to({ 0, 0 });
|
||||
|
||||
|
|
|
@ -284,8 +284,8 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
|
|||
if (button == GUI::MouseButton::Primary) {
|
||||
if (href.starts_with("javascript:"sv)) {
|
||||
document->navigate_to_javascript_url(href);
|
||||
} else if (!url.fragment().is_null() && url.equals(document->url(), AK::URL::ExcludeFragment::Yes)) {
|
||||
m_browsing_context->scroll_to_anchor(url.fragment());
|
||||
} else if (url.fragment().has_value() && url.equals(document->url(), AK::URL::ExcludeFragment::Yes)) {
|
||||
m_browsing_context->scroll_to_anchor(url.fragment()->to_deprecated_string());
|
||||
} else {
|
||||
if (m_browsing_context->is_top_level()) {
|
||||
if (auto* page = m_browsing_context->page())
|
||||
|
|
|
@ -87,9 +87,9 @@ JS::GCPtr<SVGGradientElement const> SVGGradientElement::linked_gradient() const
|
|||
if (auto href = link; !href.is_empty()) {
|
||||
auto url = document().parse_url(href);
|
||||
auto id = url.fragment();
|
||||
if (id.is_empty())
|
||||
if (!id.has_value() || id->is_empty())
|
||||
return {};
|
||||
auto element = document().get_element_by_id(id);
|
||||
auto element = document().get_element_by_id(id->to_deprecated_string());
|
||||
if (!element)
|
||||
return {};
|
||||
if (!is<SVGGradientElement>(*element))
|
||||
|
|
|
@ -46,8 +46,10 @@ Optional<Gfx::PaintStyle const&> SVGGraphicsElement::svg_paint_computed_value_to
|
|||
// FIXME: This entire function is an ad-hoc hack:
|
||||
if (!paint_value.has_value() || !paint_value->is_url())
|
||||
return {};
|
||||
auto& url = paint_value->as_url();
|
||||
auto gradient = document().get_element_by_id(url.fragment());
|
||||
auto const& url = paint_value->as_url();
|
||||
if (!url.fragment().has_value())
|
||||
return {};
|
||||
auto gradient = document().get_element_by_id(url.fragment()->to_deprecated_string());
|
||||
if (!gradient)
|
||||
return {};
|
||||
if (is<SVG::SVGGradientElement>(*gradient))
|
||||
|
|
|
@ -442,7 +442,7 @@ WebIDL::ExceptionOr<String> URL::hash() const
|
|||
auto& vm = realm().vm();
|
||||
|
||||
// 1. If this’s URL’s fragment is either null or the empty string, then return the empty string.
|
||||
if (m_url.fragment().is_null() || m_url.fragment().is_empty())
|
||||
if (!m_url.fragment().has_value() || m_url.fragment()->is_empty())
|
||||
return String {};
|
||||
|
||||
// 2. Return U+0023 (#), followed by this’s URL’s fragment.
|
||||
|
@ -469,7 +469,7 @@ void URL::set_hash(String const& hash)
|
|||
|
||||
// 3. Set this’s URL’s fragment to the empty string.
|
||||
auto url = m_url; // We copy the URL here to follow other browser's behavior of reverting the hash change if the parse failed.
|
||||
url.set_fragment(DeprecatedString::empty());
|
||||
url.set_fragment(String {});
|
||||
|
||||
// 4. Basic URL parse input with this’s URL as url and fragment state as state override.
|
||||
auto result_url = URLParser::basic_parse(input, {}, move(url), URLParser::State::Fragment);
|
||||
|
|
|
@ -79,7 +79,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::construct_impl(JS::R
|
|||
return WebIDL::SyntaxError::create(realm, "Invalid protocol"sv);
|
||||
|
||||
// 7. If urlRecord’s fragment is non-null, then throw a "SyntaxError" DOMException.
|
||||
if (!url_record.fragment().is_empty())
|
||||
if (url_record.fragment().has_value())
|
||||
return WebIDL::SyntaxError::create(realm, "Presence of URL fragment is invalid"sv);
|
||||
|
||||
Vector<String> protocols_sequence;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue