⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243161 in webkit


Ignore:
Timestamp:
Mar 19, 2019, 12:31:31 PM (7 years ago)
Author:
Devin Rousso
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/JavaScriptCore:

  • 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/JavaScriptRuntimeCompletionProvider.js:

(WI.JavaScriptRuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames):

Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r243160 r243161  
     12019-03-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Provide $event in the console when paused on an event listener
     4        https://bugs.webkit.org/show_bug.cgi?id=188672
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * inspector/InjectedScript.h:
     9        * inspector/InjectedScript.cpp:
     10        (Inspector::InjectedScript::setEventValue): Added.
     11        (Inspector::InjectedScript::clearEventValue): Added.
     12
     13        * inspector/InjectedScriptManager.h:
     14        * inspector/InjectedScriptManager.cpp:
     15        (Inspector::InjectedScriptManager::clearEventValue): Added.
     16
     17        * inspector/InjectedScriptSource.js:
     18        (WI.InjectedScript.prototype.setEventValue): Added.
     19        (WI.InjectedScript.prototype.clearEventValue): Added.
     20        (BasicCommandLineAPI):
     21
    1222019-03-19  Devin Rousso  <drousso@apple.com>
    223
  • trunk/Source/JavaScriptCore/inspector/InjectedScript.cpp

    r239976 r243161  
    348348}
    349349
     350void InjectedScript::setEventValue(JSC::JSValue value)
     351{
     352    ASSERT(!hasNoValue());
     353    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "setEventValue"_s, inspectorEnvironment()->functionCallHandler());
     354    function.appendArgument(value);
     355    makeCall(function);
     356}
     357
     358void InjectedScript::clearEventValue()
     359{
     360    ASSERT(!hasNoValue());
     361    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "clearEventValue"_s, inspectorEnvironment()->functionCallHandler());
     362    makeCall(function);
     363}
     364
    350365void InjectedScript::setExceptionValue(JSC::JSValue value)
    351366{
  • trunk/Source/JavaScriptCore/inspector/InjectedScript.h

    r239976 r243161  
    8181    RefPtr<Protocol::Runtime::ObjectPreview> previewValue(JSC::JSValue) const;
    8282
     83    void setEventValue(JSC::JSValue);
     84    void clearEventValue();
     85
    8386    void setExceptionValue(JSC::JSValue);
    8487    void clearExceptionValue();
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp

    r233122 r243161  
    123123}
    124124
     125void InjectedScriptManager::clearEventValue()
     126{
     127    for (auto& injectedScript : m_idToInjectedScript.values())
     128        injectedScript.clearEventValue();
     129}
     130
    125131void InjectedScriptManager::clearExceptionValue()
    126132{
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.h

    r225263 r243161  
    6161    InjectedScript injectedScriptForObjectId(const String& objectId);
    6262    void releaseObjectGroup(const String& objectGroup);
     63    void clearEventValue();
    6364    void clearExceptionValue();
    6465
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js

    r239976 r243161  
    354354    }
    355355
     356    setEventValue(value)
     357    {
     358        this._eventValue = value;
     359    }
     360
     361    clearEventValue()
     362    {
     363        delete this._eventValue;
     364    }
     365
    356366    setExceptionValue(value)
    357367    {
     
    14471457    this.$exception = injectedScript._exceptionValue;
    14481458
     1459    if ("_eventValue" in injectedScript)
     1460        this.$event = injectedScript._eventValue;
     1461    else if ("$event" in this)
     1462        delete this.$event;
     1463
    14491464    // $1-$99
    14501465    for (let i = 1; i <= injectedScript._savedResults.length; ++i)
  • trunk/Source/WebCore/ChangeLog

    r243160 r243161  
     12019-03-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Provide $event in the console when paused on an event listener
     4        https://bugs.webkit.org/show_bug.cgi?id=188672
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Implement similiar methods/logic as to the way that `$exception` is set.
     9
     10        * inspector/CommandLineAPIModuleSource.js:
     11        (CommandLineAPI):
     12
     13        * inspector/InspectorInstrumentation.h:
     14        (WebCore::InspectorInstrumentation::willHandleEvent):
     15        * inspector/InspectorInstrumentation.cpp:
     16        (WebCore::InspectorInstrumentation::willHandleEventImpl):
     17        (WebCore::InspectorInstrumentation::didHandleEventImpl):
     18
     19        * inspector/agents/InspectorDOMDebuggerAgent.cpp:
     20        * inspector/agents/InspectorDOMDebuggerAgent.h:
     21        (WebCore::InspectorDOMDebuggerAgent::InspectorDOMDebuggerAgent):
     22        (WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
     23        (WebCore::InspectorDOMDebuggerAgent::didHandleEvent): Added.
     24
    1252019-03-19  Devin Rousso  <drousso@apple.com>
    226
  • trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js

    r242992 r243161  
    4848{
    4949    this.$_ = injectedScript._lastResult;
     50    this.$event = injectedScript._eventValue;
    5051    this.$exception = injectedScript._exceptionValue;
    5152
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r240549 r243161  
    397397}
    398398
    399 void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, const Event& event, const RegisteredEventListener& listener)
     399void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)
    400400{
    401401    if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
     
    410410    if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
    411411        debuggerAgent->didDispatchAsyncCall();
     412
     413    if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
     414        domDebuggerAgent->didHandleEvent();
    412415}
    413416
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r243119 r243161  
    154154    static InspectorInstrumentationCookie willDispatchEvent(Document&, const Event&, bool hasEventListeners);
    155155    static void didDispatchEvent(const InspectorInstrumentationCookie&);
    156     static void willHandleEvent(ScriptExecutionContext&, const Event&, const RegisteredEventListener&);
     156    static void willHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&);
    157157    static void didHandleEvent(ScriptExecutionContext&);
    158158    static InspectorInstrumentationCookie willDispatchEventOnWindow(Frame*, const Event&, DOMWindow&);
     
    346346    static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
    347347    static InspectorInstrumentationCookie willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&, bool hasEventListeners);
    348     static void willHandleEventImpl(InstrumentingAgents&, const Event&, const RegisteredEventListener&);
     348    static void willHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);
    349349    static void didHandleEventImpl(InstrumentingAgents&);
    350350    static void didDispatchEventImpl(const InspectorInstrumentationCookie&);
     
    801801}
    802802
    803 inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, const Event& event, const RegisteredEventListener& listener)
     803inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
    804804{
    805805    FAST_RETURN_IF_NO_FRONTENDS(void());
  • trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp

    r242588 r243161  
    3838#include "InspectorDOMAgent.h"
    3939#include "InstrumentingAgents.h"
     40#include "JSEvent.h"
    4041#include "RegisteredEventListener.h"
    4142#include <JavaScriptCore/ContentSearchUtilities.h>
     43#include <JavaScriptCore/InjectedScript.h>
     44#include <JavaScriptCore/InjectedScriptManager.h>
    4245#include <JavaScriptCore/InspectorFrontendDispatchers.h>
    4346#include <JavaScriptCore/RegularExpression.h>
     
    6669    : InspectorAgentBase("DOMDebugger"_s, context)
    6770    , m_backendDispatcher(Inspector::DOMDebuggerBackendDispatcher::create(context.backendDispatcher, this))
     71    , m_injectedScriptManager(context.injectedScriptManager)
    6872    , m_domAgent(domAgent)
    6973    , m_debuggerAgent(debuggerAgent)
     
    366370}
    367371
    368 void InspectorDOMDebuggerAgent::willHandleEvent(const Event& event, const RegisteredEventListener& registeredEventListener)
    369 {
    370     if (!m_debuggerAgent->breakpointsActive())
    371         return;
     372void InspectorDOMDebuggerAgent::willHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener)
     373{
     374    if (!m_debuggerAgent->breakpointsActive())
     375        return;
     376
     377    auto state = event.target()->scriptExecutionContext()->execState();
     378    auto injectedScript = m_injectedScriptManager.injectedScriptFor(state);
     379    ASSERT(!injectedScript.hasNoValue());
     380    {
     381        JSC::JSLockHolder lock(state);
     382
     383        injectedScript.setEventValue(toJS(state, deprecatedGlobalObjectForPrototype(state), event));
     384    }
    372385
    373386    bool shouldPause = m_debuggerAgent->pauseOnNextStatementEnabled() || m_eventBreakpoints.contains(std::make_pair(Inspector::Protocol::DOMDebugger::EventBreakpointType::Listener, event.type()));
     
    388401
    389402    m_debuggerAgent->schedulePauseOnNextStatement(Inspector::DebuggerFrontendDispatcher::Reason::EventListener, WTFMove(eventData));
     403}
     404
     405void InspectorDOMDebuggerAgent::didHandleEvent()
     406{
     407    m_injectedScriptManager.clearEventValue();
    390408}
    391409
  • trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h

    r239703 r243161  
    3939#include <wtf/text/WTFString.h>
    4040
     41namespace Inspector {
     42class InjectedScriptManager;
     43}
     44
    4145namespace WebCore {
    4246
     
    7579    void willFetch(const String& url);
    7680    void frameDocumentUpdated(Frame&);
    77     void willHandleEvent(const Event&, const RegisteredEventListener&);
     81    void willHandleEvent(Event&, const RegisteredEventListener&);
     82    void didHandleEvent();
    7883    void willFireTimer(bool oneShot);
    7984    void willFireAnimationFrame();
     
    99104
    100105    RefPtr<Inspector::DOMDebuggerBackendDispatcher> m_backendDispatcher;
     106    Inspector::InjectedScriptManager& m_injectedScriptManager;
    101107    InspectorDOMAgent* m_domAgent { nullptr };
    102108    Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr };
  • trunk/Source/WebInspectorUI/ChangeLog

    r243152 r243161  
     12019-03-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Provide $event in the console when paused on an event listener
     4        https://bugs.webkit.org/show_bug.cgi?id=188672
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
     9        (WI.JavaScriptRuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames):
     10
    1112019-03-19  Devin Rousso  <drousso@apple.com>
    212
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js

    r242992 r243161  
    222222                if (WI.debuggerManager.paused) {
    223223                    let targetData = WI.debuggerManager.dataForTarget(WI.runtimeManager.activeExecutionContext.target);
    224                     if (targetData.pauseReason === WI.DebuggerManager.PauseReason.Exception)
     224                    if (targetData.pauseReason === WI.DebuggerManager.PauseReason.EventListener)
     225                        commandLineAPI.push("$event");
     226                    else if (targetData.pauseReason === WI.DebuggerManager.PauseReason.Exception)
    225227                        commandLineAPI.push("$exception");
    226228                }
Note: See TracChangeset for help on using the changeset viewer.