1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibWeb: Make URL, URLSearchParams & URLSearchParamsIterator GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 14:04:42 +02:00
parent 0dc2c27fa3
commit fe9c5395d4
11 changed files with 125 additions and 86 deletions

View file

@ -6,11 +6,17 @@
*/
#include <AK/URLParser.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/URL/URL.h>
namespace Web::URL {
DOM::ExceptionOr<NonnullRefPtr<URL>> URL::create_with_global_object(HTML::Window& window_object, String const& url, String const& base)
JS::NonnullGCPtr<URL> URL::create(HTML::Window& window, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
{
return *window.heap().allocate<URL>(window.realm(), window, move(url), move(query));
}
DOM::ExceptionOr<JS::NonnullGCPtr<URL>> URL::create_with_global_object(HTML::Window& window, String const& url, String const& base)
{
// 1. Let parsedBase be null.
Optional<AK::URL> parsed_base;
@ -35,15 +41,31 @@ DOM::ExceptionOr<NonnullRefPtr<URL>> URL::create_with_global_object(HTML::Window
auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query();
// 6. Set thiss URL to parsedURL.
// 7. Set thiss query object to a new URLSearchParams object.
auto query_object = MUST(URLSearchParams::create_with_global_object(window_object, query));
auto query_object = MUST(URLSearchParams::create_with_global_object(window, query));
// 8. Initialize thiss query object with query.
auto result_url = URL::create(move(parsed_url), move(query_object));
auto result_url = URL::create(window, move(parsed_url), move(query_object));
// 9. Set thiss query objects URL object to this.
result_url->m_query->m_url = result_url;
return result_url;
}
URL::URL(HTML::Window& window, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
: PlatformObject(window.realm())
, m_url(move(url))
, m_query(move(query))
{
set_prototype(&window.cached_web_prototype("URL"));
}
URL::~URL() = default;
void URL::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_query.ptr());
}
String URL::href() const
{
// return the serialization of thiss URL.