- Revision
- 290947
- Author
- [email protected]
- Date
- 2022-03-07 14:10:57 -0800 (Mon, 07 Mar 2022)
Log Message
Cherry-pick r290671. rdar://problem/87340464
Web app fails only when dev tools is open
https://bugs.webkit.org/show_bug.cgi?id=235017
Reviewed by Devin Rousso.
Using the `ScriptExecutionContext` from `event.target()->scriptExecutionContext()` can result the either having a
different script context from the one used when calling `willHandleEvent`, or the event target's context could be
`nullptr`. This can occur when handling the event in `EventTarget::innerInvokeEventListeners` results in a
context change for the event's target, like a MessagePort that has been `disentangle`d, which sets the script
execution context to `nullptr`. Because we only need the script execution context to get the correct injected
script, and the correct injected script for the action below will always be the same injected script used in
`willHandleEvent`, we ignore the current script execution context of the event's target and use the context the
event's target had when it began invoking event listeners.
This change protects us both from the reported crash, as well as leaving an injected script in a bad state
because we did not call `setEventValue` and `clearEventValue` on matching injected scripts for a single event.
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willHandleEventImpl):
(WebCore::InspectorInstrumentation::didHandleEventImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::willHandleEvent):
(WebCore::InspectorInstrumentation::didHandleEvent):
* inspector/agents/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
(WebCore::InspectorDOMDebuggerAgent::didHandleEvent):
* inspector/agents/InspectorDOMDebuggerAgent.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290671 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (290946 => 290947)
--- branches/safari-613-branch/Source/WebCore/ChangeLog 2022-03-07 22:10:54 UTC (rev 290946)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog 2022-03-07 22:10:57 UTC (rev 290947)
@@ -1,5 +1,70 @@
2022-03-07 Russell Epstein <[email protected]>
+ Cherry-pick r290671. rdar://problem/87340464
+
+ Web app fails only when dev tools is open
+ https://bugs.webkit.org/show_bug.cgi?id=235017
+
+ Reviewed by Devin Rousso.
+
+ Using the `ScriptExecutionContext` from `event.target()->scriptExecutionContext()` can result the either having a
+ different script context from the one used when calling `willHandleEvent`, or the event target's context could be
+ `nullptr`. This can occur when handling the event in `EventTarget::innerInvokeEventListeners` results in a
+ context change for the event's target, like a MessagePort that has been `disentangle`d, which sets the script
+ execution context to `nullptr`. Because we only need the script execution context to get the correct injected
+ script, and the correct injected script for the action below will always be the same injected script used in
+ `willHandleEvent`, we ignore the current script execution context of the event's target and use the context the
+ event's target had when it began invoking event listeners.
+
+ This change protects us both from the reported crash, as well as leaving an injected script in a bad state
+ because we did not call `setEventValue` and `clearEventValue` on matching injected scripts for a single event.
+
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore::InspectorInstrumentation::willHandleEventImpl):
+ (WebCore::InspectorInstrumentation::didHandleEventImpl):
+ * inspector/InspectorInstrumentation.h:
+ (WebCore::InspectorInstrumentation::willHandleEvent):
+ (WebCore::InspectorInstrumentation::didHandleEvent):
+ * inspector/agents/InspectorDOMDebuggerAgent.cpp:
+ (WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
+ (WebCore::InspectorDOMDebuggerAgent::didHandleEvent):
+ * inspector/agents/InspectorDOMDebuggerAgent.h:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290671 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-03-01 Patrick Angle <[email protected]>
+
+ Web app fails only when dev tools is open
+ https://bugs.webkit.org/show_bug.cgi?id=235017
+
+ Reviewed by Devin Rousso.
+
+ Using the `ScriptExecutionContext` from `event.target()->scriptExecutionContext()` can result the either having a
+ different script context from the one used when calling `willHandleEvent`, or the event target's context could be
+ `nullptr`. This can occur when handling the event in `EventTarget::innerInvokeEventListeners` results in a
+ context change for the event's target, like a MessagePort that has been `disentangle`d, which sets the script
+ execution context to `nullptr`. Because we only need the script execution context to get the correct injected
+ script, and the correct injected script for the action below will always be the same injected script used in
+ `willHandleEvent`, we ignore the current script execution context of the event's target and use the context the
+ event's target had when it began invoking event listeners.
+
+ This change protects us both from the reported crash, as well as leaving an injected script in a bad state
+ because we did not call `setEventValue` and `clearEventValue` on matching injected scripts for a single event.
+
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore::InspectorInstrumentation::willHandleEventImpl):
+ (WebCore::InspectorInstrumentation::didHandleEventImpl):
+ * inspector/InspectorInstrumentation.h:
+ (WebCore::InspectorInstrumentation::willHandleEvent):
+ (WebCore::InspectorInstrumentation::didHandleEvent):
+ * inspector/agents/InspectorDOMDebuggerAgent.cpp:
+ (WebCore::InspectorDOMDebuggerAgent::willHandleEvent):
+ (WebCore::InspectorDOMDebuggerAgent::didHandleEvent):
+ * inspector/agents/InspectorDOMDebuggerAgent.h:
+
+2022-03-07 Russell Epstein <[email protected]>
+
Cherry-pick r290606. rdar://problem/89482882
[macOS] Unable to upload ".pages" files to file inputs accepting ".pages" and ".jpeg" files
Modified: branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp (290946 => 290947)
--- branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp 2022-03-07 22:10:54 UTC (rev 290946)
+++ branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp 2022-03-07 22:10:57 UTC (rev 290947)
@@ -419,22 +419,22 @@
timelineAgent->willDispatchEvent(event, document.frame());
}
-void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)
+void InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
{
if (auto* webDebuggerAgent = instrumentingAgents.enabledWebDebuggerAgent())
webDebuggerAgent->willHandleEvent(listener);
if (auto* domDebuggerAgent = instrumentingAgents.enabledDOMDebuggerAgent())
- domDebuggerAgent->willHandleEvent(event, listener);
+ domDebuggerAgent->willHandleEvent(context, event, listener);
}
-void InspectorInstrumentation::didHandleEventImpl(InstrumentingAgents& instrumentingAgents, Event& event, const RegisteredEventListener& listener)
+void InspectorInstrumentation::didHandleEventImpl(InstrumentingAgents& instrumentingAgents, ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
{
if (auto* webDebuggerAgent = instrumentingAgents.enabledWebDebuggerAgent())
webDebuggerAgent->didDispatchAsyncCall();
if (auto* domDebuggerAgent = instrumentingAgents.enabledDOMDebuggerAgent())
- domDebuggerAgent->didHandleEvent(event, listener);
+ domDebuggerAgent->didHandleEvent(context, event, listener);
}
void InspectorInstrumentation::didDispatchEventImpl(InstrumentingAgents& instrumentingAgents, const Event& event)
Modified: branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h (290946 => 290947)
--- branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h 2022-03-07 22:10:54 UTC (rev 290946)
+++ branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h 2022-03-07 22:10:57 UTC (rev 290947)
@@ -384,8 +384,8 @@
static void willRemoveEventListenerImpl(InstrumentingAgents&, EventTarget&, const AtomString& eventType, EventListener&, bool capture);
static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomString& eventType, EventListener&, bool capture);
static void willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&);
- static void willHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);
- static void didHandleEventImpl(InstrumentingAgents&, Event&, const RegisteredEventListener&);
+ static void willHandleEventImpl(InstrumentingAgents&, ScriptExecutionContext&, Event&, const RegisteredEventListener&);
+ static void didHandleEventImpl(InstrumentingAgents&, ScriptExecutionContext&, Event&, const RegisteredEventListener&);
static void didDispatchEventImpl(InstrumentingAgents&, const Event&);
static void willDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&, DOMWindow&);
static void didDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&);
@@ -884,7 +884,7 @@
{
FAST_RETURN_IF_NO_FRONTENDS(void());
if (auto* agents = instrumentingAgents(context))
- return willHandleEventImpl(*agents, event, listener);
+ return willHandleEventImpl(*agents, context, event, listener);
}
inline void InspectorInstrumentation::didHandleEvent(ScriptExecutionContext& context, Event& event, const RegisteredEventListener& listener)
@@ -891,7 +891,7 @@
{
FAST_RETURN_IF_NO_FRONTENDS(void());
if (auto* agents = instrumentingAgents(context))
- return didHandleEventImpl(*agents, event, listener);
+ return didHandleEventImpl(*agents, context, event, listener);
}
inline void InspectorInstrumentation::willDispatchEventOnWindow(Frame* frame, const Event& event, DOMWindow& window)
Modified: branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp (290946 => 290947)
--- branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp 2022-03-07 22:10:54 UTC (rev 290946)
+++ branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp 2022-03-07 22:10:57 UTC (rev 290947)
@@ -218,9 +218,12 @@
return makeUnexpected("Not supported");
}
-void InspectorDOMDebuggerAgent::willHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener)
+void InspectorDOMDebuggerAgent::willHandleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event, const RegisteredEventListener& registeredEventListener)
{
- auto state = event.target()->scriptExecutionContext()->globalObject();
+ // `event.target()->scriptExecutionContext()` can change between `willHandleEvent` and `didHandleEvent`. The passed
+ // `scriptExecutionContext` parameter will always match in companion calls to `willHandleEvent` and
+ // `didHandleEvent`, and will not be null.
+ auto state = scriptExecutionContext.globalObject();
auto injectedScript = m_injectedScriptManager.injectedScriptFor(state);
if (injectedScript.hasNoValue())
return;
@@ -259,9 +262,12 @@
m_debuggerAgent->schedulePauseForSpecialBreakpoint(*breakpoint, Inspector::DebuggerFrontendDispatcher::Reason::Listener, WTFMove(eventData));
}
-void InspectorDOMDebuggerAgent::didHandleEvent(Event& event, const RegisteredEventListener& registeredEventListener)
+void InspectorDOMDebuggerAgent::didHandleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event, const RegisteredEventListener& registeredEventListener)
{
- auto state = event.target()->scriptExecutionContext()->globalObject();
+ // `event.target()->scriptExecutionContext()` can change between `willHandleEvent` and `didHandleEvent`. Here it
+ // could also be nullptr. The passed `scriptExecutionContext` parameter here will always match in companion calls to
+ // `willHandleEvent` and `didHandleEvent`, and will not be null.
+ auto state = scriptExecutionContext.globalObject();
auto injectedScript = m_injectedScriptManager.injectedScriptFor(state);
if (injectedScript.hasNoValue())
return;
Modified: branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h (290946 => 290947)
--- branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h 2022-03-07 22:10:54 UTC (rev 290946)
+++ branches/safari-613-branch/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h 2022-03-07 22:10:57 UTC (rev 290947)
@@ -76,8 +76,8 @@
virtual void mainFrameNavigated();
void willSendXMLHttpRequest(const String& url);
void willFetch(const String& url);
- void willHandleEvent(Event&, const RegisteredEventListener&);
- void didHandleEvent(Event&, const RegisteredEventListener&);
+ void willHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&);
+ void didHandleEvent(ScriptExecutionContext&, Event&, const RegisteredEventListener&);
void willFireTimer(bool oneShot);
void didFireTimer(bool oneShot);