Web Inspector: Console: getEventListeners should work for any EventTarget
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 09:46:01 +0000 (09:46 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 09:46:01 +0000 (09:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195713

Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: inspector/console/command-line-api-getEventListeners.html

* dom/EventTarget.h:
* dom/EventTarget.cpp:
(WebCore::EventTarget::eventTypes): Added.

* inspector/CommandLineAPIHost.idl:
* inspector/CommandLineAPIHost.h:
(WebCore::CommandLineAPIHost::init):
* inspector/CommandLineAPIHost.cpp:
(WebCore::CommandLineAPIHost::disconnect):
(WebCore::CommandLineAPIHost::getEventListeners):
(WebCore::listenerEntriesFromListenerInfo): Deleted.

* inspector/CommandLineAPIModuleSource.js:
(CommandLineAPIImpl.prototype.getEventListeners):

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):

Source/WebInspectorUI:

* UserInterface/Models/NativeFunctionParameters.js:

LayoutTests:

* inspector/console/command-line-api-getEventListeners.html:
* inspector/console/command-line-api-getEventListeners-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242940 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/console/command-line-api-getEventListeners-expected.txt
LayoutTests/inspector/console/command-line-api-getEventListeners.html
Source/WebCore/ChangeLog
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/EventTarget.h
Source/WebCore/inspector/CommandLineAPIHost.cpp
Source/WebCore/inspector/CommandLineAPIHost.h
Source/WebCore/inspector/CommandLineAPIHost.idl
Source/WebCore/inspector/CommandLineAPIModuleSource.js
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/NativeFunctionParameters.js

index 96a6884..1add711 100644 (file)
@@ -1,5 +1,15 @@
 2019-03-14  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Console: getEventListeners should work for any EventTarget
+        https://bugs.webkit.org/show_bug.cgi?id=195713
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/console/command-line-api-getEventListeners.html:
+        * inspector/console/command-line-api-getEventListeners-expected.txt:
+
+2019-03-14  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Styles: `::-webkit-scrollbar*` rules aren't shown
         https://bugs.webkit.org/show_bug.cgi?id=195123
         <rdar://problem/48450148>
index 5818200..8754c0c 100644 (file)
@@ -2,14 +2,37 @@ Test for CommandLineAPI getEventListeners.
 
 
 == Running test suite: Console.CommandLineAPI.getEventListeners
+-- Running test case: Console.CommandLineAPI.getEventListeners.NoArguments
+TypeError: Argument 1 ('target') to CommandLineAPIHost.getEventListeners must be an instance of EventTarget
+
 -- Running test case: Console.CommandLineAPI.getEventListeners.Undefined
-{}
+TypeError: Argument 1 ('target') to CommandLineAPIHost.getEventListeners must be an instance of EventTarget
 
 -- Running test case: Console.CommandLineAPI.getEventListeners.Null
-{}
+TypeError: Argument 1 ('target') to CommandLineAPIHost.getEventListeners must be an instance of EventTarget
 
 -- Running test case: Console.CommandLineAPI.getEventListeners.String
-TypeError: Argument 1 ('node') to CommandLineAPIHost.getEventListeners must be an instance of Node
+TypeError: Argument 1 ('target') to CommandLineAPIHost.getEventListeners must be an instance of EventTarget
+
+-- Running test case: Console.CommandLineAPI.getEventListeners.window
+{
+  "error": [
+    {
+      "listener": "<function bound >",
+      "once": false,
+      "passive": false,
+      "useCapture": false
+    }
+  ],
+  "load": [
+    {
+      "listener": "<function onload>",
+      "once": false,
+      "passive": false,
+      "useCapture": false
+    }
+  ]
+}
 
 -- Running test case: Console.CommandLineAPI.getEventListeners.NodeNoListeners
 {}
index 688fba4..14de12d 100644 (file)
@@ -43,6 +43,11 @@ function test()
     }
 
     addTestCase({
+        name: "Console.CommandLineAPI.getEventListeners.NoArguments",
+        expression: ``,
+    });
+
+    addTestCase({
         name: "Console.CommandLineAPI.getEventListeners.Undefined",
         expression: `undefined`,
     });
@@ -58,6 +63,11 @@ function test()
     });
 
     addTestCase({
+        name: "Console.CommandLineAPI.getEventListeners.window",
+        expression: `window`,
+    });
+
+    addTestCase({
         name: "Console.CommandLineAPI.getEventListeners.NodeNoListeners",
         expression: `document.createElement("p")`,
     });
index 6148888..7e39053 100644 (file)
@@ -1,5 +1,34 @@
 2019-03-14  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Console: getEventListeners should work for any EventTarget
+        https://bugs.webkit.org/show_bug.cgi?id=195713
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: inspector/console/command-line-api-getEventListeners.html
+
+        * dom/EventTarget.h:
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::eventTypes): Added.
+
+        * inspector/CommandLineAPIHost.idl:
+        * inspector/CommandLineAPIHost.h:
+        (WebCore::CommandLineAPIHost::init):
+        * inspector/CommandLineAPIHost.cpp:
+        (WebCore::CommandLineAPIHost::disconnect):
+        (WebCore::CommandLineAPIHost::getEventListeners):
+        (WebCore::listenerEntriesFromListenerInfo): Deleted.
+
+        * inspector/CommandLineAPIModuleSource.js:
+        (CommandLineAPIImpl.prototype.getEventListeners):
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+
+2019-03-14  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Styles: `::-webkit-scrollbar*` rules aren't shown
         https://bugs.webkit.org/show_bug.cgi?id=195123
         <rdar://problem/48450148>
index 2db2efd..9ebe1dd 100644 (file)
@@ -319,6 +319,13 @@ void EventTarget::innerInvokeEventListeners(Event& event, EventListenerVector li
         InspectorInstrumentation::didDispatchEvent(willDispatchEventCookie);
 }
 
+Vector<AtomicString> EventTarget::eventTypes()
+{
+    if (auto* data = eventTargetData())
+        return data->eventListenerMap.eventTypes();
+    return { };
+}
+
 const EventListenerVector& EventTarget::eventListeners(const AtomicString& eventType)
 {
     auto* data = eventTargetData();
index d6c5c60..02a789f 100644 (file)
@@ -101,6 +101,8 @@ public:
     bool hasEventListeners(const AtomicString& eventType) const;
     bool hasCapturingEventListeners(const AtomicString& eventType);
     bool hasActiveEventListeners(const AtomicString& eventType) const;
+
+    Vector<AtomicString> eventTypes();
     const EventListenerVector& eventListeners(const AtomicString& eventType);
 
     enum class EventInvokePhase { Capturing, Bubbling };
index 1366f06..3f983fa 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "Database.h"
 #include "Document.h"
-#include "InspectorDOMAgent.h"
+#include "EventTarget.h"
 #include "InspectorDOMStorageAgent.h"
 #include "InspectorDatabaseAgent.h"
 #include "JSCommandLineAPIHost.h"
@@ -71,7 +71,6 @@ void CommandLineAPIHost::disconnect()
 {
     m_inspectorAgent = nullptr;
     m_consoleAgent = nullptr;
-    m_domAgent = nullptr;
     m_domStorageAgent = nullptr;
     m_databaseAgent = nullptr;
 }
@@ -89,51 +88,38 @@ void CommandLineAPIHost::inspect(JSC::ExecState& state, JSC::JSValue valueToInsp
     m_inspectorAgent->inspect(WTFMove(remoteObject), WTFMove(hintsObject));
 }
 
-static Vector<CommandLineAPIHost::ListenerEntry> listenerEntriesFromListenerInfo(ExecState& state, Document& document, const EventListenerInfo& listenerInfo)
+CommandLineAPIHost::EventListenersRecord CommandLineAPIHost::getEventListeners(ExecState& state, EventTarget& target)
 {
-    VM& vm = state.vm();
-
-    Vector<CommandLineAPIHost::ListenerEntry> entries;
-    for (auto& eventListener : listenerInfo.eventListenerVector) {
-        if (!is<JSEventListener>(eventListener->callback())) {
-            ASSERT_NOT_REACHED();
-            continue;
-        }
-
-        auto& jsListener = downcast<JSEventListener>(eventListener->callback());
+    auto* scriptExecutionContext = target.scriptExecutionContext();
+    if (!scriptExecutionContext)
+        return { };
 
-        // Hide listeners from other contexts.
-        if (&jsListener.isolatedWorld() != &currentWorld(state))
-            continue;
+    EventListenersRecord result;
 
-        auto function = jsListener.jsFunction(document);
-        if (!function)
-            continue;
+    VM& vm = state.vm();
 
-        entries.append({ JSC::Strong<JSC::JSObject>(vm, function), eventListener->useCapture(), eventListener->isPassive(), eventListener->isOnce() });
-    }
+    for (auto& eventType : target.eventTypes()) {
+        Vector<CommandLineAPIHost::ListenerEntry> entries;
 
-    return entries;
-}
+        for (auto& eventListener : target.eventListeners(eventType)) {
+            if (!is<JSEventListener>(eventListener->callback()))
+                continue;
 
-auto CommandLineAPIHost::getEventListeners(JSC::ExecState& state, Node* node) -> EventListenersRecord
-{
-    if (!m_domAgent)
-        return { };
+            auto& jsListener = downcast<JSEventListener>(eventListener->callback());
 
-    if (!node)
-        return { };
+            // Hide listeners from other contexts.
+            if (&jsListener.isolatedWorld() != &currentWorld(state))
+                continue;
 
-    Vector<EventListenerInfo> listenerInfoArray;
-    m_domAgent->getEventListeners(node, listenerInfoArray, false);
+            auto* function = jsListener.jsFunction(*scriptExecutionContext);
+            if (!function)
+                continue;
 
-    EventListenersRecord result;
+            entries.append({ Strong<JSObject>(vm, function), eventListener->useCapture(), eventListener->isPassive(), eventListener->isOnce() });
+        }
 
-    for (auto& listenerInfo : listenerInfoArray) {
-        auto entries = listenerEntriesFromListenerInfo(state, node->document(), listenerInfo);
-        if (entries.isEmpty())
-            continue;
-        result.append({ listenerInfo.eventType, WTFMove(entries) });
+        if (!entries.isEmpty())
+            result.append({ eventType, WTFMove(entries) });
     }
 
     return result;
index d890997..f0d2062 100644 (file)
@@ -46,11 +46,10 @@ class InspectorConsoleAgent;
 namespace WebCore {
 
 class Database;
-class InspectorDOMAgent;
+class EventTarget;
 class InspectorDOMStorageAgent;
 class InspectorDatabaseAgent;
 class JSDOMGlobalObject;
-class Node;
 class Storage;
 
 struct EventListenerInfo;
@@ -62,14 +61,12 @@ public:
 
     void init(Inspector::InspectorAgent* inspectorAgent
         , Inspector::InspectorConsoleAgent* consoleAgent
-        , InspectorDOMAgent* domAgent
         , InspectorDOMStorageAgent* domStorageAgent
         , InspectorDatabaseAgent* databaseAgent
         )
     {
         m_inspectorAgent = inspectorAgent;
         m_consoleAgent = consoleAgent;
-        m_domAgent = domAgent;
         m_domStorageAgent = domStorageAgent;
         m_databaseAgent = databaseAgent;
     }
@@ -97,7 +94,7 @@ public:
     };
 
     using EventListenersRecord = Vector<WTF::KeyValuePair<String, Vector<ListenerEntry>>>;
-    EventListenersRecord getEventListeners(JSC::ExecState&, Node*);
+    EventListenersRecord getEventListeners(JSC::ExecState&, EventTarget&);
 
     String databaseId(Database&);
     String storageId(Storage&);
@@ -110,7 +107,6 @@ private:
 
     Inspector::InspectorAgent* m_inspectorAgent { nullptr };
     Inspector::InspectorConsoleAgent* m_consoleAgent { nullptr };
-    InspectorDOMAgent* m_domAgent { nullptr };
     InspectorDOMStorageAgent* m_domStorageAgent { nullptr };
     InspectorDatabaseAgent* m_databaseAgent { nullptr };
 
index 6b94cd4..83317bb 100644 (file)
@@ -40,7 +40,7 @@
     [CallWith=ExecState] void inspect(any objectToInspect, any hints);
     [CallWith=ExecState] any inspectedObject();
 
-    [CallWith=ExecState] record<DOMString, sequence<ListenerEntry>> getEventListeners(Node? node);
+    [CallWith=ExecState] record<DOMString, sequence<ListenerEntry>> getEventListeners(EventTarget target);
 
     DOMString databaseId(Database database);
     DOMString storageId(Storage storage);
index 92254f5..0fecdeb 100644 (file)
@@ -272,12 +272,9 @@ CommandLineAPIImpl.prototype = {
         CommandLineAPIHost.clearConsoleMessages();
     },
 
-    /**
-     * @param {Node} node
-     */
-    getEventListeners: function(node)
+    getEventListeners: function(target)
     {
-        return CommandLineAPIHost.getEventListeners(node);
+        return CommandLineAPIHost.getEventListeners(target);
     },
 
     _inspectedObject: function()
index 3969037..97f9480 100644 (file)
@@ -148,7 +148,7 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
 
     ASSERT(m_injectedScriptManager->commandLineAPIHost());
     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
-        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, m_domAgent, domStorageAgent, databaseAgent);
+        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, domStorageAgent, databaseAgent);
 }
 
 InspectorController::~InspectorController()
index 3597e1b..b063e6f 100644 (file)
@@ -80,7 +80,7 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope& workerGl
     m_agents.append(WTFMove(heapAgent));
 
     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
-        commandLineAPIHost->init(nullptr, m_instrumentingAgents->webConsoleAgent(), nullptr, nullptr, nullptr);
+        commandLineAPIHost->init(nullptr, m_instrumentingAgents->webConsoleAgent(), nullptr, nullptr);
 }
 
 WorkerInspectorController::~WorkerInspectorController()
index 1a5faa5..b569560 100644 (file)
@@ -1,5 +1,14 @@
 2019-03-14  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Console: getEventListeners should work for any EventTarget
+        https://bugs.webkit.org/show_bug.cgi?id=195713
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/NativeFunctionParameters.js:
+
+2019-03-14  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Styles: `::-webkit-scrollbar*` rules aren't shown
         https://bugs.webkit.org/show_bug.cgi?id=195123
         <rdar://problem/48450148>
index 8b77266..126f400 100644 (file)
@@ -695,7 +695,7 @@ WI.NativePrototypeFunctionParameters = {
     CommandLineAPIHost: {
         copyText: "text",
         databaseId: "database",
-        getEventListeners: "node",
+        getEventListeners: "target",
         inspect: "objectId, hints",
         storageId: "storage",
         __proto__: null,