Title: [243161] trunk/Source
Revision
243161
Author
[email protected]
Date
2019-03-19 12:31:31 -0700 (Tue, 19 Mar 2019)

Log Message

Web Inspector: Provide $event in the console when paused on an event listener
https://bugs.webkit.org/show_bug.cgi?id=188672

Reviewed by Timothy Hatcher.

Source/_javascript_Core:

* inspector/InjectedScript.h:
* inspector/InjectedScript.cpp:
(Inspector::InjectedScript::setEventValue): Added.
(Inspector::InjectedScript::clearEventValue): Added.

* inspector/InjectedScriptManager.h:
* inspector/InjectedScriptManager.cpp:
(Inspector::InjectedScriptManager::clearEventValue): Added.

* inspector/InjectedScriptSource.js:
(WI.InjectedScript.prototype.setEventValue): Added.
(WI.InjectedScript.prototype.clearEventValue): Added.
(BasicCommandLineAPI):

Source/WebCore:

Implement similiar methods/logic as to the way that `$exception` is set.

* inspector/CommandLineAPIModuleSource.js:
(CommandLineAPI):

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::willHandleEvent):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willHandleEventImpl):
(WebCore::InspectorInstrumentation::didHandleEventImpl):

* inspector/agents/InspectorDOMDebuggerAgent.cpp:
* inspector/agents/InspectorDOMDebuggerAgent.h:
(WebCore::InspectorDOMDebuggerAgent::InspectorDOMDebuggerAgent):
(WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
(WebCore::InspectorDOMDebuggerAgent::didHandleEvent): Added.

Source/WebInspectorUI:

* UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js:
(WI._javascript_RuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (243160 => 243161)


--- trunk/Source/_javascript_Core/ChangeLog	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-03-19 19:31:31 UTC (rev 243161)
@@ -1,5 +1,26 @@
 2019-03-19  Devin Rousso  <[email protected]>
 
+        Web Inspector: Provide $event in the console when paused on an event listener
+        https://bugs.webkit.org/show_bug.cgi?id=188672
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/InjectedScript.h:
+        * inspector/InjectedScript.cpp:
+        (Inspector::InjectedScript::setEventValue): Added.
+        (Inspector::InjectedScript::clearEventValue): Added.
+
+        * inspector/InjectedScriptManager.h:
+        * inspector/InjectedScriptManager.cpp:
+        (Inspector::InjectedScriptManager::clearEventValue): Added.
+
+        * inspector/InjectedScriptSource.js:
+        (WI.InjectedScript.prototype.setEventValue): Added.
+        (WI.InjectedScript.prototype.clearEventValue): Added.
+        (BasicCommandLineAPI):
+
+2019-03-19  Devin Rousso  <[email protected]>
+
         Web Inspector: ScriptProfiler: lazily create the agent
         https://bugs.webkit.org/show_bug.cgi?id=195591
         <rdar://problem/48791756>

Modified: trunk/Source/_javascript_Core/inspector/InjectedScript.cpp (243160 => 243161)


--- trunk/Source/_javascript_Core/inspector/InjectedScript.cpp	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/inspector/InjectedScript.cpp	2019-03-19 19:31:31 UTC (rev 243161)
@@ -347,6 +347,21 @@
     return BindingTraits<Protocol::Runtime::ObjectPreview>::runtimeCast(resultObject);
 }
 
+void InjectedScript::setEventValue(JSC::JSValue value)
+{
+    ASSERT(!hasNoValue());
+    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "setEventValue"_s, inspectorEnvironment()->functionCallHandler());
+    function.appendArgument(value);
+    makeCall(function);
+}
+
+void InjectedScript::clearEventValue()
+{
+    ASSERT(!hasNoValue());
+    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "clearEventValue"_s, inspectorEnvironment()->functionCallHandler());
+    makeCall(function);
+}
+
 void InjectedScript::setExceptionValue(JSC::JSValue value)
 {
     ASSERT(!hasNoValue());

Modified: trunk/Source/_javascript_Core/inspector/InjectedScript.h (243160 => 243161)


--- trunk/Source/_javascript_Core/inspector/InjectedScript.h	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/inspector/InjectedScript.h	2019-03-19 19:31:31 UTC (rev 243161)
@@ -80,6 +80,9 @@
     RefPtr<Protocol::Runtime::RemoteObject> wrapTable(JSC::JSValue table, JSC::JSValue columns) const;
     RefPtr<Protocol::Runtime::ObjectPreview> previewValue(JSC::JSValue) const;
 
+    void setEventValue(JSC::JSValue);
+    void clearEventValue();
+
     void setExceptionValue(JSC::JSValue);
     void clearExceptionValue();
 

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp (243160 => 243161)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp	2019-03-19 19:31:31 UTC (rev 243161)
@@ -122,6 +122,12 @@
         injectedScript.releaseObjectGroup(objectGroup);
 }
 
