Bug 202713 - Web Inspector: Timelines: don't call willDispatchEvent/didDispatchEvent unless there is a listener for the event
Summary: Web Inspector: Timelines: don't call willDispatchEvent/didDispatchEvent unles...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-10-08 17:10 PDT by Devin Rousso
Modified: 2019-10-10 11:05 PDT (History)
14 users (show)

See Also:


Attachments
Patch (12.18 KB, patch)
2019-10-08 17:47 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (12.37 KB, patch)
2019-10-09 10:10 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2019-10-08 17:10:23 PDT
`EventTarget::fireEventListeners` will early return if there are no event listeners for the type of the event being dispatched.  This is not the case for `DOMWindow::dispatchEvent`, which always attempts to dispatch both the capturing and bubbling phase of the event regardless of whether there are any event listeners for the dispatched event's type.
Comment 1 Devin Rousso 2019-10-08 17:47:38 PDT
Created attachment 380485 [details]
Patch
Comment 2 Chris Dumez 2019-10-08 18:45:52 PDT
Comment on attachment 380485 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=380485&action=review

> Source/WebCore/page/DOMWindow.cpp:2182
> +    if (!hasEventListeners(event.type()))

This does not look right to me, given that firing an animationend event may cause a webkitAnimationEnd event listener to get called. See legacyType() in EventTarget.cpp, called from EventTarget::fireEventListeners().
When it comes to DOM / HTML objects, I would discourage from doing such things unless the spec explicitly states it is OK.
Comment 3 Chris Dumez 2019-10-08 18:53:51 PDT
Comment on attachment 380485 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=380485&action=review

>> Source/WebCore/page/DOMWindow.cpp:2182
>> +    if (!hasEventListeners(event.type()))
> 
> This does not look right to me, given that firing an animationend event may cause a webkitAnimationEnd event listener to get called. See legacyType() in EventTarget.cpp, called from EventTarget::fireEventListeners().
> When it comes to DOM / HTML objects, I would discourage from doing such things unless the spec explicitly states it is OK.

Seems like this would also be Web observable, if the JS calls dispatchEvent() on a window (which does not have a listener for |type|, then it would previously set the event's target to window. After your change, it would fail to update the Event's target, which the page's JS could observe by checking event.target after dispatching.
Comment 4 Devin Rousso 2019-10-09 09:28:07 PDT
Comment on attachment 380485 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=380485&action=review

>>> Source/WebCore/page/DOMWindow.cpp:2182
>>> +    if (!hasEventListeners(event.type()))
>> 
>> This does not look right to me, given that firing an animationend event may cause a webkitAnimationEnd event listener to get called. See legacyType() in EventTarget.cpp, called from EventTarget::fireEventListeners().
>> When it comes to DOM / HTML objects, I would discourage from doing such things unless the spec explicitly states it is OK.
> 
> Seems like this would also be Web observable, if the JS calls dispatchEvent() on a window (which does not have a listener for |type|, then it would previously set the event's target to window. After your change, it would fail to update the Event's target, which the page's JS could observe by checking event.target after dispatching.

That's a good point.  I didn't think about events or "legacy" events.  I'll make this patch more specific to Web Inspector.  Thanks!
Comment 5 Devin Rousso 2019-10-09 09:28:23 PDT
Comment on attachment 380485 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=380485&action=review

>>>> Source/WebCore/page/DOMWindow.cpp:2182
>>>> +    if (!hasEventListeners(event.type()))
>>> 
>>> This does not look right to me, given that firing an animationend event may cause a webkitAnimationEnd event listener to get called. See legacyType() in EventTarget.cpp, called from EventTarget::fireEventListeners().
>>> When it comes to DOM / HTML objects, I would discourage from doing such things unless the spec explicitly states it is OK.
>> 
>> Seems like this would also be Web observable, if the JS calls dispatchEvent() on a window (which does not have a listener for |type|, then it would previously set the event's target to window. After your change, it would fail to update the Event's target, which the page's JS could observe by checking event.target after dispatching.
> 
> That's a good point.  I didn't think about events or "legacy" events.  I'll make this patch more specific to Web Inspector.  Thanks!

s/events/custom
Comment 6 Devin Rousso 2019-10-09 10:10:36 PDT
Created attachment 380539 [details]
Patch
Comment 7 Truitt Savell 2019-10-10 09:58:12 PDT
Can we get this reviewed and landed today?
Comment 8 Joseph Pecoraro 2019-10-10 10:10:12 PDT
Comment on attachment 380539 [details]
Patch

r=me
Comment 9 BJ Burg 2019-10-10 10:12:55 PDT
Comment on attachment 380539 [details]
Patch

LGTM
Comment 10 WebKit Commit Bot 2019-10-10 11:04:52 PDT
Comment on attachment 380539 [details]
Patch

Clearing flags on attachment: 380539

Committed r250977: <https://trac.webkit.org/changeset/250977>
Comment 11 WebKit Commit Bot 2019-10-10 11:04:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2019-10-10 11:05:31 PDT
<rdar://problem/56161305>