Get rid of StringCapture.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jun 2016 05:47:12 +0000 (05:47 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jun 2016 05:47:12 +0000 (05:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158285

Reviewed by Chris Dumez.

Source/WebCore:

No new tests (Refactor, no behavior change).

* dom/Document.cpp:
(WebCore::Document::addConsoleMessage):
(WebCore::Document::addMessage):

* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::installContentFilterUnblockHandler):

* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):

* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(WebVideoFullscreenControllerContext::setExternalPlayback):

* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::addConsoleMessage):
(WebCore::WorkerGlobalScope::addMessage):

* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
(WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject):

Source/WTF:

* wtf/text/WTFString.h:
(WTF::StringCapture::StringCapture): Deleted.
(WTF::StringCapture::string): Deleted.
(WTF::StringCapture::releaseString): Deleted.
(WTF::StringCapture::operator=): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/text/WTFString.h
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm
Source/WebCore/workers/WorkerGlobalScope.cpp
Source/WebCore/workers/WorkerMessagingProxy.cpp

index d66ccfc..e96e975 100644 (file)
@@ -1,3 +1,16 @@
+2016-06-01  Brady Eidson  <beidson@apple.com>
+
+        Get rid of StringCapture.
+        https://bugs.webkit.org/show_bug.cgi?id=158285
+
+        Reviewed by Chris Dumez.
+
+        * wtf/text/WTFString.h:
+        (WTF::StringCapture::StringCapture): Deleted.
+        (WTF::StringCapture::string): Deleted.
+        (WTF::StringCapture::releaseString): Deleted.
+        (WTF::StringCapture::operator=): Deleted.
+
 2016-06-01  Benjamin Poulain  <bpoulain@apple.com>
 
         [JSC] Some setters for components of Date do not timeClip() their result
index ef621fc..f71f2c0 100644 (file)
@@ -690,25 +690,6 @@ private:
     const char* m_characters;
 };
 
-// For thread-safe lambda capture:
-// StringCapture stringCapture(string);
-// auto lambdaThatRunsInOtherThread = [stringCapture] { String string = stringCapture.string(); ... }
-// FIXME: Remove when we can use C++14 initialized lambda capture: [string = string.isolatedCopy()].
-class StringCapture {
-public:
-    StringCapture() { }
-    StringCapture(const String& string) : m_string(string) { }
-    explicit StringCapture(String&& string) : m_string(string) { }
-    StringCapture(const StringCapture& other) : m_string(other.m_string.isolatedCopy()) { }
-    const String& string() const { return m_string; }
-    String releaseString() { return WTFMove(m_string); }
-
-    void operator=(const StringCapture& other) { m_string = other.m_string.isolatedCopy(); }
-
-private:
-    String m_string;
-};
-
 // Shared global empty string.
 WTF_EXPORT_STRING_API const String& emptyString();
 
@@ -758,7 +739,6 @@ using WTF::isAllSpecialCharacters;
 using WTF::isSpaceOrNewline;
 using WTF::reverseFind;
 using WTF::ASCIILiteral;
-using WTF::StringCapture;
 
 #include <wtf/text/AtomicString.h>
 
index 80a0369..9c0472e 100644 (file)
@@ -1,3 +1,36 @@
+2016-06-01  Brady Eidson  <beidson@apple.com>
+
+        Get rid of StringCapture.
+        https://bugs.webkit.org/show_bug.cgi?id=158285
+
+        Reviewed by Chris Dumez.
+
+        No new tests (Refactor, no behavior change).
+
+        * dom/Document.cpp:
+        (WebCore::Document::addConsoleMessage):
+        (WebCore::Document::addMessage):
+        
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):
+        
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::installContentFilterUnblockHandler):
+        
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):
+        
+        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+        (WebVideoFullscreenControllerContext::setExternalPlayback):
+        
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::addConsoleMessage):
+        (WebCore::WorkerGlobalScope::addMessage):
+        
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
+        (WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject):
+
 2016-05-31  Darin Adler  <darin@apple.com>
 
         Audit RenderObject casts and fix problems and style issues found
