Initializing the main thread should initialize the main run loop
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jun 2020 19:28:18 +0000 (19:28 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jun 2020 19:28:18 +0000 (19:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213637

Reviewed by Anders Carlsson.

Source/JavaScriptCore:

* JavaScriptCore.order: Removed some defunct stuff.
* shell/playstation/TestShell.cpp:
(setupTestRun): Merged initializeThreading call with
initializeMainThread call because initializeMainThread is a superset.

Source/WebCore:

* platform/ios/wak/WebCoreThread.mm:
(RunWebThread): Removed call to initializeMainThread() because the main
thread calls it before starting the web thread, so it's a no-op. (And if
it were an op, it would be broken.)
(StartWebThread): Merged RunLoop::initializeMain and initializeThreading
into initializeMainThread.

Source/WebDriver:

* WebDriverService.cpp:
(WebDriver::WebDriverService::run):

Source/WebKit:

* Shared/Cocoa/WebKit2InitializeCocoa.mm:
(WebKit::runInitializationCode):
(WebKit::InitializeWebKit2):
* Shared/WebKit2Initialize.cpp:
(WebKit::InitializeWebKit2):

Source/WebKitLegacy/mac:

* History/WebBackForwardList.mm:
(+[WebBackForwardList initialize]):
* History/WebHistoryItem.mm:
(+[WebHistoryItem initialize]):
* Misc/WebCache.mm:
(+[WebCache initialize]):
* Misc/WebElementDictionary.mm:
(+[WebElementDictionary initialize]):
* Misc/WebIconDatabase.mm:
* Plugins/Hosted/WebHostedNetscapePluginView.mm:
(+[WebHostedNetscapePluginView initialize]):
* Plugins/WebBaseNetscapePluginView.mm:
* Plugins/WebBasePluginPackage.mm:
(+[WebBasePluginPackage initialize]):
* Plugins/WebNetscapePluginView.mm:
(+[WebNetscapePluginView initialize]):
* WebCoreSupport/WebEditorClient.mm:
(+[WebUndoStep initialize]):
* WebCoreSupport/WebFrameLoaderClient.mm:
(+[WebFramePolicyListener initialize]):
* WebView/WebArchive.mm:
(+[WebArchivePrivate initialize]):
* WebView/WebDataSource.mm:
(+[WebDataSource initialize]):
* WebView/WebHTMLView.mm:
(+[WebHTMLViewPrivate initialize]):
(+[WebHTMLView initialize]):
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
* WebView/WebResource.mm:
(+[WebResourcePrivate initialize]):
* WebView/WebTextIterator.mm:
(+[WebTextIteratorPrivate initialize]):
* WebView/WebView.mm:
(+[WebView initialize]):
* WebView/WebViewData.mm:
(+[WebViewPrivate initialize]):

Source/WebKitLegacy/win:

* WebView.cpp:
(WebView::WebView):

Source/WTF:

Previously, some code initialized one, some the other, and some both;
and some code tried to initialize more than once; and some code tried
to initialize in ways that would crash but luckily got pre-empted by
other code that had already initialized.

In addition to general confusion, this setup made it subtly high stakes
to call certain functions, like callOnMainThread or
RunLoop::main().dispatch(), because they might crash if the right
initialization had not been performed.

Let's fix that.

* wtf/MainThread.cpp:
(WTF::initializeMainThread): Removed defunct comment about
initializeMainThreadToProcessMainThread. Shrank scope of initializeKey.
* wtf/RunLoop.cpp:
(WTF::RunLoop::initializeMain): Don't call initializeMainThread anymore
because it calls us now. No need for a store fence since we run on the
main thread and we don't store anything.
(WTF::RunLoop::initializeWeb): Upgrade to RELEASE_ASSERT.
* wtf/RunLoop.h: Removed incorrect comment. (Fascinating to wonder when
it became incorrect.)

Tools:

Updated TestWebKitAPI to stop using RunLoop::initializeMain directly.

* TestWebKitAPI/Tests/WTF/RefPtr.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WTF/RunLoop.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
(ApplicationManifestParserTest::SetUp):
* TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
(TestWebKitAPI::ComplexTextControllerTest::SetUp):
* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::ContentExtensionTest::SetUp):
* TestWebKitAPI/Tests/WebCore/DNS.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/FileMonitor.cpp:
(TestWebKitAPI::TEST_F):
* TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:
(initializeInAppBrowserPrivacyTestSettings):
* TestWebKitAPI/TestsController.cpp:
(TestWebKitAPI::TestsController::TestsController):
* WebKitTestRunner/TestController.cpp:
(TestController::initialize):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263575 268f45cc-cd09-0410-ab3c-d52691b4dbfc

