Changeset 290671 in webkit
- Timestamp:
- Mar 1, 2022, 1:19:10 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
inspector/InspectorInstrumentation.cpp (modified) (3 diffs)
-
inspector/InspectorInstrumentation.h (modified) (3 diffs)
-
inspector/agents/InspectorDOMDebuggerAgent.cpp (modified) (2 diffs)
-
inspector/agents/InspectorDOMDebuggerAgent.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r290667 r290671 1 2022-03-01 Patrick Angle <pangle@apple.com> 2 3 Web app fails only when dev tools is open 4 https://bugs.webkit.org/show_bug.cgi?id=235017 5 6 Reviewed by Devin Rousso. 7 8 Using the `ScriptExecutionContext` from `event.target()->scriptExecutionContext()` can result the either having a 9 different script context from the one used when calling `willHandleEvent`, or the event target's context could be 10 `nullptr`. This can occur when handling the event in `EventTarget::innerInvokeEventListeners` results in a 11 context change for the event's target, like a MessagePort that has been `disentangle`d, which sets the script 12 execution context to `nullptr`. Because we only need the script execution context to get the correct injected 13 script, and the correct injected script for the action below will always be the same injected script used in 14 `willHandleEvent`, we ignore the current script execution context of the event's target and use the context the 15 event's target had when it began invoking event listeners. 16 17 This change protects us both from the reported crash, as well as leaving an injected script in a bad state 18 because we did not call `setEventValue` and `clearEventValue` on matching injected scripts for a single event. 19 20 * inspector/InspectorInstrumentation.cpp: 21 (WebCore::InspectorInstrumentation::willHandleEventImpl): 22 (WebCore::InspectorInstrumentation::didHandleEventImpl): 23 * inspector/InspectorInstrumentation.h: 24 (WebCore::InspectorInstrumentation::willHandleEvent): 25 (WebCore::InspectorInstrumentation::didHandleEvent): 26 * inspector/agents/InspectorDOMDebuggerAgent.cpp: 27 (WebCore::InspectorDOMDebuggerAgent::willHandleEvent): 28 (WebCore::InspectorDOMDebuggerAgent::didHandleEvent): 29 * inspector/agents/InspectorDOMDebuggerAgent.h: 30 1 31 2022-03-01 Martin Robinson <mrobinson@webkit.org> 2 32 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp
r290223 r290671 420 420 } 421 421 422 void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)422 void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener) 423 423 { 424 424 if (auto* webDebuggerAgent = instrumentingAgents.enabledWebDebuggerAgent()) … … 426 426 427 427 if (auto* domDebuggerAgent = instrumentingAgents.enabledDOMDebuggerAgent()) 428 domDebuggerAgent->willHandleEvent( event, listener);429 } 430 431 void InspectorInstrumentation::didHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)428 domDebuggerAgent->willHandleEvent(context, event, listener); 429 } 430 431 void InspectorInstrumentation::didHandleEventImpl(InstrumentingAgents& instrumentingAgents, ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener) 432 432 { 433 433 if (auto* webDebuggerAgent = instrumentingAgents.enabledWebDebuggerAgent()) … … 435 435 436 436 if (auto* domDebuggerAgent = instrumentingAgents.enabledDOMDebuggerAgent()) 437 domDebuggerAgent->didHandleEvent( event, listener);437 domDebuggerAgent->didHandleEvent(context, event, listener); 438 438 } 439 439 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.h
r290223 r290671 390 390 static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomString& eventType, EventListener&, bool capture); 391 391 static void willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&); 392 static void willHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);393 static void didHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);392 static void willHandleEventImpl(InstrumentingAgents&, ScriptExecutionContext&, Event&, const RegisteredEventListener&); 393 static void didHandleEventImpl(InstrumentingAgents&, ScriptExecutionContext&, Event&, const RegisteredEventListener&); 394 394 static void didDispatchEventImpl(InstrumentingAgents&, const Event&); 395 395 static void willDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&, DOMWindow&); … … 893 893 FAST_RETURN_IF_NO_FRONTENDS(void()); 894 894 if (auto* agents = instrumentingAgents(context)) 895 return willHandleEventImpl(*agents, event, listener);895 return willHandleEventImpl(*agents, context, event, listener); 896 896 } 897 897 … … 900 900 FAST_RETURN_IF_NO_FRONTENDS(void()); 901 901 if (auto* agents = instrumentingAgents(context)) 902 return didHandleEventImpl(*agents, event, listener);902 return didHandleEventImpl(*agents, context, event, listener); 903 903 } 904 904 -
trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp
r278253 r290671 219 219 } 220 220 221 void InspectorDOMDebuggerAgent::willHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener) 222 { 223 auto state = event.target()->scriptExecutionContext()->globalObject(); 221 void InspectorDOMDebuggerAgent::willHandleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event, const RegisteredEventListener& registeredEventListener) 222 { 223 // `event.target()->scriptExecutionContext()` can change between `willHandleEvent` and `didHandleEvent`. The passed 224 // `scriptExecutionContext` parameter will always match in companion calls to `willHandleEvent` and 225 // `didHandleEvent`, and will not be null. 226 auto state = scriptExecutionContext.globalObject(); 224 227 auto injectedScript = m_injectedScriptManager.injectedScriptFor(state); 225 228 if (injectedScript.hasNoValue()) … … 260 263 } 261 264 262 void InspectorDOMDebuggerAgent::didHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener) 263 { 264 auto state = event.target()->scriptExecutionContext()->globalObject(); 265 void InspectorDOMDebuggerAgent::didHandleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event, const RegisteredEventListener& registeredEventListener) 266 { 267 // `event.target()->scriptExecutionContext()` can change between `willHandleEvent` and `didHandleEvent`. Here it 268 // could also be nullptr. The passed `scriptExecutionContext` parameter here will always match in companion calls to 269 // `willHandleEvent` and `didHandleEvent`, and will not be null. 270 auto state = scriptExecutionContext.globalObject(); 265 271 auto injectedScript = m_injectedScriptManager.injectedScriptFor(state); 266 272 if (injectedScript.hasNoValue()) -
trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h
r278253 r290671 77 77 void willSendXMLHttpRequest(const String& url); 78 78 void willFetch(const String& url); 79 void willHandleEvent( Event&, const RegisteredEventListener&);80 void didHandleEvent( Event&, const RegisteredEventListener&);79 void willHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&); 80 void didHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&); 81 81 void willFireTimer(bool oneShot); 82 82 void didFireTimer(bool oneShot);
Note:
See TracChangeset
for help on using the changeset viewer.