+void InjectedScriptManager::clearEventValue()
+{
+    for (auto& injectedScript : m_idToInjectedScript.values())
+        injectedScript.clearEventValue();
+}
+
 void InjectedScriptManager::clearExceptionValue()
 {
     for (auto& injectedScript : m_idToInjectedScript.values())

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h (243160 => 243161)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h	2019-03-19 19:31:31 UTC (rev 243161)
@@ -60,6 +60,7 @@
     int injectedScriptIdFor(JSC::ExecState*);
     InjectedScript injectedScriptForObjectId(const String& objectId);
     void releaseObjectGroup(const String& objectGroup);
+    void clearEventValue();
     void clearExceptionValue();
 
 protected:

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js (243160 => 243161)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2019-03-19 19:31:31 UTC (rev 243161)
@@ -353,6 +353,16 @@
         return RemoteObject.createObjectPreviewForValue(value, true);
     }
 
+    setEventValue(value)
+    {
+        this._eventValue = value;
+    }
+
+    clearEventValue()
+    {
+        delete this._eventValue;
+    }
+
     setExceptionValue(value)
     {
         this._exceptionValue = value;
@@ -1446,6 +1456,11 @@
     this.$_ = injectedScript._lastResult;
     this.$exception = injectedScript._exceptionValue;
 
+    if ("_eventValue" in injectedScript)
+        this.$event = injectedScript._eventValue;
+    else if ("$event" in this)
+        delete this.$event;
+
     // $1-$99
     for (let i = 1; i <= injectedScript._savedResults.length; ++i)
         this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));

Modified: trunk/Source/WebCore/ChangeLog (243160 => 243161)


--- trunk/Source/WebCore/ChangeLog	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/ChangeLog	2019-03-19 19:31:31 UTC (rev 243161)
@@ -1,5 +1,29 @@
 2019-03-19  Devin Rousso  <[email protected]>
 