48 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.order
Source/JavaScriptCore/shell/playstation/TestShell.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/MainThread.cpp
Source/WTF/wtf/RunLoop.cpp
Source/WTF/wtf/RunLoop.h
Source/WebCore/ChangeLog
Source/WebCore/platform/ios/wak/WebCoreThread.mm
Source/WebDriver/ChangeLog
Source/WebDriver/WebDriverService.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm
Source/WebKit/Shared/WebKit2Initialize.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/History/WebBackForwardList.mm
Source/WebKitLegacy/mac/History/WebHistoryItem.mm
Source/WebKitLegacy/mac/Misc/WebCache.mm
Source/WebKitLegacy/mac/Misc/WebElementDictionary.mm
Source/WebKitLegacy/mac/Misc/WebIconDatabase.mm
Source/WebKitLegacy/mac/Plugins/Hosted/WebHostedNetscapePluginView.mm
Source/WebKitLegacy/mac/Plugins/WebBaseNetscapePluginView.mm
Source/WebKitLegacy/mac/Plugins/WebBasePluginPackage.mm
Source/WebKitLegacy/mac/Plugins/WebNetscapePluginView.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm
Source/WebKitLegacy/mac/WebView/WebArchive.mm
Source/WebKitLegacy/mac/WebView/WebDataSource.mm
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebResource.mm
Source/WebKitLegacy/mac/WebView/WebTextIterator.mm
Source/WebKitLegacy/mac/WebView/WebView.mm
Source/WebKitLegacy/mac/WebView/WebViewData.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebView.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp
Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp
Tools/TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp
Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp
Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp
Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp
Tools/TestWebKitAPI/Tests/WebCore/DNS.cpp
Tools/TestWebKitAPI/Tests/WebCore/FileMonitor.cpp
Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm
Tools/TestWebKitAPI/TestsController.cpp
Tools/WebKitTestRunner/TestController.cpp

index 9bc9914..092e009 100644 (file)
@@ -1,3 +1,15 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * JavaScriptCore.order: Removed some defunct stuff.
+        * shell/playstation/TestShell.cpp:
+        (setupTestRun): Merged initializeThreading call with
+        initializeMainThread call because initializeMainThread is a superset.
+
 2020-06-25  Yusuke Suzuki  <ysuzuki@apple.com>
 
         REGRESSION(r263035): stress/get-prototype-of.js broken on s390x
index 6b6943c..cf34559 100644 (file)
@@ -49,9 +49,6 @@ __ZN3WTF8fastFreeEPv
 __ZN3JSC13CodeProfiling15notifyAllocatorEPN3WTF13MetaAllocatorE
 __ZN3JSC7JSStack19initializeThreadingEv
 __ZN3JSC5LLInt10initializeEv
-__ZN3WTF39initializeMainThreadToProcessMainThreadEv
-__ZN3WTFL43initializeMainThreadToProcessMainThreadOnceEv
-__ZN3WTF47initializeMainThreadToProcessMainThreadPlatformEv
 __ZN3WTF19initializeGCThreadsEv
 __ZN3WTF18FunctionDispatcherC2Ev
 __ZN3WTF20initializeMainThreadEv
index 57a24fe..82c9f80 100644 (file)
@@ -30,13 +30,11 @@ extern "C" void setupTestRun()
     // Need to initialize WTF threading before we start any threads. Cannot initialize JSC
     // threading yet, since that would do somethings that we'd like to defer until after we
     // have a chance to parse options.
-    WTF::initializeThreading();
+    WTF::initializeMainThread();
 
     // Need to override and enable restricted options before we start parsing options below.
     Config::enableRestrictedOptions();
 
-    // Initialize JSC before getting VM.
-    WTF::initializeMainThread();
     JSC::initializeThreading();
 
 #if ENABLE(WEBASSEMBLY)
