Bug 226692 - Reduce use of legacy EventLoopEventQueue and EventLoopTaskQueue
Summary: Reduce use of legacy EventLoopEventQueue and EventLoopTaskQueue
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-05 19:39 PDT by Chris Dumez
Modified: 2021-06-06 14:01 PDT (History)
18 users (show)

See Also:


Attachments
Patch (45.36 KB, patch)
2021-06-05 19:45 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (43.44 KB, patch)
2021-06-05 19:49 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (43.62 KB, patch)
2021-06-05 20:59 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (43.62 KB, patch)
2021-06-05 21:19 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (43.63 KB, patch)
2021-06-06 11:12 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-06-05 19:39:04 PDT
Reduce use of legacy EventLoopEventQueue and EventLoopTaskQueue, and use the HTML event loop directly instead.
Comment 1 Chris Dumez 2021-06-05 19:45:04 PDT
Created attachment 430669 [details]
Patch
Comment 2 Chris Dumez 2021-06-05 19:49:36 PDT
Created attachment 430670 [details]
Patch
Comment 3 Chris Dumez 2021-06-05 20:59:00 PDT
Created attachment 430672 [details]
Patch
Comment 4 Chris Dumez 2021-06-05 21:19:09 PDT
Created attachment 430674 [details]
Patch
Comment 5 Darin Adler 2021-06-05 22:30:29 PDT
Comment on attachment 430674 [details]
Patch

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

> Source/WebCore/Modules/remoteplayback/RemotePlayback.cpp:293
> +    queueTaskToDispatchEvent(*this, TaskSource::MediaElement, event.releaseNonNull());

The old code would silently do nothing if m_state had a bad value. I think this one will crash. Not that a bad value is really possible, but it is a change in behavior.

Also, if we are going to refactor to share more code like this, why not have the switch statement just put the event name into an AtomString or const AtomString*, and share the call to Event::create too?

> Source/WebCore/dom/FullscreenManager.cpp:68
> +                weakThis->dispatchFullscreenChangeEvents();

I’d think that generally we’d want to do something more like:

    makeRef(*weakThis)->dispatchFullscreenChangeEvents();

I will guess that there is no practical real issue in this case, but our object lifetime strategy is normally to say the caller should be holding a reference to objects before calling functions on them. I’d like these rules to be easier to understand and less situational, but this is what I’ve gleaned from talking to others about our lifetime strategy.
Comment 6 Chris Dumez 2021-06-05 22:43:56 PDT
Comment on attachment 430674 [details]
Patch

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

>> Source/WebCore/Modules/remoteplayback/RemotePlayback.cpp:293
>> +    queueTaskToDispatchEvent(*this, TaskSource::MediaElement, event.releaseNonNull());
> 
> The old code would silently do nothing if m_state had a bad value. I think this one will crash. Not that a bad value is really possible, but it is a change in behavior.
> 
> Also, if we are going to refactor to share more code like this, why not have the switch statement just put the event name into an AtomString or const AtomString*, and share the call to Event::create too?

I did not really see the harm since the switch case was handling all enum values. That said, I like your suggestion of extracting the event from the switch better. I’ll do that before landing.

>> Source/WebCore/dom/FullscreenManager.cpp:68
>> +                weakThis->dispatchFullscreenChangeEvents();
> 
> I’d think that generally we’d want to do something more like:
> 
>     makeRef(*weakThis)->dispatchFullscreenChangeEvents();
> 
> I will guess that there is no practical real issue in this case, but our object lifetime strategy is normally to say the caller should be holding a reference to objects before calling functions on them. I’d like these rules to be easier to understand and less situational, but this is what I’ve gleaned from talking to others about our lifetime strategy.

Not a new issue as the previous code was not protecting this either, but I will make the change since it is safer.
Comment 7 Chris Dumez 2021-06-06 11:04:58 PDT
(In reply to Chris Dumez from comment #6)
> Comment on attachment 430674 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=430674&action=review
> 
> >> Source/WebCore/Modules/remoteplayback/RemotePlayback.cpp:293
> >> +    queueTaskToDispatchEvent(*this, TaskSource::MediaElement, event.releaseNonNull());
> > 
> > The old code would silently do nothing if m_state had a bad value. I think this one will crash. Not that a bad value is really possible, but it is a change in behavior.
> > 
> > Also, if we are going to refactor to share more code like this, why not have the switch statement just put the event name into an AtomString or const AtomString*, and share the call to Event::create too?
> 
> I did not really see the harm since the switch case was handling all enum
> values. That said, I like your suggestion of extracting the event from the
> switch better. I’ll do that before landing.
> 
> >> Source/WebCore/dom/FullscreenManager.cpp:68
> >> +                weakThis->dispatchFullscreenChangeEvents();
> > 
> > I’d think that generally we’d want to do something more like:
> > 
> >     makeRef(*weakThis)->dispatchFullscreenChangeEvents();
> > 
> > I will guess that there is no practical real issue in this case, but our object lifetime strategy is normally to say the caller should be holding a reference to objects before calling functions on them. I’d like these rules to be easier to understand and less situational, but this is what I’ve gleaned from talking to others about our lifetime strategy.
> 
> Not a new issue as the previous code was not protecting this either, but I
> will make the change since it is safer.

Same issue as with the last patch you suggested this. FullscreenManager is not RefCounted.
Comment 8 Chris Dumez 2021-06-06 11:12:29 PDT
Created attachment 430687 [details]
Patch
Comment 9 Ryosuke Niwa 2021-06-06 12:02:45 PDT
(In reply to Chris Dumez from comment #7)
> (In reply to Chris Dumez from comment #6)
> > Comment on attachment 430674 [details]
> > Patch
> > >> Source/WebCore/dom/FullscreenManager.cpp:68
> > >> +                weakThis->dispatchFullscreenChangeEvents();
> > > 
> > > I’d think that generally we’d want to do something more like:
> > > 
> > >     makeRef(*weakThis)->dispatchFullscreenChangeEvents();
> > > 
> > > I will guess that there is no practical real issue in this case, but our object lifetime strategy is normally to say the caller should be holding a reference to objects before calling functions on them. I’d like these rules to be easier to understand and less situational, but this is what I’ve gleaned from talking to others about our lifetime strategy.
> > 
> > Not a new issue as the previous code was not protecting this either, but I
> > will make the change since it is safer.
> 
> Same issue as with the last patch you suggested this. FullscreenManager is
> not RefCounted.

We should CheckedPtr in these instances.
Comment 10 EWS 2021-06-06 12:13:15 PDT
Committed r278538 (238536@main): <https://commits.webkit.org/238536@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 430687 [details].
Comment 11 Radar WebKit Bug Importer 2021-06-06 12:14:16 PDT
<rdar://problem/78926233>