Bug 167953

Summary: Initialize the main RunLoop in iOS WebKitLegacy
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: WebCore Misc.Assignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, bburg, commit-queue, joepeck
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix
joepeck: review-
[PATCH] Proposed Fix none

Description Joseph Pecoraro 2017-02-07 13:19:47 PST
Initialize the main RunLoop in iOS WebKitLegacy in WebKitInitialize.

Most API entry points initialize the main runloop on mac, but iOS ignores them. Do it here along with the other initialization.
Comment 1 Joseph Pecoraro 2017-02-07 13:28:44 PST
While this is under WebKitInitialize it is not inside it. Retitling.
Comment 2 Joseph Pecoraro 2017-02-07 13:29:49 PST
Created attachment 300843 [details]
[PATCH] Proposed Fix
Comment 3 Alexey Proskuryakov 2017-02-07 13:42:32 PST
Comment on attachment 300843 [details]
[PATCH] Proposed Fix

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

> Source/WebCore/platform/ios/wak/WebCoreThread.mm:655
> +    RunLoop::initializeMainRunLoop();

Will RunLoop be confused because its initialization happens on the web thread, not the main one?
Comment 4 Joseph Pecoraro 2017-02-07 13:50:32 PST
Comment on attachment 300843 [details]
[PATCH] Proposed Fix

I believe you are correct. What concerns me is that there is an ASSERT(pthread_main_np()) that I added that doesn't fire, so now I'm rather confused.
Comment 5 Joseph Pecoraro 2017-02-07 14:09:34 PST
I found my problem. I added the ASSERT in WTF and built WTF and WebCore but didn't build JavaScriptCore. So my assertion didn't actually materialize. Thanks for the careful review
Comment 6 Joseph Pecoraro 2017-02-07 14:10:19 PST
Created attachment 300851 [details]
[PATCH] Proposed Fix
Comment 7 Alexey Proskuryakov 2017-02-07 15:09:08 PST
Comment on attachment 300851 [details]
[PATCH] Proposed Fix

r=me, however I have another thought about this. Since apparently nothing uses the runloop with iOS WK1, wouldn't it be better to leave it uninitialized for a clear failure to occur if someone tries to use it?

As we initialize it to the actual main thread, it may become more likely that WebCore code will schedule something to run on this thread, which is a bad bad idea.
Comment 8 Alexey Proskuryakov 2017-02-07 15:09:43 PST
I suggest double checking with Anders about what he thinks.
Comment 9 Joseph Pecoraro 2017-02-07 16:12:20 PST
(In reply to comment #7)
> Comment on attachment 300851 [details]
> [PATCH] Proposed Fix
> 
> r=me, however I have another thought about this. Since apparently nothing
> uses the runloop with iOS WK1, wouldn't it be better to leave it
> uninitialized for a clear failure to occur if someone tries to use it?
> 
> As we initialize it to the actual main thread, it may become more likely
> that WebCore code will schedule something to run on this thread, which is a
> bad bad idea.

There are already a few places in WebCore that use RunLoop::main, but as you point out in iOS WebKit1 they may want to be using the WebThread.
Comment 10 Alexey Proskuryakov 2017-02-07 17:00:25 PST
Maybe we should assert when trying to use an uninitialized RunLoop instead.
Comment 11 Joseph Pecoraro 2017-02-08 11:37:36 PST
> There are already a few places in WebCore that use RunLoop::main, but as you
> point out in iOS WebKit1 they may want to be using the WebThread.

Filed Bug 168008.
Comment 12 Joseph Pecoraro 2017-02-08 11:38:18 PST
(In reply to comment #10)
> Maybe we should assert when trying to use an uninitialized RunLoop instead.

That is the assert that is already firing in a few TestAPI Tests in iso-simulator already.
Comment 13 WebKit Commit Bot 2017-02-08 12:05:35 PST
Comment on attachment 300851 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 300851

Committed r211890: <http://trac.webkit.org/changeset/211890>
Comment 14 WebKit Commit Bot 2017-02-08 12:05:39 PST
All reviewed patches have been landed.  Closing bug.
Comment 15 Alexey Proskuryakov 2017-02-08 12:07:58 PST
> > Maybe we should assert when trying to use an uninitialized RunLoop instead.

> That is the assert that is already firing in a few TestAPI Tests in iso-simulator already.

I'm confused. Does this landed change mean that it won't fire any more?
Comment 16 Joseph Pecoraro 2017-02-08 14:39:02 PST
(In reply to comment #15)
> > > Maybe we should assert when trying to use an uninitialized RunLoop instead.
> 
> > That is the assert that is already firing in a few TestAPI Tests in iso-simulator already.
> 
> I'm confused. Does this landed change mean that it won't fire any more?

Correct this fixes those assertions by ensuring we initialize on iOS.