index 427b016..d6ca731 100644 (file)
@@ -1,3 +1,33 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        Previously, some code initialized one, some the other, and some both;
+        and some code tried to initialize more than once; and some code tried
+        to initialize in ways that would crash but luckily got pre-empted by
+        other code that had already initialized.
+
+        In addition to general confusion, this setup made it subtly high stakes
+        to call certain functions, like callOnMainThread or
+        RunLoop::main().dispatch(), because they might crash if the right
+        initialization had not been performed.
+
+        Let's fix that.
+
+        * wtf/MainThread.cpp:
+        (WTF::initializeMainThread): Removed defunct comment about
+        initializeMainThreadToProcessMainThread. Shrank scope of initializeKey.
+        * wtf/RunLoop.cpp:
+        (WTF::RunLoop::initializeMain): Don't call initializeMainThread anymore
+        because it calls us now. No need for a store fence since we run on the
+        main thread and we don't store anything.
+        (WTF::RunLoop::initializeWeb): Upgrade to RELEASE_ASSERT.
+        * wtf/RunLoop.h: Removed incorrect comment. (Fascinating to wonder when
+        it became incorrect.)
+
 2020-06-25  Sam Weinig  <weinig@apple.com>
 
         Add a new templated string type to help write more idiomatic parsing code
index dd0ceea..437c9d4 100644 (file)
@@ -49,13 +49,13 @@ static Deque<Function<void ()>>& functionQueue()
     return functionQueue;
 }
 
-// Share this initializeKey with initializeMainThread and initializeMainThreadToProcessMainThread.
-static std::once_flag initializeKey;
 void initializeMainThread()
 {
+    static std::once_flag initializeKey;
     std::call_once(initializeKey, [] {
         initializeThreading();
         initializeMainThreadPlatform();
+        RunLoop::initializeMain();
     });
 }
 
index fb4b29b..4707d4e 100644 (file)
@@ -54,10 +54,7 @@ private:
 
 void RunLoop::initializeMain()
 {
-    if (s_mainRunLoop)
-        return;
-    initializeMainThread();
-    WTF::storeStoreFence();
+    RELEASE_ASSERT(!s_mainRunLoop);
     s_mainRunLoop = &RunLoop::current();
 }
 
@@ -81,6 +78,7 @@ RunLoop* RunLoop::mainIfExists()
 #if USE(WEB_THREAD)
 void RunLoop::initializeWeb()
 {
+    RELEASE_ASSERT(!s_webRunLoop);
     s_webRunLoop = &RunLoop::current();
 }
 
index cdde1ff..5f00b26 100644 (file)
@@ -58,8 +58,7 @@ using RunLoopMode = unsigned;
 class RunLoop final : public FunctionDispatcher {
     WTF_MAKE_NONCOPYABLE(RunLoop);
 public:
-    // Must be called from the main thread (except for the Mac platform, where it
-    // can be called from any thread).
+    // Must be called from the main thread.
     WTF_EXPORT_PRIVATE static void initializeMain();
 #if USE(WEB_THREAD)
     WTF_EXPORT_PRIVATE static void initializeWeb();
index 094f716..d8aa3db 100644 (file)
@@ -1,3 +1,17 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * platform/ios/wak/WebCoreThread.mm:
+        (RunWebThread): Removed call to initializeMainThread() because the main
+        thread calls it before starting the web thread, so it's a no-op. (And if
+        it were an op, it would be broken.)
+        (StartWebThread): Merged RunLoop::initializeMain and initializeThreading
+        into initializeMainThread.
+
 2020-06-26  Andres Gonzalez  <andresg_22@apple.com>
 
         Fix for crash in AXIsolatedObject::relativeFrame.
index 2d488c6..b348b71 100644 (file)
@@ -584,10 +584,9 @@ static void* RunWebThread(void*)
 {
     FloatingPointEnvironment::singleton().propagateMainThreadEnvironment();
 
-    // WTF::initializeMainThread() needs to be called before JSC::initializeThreading() since the
+    // WTF::initializeWebThread() needs to be called before JSC::initializeThreading() since the
     // code invoked by the latter needs to know if it's running on the WebThread. See
     // <rdar://problem/8502487>.
-    WTF::initializeMainThread();
     WTF::initializeWebThread();
     JSC::initializeThreading();
     
@@ -633,7 +632,7 @@ static void StartWebThread()
     webThreadStarted = TRUE;
 
     // ThreadGlobalData touches AtomString, which requires Threading initialization.
-    WTF::initializeThreading();
+    WTF::initializeMainThread();
 
     // Initialize AtomString on the main thread.
     WTF::AtomString::init();
@@ -643,8 +642,6 @@ static void StartWebThread()
     WebCore::ThreadGlobalData& unused = WebCore::threadGlobalData();
     UNUSED_PARAM(unused);
 
-    RunLoop::initializeMain();
-
     // register class for WebThread deallocation
     WebCoreObjCDeallocOnWebThread([WAKWindow class]);
     WebCoreObjCDeallocWithWebThreadLock([WAKView class]);
index 0b69593..7bbd860 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::run):
+
 2020-06-23  Chris Dumez  <cdumez@apple.com>
 
         Remove a lot of unnecessary calls to Ref::copyRef()
