1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 01:17:46 +00:00

LibWeb: Move setting of Web object prototypes to initialize()

This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
This commit is contained in:
Timothy Flynn 2023-01-10 06:28:20 -05:00 committed by Andreas Kling
parent 7bd8fd000f
commit 834202aeb9
339 changed files with 1294 additions and 187 deletions

View file

@ -17,10 +17,15 @@ FocusEvent* FocusEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString con
FocusEvent::FocusEvent(JS::Realm& realm, DeprecatedFlyString const& event_name, FocusEventInit const& event_init)
: UIEvent(realm, event_name)
{
set_prototype(&Bindings::cached_web_prototype(realm, "FocusEvent"));
set_related_target(const_cast<DOM::EventTarget*>(event_init.related_target.ptr()));
}
FocusEvent::~FocusEvent() = default;
void FocusEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::FocusEventPrototype>(realm, "FocusEvent"));
}
}

View file

@ -24,6 +24,8 @@ public:
private:
FocusEvent(JS::Realm&, DeprecatedFlyString const& event_name, FocusEventInit const&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -128,9 +128,14 @@ KeyboardEvent::KeyboardEvent(JS::Realm& realm, DeprecatedFlyString const& event_
, m_key_code(event_init.key_code)
, m_char_code(event_init.char_code)
{
set_prototype(&Bindings::cached_web_prototype(realm, "KeyboardEvent"));
}
KeyboardEvent::~KeyboardEvent() = default;
void KeyboardEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::KeyboardEventPrototype>(realm, "KeyboardEvent"));
}
}

View file

@ -56,6 +56,8 @@ public:
private:
KeyboardEvent(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init);
virtual void initialize(JS::Realm&) override;
DeprecatedString m_key;
DeprecatedString m_code;
u32 m_location { 0 };

View file

@ -24,12 +24,17 @@ MouseEvent::MouseEvent(JS::Realm& realm, DeprecatedFlyString const& event_name,
, m_button(event_init.button)
, m_buttons(event_init.buttons)
{
set_prototype(&Bindings::cached_web_prototype(realm, "MouseEvent"));
set_event_characteristics();
}
MouseEvent::~MouseEvent() = default;
void MouseEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::MouseEventPrototype>(realm, "MouseEvent"));
}
// https://www.w3.org/TR/uievents/#dom-mouseevent-button
static i16 determine_button(unsigned mouse_button)
{

View file

@ -58,6 +58,8 @@ public:
protected:
MouseEvent(JS::Realm&, DeprecatedFlyString const& event_name, MouseEventInit const& event_init);
virtual void initialize(JS::Realm&) override;
private:
void set_event_characteristics();

View file

@ -22,7 +22,6 @@ UIEvent* UIEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& ev
UIEvent::UIEvent(JS::Realm& realm, DeprecatedFlyString const& event_name)
: Event(realm, event_name)
{
set_prototype(&Bindings::cached_web_prototype(realm, "UIEvent"));
}
UIEvent::UIEvent(JS::Realm& realm, DeprecatedFlyString const& event_name, UIEventInit const& event_init)
@ -30,11 +29,16 @@ UIEvent::UIEvent(JS::Realm& realm, DeprecatedFlyString const& event_name, UIEven
, m_view(event_init.view)
, m_detail(event_init.detail)
{
set_prototype(&Bindings::cached_web_prototype(realm, "UIEvent"));
}
UIEvent::~UIEvent() = default;
void UIEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::UIEventPrototype>(realm, "UIEvent"));
}
void UIEvent::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);

View file

@ -41,6 +41,7 @@ protected:
UIEvent(JS::Realm&, DeprecatedFlyString const& event_name);
UIEvent(JS::Realm&, DeprecatedFlyString const& event_name, UIEventInit const& event_init);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<HTML::Window> m_view;

View file

@ -17,12 +17,17 @@ WheelEvent::WheelEvent(JS::Realm& realm, DeprecatedFlyString const& event_name,
, m_delta_y(event_init.delta_y)
, m_delta_mode(event_init.delta_mode)
{
set_prototype(&Bindings::cached_web_prototype(realm, "WheelEvent"));
set_event_characteristics();
}
WheelEvent::~WheelEvent() = default;
void WheelEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::WheelEventPrototype>(realm, "WheelEvent"));
}
WheelEvent* WheelEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, WheelEventInit const& event_init)
{
return realm.heap().allocate<WheelEvent>(realm, realm, event_name, event_init);

View file

@ -42,6 +42,8 @@ public:
private:
WheelEvent(JS::Realm&, DeprecatedFlyString const& event_name, WheelEventInit const& event_init);
virtual void initialize(JS::Realm&) override;
void set_event_characteristics();
double m_delta_x { 0 };