1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

LibWeb: Remove unecessary dependence on Window from assorted classes

These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
This commit is contained in:
Andrew Kaster 2022-09-25 18:11:21 -06:00 committed by Linus Groh
parent 4878a18ee7
commit 4bb6345b2f
30 changed files with 125 additions and 126 deletions

View file

@ -6,17 +6,17 @@
*/
#include <AK/URLParser.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/URL/URL.h>
namespace Web::URL {
JS::NonnullGCPtr<URL> URL::create(HTML::Window& window, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
JS::NonnullGCPtr<URL> URL::create(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
{
return *window.heap().allocate<URL>(window.realm(), window, move(url), move(query));
return *realm.heap().allocate<URL>(realm, realm, move(url), move(query));
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::create_with_global_object(HTML::Window& window, String const& url, String const& base)
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, String const& url, String const& base)
{
// 1. Let parsedBase be null.
Optional<AK::URL> parsed_base;
@ -41,21 +41,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::create_with_global_object(HTML::
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, query));
auto query_object = MUST(URLSearchParams::construct_impl(realm, query));
// 8. Initialize thiss query object with query.
auto result_url = URL::create(window, move(parsed_url), move(query_object));
auto result_url = URL::create(realm, 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())
URL::URL(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
: PlatformObject(realm)
, m_url(move(url))
, m_query(move(query))
{
set_prototype(&window.cached_web_prototype("URL"));
set_prototype(&Bindings::cached_web_prototype(realm, "URL"));
}
URL::~URL() = default;

View file

@ -19,8 +19,8 @@ class URL : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<URL> create(HTML::Window&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> create_with_global_object(HTML::Window&, String const& url, String const& base);
static JS::NonnullGCPtr<URL> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, String const& base);
virtual ~URL() override;
@ -63,7 +63,7 @@ public:
void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); }
private:
URL(HTML::Window&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -7,17 +7,17 @@
#include <AK/QuickSort.h>
#include <AK/StringBuilder.h>
#include <AK/Utf8View.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/URL/URL.h>
#include <LibWeb/URL/URLSearchParams.h>
namespace Web::URL {
URLSearchParams::URLSearchParams(HTML::Window& window, Vector<QueryParam> list)
: PlatformObject(window.realm())
URLSearchParams::URLSearchParams(JS::Realm& realm, Vector<QueryParam> list)
: PlatformObject(realm)
, m_list(move(list))
{
set_prototype(&window.cached_web_prototype("URLSearchParams"));
set_prototype(&Bindings::cached_web_prototype(realm, "URLSearchParams"));
}
URLSearchParams::~URLSearchParams() = default;
@ -82,14 +82,14 @@ Vector<QueryParam> url_decode(StringView input)
return output;
}
JS::NonnullGCPtr<URLSearchParams> URLSearchParams::create(HTML::Window& window, Vector<QueryParam> list)
JS::NonnullGCPtr<URLSearchParams> URLSearchParams::create(JS::Realm& realm, Vector<QueryParam> list)
{
return *window.heap().allocate<URLSearchParams>(window.realm(), window, move(list));
return *realm.heap().allocate<URLSearchParams>(realm, realm, move(list));
}
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
// https://url.spec.whatwg.org/#urlsearchparams-initialize
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_with_global_object(HTML::Window& window, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
{
// 1. If init is a string and starts with U+003F (?), then remove the first code point from init.
// NOTE: We do this when we know that it's a string on step 3 of initialization.
@ -114,7 +114,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
list.append(QueryParam { .name = pair[0], .value = pair[1] });
}
return URLSearchParams::create(window, move(list));
return URLSearchParams::create(realm, move(list));
}
// 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to querys list.
@ -127,7 +127,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
for (auto const& pair : init_record)
list.append(QueryParam { .name = pair.key, .value = pair.value });
return URLSearchParams::create(window, move(list));
return URLSearchParams::create(realm, move(list));
}
// 3. Otherwise:
@ -139,7 +139,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
StringView stripped_init = init_string.substring_view(init_string.starts_with('?'));
// b. Set querys list to the result of parsing init.
return URLSearchParams::create(window, url_decode(stripped_init));
return URLSearchParams::create(realm, url_decode(stripped_init));
}
void URLSearchParams::append(String const& name, String const& value)

View file

@ -23,8 +23,8 @@ class URLSearchParams : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<URLSearchParams> create(HTML::Window&, Vector<QueryParam> list);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create_with_global_object(HTML::Window&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
static JS::NonnullGCPtr<URLSearchParams> create(JS::Realm&, Vector<QueryParam> list);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
virtual ~URLSearchParams() override;
@ -46,7 +46,7 @@ private:
friend class URL;
friend class URLSearchParamsIterator;
URLSearchParams(HTML::Window&, Vector<QueryParam> list);
URLSearchParams(JS::Realm&, Vector<QueryParam> list);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -6,8 +6,8 @@
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/IteratorOperations.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/URLSearchParamsIteratorPrototype.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/URL/URLSearchParamsIterator.h>
namespace Web::URL {
@ -22,7 +22,7 @@ URLSearchParamsIterator::URLSearchParamsIterator(URLSearchParams const& url_sear
, m_url_search_params(url_search_params)
, m_iteration_kind(iteration_kind)
{
set_prototype(&url_search_params.global_object().ensure_web_prototype<Bindings::URLSearchParamsIteratorPrototype>("URLSearchParamsIterator"));
set_prototype(&Bindings::ensure_web_prototype<Bindings::URLSearchParamsIteratorPrototype>(url_search_params.realm(), "URLSearchParamsIterator"));
}
URLSearchParamsIterator::~URLSearchParamsIterator() = default;