+        Web Inspector: Provide $event in the console when paused on an event listener
+        https://bugs.webkit.org/show_bug.cgi?id=188672
+
+        Reviewed by Timothy Hatcher.
+
+        Implement similiar methods/logic as to the way that `$exception` is set.
+
+        * inspector/CommandLineAPIModuleSource.js:
+        (CommandLineAPI):
+
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::willHandleEvent):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willHandleEventImpl):
+        (WebCore::InspectorInstrumentation::didHandleEventImpl):
+
+        * inspector/agents/InspectorDOMDebuggerAgent.cpp:
+        * inspector/agents/InspectorDOMDebuggerAgent.h:
+        (WebCore::InspectorDOMDebuggerAgent::InspectorDOMDebuggerAgent):
+        (WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
+        (WebCore::InspectorDOMDebuggerAgent::didHandleEvent): Added.
+
+2019-03-19  Devin Rousso  <[email protected]>
+
         Web Inspector: ScriptProfiler: lazily create the agent
         https://bugs.webkit.org/show_bug.cgi?id=195591
         <rdar://problem/48791756>

Modified: trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js (243160 => 243161)


--- trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js	2019-03-19 19:31:31 UTC (rev 243161)
@@ -47,6 +47,7 @@
 function CommandLineAPI(commandLineAPIImpl, callFrame)
 {
     this.$_ = injectedScript._lastResult;
+    this.$event = injectedScript._eventValue;
     this.$exception = injectedScript._exceptionValue;
 
     // $0

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (243160 => 243161)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2019-03-19 19:31:31 UTC (rev 243161)
@@ -396,7 +396,7 @@
     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
 }
 
-void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, const Event& event, const RegisteredEventListener& listener)
+void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)
 {
     if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
         pageDebuggerAgent->willHandleEvent(listener);
@@ -409,6 +409,9 @@
 {
     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
         debuggerAgent->didDispatchAsyncCall();
+
+    if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
+        domDebuggerAgent->didHandleEvent();
 }
 
 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (243160 => 243161)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2019-03-19 19:31:31 UTC (rev 243161)
@@ -153,7 +153,7 @@
     static bool isEventListenerDisabled(EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
     static InspectorInstrumentationCookie willDispatchEvent(Document&, const Event&, bool hasEventListeners);
     static void didDispatchEvent(const InspectorInstrumentationCookie&);
-    static void willHandleEvent(ScriptExecutionContext&, const Event&, const RegisteredEventListener&);
+    static void willHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&);
     static void didHandleEvent(ScriptExecutionContext&);
     static InspectorInstrumentationCookie willDispatchEventOnWindow(Frame*, const Event&, DOMWindow&);
     static void didDispatchEventOnWindow(const InspectorInstrumentationCookie&);
@@ -345,7 +345,7 @@
     static void willRemoveEventListenerImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
     static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
     static InspectorInstrumentationCookie willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&, bool hasEventListeners);
-    static void willHandleEventImpl(InstrumentingAgents&, const Event&, const RegisteredEventListener&);
+    static void willHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);
     static void didHandleEventImpl(InstrumentingAgents&);
     static void didDispatchEventImpl(const InspectorInstrumentationCookie&);
     static InspectorInstrumentationCookie willDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&, DOMWindow&);
@@ -800,7 +800,7 @@
         didDispatchEventImpl(cookie);
 }
 
-inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, const Event& event, const RegisteredEventListener& listener)
+inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))

Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp (243160 => 243161)


--- trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp	2019-03-19 19:31:31 UTC (rev 243161)
@@ -37,8 +37,11 @@
 #include "HTMLElement.h"
 #include "InspectorDOMAgent.h"
 #include "InstrumentingAgents.h"
+#include "JSEvent.h"
 #include "RegisteredEventListener.h"
 #include <_javascript_Core/ContentSearchUtilities.h>
+#include <_javascript_Core/InjectedScript.h>
+#include <_javascript_Core/InjectedScriptManager.h>
 #include <_javascript_Core/InspectorFrontendDispatchers.h>
 #include <_javascript_Core/RegularExpression.h>
 #include <wtf/JSONValues.h>
@@ -65,6 +68,7 @@
 InspectorDOMDebuggerAgent::InspectorDOMDebuggerAgent(WebAgentContext& context, InspectorDOMAgent* domAgent, InspectorDebuggerAgent* debuggerAgent)
     : InspectorAgentBase("DOMDebugger"_s, context)
     , m_backendDispatcher(Inspector::DOMDebuggerBackendDispatcher::create(context.backendDispatcher, this))
+    , m_injectedScriptManager(context.injectedScriptManager)
     , m_domAgent(domAgent)
     , m_debuggerAgent(debuggerAgent)
 {
@@ -365,11 +369,20 @@
         updateSubtreeBreakpoints(child, newRootMask, set);
 }
 
-void InspectorDOMDebuggerAgent::willHandleEvent(const Event& event, const RegisteredEventListener& registeredEventListener)
+void InspectorDOMDebuggerAgent::willHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener)
 {
     if (!m_debuggerAgent->breakpointsActive())
         return;
 
+    auto state = event.target()->scriptExecutionContext()->execState();
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(state);
+    ASSERT(!injectedScript.hasNoValue());
+    {
+        JSC::JSLockHolder lock(state);
+
+        injectedScript.setEventValue(toJS(state, deprecatedGlobalObjectForPrototype(state), event));
+    }
+
     bool shouldPause = m_debuggerAgent->pauseOnNextStatementEnabled() || m_eventBreakpoints.contains(std::make_pair(Inspector::Protocol::DOMDebugger::EventBreakpointType::Listener, event.type()));
 
     if (!shouldPause && m_domAgent)
@@ -389,6 +402,11 @@
     m_debuggerAgent->schedulePauseOnNextStatement(Inspector::DebuggerFrontendDispatcher::Reason::EventListener, WTFMove(eventData));
 }
 
+void InspectorDOMDebuggerAgent::didHandleEvent()
+{
+    m_injectedScriptManager.clearEventValue();
+}
+
 void InspectorDOMDebuggerAgent::willFireTimer(bool oneShot)
 {
     if (!m_debuggerAgent->breakpointsActive())

Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h (243160 => 243161)


--- trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h	2019-03-19 19:31:31 UTC (rev 243161)
@@ -38,6 +38,10 @@
 #include <wtf/JSONValues.h>
 #include <wtf/text/WTFString.h>
 
+namespace Inspector {
+class InjectedScriptManager;
+}
+
 namespace WebCore {
 
 class Element;
@@ -74,7 +78,8 @@
     void willSendXMLHttpRequest(const String& url);
     void willFetch(const String& url);
     void frameDocumentUpdated(Frame&);
-    void willHandleEvent(const Event&, const RegisteredEventListener&);
+    void willHandleEvent(Event&, const RegisteredEventListener&);
+    void didHandleEvent();
     void willFireTimer(bool oneShot);
     void willFireAnimationFrame();
     void mainFrameDOMContentLoaded();
@@ -98,6 +103,7 @@
     void discardBindings();
 
     RefPtr<Inspector::DOMDebuggerBackendDispatcher> m_backendDispatcher;
+    Inspector::InjectedScriptManager& m_injectedScriptManager;
     InspectorDOMAgent* m_domAgent { nullptr };
     Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr };
 

Modified: trunk/Source/WebInspectorUI/ChangeLog (243160 => 243161)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-03-19 19:31:31 UTC (rev 243161)
@@ -1,5 +1,15 @@
 2019-03-19  Devin Rousso  <[email protected]>
 
+        Web Inspector: Provide $event in the console when paused on an event listener
+        https://bugs.webkit.org/show_bug.cgi?id=188672
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js:
+        (WI._javascript_RuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames):
+
+2019-03-19  Devin Rousso  <[email protected]>
+
         Web Inspector: DOM: "Capture Screenshot" should only be shown if the node is attached
         https://bugs.webkit.org/show_bug.cgi?id=195793
         <rdar://problem/48916594>

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js (243160 => 243161)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js	2019-03-19 19:25:52 UTC (rev 243160)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js	2019-03-19 19:31:31 UTC (rev 243161)
@@ -221,7 +221,9 @@
                 let commandLineAPI = WI._javascript_RuntimeCompletionProvider._commandLineAPI.slice(0);
                 if (WI.debuggerManager.paused) {
                     let targetData = WI.debuggerManager.dataForTarget(WI.runtimeManager.activeExecutionContext.target);
-                    if (targetData.pauseReason === WI.DebuggerManager.PauseReason.Exception)
+                    if (targetData.pauseReason === WI.DebuggerManager.PauseReason.EventListener)
+                        commandLineAPI.push("$event");
+                    else if (targetData.pauseReason === WI.DebuggerManager.PauseReason.Exception)
                         commandLineAPI.push("$exception");
                 }
                 for (let name of commandLineAPI)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to