diff options
author | Andrew Kaster <akaster@serenityos.org> | 2022-09-25 16:15:49 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-01 21:05:32 +0100 |
commit | 8de7e49a5648cdf084689a6b6cb49715f8ccad02 (patch) | |
tree | 24620bc96e781ac58ff091341de488717699822b /Userland/Libraries/LibWeb/DOM/Event.cpp | |
parent | 8407bf60c56bc41d6f450bb21495c8591b9271bd (diff) | |
download | serenity-8de7e49a5648cdf084689a6b6cb49715f8ccad02.zip |
LibWeb: Remove unecessary dependence on Window from DOM and WebIDL
These classes only needed Window to get at its realm. Pass a realm
directly to construct DOM and WebIDL classes.
This change importantly removes the guarantee that a Document will
always have a non-null Window object. Only Documents created by a
BrowsingContext will have a non-null Window object. Documents created by
for example, DocumentFragment, will not have a Window (soon).
This incremental commit leaves some workarounds in place to keep other
parts of the code building.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Event.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Event.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index 7527725c82..a6449f36c9 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -7,6 +7,7 @@ */ #include <AK/TypeCasts.h> +#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Node.h> #include <LibWeb/DOM/ShadowRoot.h> @@ -14,25 +15,30 @@ namespace Web::DOM { -JS::NonnullGCPtr<Event> Event::create(HTML::Window& window_object, FlyString const& event_name, EventInit const& event_init) +JS::NonnullGCPtr<Event> Event::create(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init) { - return *window_object.heap().allocate<Event>(window_object.realm(), window_object, event_name, event_init); + return *realm.heap().allocate<Event>(realm, realm, event_name, event_init); } -JS::NonnullGCPtr<Event> Event::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, EventInit const& event_init) +JS::NonnullGCPtr<Event> Event::create(HTML::Window& window, FlyString const& event_name, EventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(window.realm(), event_name, event_init); } -Event::Event(HTML::Window& window, FlyString const& type) - : PlatformObject(window.cached_web_prototype("Event")) +JS::NonnullGCPtr<Event> Event::construct_impl(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init) +{ + return create(realm, event_name, event_init); +} + +Event::Event(JS::Realm& realm, FlyString const& type) + : PlatformObject(Bindings::cached_web_prototype(realm, "Event")) , m_type(type) , m_initialized(true) { } -Event::Event(HTML::Window& window, FlyString const& type, EventInit const& event_init) - : PlatformObject(window.cached_web_prototype("Event")) +Event::Event(JS::Realm& realm, FlyString const& type, EventInit const& event_init) + : PlatformObject(Bindings::cached_web_prototype(realm, "Event")) , m_type(type) , m_bubbles(event_init.bubbles) , m_cancelable(event_init.cancelable) @@ -41,6 +47,16 @@ Event::Event(HTML::Window& window, FlyString const& type, EventInit const& event { } +Event::Event(HTML::Window& window, FlyString const& type, EventInit const& event_init) + : Event(window.realm(), type, event_init) +{ +} + +Event::Event(HTML::Window& window, FlyString const& type) + : Event(window.realm(), type) +{ +} + void Event::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); |