- Revision
- 201496
- Author
- beid...@apple.com
- Date
- 2016-05-29 21:30:22 -0700 (Sun, 29 May 2016)
Log Message
Make ScriptExecutionContext::Task work in terms of wtf::NoncopyableFunction instead of std::function.
https://bugs.webkit.org/show_bug.cgi?id=158187
Reviewed by Chris Dumez.
No new tests (Refactor, no behavior change).
Also make postTask take an rvalue reference.
* bindings/js/JSDOMGlobalObjectTask.cpp:
(WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
* dom/Document.cpp:
(WebCore::Document::postTask):
* dom/Document.h:
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::Task::Task):
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::postTask):
* workers/WorkerGlobalScope.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (201495 => 201496)
--- trunk/Source/WebCore/ChangeLog 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/ChangeLog 2016-05-30 04:30:22 UTC (rev 201496)
@@ -1,3 +1,28 @@
+2016-05-29 Brady Eidson <beid...@apple.com>
+
+ Make ScriptExecutionContext::Task work in terms of wtf::NoncopyableFunction instead of std::function.
+ https://bugs.webkit.org/show_bug.cgi?id=158187
+
+ Reviewed by Chris Dumez.
+
+ No new tests (Refactor, no behavior change).
+
+ Also make postTask take an rvalue reference.
+
+ * bindings/js/JSDOMGlobalObjectTask.cpp:
+ (WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
+
+ * dom/Document.cpp:
+ (WebCore::Document::postTask):
+ * dom/Document.h:
+
+ * dom/ScriptExecutionContext.h:
+ (WebCore::ScriptExecutionContext::Task::Task):
+
+ * workers/WorkerGlobalScope.cpp:
+ (WebCore::WorkerGlobalScope::postTask):
+ * workers/WorkerGlobalScope.h:
+
2016-05-28 Chris Dumez <cdu...@apple.com>
Templatize NoncopyableFunction class similarly to std::function
Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp (201495 => 201496)
--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp 2016-05-30 04:30:22 UTC (rev 201496)
@@ -80,7 +80,7 @@
};
JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject* globalObject, Ref<Microtask>&& task)
- : ScriptExecutionContext::Task(nullptr)
+ : ScriptExecutionContext::Task({ })
{
RefPtr<JSGlobalObjectCallback> callback = JSGlobalObjectCallback::create(globalObject, WTFMove(task));
m_task = [callback] (ScriptExecutionContext&) {
Modified: trunk/Source/WebCore/dom/Document.cpp (201495 => 201496)
--- trunk/Source/WebCore/dom/Document.cpp 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-05-30 04:30:22 UTC (rev 201496)
@@ -5384,7 +5384,7 @@
return topDocument().securityOrigin();
}
-void Document::postTask(Task task)
+void Document::postTask(Task&& task)
{
callOnMainThread([documentReference = m_weakFactory.createWeakPtr(), task = WTFMove(task)]() mutable {
ASSERT(isMainThread());
Modified: trunk/Source/WebCore/dom/Document.h (201495 => 201496)
--- trunk/Source/WebCore/dom/Document.h 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/dom/Document.h 2016-05-30 04:30:22 UTC (rev 201496)
@@ -975,7 +975,7 @@
bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
void parseDNSPrefetchControlHeader(const String&);
- void postTask(Task) final; // Executes the task on context's thread asynchronously.
+ void postTask(Task&&) final; // Executes the task on context's thread asynchronously.
#if ENABLE(REQUEST_ANIMATION_FRAME)
ScriptedAnimationController* scriptedAnimationController() { return m_scriptedAnimationController.get(); }
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (201495 => 201496)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2016-05-30 04:30:22 UTC (rev 201496)
@@ -35,6 +35,7 @@
#include "Supplementable.h"
#include <runtime/ConsoleTypes.h>
#include <wtf/HashSet.h>
+#include <wtf/NoncopyableFunction.h>
namespace JSC {
class ExecState;
@@ -132,20 +133,20 @@
public:
enum CleanupTaskTag { CleanupTask };
- template<typename T, typename = typename std::enable_if<!std::is_base_of<Task, T>::value && std::is_convertible<T, std::function<void (ScriptExecutionContext&)>>::value>::type>
+ template<typename T, typename = typename std::enable_if<!std::is_base_of<Task, T>::value && std::is_convertible<T, NoncopyableFunction<void (ScriptExecutionContext&)>>::value>::type>
Task(T task)
: m_task(WTFMove(task))
, m_isCleanupTask(false)
{
}
- Task(std::function<void()> task)
+ Task(std::function<void ()> task)
: m_task([task](ScriptExecutionContext&) { task(); })
, m_isCleanupTask(false)
{
}
- template<typename T, typename = typename std::enable_if<std::is_convertible<T, std::function<void (ScriptExecutionContext&)>>::value>::type>
+ template<typename T, typename = typename std::enable_if<std::is_convertible<T, NoncopyableFunction<void (ScriptExecutionContext&)>>::value>::type>
Task(CleanupTaskTag, T task)
: m_task(WTFMove(task))
, m_isCleanupTask(true)
@@ -162,11 +163,11 @@
bool isCleanupTask() const { return m_isCleanupTask; }
protected:
- std::function<void (ScriptExecutionContext&)> m_task;
+ NoncopyableFunction<void (ScriptExecutionContext&)> m_task;
bool m_isCleanupTask;
};
- virtual void postTask(Task) = 0; // Executes the task on context's thread asynchronously.
+ virtual void postTask(Task&&) = 0; // Executes the task on context's thread asynchronously.
template<typename... Arguments>
void postCrossThreadTask(Arguments&&... arguments)
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (201495 => 201496)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2016-05-30 04:30:22 UTC (rev 201496)
@@ -173,7 +173,7 @@
return *m_navigator;
}
-void WorkerGlobalScope::postTask(Task task)
+void WorkerGlobalScope::postTask(Task&& task)
{
thread().runLoop().postTask(WTFMove(task));
}
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (201495 => 201496)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.h 2016-05-29 19:01:36 UTC (rev 201495)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h 2016-05-30 04:30:22 UTC (rev 201496)
@@ -88,7 +88,7 @@
using ScriptExecutionContext::hasPendingActivity;
- void postTask(Task) override; // Executes the task on context's thread asynchronously.
+ void postTask(Task&&) final; // Executes the task on context's thread asynchronously.
// WorkerGlobalScope
WorkerGlobalScope& self() { return *this; }