Source/JavaScriptCore/ChangeLog

 12018-08-16 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 NOBODY (OOPS!).
 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
1222018-08-16 Devin Rousso <drousso@apple.com>
223
324 Web Inspector: allow breakpoints to be set for specific event listeners

Source/JavaScriptCore/inspector/InjectedScript.cpp

@@RefPtr<Protocol::Runtime::ObjectPreview> InjectedScript::previewValue(JSC::JSVal
321321 return BindingTraits<Protocol::Runtime::ObjectPreview>::runtimeCast(resultObject);
322322}
323323
 324void InjectedScript::setEventValue(JSC::JSValue value)
 325{
 326 ASSERT(!hasNoValue());
 327 Deprecated::ScriptFunctionCall function(injectedScriptObject(), "setEventValue"_s, inspectorEnvironment()->functionCallHandler());
 328 function.appendArgument(value);
 329 makeCall(function);
 330}
 331
 332void InjectedScript::clearEventValue()
 333{
 334 ASSERT(!hasNoValue());
 335 Deprecated::ScriptFunctionCall function(injectedScriptObject(), "clearEventValue"_s, inspectorEnvironment()->functionCallHandler());
 336 makeCall(function);
 337}
 338
324339void InjectedScript::setExceptionValue(JSC::JSValue value)
325340{
326341 ASSERT(!hasNoValue());

Source/JavaScriptCore/inspector/InjectedScript.h

@@public:
6868 RefPtr<Protocol::Runtime::RemoteObject> wrapTable(JSC::JSValue table, JSC::JSValue columns) const;
6969 RefPtr<Protocol::Runtime::ObjectPreview> previewValue(JSC::JSValue) const;
7070
 71 void setEventValue(JSC::JSValue);
 72 void clearEventValue();
 73
7174 void setExceptionValue(JSC::JSValue);
7275 void clearExceptionValue();
7376

Source/JavaScriptCore/inspector/InjectedScriptManager.cpp

@@void InjectedScriptManager::releaseObjectGroup(const String& objectGroup)
122122 injectedScript.releaseObjectGroup(objectGroup);
123123}
124124
 125void InjectedScriptManager::clearEventValue()
 126{
 127 for (auto& injectedScript : m_idToInjectedScript.values())
 128 injectedScript.clearEventValue();
 129}
 130
125131void InjectedScriptManager::clearExceptionValue()
126132{
127133 for (auto& injectedScript : m_idToInjectedScript.values())

Source/JavaScriptCore/inspector/InjectedScriptManager.h

@@public:
6060 int injectedScriptIdFor(JSC::ExecState*);
6161 InjectedScript injectedScriptForObjectId(const String& objectId);
6262 void releaseObjectGroup(const String& objectGroup);
 63 void clearEventValue();
6364 void clearExceptionValue();
6465
6566protected:

Source/JavaScriptCore/inspector/InjectedScriptSource.js

@@let InjectedScript = class InjectedScript
306306 return RemoteObject.createObjectPreviewForValue(value, true);
307307 }
308308
 309 setEventValue(value)
 310 {
 311 this._eventValue = value;
 312 }
 313
 314 clearEventValue()
 315 {
 316 delete this._eventValue;
 317 }
 318
309319 setExceptionValue(value)
310320 {
311321 this._exceptionValue = value;

@@function bind(func, thisObject, ...outerArgs)
13831393function BasicCommandLineAPI(callFrame)
13841394{
13851395 this.$_ = injectedScript._lastResult;
 1396 this.$event = injectedScript._eventValue;
13861397 this.$exception = injectedScript._exceptionValue;
13871398
13881399 // $1-$99

Source/WebCore/ChangeLog

 12018-08-16 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 NOBODY (OOPS!).
 7
 8 No new tests (OOPS!).
 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
1252018-08-16 Devin Rousso <drousso@apple.com>
226
327 Web Inspector: allow breakpoints to be set for specific event listeners

Source/WebCore/inspector/CommandLineAPIModuleSource.js

@@function bind(func, thisObject, ...outerArgs)
4747function CommandLineAPI(commandLineAPIImpl, callFrame)
4848{
4949 this.$_ = injectedScript._lastResult;
 50 this.$event = injectedScript._eventValue;
5051 this.$exception = injectedScript._exceptionValue;
5152
5253 // $0

Source/WebCore/inspector/InspectorInstrumentation.cpp

@@InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(I
388388 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
389389}
390390
391 void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, const Event& event, const RegisteredEventListener& listener)
 391void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)
392392{
393393 if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
394394 pageDebuggerAgent->willHandleEvent(listener);

@@void InspectorInstrumentation::didHandleEventImpl(InstrumentingAgents& instrumen
401401{
402402 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
403403 debuggerAgent->didDispatchAsyncCall();
 404
 405 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
 406 domDebuggerAgent->didHandleEvent();
404407}
405408
406409void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)

Source/WebCore/inspector/InspectorInstrumentation.h

@@public:
151151 static bool isEventListenerDisabled(EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
152152 static InspectorInstrumentationCookie willDispatchEvent(Document&, const Event&, bool hasEventListeners);
153153 static void didDispatchEvent(const InspectorInstrumentationCookie&);
154  static void willHandleEvent(ScriptExecutionContext&, const Event&, const RegisteredEventListener&);
 154 static void willHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&);
155155 static void didHandleEvent(ScriptExecutionContext&);
156156 static InspectorInstrumentationCookie willDispatchEventOnWindow(Frame*, const Event&, DOMWindow&);
157157 static void didDispatchEventOnWindow(const InspectorInstrumentationCookie&);

@@private:
334334 static void willRemoveEventListenerImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
335335 static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
336336 static InspectorInstrumentationCookie willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&, bool hasEventListeners);
337  static void willHandleEventImpl(InstrumentingAgents&, const Event&, const RegisteredEventListener&);
 337 static void willHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);
338338 static void didHandleEventImpl(InstrumentingAgents&);
339339 static void didDispatchEventImpl(const InspectorInstrumentationCookie&);
340340 static InspectorInstrumentationCookie willDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&, DOMWindow&);

@@inline void InspectorInstrumentation::didDispatchEvent(const InspectorInstrument
763763 didDispatchEventImpl(cookie);
764764}
765765
766 inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, const Event& event, const RegisteredEventListener& listener)
 766inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
767767{
768768 FAST_RETURN_IF_NO_FRONTENDS(void());
769769 if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))

Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp

3737#include "HTMLElement.h"
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>
4447#include <wtf/JSONValues.h>

@@using namespace Inspector;
6871InspectorDOMDebuggerAgent::InspectorDOMDebuggerAgent(WebAgentContext& context, InspectorDOMAgent* domAgent, InspectorDebuggerAgent* debuggerAgent)
6972 : InspectorAgentBase("DOMDebugger"_s, context)
7073 , m_backendDispatcher(Inspector::DOMDebuggerBackendDispatcher::create(context.backendDispatcher, this))
 74 , m_injectedScriptManager(context.injectedScriptManager)
7175 , m_domAgent(domAgent)
7276 , m_debuggerAgent(debuggerAgent)
7377{

@@void InspectorDOMDebuggerAgent::updateSubtreeBreakpoints(Node* node, uint32_t ro
364368 updateSubtreeBreakpoints(child, newRootMask, set);
365369}
366370
367 void InspectorDOMDebuggerAgent::willHandleEvent(const Event& event, const RegisteredEventListener& registeredEventListener)
 371void InspectorDOMDebuggerAgent::willHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener)
368372{
369373 bool shouldPause = m_debuggerAgent->pauseOnNextStatementEnabled() || m_eventListenerBreakpoints.contains(listenerEventCategoryType + event.type());
370374
371375 if (!shouldPause && m_domAgent)
372376 shouldPause = m_domAgent->hasBreakpointForEventListener(*event.currentTarget(), event.type(), registeredEventListener.callback(), registeredEventListener.useCapture());
373377
 378 auto& state = *event.target()->scriptExecutionContext()->execState();
 379 auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
 380 ASSERT(!injectedScript.hasNoValue());
 381
 382 {
 383 JSC::JSLockHolder lock(&state);
 384
 385 injectedScript.setEventValue(toJS(&state, deprecatedGlobalObjectForPrototype(&state), event));
 386 }
 387
374388 if (!shouldPause)
375389 return;
376390

@@void InspectorDOMDebuggerAgent::willHandleEvent(const Event& event, const Regist
385399 m_debuggerAgent->schedulePauseOnNextStatement(Inspector::DebuggerFrontendDispatcher::Reason::EventListener, WTFMove(eventData));
386400}
387401
 402void InspectorDOMDebuggerAgent::didHandleEvent()
 403{
 404 m_injectedScriptManager.clearEventValue();
 405}
 406
388407void InspectorDOMDebuggerAgent::pauseOnNativeEventIfNeeded(const String& eventName, bool synchronous)
389408{
390409 bool shouldPause = m_debuggerAgent->pauseOnNextStatementEnabled() || m_eventListenerBreakpoints.contains(instrumentationEventCategoryType + eventName);

Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h

3838#include <wtf/JSONValues.h>
3939#include <wtf/text/WTFString.h>
4040
 41namespace Inspector {
 42class InjectedScriptManager;
 43}
 44
4145namespace WebCore {
4246
4347class Element;

@@public:
7579 void willModifyDOMAttr(Element&);
7680 void willSendXMLHttpRequest(const String& url);
7781 void frameDocumentUpdated(Frame&);
78  void willHandleEvent(const Event&, const RegisteredEventListener&);
 82 void willHandleEvent(Event&, const RegisteredEventListener&);
 83 void didHandleEvent();
7984 void pauseOnNativeEventIfNeeded(const String& eventName, bool synchronous);
8085 void mainFrameDOMContentLoaded();
8186

@@private:
97102 void removeBreakpoint(ErrorString&, const String& eventName);
98103
99104 RefPtr<Inspector::DOMDebuggerBackendDispatcher> m_backendDispatcher;
 105 Inspector::InjectedScriptManager& m_injectedScriptManager;
100106 InspectorDOMAgent* m_domAgent { nullptr };
101107 Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr };
102108

Source/WebInspectorUI/ChangeLog

 12018-08-16 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 NOBODY (OOPS!).
 7
 8 * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
 9 (WI.JavaScriptRuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames):
 10
1112018-08-16 Devin Rousso <drousso@apple.com>
212
313 Web Inspector: allow breakpoints to be set for specific event listeners

Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js

@@WI.JavaScriptRuntimeCompletionProvider = class JavaScriptRuntimeCompletionProvid
221221 var commandLineAPI = ["$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners", "$0", "$_"];
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 }
227229 for (var i = 0; i < commandLineAPI.length; ++i)