mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +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:
parent
fd83918476
commit
0639e77898
13 changed files with 26 additions and 14 deletions
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
EventTargetWrapper* wrap(JS::GlobalObject& global_object, DOM::EventTarget& target)
|
||||
JS::Object* wrap(JS::GlobalObject& global_object, DOM::EventTarget& target)
|
||||
{
|
||||
return target.create_wrapper(global_object);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
EventTargetWrapper* wrap(JS::GlobalObject&, DOM::EventTarget&);
|
||||
JS::Object* wrap(JS::GlobalObject&, DOM::EventTarget&);
|
||||
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ void WindowObject::initialize()
|
|||
{
|
||||
GlobalObject::initialize();
|
||||
|
||||
set_prototype(&ensure_web_prototype<EventTargetPrototype>("EventTarget"));
|
||||
|
||||
define_property("window", this, JS::Attribute::Enumerable);
|
||||
define_property("frames", this, JS::Attribute::Enumerable);
|
||||
define_property("self", this, JS::Attribute::Enumerable);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue