Skip to content
Permalink
Browse files
Web Inspector: Console: getEventListeners should work for any EventTa…
…rget

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:


Canonical link: https://commits.webkit.org/210030@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242940 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dcrousso committed Mar 14, 2019
1 parent 6f4c7c8 commit 0f8b48a698cac566a6a725d447d1e39d21abe869
Showing 14 changed files with 124 additions and 55 deletions.
@@ -1,3 +1,13 @@
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
@@ -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
{}
@@ -42,6 +42,11 @@
});
}

addTestCase({
name: "Console.CommandLineAPI.getEventListeners.NoArguments",
expression: ``,
});

addTestCase({
name: "Console.CommandLineAPI.getEventListeners.Undefined",
expression: `undefined`,
@@ -57,6 +62,11 @@
expression: `"test"`,
});

addTestCase({
name: "Console.CommandLineAPI.getEventListeners.window",
expression: `window`,
});

addTestCase({
name: "Console.CommandLineAPI.getEventListeners.NodeNoListeners",
expression: `document.createElement("p")`,
@@ -1,3 +1,32 @@
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
@@ -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();
@@ -101,6 +101,8 @@ class EventTarget : public ScriptWrappable {
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 };
@@ -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;
@@ -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 @@ class CommandLineAPIHost : public RefCounted<CommandLineAPIHost> {

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 @@ class CommandLineAPIHost : public RefCounted<CommandLineAPIHost> {
};

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 @@ class CommandLineAPIHost : public RefCounted<CommandLineAPIHost> {

Inspector::InspectorAgent* m_inspectorAgent { nullptr };
Inspector::InspectorConsoleAgent* m_consoleAgent { nullptr };
InspectorDOMAgent* m_domAgent { nullptr };
InspectorDOMStorageAgent* m_domStorageAgent { nullptr };
InspectorDatabaseAgent* m_databaseAgent { nullptr };

@@ -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);
@@ -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()
@@ -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()
@@ -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()
@@ -1,3 +1,12 @@
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
@@ -695,7 +695,7 @@ WI.NativePrototypeFunctionParameters = {
CommandLineAPIHost: {
copyText: "text",
databaseId: "database",
getEventListeners: "node",
getEventListeners: "target",
inspect: "objectId, hints",
storageId: "storage",
__proto__: null,

0 comments on commit 0f8b48a

Please sign in to comment.