1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibWeb: Add the URL::href attribute and URL::to_json method

This commit is contained in:
Idan Horowitz 2021-09-14 00:13:32 +03:00 committed by Andreas Kling
parent e6abc1b44e
commit 1841fbd3e4
3 changed files with 38 additions and 2 deletions

View file

@ -44,4 +44,35 @@ DOM::ExceptionOr<NonnullRefPtr<URL>> URL::create_with_global_object(Bindings::Wi
return result_url;
}
String URL::href() const
{
// return the serialization of thiss URL.
return m_url.serialize();
}
String URL::to_json() const
{
// return the serialization of thiss URL.
return m_url.serialize();
}
DOM::ExceptionOr<void> URL::set_href(String const& href)
{
// 1. Let parsedURL be the result of running the basic URL parser on the given value.
AK::URL parsed_url = href;
// 2. If parsedURL is failure, then throw a TypeError.
if (!parsed_url.is_valid())
return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, "Invalid URL" };
// 3. Set thiss URL to parsedURL.
m_url = move(parsed_url);
// 4. Empty thiss query objects list.
m_query->m_list.clear();
// 5. Let query be thiss URLs query.
auto& query = m_url.query();
// 6. If query is non-null, then set thiss query objects list to the result of parsing query.
if (!query.is_null())
m_query->m_list = url_decode(query);
return {};
}
}