index 24997ad..9bb976d 100644 (file)
@@ -96,7 +96,7 @@ int WebDriverService::run(int argc, char** argv)
         return EXIT_FAILURE;
     }
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     if (!m_server.listen(host, port))
         return EXIT_FAILURE;
index 73ad30d..77b1904 100644 (file)
@@ -1,3 +1,16 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/Cocoa/WebKit2InitializeCocoa.mm:
+        (WebKit::runInitializationCode):
+        (WebKit::InitializeWebKit2):
+        * Shared/WebKit2Initialize.cpp:
+        (WebKit::InitializeWebKit2):
+
 2020-06-26  Chris Dumez  <cdumez@apple.com>
 
         [iOS] Network process is crashing when launching TJMaxx app due to invalid NetworkProcess::DestroySession IPC message
index a8cb205..60b32da 100644 (file)
@@ -53,7 +53,7 @@ static void runInitializationCode(void* = nullptr)
 #endif
 
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     WTF::RefCountedBase::enableThreadingChecksGlobally();
 
@@ -65,7 +65,7 @@ static void runInitializationCode(void* = nullptr)
 
 void InitializeWebKit2()
 {
-    // Make sure the initialization code is run only once and on the main thread since things like RunLoop::initializeMain()
+    // Make sure the initialization code is run only once and on the main thread since things like initializeMainThread()
     // are only safe to call on the main thread.
     std::call_once(flag, [] {
         if ([NSThread isMainThread] || linkedOnOrAfter(SDKVersion::FirstWithInitializeWebKit2MainThreadAssertion))
index b204c9a..df7ae01 100644 (file)
@@ -40,7 +40,7 @@ namespace WebKit {
 void InitializeWebKit2()
 {
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     AtomString::init();
 
     WTF::RefCountedBase::enableThreadingChecksGlobally();
index 3531e49..652c908 100644 (file)
@@ -1,3 +1,48 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * History/WebBackForwardList.mm:
+        (+[WebBackForwardList initialize]):
+        * History/WebHistoryItem.mm:
+        (+[WebHistoryItem initialize]):
+        * Misc/WebCache.mm:
+        (+[WebCache initialize]):
+        * Misc/WebElementDictionary.mm:
+        (+[WebElementDictionary initialize]):
+        * Misc/WebIconDatabase.mm:
+        * Plugins/Hosted/WebHostedNetscapePluginView.mm:
+        (+[WebHostedNetscapePluginView initialize]):
+        * Plugins/WebBaseNetscapePluginView.mm:
+        * Plugins/WebBasePluginPackage.mm:
+        (+[WebBasePluginPackage initialize]):
+        * Plugins/WebNetscapePluginView.mm:
+        (+[WebNetscapePluginView initialize]):
+        * WebCoreSupport/WebEditorClient.mm:
+        (+[WebUndoStep initialize]):
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (+[WebFramePolicyListener initialize]):
+        * WebView/WebArchive.mm:
+        (+[WebArchivePrivate initialize]):
+        * WebView/WebDataSource.mm:
+        (+[WebDataSource initialize]):
+        * WebView/WebHTMLView.mm:
+        (+[WebHTMLViewPrivate initialize]):
+        (+[WebHTMLView initialize]):
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        * WebView/WebResource.mm:
+        (+[WebResourcePrivate initialize]):
+        * WebView/WebTextIterator.mm:
+        (+[WebTextIteratorPrivate initialize]):
+        * WebView/WebView.mm:
+        (+[WebView initialize]):
+        * WebView/WebViewData.mm:
+        (+[WebViewPrivate initialize]):
+
 2020-06-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Add a test to verify that async clipboard API write access is granted when copying in subframes
index c8f7658..e90e2bc 100644 (file)
@@ -99,7 +99,7 @@ WebBackForwardList *kit(BackForwardList* backForwardList)
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 220f5aa..fa42d19 100644 (file)
@@ -126,7 +126,7 @@ void WKNotifyHistoryItemChanged(HistoryItem&)
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 1c958ff..39b841f 100644 (file)
@@ -64,7 +64,7 @@ class DefaultStorageSessionProvider : public WebCore::StorageSessionProvider {
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index c27da8a..e574ffb 100644 (file)
@@ -68,7 +68,7 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 1374b4f..8d17fa1 100644 (file)
@@ -98,7 +98,7 @@ ALLOW_DEPRECATED_IMPLEMENTATIONS_END
 + (void)initialize
 {
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 }
 
 + (WebIconDatabase *)sharedIconDatabase
index da777f3..4b99b53 100644 (file)
@@ -106,7 +106,7 @@ extern "C" {
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
     sendUserChangeNotifications();
 }
index 9b47766..c917a39 100644 (file)
@@ -71,7 +71,7 @@ using namespace WebCore;
 + (void)initialize
 {
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     WebKit::sendUserChangeNotifications();
 }
 
index 09aeea2..3331baf 100644 (file)
@@ -60,7 +60,7 @@
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 7f5ce9a..9830cec 100644 (file)
@@ -163,7 +163,7 @@ typedef struct {
 + (void)initialize
 {
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     sendUserChangeNotifications();
 }
 
index 597af7e..b276ed4 100644 (file)
@@ -139,7 +139,7 @@ static WebViewInsertAction kit(EditorInsertAction action)
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 0291be1..7c22d96 100644 (file)
@@ -2343,7 +2343,7 @@ void WebFrameLoaderClient::finishedLoadingIcon(uint64_t callbackID, WebCore::Sha
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 1e96a8d..8f4106d 100644 (file)
@@ -70,7 +70,7 @@ static NSString * const WebSubframeArchivesKey = @"WebSubframeArchives";
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 86a65d5..3b97a8c 100644 (file)
@@ -154,7 +154,7 @@ void addTypesFromClass(NSMutableDictionary *allTypes, Class objCClass, NSArray *
     if (self == [WebDataSource class]) {
 #if !PLATFORM(IOS_FAMILY)
         JSC::initializeThreading();
-        RunLoop::initializeMain();
+        WTF::initializeMainThread();
 #endif
     }
 }
index 9fcd43b..3c1da21 100644 (file)
@@ -1032,7 +1032,7 @@ static NSControlStateValue kit(TriState state)
     // And some of this work is likely redundant since +[WebHTMLView initialize] is guaranteed to run first.
 
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     if (!oldSetCursorForMouseLocationIMP) {
         Method setCursorMethod = class_getInstanceMethod([NSWindow class], @selector(_setCursorForMouseLocation:));
@@ -2566,7 +2566,7 @@ ALLOW_DEPRECATED_DECLARATIONS_END
     [NSApp registerServicesMenuSendTypes:[[self class] _selectionPasteboardTypes] returnTypes:[[self class] _insertablePasteboardTypes]];
 
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 }
 
 #endif
index 5c8d3cf..09e305a 100644 (file)
@@ -388,7 +388,7 @@ public:
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     bool attachmentElementEnabled = MacApplication::isAppleMail();
     bool webSQLEnabled = false;
 #else
index 8351743..49caf90 100644 (file)
@@ -68,7 +68,7 @@ static NSString * const WebResourceResponseKey =          @"WebResourceResponse"
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index ef161ae..f1b23e2 100644 (file)
@@ -48,7 +48,7 @@
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index ea800b4..6aca89d 100644 (file)
@@ -5558,7 +5558,7 @@ IGNORE_WARNINGS_END
 
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 
     WTF::RefCountedBase::enableThreadingChecksGlobally();
index 7d8a8e3..c2d485e 100644 (file)
@@ -168,7 +168,7 @@ void WebViewLayerFlushScheduler::layerFlushCallback()
 {
 #if !PLATFORM(IOS_FAMILY)
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 #endif
 }
 
index 227581a..b30dc5c 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        * WebView.cpp:
+        (WebView::WebView):
+
 2020-06-19  Chris Dumez  <cdumez@apple.com>
 
         Move Prefixed WebAudio interfaces behind their own feature flag
index cb11dde..22c5075 100644 (file)
@@ -421,7 +421,7 @@ bool WebView::s_allowSiteSpecificHacks = false;
 WebView::WebView()
 {
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     WTF::setProcessPrivileges(allPrivileges());
     WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true);
 
index 815a267..3d8fb0b 100644 (file)
@@ -1,3 +1,35 @@
+2020-06-26  Geoffrey Garen  <ggaren@apple.com>
+
+        Initializing the main thread should initialize the main run loop
+        https://bugs.webkit.org/show_bug.cgi?id=213637
+
+        Reviewed by Anders Carlsson.
+
+        Updated TestWebKitAPI to stop using RunLoop::initializeMain directly.
+
+        * TestWebKitAPI/Tests/WTF/RefPtr.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WTF/RunLoop.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
+        (ApplicationManifestParserTest::SetUp):
+        * TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
+        (TestWebKitAPI::ComplexTextControllerTest::SetUp):
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::ContentExtensionTest::SetUp):
+        * TestWebKitAPI/Tests/WebCore/DNS.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/FileMonitor.cpp:
+        (TestWebKitAPI::TEST_F):
+        * TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:
+        (initializeInAppBrowserPrivacyTestSettings):
+        * TestWebKitAPI/TestsController.cpp:
+        (TestWebKitAPI::TestsController::TestsController):
+        * WebKitTestRunner/TestController.cpp:
+        (TestController::initialize):
+
 2020-06-26  Jonathan Bedard  <jbedard@apple.com>
 
         run-javascriptcore-tests: Support Apple Silicon running x86 processes
index 37fe48c..ee74a80 100644 (file)
@@ -585,7 +585,7 @@ TEST(WTF_RefPtr, ReleaseInNonMainThread)
 
 TEST(WTF_RefPtr, ReleaseInNonMainThreadDestroyInMainThread)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     done = false;
     Thread::create("", [object = MainThreadSafeRefCountedObject::create()] { });
     TestWebKitAPI::Util::run(&done);
index 93e94c4..49f6e9c 100644 (file)
@@ -36,7 +36,7 @@ static int count = 100;
 
 TEST(WTF_RunLoop, Deadlock)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     struct DispatchFromDestructorTester {
         ~DispatchFromDestructorTester() {
@@ -76,7 +76,7 @@ private:
 
 TEST(WTF_RunLoop, OneShotTimer)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     bool testFinished = false;
     DerivedOneShotTimer timer(testFinished);
@@ -108,7 +108,7 @@ private:
 
 TEST(WTF_RunLoop, RepeatingTimer)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     bool testFinished = false;
     DerivedRepeatingTimer timer(testFinished);
index e926bf3..7b563d3 100644 (file)
@@ -39,7 +39,7 @@ TEST(AbortableTaskQueue, AsyncTasks)
     AbortableTaskQueue taskQueue;
     bool testFinished { false };
     int currentStep { 0 };
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto backgroundThreadFunction = [&]() {
         EXPECT_FALSE(isMainThread());
@@ -101,7 +101,7 @@ TEST(AbortableTaskQueue, SyncTasks)
     bool testFinished { false };
     bool destructedResponseFlag { false };
     int currentStep { 0 };
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto backgroundThreadFunction = [&]() {
         EXPECT_FALSE(isMainThread());
@@ -183,7 +183,7 @@ TEST(AbortableTaskQueue, Abort)
 
     AbortableTaskQueue taskQueue;
     bool testFinished { false };
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto backgroundThreadFunction = [&]() {
         EXPECT_FALSE(isMainThread());
@@ -240,7 +240,7 @@ TEST(AbortableTaskQueue, AbortBeforeSyncTaskRun)
 {
     AbortableTaskQueue taskQueue;
     bool testFinished { false };
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto backgroundThreadFunction = [&]() {
         EXPECT_FALSE(isMainThread());
@@ -277,7 +277,7 @@ TEST(AbortableTaskQueue, AbortedBySyncTaskHandler)
     bool testFinished { false };
     int currentStep { 0 };
     bool destructedResponseFlag { false };
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto backgroundThreadFunction = [&]() {
         EXPECT_FALSE(isMainThread());
index d8d81c1..b44f543 100644 (file)
@@ -57,7 +57,7 @@ public:
     virtual void SetUp()
     {
         JSC::initializeThreading();
-        RunLoop::initializeMain();
+        WTF::initializeMainThread();
 
         m_manifestURL = { { }, "https://example.com/manifest.json" };
         m_documentURL = { { }, "https://example.com/" };
index 1fb4d22..3b52ac0 100644 (file)
@@ -40,7 +40,7 @@ public:
     virtual void SetUp()
     {
         JSC::initializeThreading();
-        RunLoop::initializeMain();
+        WTF::initializeMainThread();
     }
 };
 
index 55e9c63..13a8f90 100644 (file)
@@ -76,7 +76,7 @@ public:
     virtual void SetUp()
     {
         JSC::initializeThreading();
-        RunLoop::initializeMain();
+        WTF::initializeMainThread();
     }
 };
 
index 3deaaac..d54335b 100644 (file)
@@ -41,7 +41,7 @@ bool done = false;
 
 TEST(DNSTest, cancelResolveDNS)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     const String hostname = String("www.webkit.org");
     uint64_t identifier = 1;
@@ -63,7 +63,7 @@ TEST(DNSTest, cancelResolveDNS)
 
 TEST(DNSTest, cannotResolveDNS)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     const String hostname = String("notavaliddomain.notavaliddomain");
     uint64_t identifier = 1;
@@ -84,7 +84,7 @@ TEST(DNSTest, cannotResolveDNS)
 
 TEST(DNSTest, resolveDNS)
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     const String hostname = String("www.webkit.org");
     uint64_t identifier = 1;
index 22a7465..5848c2a 100644 (file)
@@ -52,7 +52,7 @@ class FileMonitorTest : public testing::Test {
 public:
     void SetUp() override
     {
-        RunLoop::initializeMain();
+        WTF::initializeMainThread();
         
         // create temp file
         FileSystem::PlatformFileHandle handle;
@@ -144,7 +144,7 @@ TEST_F(FileMonitorTest, DetectChange)
 {
     EXPECT_TRUE(FileSystem::fileExists(tempFilePath()));
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto testQueue = WorkQueue::create("Test Work Queue");
 
@@ -186,7 +186,7 @@ TEST_F(FileMonitorTest, DetectMultipleChanges)
 {
     EXPECT_TRUE(FileSystem::fileExists(tempFilePath()));
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto testQueue = WorkQueue::create("Test Work Queue");
 
@@ -246,7 +246,7 @@ TEST_F(FileMonitorTest, DetectDeletion)
 {
     EXPECT_TRUE(FileSystem::fileExists(tempFilePath()));
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto testQueue = WorkQueue::create("Test Work Queue");
 
@@ -285,7 +285,7 @@ TEST_F(FileMonitorTest, DetectChangeAndThenDelete)
 {
     EXPECT_TRUE(FileSystem::fileExists(tempFilePath()));
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto testQueue = WorkQueue::create("Test Work Queue");
 
@@ -342,7 +342,7 @@ TEST_F(FileMonitorTest, DetectDeleteButNotSubsequentChange)
 {
     EXPECT_TRUE(FileSystem::fileExists(tempFilePath()));
 
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
 
     auto testQueue = WorkQueue::create("Test Work Queue");
 
index 16e6c1c..6753b2f 100644 (file)
@@ -124,7 +124,7 @@ static void cleanUpInAppBrowserPrivacyTestSettings()
 
 static void initializeInAppBrowserPrivacyTestSettings()
 {
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     WebCore::clearApplicationBundleIdentifierTestingOverride();
     IN_APP_BROWSER_PRIVACY_ADDITIONS
 }
index a466429..b9db590 100644 (file)
@@ -74,7 +74,6 @@ TestsController::TestsController()
     // the ThreadRestrictionVerifier - https://bugs.webkit.org/show_bug.cgi?id=66112
     // We should make sure that all objects tested either initialize threading or inherit from
     // ThreadSafeRefCounted so that we don't have to initialize threading at all here.
-    WTF::initializeThreading();
     WTF::initializeMainThread();
     WTF::setProcessPrivileges(allPrivileges());
     AtomString::init();
index db57f07..35006ac 100644 (file)
@@ -445,7 +445,7 @@ void TestController::initialize(int argc, const char* argv[])
     AutodrainedPool pool;
 
     JSC::initializeThreading();
-    RunLoop::initializeMain();
+    WTF::initializeMainThread();
     WTF::setProcessPrivileges(allPrivileges());
 
     platformInitialize();