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

LibWeb: Make the Window object "inherit" from EventTarget :^)

Since Web::Bindings::WindowObject inherits from JS::GlobalObject, it
cannot also inherit from Web::Bindings::EventTargetWrapper.

However, that's not actually necessary. Instead, we simply set the
Window object's prototype to the EventTargetPrototype, and add a little
extra branch in the impl_from() function that turns the JS "this" value
into a DOM::EventTarget*.

With this, you can now call window.addEventListener()! Very cool :^)

Fixes #4758.
This commit is contained in:
Andreas Kling 2021-01-18 12:15:02 +01:00
parent fd83918476
commit 0639e77898
13 changed files with 26 additions and 14 deletions

View file

@ -66,7 +66,7 @@ private:
virtual void ref_event_target() override { ref(); }
virtual void unref_event_target() override { unref(); }
virtual bool dispatch_event(NonnullRefPtr<DOM::Event>) override;
virtual Bindings::EventTargetWrapper* create_wrapper(JS::GlobalObject&) override;
virtual JS::Object* create_wrapper(JS::GlobalObject&) override;
void set_ready_state(ReadyState);