diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-08 22:29:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-06 00:27:09 +0200 |
commit | 7c3db526b0b7a9f516499b00e901ec55c695c02e (patch) | |
tree | ce8243216d2b0446c35447db92d7991a1439e626 /Userland/Libraries/LibWeb/DOM/Event.h | |
parent | a4ddb0ef8746be22b07fce3cc67b9664a4bd01ef (diff) | |
download | serenity-7c3db526b0b7a9f516499b00e901ec55c695c02e.zip |
LibWeb: Make DOM::Event and all its subclasses GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Event.h')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Event.h | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Event.h b/Userland/Libraries/LibWeb/DOM/Event.h index 76d426c7c0..51e8533025 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.h +++ b/Userland/Libraries/LibWeb/DOM/Event.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,8 +7,8 @@ #pragma once #include <AK/FlyString.h> +#include <LibWeb/Bindings/PlatformObject.h> #include <LibWeb/Bindings/WindowObject.h> -#include <LibWeb/Bindings/Wrappable.h> #include <LibWeb/DOM/EventTarget.h> namespace Web::DOM { @@ -19,12 +19,10 @@ struct EventInit { bool composed { false }; }; -class Event - : public RefCounted<Event> - , public Bindings::Wrappable { -public: - using WrapperType = Bindings::EventWrapper; +class Event : public Bindings::PlatformObject { + JS_OBJECT(Event, Bindings::PlatformObject); +public: enum Phase : u16 { None = 0, CapturingPhase = 1, @@ -47,17 +45,16 @@ public: using Path = Vector<PathEntry>; - static NonnullRefPtr<Event> create(FlyString const& event_name, EventInit const& event_init = {}) - { - return adopt_ref(*new Event(event_name, event_init)); - } - static NonnullRefPtr<Event> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, EventInit const& event_init) - { - return Event::create(event_name, event_init); - } + static JS::NonnullGCPtr<Event> create(Bindings::WindowObject&, FlyString const& event_name, EventInit const& event_init = {}); + static JS::NonnullGCPtr<Event> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, EventInit const& event_init); + + Event(Bindings::WindowObject&, FlyString const& type); + Event(Bindings::WindowObject&, FlyString const& type, EventInit const& event_init); virtual ~Event() = default; + Event& impl() { return *this; } + double time_stamp() const; FlyString const& type() const { return m_type; } @@ -149,21 +146,7 @@ public: NonnullRefPtrVector<EventTarget> composed_path() const; protected: - explicit Event(FlyString const& type) - : m_type(type) - , m_initialized(true) - { - } - Event(FlyString const& type, EventInit const& event_init) - : m_type(type) - , m_bubbles(event_init.bubbles) - , m_cancelable(event_init.cancelable) - , m_composed(event_init.composed) - , m_initialized(true) - { - } - - void initialize(String const&, bool, bool); + void initialize_event(String const&, bool, bool); private: FlyString m_type; @@ -195,3 +178,8 @@ private: }; } + +namespace Web::Bindings { +inline JS::Object* wrap(JS::Realm&, Web::DOM::Event& object) { return &object; } +using EventWrapper = Web::DOM::Event; +} |