Bug 204447 - Use the event loop instead of DocumentEventQueue and WorkerEventQueue
Summary: Use the event loop instead of DocumentEventQueue and WorkerEventQueue
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks: 203137
  Show dependency treegraph
 
Reported: 2019-11-21 01:11 PST by Ryosuke Niwa
Modified: 2019-12-04 00:12 PST (History)
21 users (show)

See Also:


Attachments
WIP (18.05 KB, patch)
2019-11-21 01:13 PST, Ryosuke Niwa
ews-watchlist: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews212 for win-future (14.37 MB, application/zip)
2019-11-21 03:10 PST, EWS Watchlist
no flags Details
WIP2 (19.44 KB, patch)
2019-11-21 16:42 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP3 (21.89 KB, patch)
2019-11-21 19:46 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch (28.04 KB, patch)
2019-11-21 23:12 PST, Ryosuke Niwa
koivisto: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2019-11-21 01:11:56 PST
Delete DocumentEventQueue and WorkerEventQueue in favor of integration with the HTML5 event loop.
Comment 1 Ryosuke Niwa 2019-11-21 01:13:17 PST
Created attachment 384036 [details]
WIP
Comment 2 EWS Watchlist 2019-11-21 03:10:07 PST
Comment on attachment 384036 [details]
WIP

Attachment 384036 [details] did not pass win-ews (win):
Output: https://webkit-queues.webkit.org/results/13270839

New failing tests:
fast/events/change-overflow-on-overflow-change.html
fast/events/overflow-events-writing-mode.html
fast/events/overflow-events.html
fast/events/overflowchanged-inside-selection-collapse-crash.html
Comment 3 EWS Watchlist 2019-11-21 03:10:09 PST
Created attachment 384040 [details]
Archive of layout-test-results from ews212 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews212  Port: win-future  Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Comment 4 Ryosuke Niwa 2019-11-21 16:42:54 PST
Created attachment 384103 [details]
WIP2
Comment 5 Ryosuke Niwa 2019-11-21 19:46:50 PST
Created attachment 384121 [details]
WIP3
Comment 6 Ryosuke Niwa 2019-11-21 19:53:20 PST
Given the number of code changes that could result in flaky tests, etc... we should probably split the patch to delete DocumentEventQueue and WorkerEventQueue so that reverting would be easy in the case of test regressions.
Comment 7 Radar WebKit Bug Importer 2019-11-21 22:52:24 PST
<rdar://problem/57420691>
Comment 8 Ryosuke Niwa 2019-11-21 23:12:15 PST
Created attachment 384126 [details]
Patch
Comment 9 Ryosuke Niwa 2019-11-21 23:12:59 PST
Comment on attachment 384126 [details]
Patch

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

> Source/WebCore/ChangeLog:22
> +

Note that I'm purposefully not deleting DocumentEventQueue and WorkerEventQueue for now to make reverts easy.
Comment 10 Ryosuke Niwa 2019-11-22 10:12:30 PST
Ping reviewers.
Comment 11 Ryosuke Niwa 2019-11-22 20:29:03 PST
Landed in https://trac.webkit.org/r252824
Comment 12 Darin Adler 2019-12-03 15:17:46 PST
Comment on attachment 384126 [details]
Patch

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

> Source/WebCore/page/PointerCaptureController.cpp:153
> +            // FIXME: Spec doesn't specify which task soruce to use.

Typo in this comment.
Comment 13 Darin Adler 2019-12-03 15:18:38 PST
Comment on attachment 384126 [details]
Patch

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

> Source/WebCore/page/PointerLockController.cpp:220
> +    if (auto protectedDocument = makeRefPtr(document))
> +        protectedDocument->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(type, Event::CanBubble::Yes, Event::IsCancelable::No));

Coding style question: Seems super-subtle to know that we need to protect the document here. Should queueTaskToDispatchEvent do it instead?
Comment 14 Ryosuke Niwa 2019-12-03 18:44:50 PST
(In reply to Darin Adler from comment #13)
> Comment on attachment 384126 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=384126&action=review
> 
> > Source/WebCore/page/PointerLockController.cpp:220
> > +    if (auto protectedDocument = makeRefPtr(document))
> > +        protectedDocument->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(type, Event::CanBubble::Yes, Event::IsCancelable::No));
> 
> Coding style question: Seems super-subtle to know that we need to protect
> the document here. Should queueTaskToDispatchEvent do it instead?

I've been thinking about this raw pointer vs. smart pointer issue for a while now, and my thinking is so far is that we can probably use some simple rule like these:

Any raw pointer or reference to a referenced counted type (i.e. class has ref/deref member functions) should be replaced by a Ref or RefPtr unless those are raw pointers or references passed to the function as an argument, or there is another Ref or RefPtr which stores the same object which does not get cleared or destroyed until all uses of those raw pointers or references.

A slight variant of this rule, which might be more precise to express is as follows:

When calling a non-trivial function G in a function F, every argument of G that is referenced count (i.e. has ref()/deref() member functions) should be stored in Ref or RefPtr in F. That is to say, there must be at least one Ref or RefPtr in the same code block or its ancestor block that is guaranteed to hold the same value as each argument that is referenced count. If one of those arguments of G is also an argument of F, then those arguments do not have Ref/RefPtr in F by transitive property (because the caller of F must have kept those arguments alive).

For example, in the following function f, the local variable `node` should be replaced by RefPtr<Node> but `document` doesn't need to be stored in Ref<Document> because it's an argument.

Node* firstGrandChild(Document& document) {
    Node* node = document.firstChild();
    if (!node)
        return nullptr;
    return node->firstChild();
}

I'm working with a few other folks to come up with a more concrete proposal about this; hopefully in near future.
Comment 15 Ryosuke Niwa 2019-12-03 19:30:30 PST
(In reply to Darin Adler from comment #12)
> Comment on attachment 384126 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=384126&action=review
> 
> > Source/WebCore/page/PointerCaptureController.cpp:153
> > +            // FIXME: Spec doesn't specify which task soruce to use.
> 
> Typo in this comment.

Fixed the typo in https://trac.webkit.org/r253086.