mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:57:34 +00:00
LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
This commit is contained in:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/DOMEventListener.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
@ -17,16 +18,12 @@
|
|||
|
||||
namespace Web::DOM {
|
||||
|
||||
class EventTarget {
|
||||
AK_MAKE_NONCOPYABLE(EventTarget);
|
||||
AK_MAKE_NONMOVABLE(EventTarget);
|
||||
class EventTarget : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(EventTarget, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
virtual ~EventTarget();
|
||||
|
||||
void ref() { ref_event_target(); }
|
||||
void unref() { unref_event_target(); }
|
||||
|
||||
virtual bool is_focusable() const { return false; }
|
||||
|
||||
void add_event_listener(FlyString const& type, IDLEventListener* callback, Variant<AddEventListenerOptions, bool> const& options);
|
||||
|
@ -39,16 +36,13 @@ public:
|
|||
virtual bool dispatch_event(Event&);
|
||||
ExceptionOr<bool> dispatch_event_binding(Event&);
|
||||
|
||||
virtual JS::Object* create_wrapper(JS::Realm&) = 0;
|
||||
|
||||
virtual EventTarget* get_parent(Event const&) { return nullptr; }
|
||||
|
||||
void add_an_event_listener(DOMEventListener&);
|
||||
void remove_an_event_listener(DOMEventListener&);
|
||||
void remove_from_event_listener_list(DOMEventListener&);
|
||||
|
||||
auto& event_listener_list() { return m_event_listener_list; }
|
||||
auto const& event_listener_list() const { return m_event_listener_list; }
|
||||
Vector<JS::Handle<DOMEventListener>> event_listener_list();
|
||||
|
||||
Function<void(Event const&)> activation_behavior;
|
||||
|
||||
|
@ -61,19 +55,18 @@ public:
|
|||
void set_event_handler_attribute(FlyString const& name, Bindings::CallbackType*);
|
||||
|
||||
protected:
|
||||
EventTarget();
|
||||
|
||||
virtual void ref_event_target() = 0;
|
||||
virtual void unref_event_target() = 0;
|
||||
explicit EventTarget(JS::Realm&);
|
||||
|
||||
void element_event_handler_attribute_changed(FlyString const& local_name, String const& value);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
Vector<JS::Handle<DOMEventListener>> m_event_listener_list;
|
||||
Vector<JS::NonnullGCPtr<DOMEventListener>> m_event_listener_list;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-map
|
||||
// Spec Note: The order of the entries of event handler map could be arbitrary. It is not observable through any algorithms that operate on the map.
|
||||
HashMap<FlyString, JS::Handle<HTML::EventHandler>> m_event_handler_map;
|
||||
HashMap<FlyString, JS::GCPtr<HTML::EventHandler>> m_event_handler_map;
|
||||
|
||||
Bindings::CallbackType* get_current_value_of_event_handler(FlyString const& name);
|
||||
void activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler);
|
||||
|
@ -84,3 +77,5 @@ private:
|
|||
bool is_window_reflecting_body_element_event_handler(FlyString const& name);
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(EventTarget, Web::DOM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue