diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-18 12:15:02 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-18 12:18:29 +0100 |
commit | 0639e778986877ef0a6883eb9011ad8b4f56b642 (patch) | |
tree | 32afd1a67fa823a59d25e4181c3503471b63c8f6 /Userland/Libraries/LibWeb/DOM | |
parent | fd83918476dd4d91a07df44c831275f0b5cdd7e9 (diff) | |
download | serenity-0639e778986877ef0a6883eb9011ad8b4f56b642.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/EventTarget.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Window.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Window.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/XMLHttpRequest.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/XMLHttpRequest.h | 2 |
7 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.h b/Userland/Libraries/LibWeb/DOM/EventTarget.h index 32399a6a7a..f03d4a4fb2 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.h +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.h @@ -51,7 +51,7 @@ public: void remove_from_event_listener_list(NonnullRefPtr<EventListener>); virtual bool dispatch_event(NonnullRefPtr<Event>) = 0; - virtual Bindings::EventTargetWrapper* create_wrapper(JS::GlobalObject&) = 0; + virtual JS::Object* create_wrapper(JS::GlobalObject&) = 0; Bindings::ScriptExecutionContext* script_execution_context() { return m_script_execution_context; } virtual EventTarget* get_parent(const Event&) { return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 6890e4fda5..9bfe3aecca 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -213,7 +213,7 @@ bool Node::is_editable() const return parent() && parent()->is_editable(); } -Bindings::EventTargetWrapper* Node::create_wrapper(JS::GlobalObject& global_object) +JS::Object* Node::create_wrapper(JS::GlobalObject& global_object) { return wrap(global_object, *this); } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index d3eaab1b8b..d29f0a471f 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -61,7 +61,7 @@ public: virtual void ref_event_target() final { ref(); } virtual void unref_event_target() final { unref(); } virtual bool dispatch_event(NonnullRefPtr<Event>) final; - virtual Bindings::EventTargetWrapper* create_wrapper(JS::GlobalObject&) override; + virtual JS::Object* create_wrapper(JS::GlobalObject&) override; virtual ~Node(); diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index d10620bc1e..648d083696 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -169,9 +169,9 @@ bool Window::dispatch_event(NonnullRefPtr<Event> event) return EventDispatcher::dispatch(*this, event, true); } -Bindings::EventTargetWrapper* Window::create_wrapper(JS::GlobalObject&) +JS::Object* Window::create_wrapper(JS::GlobalObject& global_object) { - ASSERT_NOT_REACHED(); + return &global_object; } } diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h index 4118bebbe2..725da546d7 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.h +++ b/Userland/Libraries/LibWeb/DOM/Window.h @@ -50,7 +50,7 @@ public: virtual void ref_event_target() override { RefCounted::ref(); } virtual void unref_event_target() override { RefCounted::unref(); } virtual bool dispatch_event(NonnullRefPtr<Event>) override; - virtual Bindings::EventTargetWrapper* create_wrapper(JS::GlobalObject&) override; + virtual JS::Object* create_wrapper(JS::GlobalObject&) override; const Document& document() const { return m_document; } Document& document() { return m_document; } diff --git a/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.cpp index e763a2f337..a6485d33f4 100644 --- a/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.cpp @@ -113,7 +113,7 @@ bool XMLHttpRequest::dispatch_event(NonnullRefPtr<DOM::Event> event) return DOM::EventDispatcher::dispatch(*this, move(event)); } -Bindings::EventTargetWrapper* XMLHttpRequest::create_wrapper(JS::GlobalObject& global_object) +JS::Object* XMLHttpRequest::create_wrapper(JS::GlobalObject& global_object) { return wrap(global_object, *this); } diff --git a/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.h b/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.h index 33a6038863..2bb7b73e28 100644 --- a/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/DOM/XMLHttpRequest.h @@ -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); |