index 751c173..1e43e79 100644 (file)
@@ -5333,7 +5333,7 @@ void Document::parseDNSPrefetchControlHeader(const String& dnsPrefetchControl)
 void Document::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
@@ -5344,7 +5344,7 @@ void Document::addConsoleMessage(MessageSource source, MessageLevel level, const
 void Document::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&& callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
index 065a288..d7c2034 100644 (file)
@@ -210,9 +210,9 @@ public:
 protected:
     class AddConsoleMessageTask : public Task {
     public:
-        AddConsoleMessageTask(MessageSource source, MessageLevel level, const StringCapture& message)
-            : Task([source, level, message](ScriptExecutionContext& context) {
-                context.addConsoleMessage(source, level, message.string());
+        AddConsoleMessageTask(MessageSource source, MessageLevel level, const String& message)
+            : Task([source, level, message = message.isolatedCopy()](ScriptExecutionContext& context) {
+                context.addConsoleMessage(source, level, message);
             })
         {
         }
index 97cbf63..9df5650 100644 (file)
@@ -1703,10 +1703,9 @@ void DocumentLoader::installContentFilterUnblockHandler(ContentFilter& contentFi
     String unblockRequestDeniedScript { contentFilter.unblockRequestDeniedScript() };
     if (!unblockRequestDeniedScript.isEmpty() && frame) {
         static_assert(std::is_base_of<ThreadSafeRefCounted<Frame>, Frame>::value, "Frame must be ThreadSafeRefCounted.");
-        StringCapture capturedScript { unblockRequestDeniedScript };
-        unblockHandler.wrapWithDecisionHandler([frame, capturedScript](bool unblocked) {
+        unblockHandler.wrapWithDecisionHandler([frame = WTFMove(frame), script = unblockRequestDeniedScript.isolatedCopy()](bool unblocked) {
             if (!unblocked)
-                frame->script().executeScript(capturedScript.string());
+                frame->script().executeScript(script);
         });
     }
     frameLoader()->client().contentFilterDidBlockLoad(WTFMove(unblockHandler));
index ebd60ff..410118b 100644 (file)
@@ -90,28 +90,23 @@ WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(ThreadableLoaderClien
     , m_loaderProxy(loaderProxy)
     , m_taskMode(taskMode.isolatedCopy())
 {
-    auto* requestData = request.copyData().release();
-    auto* optionsCopy = options.isolatedCopy().release();
-
     ASSERT(securityOrigin);
     ASSERT(contentSecurityPolicy);
-    auto* contentSecurityPolicyCopy = std::make_unique<ContentSecurityPolicy>(*securityOrigin).release();
+
+    auto contentSecurityPolicyCopy = std::make_unique<ContentSecurityPolicy>(*securityOrigin);
     contentSecurityPolicyCopy->copyStateFrom(contentSecurityPolicy);
 
-    StringCapture capturedOutgoingReferrer(outgoingReferrer);
-    m_loaderProxy.postTaskToLoader([this, requestData, optionsCopy, contentSecurityPolicyCopy, capturedOutgoingReferrer](ScriptExecutionContext& context) {
+    m_loaderProxy.postTaskToLoader([this, requestData = request.copyData(), options = options.isolatedCopy(), contentSecurityPolicyCopy = WTFMove(contentSecurityPolicyCopy), outgoingReferrer = outgoingReferrer.isolatedCopy()](ScriptExecutionContext& context) mutable {
         ASSERT(isMainThread());
         Document& document = downcast<Document>(context);
 
-        auto request = ResourceRequest::adopt(std::unique_ptr<CrossThreadResourceRequestData>(requestData));
-        request->setHTTPReferrer(capturedOutgoingReferrer.string());
-
-        auto options = std::unique_ptr<ThreadableLoaderOptions>(optionsCopy);
+        auto request = ResourceRequest::adopt(WTFMove(requestData));
+        request->setHTTPReferrer(outgoingReferrer);
 
         // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
         // will return a 0 value. Either this should return 0 or the other code path should do a callback with
         // a failure.
-        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, *request, *options, std::unique_ptr<ContentSecurityPolicy>(contentSecurityPolicyCopy));
+        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, *request, *options, WTFMove(contentSecurityPolicyCopy));
         ASSERT(m_mainThreadLoader || m_loadingFinished);
     });
 }
index d688505..5a7b74a 100644 (file)
@@ -434,11 +434,9 @@ void WebVideoFullscreenControllerContext::setLegibleMediaSelectionOptions(const
 void WebVideoFullscreenControllerContext::setExternalPlayback(bool enabled, ExternalPlaybackTargetType type, String localizedDeviceName)
 {
     ASSERT(WebThreadIsCurrent());
-    RefPtr<WebVideoFullscreenControllerContext> protectedThis(this);
-    StringCapture capturedLocalizedDeviceName(localizedDeviceName);
-    dispatch_async(dispatch_get_main_queue(), [protectedThis, this, enabled, type, capturedLocalizedDeviceName] {
+    callOnMainThread([protectedThis = Ref<WebVideoFullscreenControllerContext>(*this), this, enabled, type, localizedDeviceName = localizedDeviceName.isolatedCopy()] {
         if (m_interface)
-            m_interface->setExternalPlayback(enabled, type, capturedLocalizedDeviceName.string());
+            m_interface->setExternalPlayback(enabled, type, localizedDeviceName);
     });
 }
 
index 15456e4..6ae96a4 100644 (file)
@@ -253,7 +253,7 @@ void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const
 void WorkerGlobalScope::addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage> message)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(message->source(), message->level(), StringCapture(message->message())));
+        postTask(AddConsoleMessageTask(message->source(), message->level(), message->message()));
         return;
     }
 
@@ -264,7 +264,7 @@ void WorkerGlobalScope::addConsoleMessage(std::unique_ptr<Inspector::ConsoleMess
 void WorkerGlobalScope::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
@@ -275,7 +275,7 @@ void WorkerGlobalScope::addConsoleMessage(MessageSource source, MessageLevel lev
 void WorkerGlobalScope::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<ScriptCallStack>&& callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
index e9a9091..2ec4cc9 100644 (file)
@@ -141,9 +141,7 @@ bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionCon
 
 void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    StringCapture capturedErrorMessage(errorMessage);
-    StringCapture capturedSourceURL(sourceURL);
-    m_scriptExecutionContext->postTask([this, capturedErrorMessage, capturedSourceURL, lineNumber, columnNumber] (ScriptExecutionContext& context) {
+    m_scriptExecutionContext->postTask([this, errorMessage = errorMessage.isolatedCopy(), sourceURL = sourceURL.isolatedCopy(), lineNumber, columnNumber] (ScriptExecutionContext& context) {
         Worker* workerObject = this->workerObject();
         if (!workerObject)
             return;
@@ -151,20 +149,18 @@ void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessag
         // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
         // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
 
-        bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(capturedErrorMessage.string(), capturedSourceURL.string(), lineNumber, columnNumber));
+        bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber));
         if (!errorHandled)
-            context.reportException(capturedErrorMessage.string(), lineNumber, columnNumber, capturedSourceURL.string(), 0);
+            context.reportException(errorMessage, lineNumber, columnNumber, sourceURL, 0);
     });
 }
 
 void WorkerMessagingProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    StringCapture capturedMessage(message);
-    StringCapture capturedSourceURL(sourceURL);
-    m_scriptExecutionContext->postTask([this, source, level, capturedMessage, capturedSourceURL, lineNumber, columnNumber] (ScriptExecutionContext& context) {
+    m_scriptExecutionContext->postTask([this, source, level, message = message.isolatedCopy(), sourceURL = sourceURL.isolatedCopy(), lineNumber, columnNumber] (ScriptExecutionContext& context) {
         if (askedToTerminate())
             return;
-        context.addConsoleMessage(source, level, capturedMessage.string(), capturedSourceURL.string(), lineNumber, columnNumber);
+        context.addConsoleMessage(source, level, message, sourceURL, lineNumber, columnNumber);
     });
 }