1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:37:36 +00:00

LibWeb: Make DOM::Event and all its subclasses GC-allocated

This commit is contained in:
Andreas Kling 2022-08-08 22:29:40 +02:00
parent a4ddb0ef87
commit 7c3db526b0
76 changed files with 892 additions and 565 deletions

View file

@ -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;
}