This returns true if the EventTarget has one or more registered listeners for a given even type.
@@ -735,4 +735,13 @@ bool EventTarget::dispatch_event(Event& event)
return EventDispatcher::dispatch(*this, event);
}
+bool EventTarget::has_event_listener(FlyString const& type) const
+{
+ for (auto& listener : m_event_listener_list) {
+ if (listener->type == type)
+ return true;
+ }
+ return false;
+}
+
@@ -54,6 +54,8 @@ public:
WebIDL::CallbackType* event_handler_attribute(FlyString const& name);
void set_event_handler_attribute(FlyString const& name, WebIDL::CallbackType*);
+ bool has_event_listener(FlyString const& type) const;
protected:
explicit EventTarget(JS::Realm&);