1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:27:35 +00:00

LibWeb: Implement the EventTarget constructor

This is typically used as `class A extends EventTarget`. It's usage can
be found on websites such as https://loadout.tf/

This has the quirk that we don't do set the EventTarget prototype for
HTML::Window, as it would cause a null deref on startup. However, given
it wasn't doing this before, I don't think it should cause any issues.
This commit is contained in:
Luke Wilde 2023-05-03 21:10:26 +01:00 committed by Andreas Kling
parent 1127bdb65c
commit 344785ae3a
3 changed files with 24 additions and 0 deletions

View file

@ -42,6 +42,25 @@ EventTarget::EventTarget(JS::Realm& realm)
EventTarget::~EventTarget() = default;
// https://dom.spec.whatwg.org/#dom-eventtarget-eventtarget
WebIDL::ExceptionOr<JS::NonnullGCPtr<EventTarget>> EventTarget::construct_impl(JS::Realm& realm)
{
// The new EventTarget() constructor steps are to do nothing.
return MUST_OR_THROW_OOM(realm.heap().allocate<EventTarget>(realm, realm));
}
JS::ThrowCompletionOr<void> EventTarget::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
// FIXME: We can't do this for HTML::Window currently, as this will run when creating the initial global object.
// During this time, the ESO is not setup, so it will cause a nullptr dereference in host_defined_intrinsics.
if (!is<HTML::Window>(this))
set_prototype(&Bindings::ensure_web_prototype<Bindings::EventTargetPrototype>(realm, "EventTarget"));
return {};
}
void EventTarget::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);