ScriptExecutionContext::Task should work well with C++11 lambdas
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 27 Apr 2014 14:07:03 +0000 (14:07 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 27 Apr 2014 14:07:03 +0000 (14:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129795

Reviewed by Darin Adler.

Instead of having classes that subclass ScriptExecutionContext::Task and override
the performTask(ScriptExecutionContext*) method, have the ScriptExecutionContext::Task
take in a std::function<void (ScriptExecutionContext*)>-like object trough the constructor
which would contain the code currently kept in the performTask() methods.

This enables inlining C++11 lambdas into ScriptExecutionContext::postTask() calls. For
cleanup tasks, the Task object can be implicitly constructed by using the initializer list
constructor with the first argument being the ScriptExecutionContext::Task::CleanupTask tag.
The ScriptExecutionContext class remains non-copyable and now stores the passed-in invokable
object in the std::function wrapper, along with a boolean member that indicates whether the
task is of cleanup nature.

* Modules/quota/StorageErrorCallback.cpp:
(WebCore::StorageErrorCallback::CallbackTask::CallbackTask):
(WebCore::StorageErrorCallback::CallbackTask::performTask): Deleted.
* Modules/quota/StorageErrorCallback.h:
(WebCore::StorageErrorCallback::CallbackTask::create): Deleted.
* Modules/webdatabase/Database.cpp:
(WebCore::Database::~Database):
(WebCore::Database::runTransaction):
(WebCore::Database::scheduleTransactionCallback):
(WebCore::DerefContextTask::create): Deleted.
(WebCore::DerefContextTask::performTask): Deleted.
(WebCore::DerefContextTask::isCleanupTask): Deleted.
(WebCore::DerefContextTask::DerefContextTask): Deleted.
(WebCore::callTransactionErrorCallback): Deleted.
(WebCore::DeliverPendingCallbackTask::create): Deleted.
(WebCore::DeliverPendingCallbackTask::performTask): Deleted.
(WebCore::DeliverPendingCallbackTask::DeliverPendingCallbackTask): Deleted.
* Modules/webdatabase/DatabaseManager.cpp:
(WebCore::DatabaseManager::openDatabase):
(WebCore::DatabaseCreationCallbackTask::create): Deleted.
(WebCore::DatabaseCreationCallbackTask::performTask): Deleted.
(WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask): Deleted.
* Modules/webdatabase/DatabaseSync.cpp:
(WebCore::CloseSyncDatabaseOnContextThreadTask::create): Deleted.
(WebCore::CloseSyncDatabaseOnContextThreadTask::performTask): Deleted.
(WebCore::CloseSyncDatabaseOnContextThreadTask::CloseSyncDatabaseOnContextThreadTask): Deleted.
* Modules/webdatabase/SQLCallbackWrapper.h:
(WebCore::SQLCallbackWrapper::clear):
(WebCore::SQLCallbackWrapper::SafeReleaseTask::create): Deleted.
(WebCore::SQLCallbackWrapper::SafeReleaseTask::performTask): Deleted.
(WebCore::SQLCallbackWrapper::SafeReleaseTask::isCleanupTask): Deleted.
(WebCore::SQLCallbackWrapper::SafeReleaseTask::SafeReleaseTask): Deleted.
* Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:
(WebCore::ThreadableWebSocketChannelClientWrapper::didConnect):
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveMessage):
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData):
(WebCore::ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmount):
(WebCore::ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake):
(WebCore::ThreadableWebSocketChannelClientWrapper::didClose):
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveMessageError):
(WebCore::ThreadableWebSocketChannelClientWrapper::processPendingTasks):
* Modules/websockets/ThreadableWebSocketChannelClientWrapper.h:
* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize):
(WebCore::WorkerThreadableWebSocketChannel::mainThreadDestroy):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::disconnect):
(WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::create): Deleted.
(WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::~WorkerGlobalScopeDidInitializeTask): Deleted.
(WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::WorkerGlobalScopeDidInitializeTask): Deleted.
* Modules/websockets/WorkerThreadableWebSocketChannel.h:
* bindings/js/JSCallbackData.h:
(WebCore::DeleteCallbackDataTask::DeleteCallbackDataTask):
(WebCore::DeleteCallbackDataTask::create): Deleted.
(WebCore::DeleteCallbackDataTask::performTask): Deleted.
(WebCore::DeleteCallbackDataTask::isCleanupTask): Deleted.
* bindings/js/JSDOMGlobalObjectTask.cpp:
(WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
(WebCore::JSGlobalObjectTask::~JSGlobalObjectTask): Deleted.
(WebCore::JSGlobalObjectTask::performTask): Deleted.
* bindings/js/JSDOMGlobalObjectTask.h:
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::queueTaskToEventLoop):
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateCallbackImplementation):
* dom/CrossThreadTask.h:
(WebCore::CrossThreadTask1::performTask):
(WebCore::CrossThreadTask2::performTask):
(WebCore::CrossThreadTask3::performTask):
(WebCore::CrossThreadTask4::performTask):
(WebCore::CrossThreadTask5::performTask):
(WebCore::CrossThreadTask6::performTask):
(WebCore::CrossThreadTask7::performTask):
(WebCore::CrossThreadTask8::performTask):
(WebCore::createCallbackTask):
(WebCore::CrossThreadTask1::create): Deleted.
(WebCore::CrossThreadTask2::create): Deleted.
(WebCore::CrossThreadTask3::create): Deleted.
(WebCore::CrossThreadTask4::create): Deleted.
(WebCore::CrossThreadTask5::create): Deleted.
(WebCore::CrossThreadTask6::create): Deleted.
(WebCore::CrossThreadTask7::create): Deleted.
(WebCore::CrossThreadTask8::create): Deleted.
* dom/Document.cpp:
(WebCore::Document::addConsoleMessage):
(WebCore::Document::addMessage):
(WebCore::Document::postTask):
(WebCore::Document::pendingTasksTimerFired):
(WebCore::PerformTaskContext::PerformTaskContext): Deleted.
(WebCore::Document::didReceiveTask): Deleted.
* dom/Document.h:
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::processMessagePortMessagesSoon):
(WebCore::ScriptExecutionContext::timerAlignmentInterval):
(WebCore::ProcessMessagesSoonTask::create): Deleted.
(WebCore::ScriptExecutionContext::AddConsoleMessageTask::performTask): Deleted.
(WebCore::ScriptExecutionContext::Task::~Task): Deleted.
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::Task::Task):
(WebCore::ScriptExecutionContext::Task::performTask):
(WebCore::ScriptExecutionContext::Task::isCleanupTask):
(WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):
(WebCore::ScriptExecutionContext::AddConsoleMessageTask::create): Deleted.
* dom/StringCallback.cpp:
(WebCore::StringCallback::scheduleCallback):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::postListenerTask):
(WebCore::CallCacheListenerTask::create): Deleted.
(WebCore::CallCacheListenerTask::CallCacheListenerTask): Deleted.
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerProxy::postTaskToLoader):
(WebCore::SharedWorkerProxy::postTaskForModeToWorkerGlobalScope):
(WebCore::SharedWorkerConnectTask::SharedWorkerConnectTask):
(WebCore::DefaultSharedWorkerRepository::workerScriptLoaded):
(WebCore::DefaultSharedWorkerRepository::connectToWorker):
(WebCore::SharedWorkerConnectTask::create): Deleted.
(WebCore::SharedWorkerConnectTask::performTask): Deleted.
* workers/WorkerEventQueue.cpp:
(WebCore::WorkerEventQueue::EventDispatcher::EventDispatcher):
(WebCore::WorkerEventQueue::EventDispatcher::~EventDispatcher):
(WebCore::WorkerEventQueue::EventDispatcher::dispatch):
(WebCore::WorkerEventQueue::enqueueEvent):
(WebCore::WorkerEventQueue::cancelEvent):
(WebCore::WorkerEventQueue::close):
* workers/WorkerEventQueue.h:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::close):
(WebCore::WorkerGlobalScope::postTask):
(WebCore::WorkerGlobalScope::addConsoleMessage):
(WebCore::WorkerGlobalScope::addMessage):
(WebCore::CloseWorkerGlobalScopeTask::create): Deleted.
(WebCore::CloseWorkerGlobalScopeTask::performTask): Deleted.
(WebCore::CloseWorkerGlobalScopeTask::isCleanupTask): Deleted.
* workers/WorkerGlobalScope.h:
* workers/WorkerLoaderProxy.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
(WebCore::WorkerMessagingProxy::postMessageToWorkerGlobalScope):
(WebCore::WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope):
(WebCore::WorkerMessagingProxy::postTaskToLoader):
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
(WebCore::WorkerMessagingProxy::workerThreadCreated):
(WebCore::WorkerMessagingProxy::notifyNetworkStateChange):
(WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyed):
(WebCore::WorkerMessagingProxy::workerGlobalScopeClosed):
(WebCore::WorkerMessagingProxy::postMessageToPageInspector):
(WebCore::WorkerMessagingProxy::confirmMessageFromWorkerObject):
(WebCore::WorkerMessagingProxy::reportPendingActivity):
(WebCore::MessageWorkerGlobalScopeTask::create): Deleted.
(WebCore::MessageWorkerGlobalScopeTask::MessageWorkerGlobalScopeTask): Deleted.
(WebCore::MessageWorkerGlobalScopeTask::performTask): Deleted.
(WebCore::MessageWorkerTask::create): Deleted.
(WebCore::MessageWorkerTask::MessageWorkerTask): Deleted.
(WebCore::MessageWorkerTask::performTask): Deleted.
(WebCore::WorkerExceptionTask::create): Deleted.
(WebCore::WorkerExceptionTask::WorkerExceptionTask): Deleted.
(WebCore::WorkerExceptionTask::performTask): Deleted.
(WebCore::WorkerGlobalScopeDestroyedTask::create): Deleted.
(WebCore::WorkerGlobalScopeDestroyedTask::WorkerGlobalScopeDestroyedTask): Deleted.
(WebCore::WorkerGlobalScopeDestroyedTask::performTask): Deleted.
(WebCore::WorkerTerminateTask::create): Deleted.
(WebCore::WorkerTerminateTask::WorkerTerminateTask): Deleted.
(WebCore::WorkerTerminateTask::performTask): Deleted.
(WebCore::WorkerThreadActivityReportTask::create): Deleted.
(WebCore::WorkerThreadActivityReportTask::WorkerThreadActivityReportTask): Deleted.
(WebCore::WorkerThreadActivityReportTask::performTask): Deleted.
(WebCore::PostMessageToPageInspectorTask::create): Deleted.
(WebCore::PostMessageToPageInspectorTask::PostMessageToPageInspectorTask): Deleted.
(WebCore::PostMessageToPageInspectorTask::performTask): Deleted.
(WebCore::NotifyNetworkStateChangeTask::create): Deleted.
(WebCore::NotifyNetworkStateChangeTask::NotifyNetworkStateChangeTask): Deleted.
(WebCore::NotifyNetworkStateChangeTask::performTask): Deleted.
* workers/WorkerMessagingProxy.h:
* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::postTask):
(WebCore::WorkerRunLoop::postTaskAndTerminate):
(WebCore::WorkerRunLoop::postTaskForMode):
(WebCore::WorkerRunLoop::Task::create):
(WebCore::WorkerRunLoop::Task::performTask):
(WebCore::WorkerRunLoop::Task::Task):
* workers/WorkerRunLoop.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::stop):
(WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThreads):
(WebCore::WorkerThreadShutdownFinishTask::create): Deleted.
(WebCore::WorkerThreadShutdownFinishTask::performTask): Deleted.
(WebCore::WorkerThreadShutdownFinishTask::isCleanupTask): Deleted.
(WebCore::WorkerThreadShutdownStartTask::create): Deleted.
(WebCore::WorkerThreadShutdownStartTask::performTask): Deleted.
(WebCore::WorkerThreadShutdownStartTask::isCleanupTask): Deleted.

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

35 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/quota/StorageErrorCallback.cpp
Source/WebCore/Modules/quota/StorageErrorCallback.h
Source/WebCore/Modules/webdatabase/Database.cpp
Source/WebCore/Modules/webdatabase/DatabaseManager.cpp
Source/WebCore/Modules/webdatabase/DatabaseSync.cpp
Source/WebCore/Modules/webdatabase/SQLCallbackWrapper.h
Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.h
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h
Source/WebCore/bindings/js/JSCallbackData.h
Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp
Source/WebCore/bindings/js/JSDOMGlobalObjectTask.h
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/dom/CrossThreadTask.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/dom/StringCallback.cpp
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
Source/WebCore/workers/WorkerEventQueue.cpp
Source/WebCore/workers/WorkerEventQueue.h
Source/WebCore/workers/WorkerGlobalScope.cpp
Source/WebCore/workers/WorkerGlobalScope.h
Source/WebCore/workers/WorkerLoaderProxy.h
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebCore/workers/WorkerMessagingProxy.h
Source/WebCore/workers/WorkerRunLoop.cpp
Source/WebCore/workers/WorkerRunLoop.h
Source/WebCore/workers/WorkerThread.cpp

index d7d096a..7b348f2 100644 (file)
@@ -1,3 +1,214 @@
+2014-04-27  Zan Dobersek  <zdobersek@igalia.com>
+
+        ScriptExecutionContext::Task should work well with C++11 lambdas
+        https://bugs.webkit.org/show_bug.cgi?id=129795
+
+        Reviewed by Darin Adler.
+
+        Instead of having classes that subclass ScriptExecutionContext::Task and override
+        the performTask(ScriptExecutionContext*) method, have the ScriptExecutionContext::Task
+        take in a std::function<void (ScriptExecutionContext*)>-like object trough the constructor
+        which would contain the code currently kept in the performTask() methods.
+
+        This enables inlining C++11 lambdas into ScriptExecutionContext::postTask() calls. For
+        cleanup tasks, the Task object can be implicitly constructed by using the initializer list
+        constructor with the first argument being the ScriptExecutionContext::Task::CleanupTask tag.
+        The ScriptExecutionContext class remains non-copyable and now stores the passed-in invokable
+        object in the std::function wrapper, along with a boolean member that indicates whether the
+        task is of cleanup nature.
+
+        * Modules/quota/StorageErrorCallback.cpp:
+        (WebCore::StorageErrorCallback::CallbackTask::CallbackTask):
+        (WebCore::StorageErrorCallback::CallbackTask::performTask): Deleted.
+        * Modules/quota/StorageErrorCallback.h:
+        (WebCore::StorageErrorCallback::CallbackTask::create): Deleted.
+        * Modules/webdatabase/Database.cpp:
+        (WebCore::Database::~Database):
+        (WebCore::Database::runTransaction):
+        (WebCore::Database::scheduleTransactionCallback):
+        (WebCore::DerefContextTask::create): Deleted.
+        (WebCore::DerefContextTask::performTask): Deleted.
+        (WebCore::DerefContextTask::isCleanupTask): Deleted.
+        (WebCore::DerefContextTask::DerefContextTask): Deleted.
+        (WebCore::callTransactionErrorCallback): Deleted.
+        (WebCore::DeliverPendingCallbackTask::create): Deleted.
+        (WebCore::DeliverPendingCallbackTask::performTask): Deleted.
+        (WebCore::DeliverPendingCallbackTask::DeliverPendingCallbackTask): Deleted.
+        * Modules/webdatabase/DatabaseManager.cpp:
+        (WebCore::DatabaseManager::openDatabase):
+        (WebCore::DatabaseCreationCallbackTask::create): Deleted.
+        (WebCore::DatabaseCreationCallbackTask::performTask): Deleted.
+        (WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask): Deleted.
+        * Modules/webdatabase/DatabaseSync.cpp:
+        (WebCore::CloseSyncDatabaseOnContextThreadTask::create): Deleted.
+        (WebCore::CloseSyncDatabaseOnContextThreadTask::performTask): Deleted.
+        (WebCore::CloseSyncDatabaseOnContextThreadTask::CloseSyncDatabaseOnContextThreadTask): Deleted.
+        * Modules/webdatabase/SQLCallbackWrapper.h:
+        (WebCore::SQLCallbackWrapper::clear):
+        (WebCore::SQLCallbackWrapper::SafeReleaseTask::create): Deleted.
+        (WebCore::SQLCallbackWrapper::SafeReleaseTask::performTask): Deleted.
+        (WebCore::SQLCallbackWrapper::SafeReleaseTask::isCleanupTask): Deleted.
+        (WebCore::SQLCallbackWrapper::SafeReleaseTask::SafeReleaseTask): Deleted.
+        * Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didConnect):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveMessage):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmount):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didClose):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveMessageError):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::processPendingTasks):
+        * Modules/websockets/ThreadableWebSocketChannelClientWrapper.h:
+        * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize):
+        (WebCore::WorkerThreadableWebSocketChannel::mainThreadDestroy):
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::disconnect):
+        (WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::create): Deleted.
+        (WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::~WorkerGlobalScopeDidInitializeTask): Deleted.
+        (WebCore::WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::WorkerGlobalScopeDidInitializeTask): Deleted.
+        * Modules/websockets/WorkerThreadableWebSocketChannel.h:
+        * bindings/js/JSCallbackData.h:
+        (WebCore::DeleteCallbackDataTask::DeleteCallbackDataTask):
+        (WebCore::DeleteCallbackDataTask::create): Deleted.
+        (WebCore::DeleteCallbackDataTask::performTask): Deleted.
+        (WebCore::DeleteCallbackDataTask::isCleanupTask): Deleted.
+        * bindings/js/JSDOMGlobalObjectTask.cpp:
+        (WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
+        (WebCore::JSGlobalObjectTask::~JSGlobalObjectTask): Deleted.
+        (WebCore::JSGlobalObjectTask::performTask): Deleted.
+        * bindings/js/JSDOMGlobalObjectTask.h:
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::queueTaskToEventLoop):
+        * bindings/js/JSWorkerGlobalScopeBase.cpp:
+        (WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateCallbackImplementation):
+        * dom/CrossThreadTask.h:
+        (WebCore::CrossThreadTask1::performTask):
+        (WebCore::CrossThreadTask2::performTask):
+        (WebCore::CrossThreadTask3::performTask):
+        (WebCore::CrossThreadTask4::performTask):
+        (WebCore::CrossThreadTask5::performTask):
+        (WebCore::CrossThreadTask6::performTask):
+        (WebCore::CrossThreadTask7::performTask):
+        (WebCore::CrossThreadTask8::performTask):
+        (WebCore::createCallbackTask):
+        (WebCore::CrossThreadTask1::create): Deleted.
+        (WebCore::CrossThreadTask2::create): Deleted.
+        (WebCore::CrossThreadTask3::create): Deleted.
+        (WebCore::CrossThreadTask4::create): Deleted.
+        (WebCore::CrossThreadTask5::create): Deleted.
+        (WebCore::CrossThreadTask6::create): Deleted.
+        (WebCore::CrossThreadTask7::create): Deleted.
+        (WebCore::CrossThreadTask8::create): Deleted.
+        * dom/Document.cpp:
+        (WebCore::Document::addConsoleMessage):
+        (WebCore::Document::addMessage):
+        (WebCore::Document::postTask):
+        (WebCore::Document::pendingTasksTimerFired):
+        (WebCore::PerformTaskContext::PerformTaskContext): Deleted.
+        (WebCore::Document::didReceiveTask): Deleted.
+        * dom/Document.h:
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::processMessagePortMessagesSoon):
+        (WebCore::ScriptExecutionContext::timerAlignmentInterval):
+        (WebCore::ProcessMessagesSoonTask::create): Deleted.
+        (WebCore::ScriptExecutionContext::AddConsoleMessageTask::performTask): Deleted.
+        (WebCore::ScriptExecutionContext::Task::~Task): Deleted.
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::Task::Task):
+        (WebCore::ScriptExecutionContext::Task::performTask):
+        (WebCore::ScriptExecutionContext::Task::isCleanupTask):
+        (WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):
+        (WebCore::ScriptExecutionContext::AddConsoleMessageTask::create): Deleted.
+        * dom/StringCallback.cpp:
+        (WebCore::StringCallback::scheduleCallback):
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::postListenerTask):
+        (WebCore::CallCacheListenerTask::create): Deleted.
+        (WebCore::CallCacheListenerTask::CallCacheListenerTask): Deleted.
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::SharedWorkerProxy::postTaskToLoader):
+        (WebCore::SharedWorkerProxy::postTaskForModeToWorkerGlobalScope):
+        (WebCore::SharedWorkerConnectTask::SharedWorkerConnectTask):
+        (WebCore::DefaultSharedWorkerRepository::workerScriptLoaded):
+        (WebCore::DefaultSharedWorkerRepository::connectToWorker):
+        (WebCore::SharedWorkerConnectTask::create): Deleted.
+        (WebCore::SharedWorkerConnectTask::performTask): Deleted.
+        * workers/WorkerEventQueue.cpp:
+        (WebCore::WorkerEventQueue::EventDispatcher::EventDispatcher):
+        (WebCore::WorkerEventQueue::EventDispatcher::~EventDispatcher):
+        (WebCore::WorkerEventQueue::EventDispatcher::dispatch):
+        (WebCore::WorkerEventQueue::enqueueEvent):
+        (WebCore::WorkerEventQueue::cancelEvent):
+        (WebCore::WorkerEventQueue::close):
+        * workers/WorkerEventQueue.h:
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::close):
+        (WebCore::WorkerGlobalScope::postTask):
+        (WebCore::WorkerGlobalScope::addConsoleMessage):
+        (WebCore::WorkerGlobalScope::addMessage):
+        (WebCore::CloseWorkerGlobalScopeTask::create): Deleted.
+        (WebCore::CloseWorkerGlobalScopeTask::performTask): Deleted.
+        (WebCore::CloseWorkerGlobalScopeTask::isCleanupTask): Deleted.
+        * workers/WorkerGlobalScope.h:
+        * workers/WorkerLoaderProxy.h:
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
+        (WebCore::WorkerMessagingProxy::postMessageToWorkerGlobalScope):
+        (WebCore::WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope):
+        (WebCore::WorkerMessagingProxy::postTaskToLoader):
+        (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
+        (WebCore::WorkerMessagingProxy::workerThreadCreated):
+        (WebCore::WorkerMessagingProxy::notifyNetworkStateChange):
+        (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyed):
+        (WebCore::WorkerMessagingProxy::workerGlobalScopeClosed):
+        (WebCore::WorkerMessagingProxy::postMessageToPageInspector):
+        (WebCore::WorkerMessagingProxy::confirmMessageFromWorkerObject):
+        (WebCore::WorkerMessagingProxy::reportPendingActivity):
+        (WebCore::MessageWorkerGlobalScopeTask::create): Deleted.
+        (WebCore::MessageWorkerGlobalScopeTask::MessageWorkerGlobalScopeTask): Deleted.
+        (WebCore::MessageWorkerGlobalScopeTask::performTask): Deleted.
+        (WebCore::MessageWorkerTask::create): Deleted.
+        (WebCore::MessageWorkerTask::MessageWorkerTask): Deleted.
+        (WebCore::MessageWorkerTask::performTask): Deleted.
+        (WebCore::WorkerExceptionTask::create): Deleted.
+        (WebCore::WorkerExceptionTask::WorkerExceptionTask): Deleted.
+        (WebCore::WorkerExceptionTask::performTask): Deleted.
+        (WebCore::WorkerGlobalScopeDestroyedTask::create): Deleted.
+        (WebCore::WorkerGlobalScopeDestroyedTask::WorkerGlobalScopeDestroyedTask): Deleted.
+        (WebCore::WorkerGlobalScopeDestroyedTask::performTask): Deleted.
+        (WebCore::WorkerTerminateTask::create): Deleted.
+        (WebCore::WorkerTerminateTask::WorkerTerminateTask): Deleted.
+        (WebCore::WorkerTerminateTask::performTask): Deleted.
+        (WebCore::WorkerThreadActivityReportTask::create): Deleted.
+        (WebCore::WorkerThreadActivityReportTask::WorkerThreadActivityReportTask): Deleted.
+        (WebCore::WorkerThreadActivityReportTask::performTask): Deleted.
+        (WebCore::PostMessageToPageInspectorTask::create): Deleted.
+        (WebCore::PostMessageToPageInspectorTask::PostMessageToPageInspectorTask): Deleted.
+        (WebCore::PostMessageToPageInspectorTask::performTask): Deleted.
+        (WebCore::NotifyNetworkStateChangeTask::create): Deleted.
+        (WebCore::NotifyNetworkStateChangeTask::NotifyNetworkStateChangeTask): Deleted.
+        (WebCore::NotifyNetworkStateChangeTask::performTask): Deleted.
+        * workers/WorkerMessagingProxy.h:
+        * workers/WorkerRunLoop.cpp:
+        (WebCore::WorkerRunLoop::postTask):
+        (WebCore::WorkerRunLoop::postTaskAndTerminate):
+        (WebCore::WorkerRunLoop::postTaskForMode):
+        (WebCore::WorkerRunLoop::Task::create):
+        (WebCore::WorkerRunLoop::Task::performTask):
+        (WebCore::WorkerRunLoop::Task::Task):
+        * workers/WorkerRunLoop.h:
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerThread::stop):
+        (WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThreads):
+        (WebCore::WorkerThreadShutdownFinishTask::create): Deleted.
+        (WebCore::WorkerThreadShutdownFinishTask::performTask): Deleted.
+        (WebCore::WorkerThreadShutdownFinishTask::isCleanupTask): Deleted.
+        (WebCore::WorkerThreadShutdownStartTask::create): Deleted.
+        (WebCore::WorkerThreadShutdownStartTask::performTask): Deleted.
+        (WebCore::WorkerThreadShutdownStartTask::isCleanupTask): Deleted.
+
 2014-04-27  Antti Koivisto  <antti@apple.com>
 
         Coalesce responses on network process side
index 983a542..1f53b03 100644 (file)
 namespace WebCore {
 
 StorageErrorCallback::CallbackTask::CallbackTask(PassRefPtr<StorageErrorCallback> callback, ExceptionCode ec)
-    : m_callback(callback)
-    , m_ec(ec)
+    : ScriptExecutionContext::Task([=] (ScriptExecutionContext*) {
+        if (callback)
+            callback->handleEvent(DOMCoreException::create(ExceptionCodeDescription(ec)).get());
+    })
 {
 }
 
-void StorageErrorCallback::CallbackTask::performTask(ScriptExecutionContext*)
-{
-    if (!m_callback)
-        return;
-    ExceptionCodeDescription description(m_ec);
-    m_callback->handleEvent(DOMCoreException::create(description).get());
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(QUOTA)
index ffce7b6..56f3bf6 100644 (file)
@@ -50,16 +50,9 @@ public:
 
     class CallbackTask : public ScriptExecutionContext::Task {
     public:
-        static PassOwnPtr<CallbackTask> create(PassRefPtr<StorageErrorCallback> callback, ExceptionCode ec)
-        {
-            return adoptPtr(new CallbackTask(callback, ec));
-        }
-
-        virtual void performTask(ScriptExecutionContext*);
-
-    private:
         CallbackTask(PassRefPtr<StorageErrorCallback>, ExceptionCode);
 
+    private:
         RefPtr<StorageErrorCallback> m_callback;
         ExceptionCode m_ec;
     };
index e161d9d..ef1e333 100644 (file)
@@ -87,39 +87,17 @@ Database::Database(PassRefPtr<DatabaseBackendContext> databaseContext,
     ASSERT(m_databaseContext->databaseThread());
 }
 
-class DerefContextTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<DerefContextTask> create(PassRefPtr<ScriptExecutionContext> context)
-    {
-        return adoptPtr(new DerefContextTask(context));
-    }
-
-    virtual void performTask(ScriptExecutionContext* context)
-    {
-        ASSERT_UNUSED(context, context == m_context);
-        m_context.clear();
-    }
-
-    virtual bool isCleanupTask() const { return true; }
-
-private:
-    DerefContextTask(PassRefPtr<ScriptExecutionContext> context)
-        : m_context(context)
-    {
-    }
-    
-    RefPtr<ScriptExecutionContext> m_context;
-};
-
 Database::~Database()
 {
     // The reference to the ScriptExecutionContext needs to be cleared on the JavaScript thread.  If we're on that thread already, we can just let the RefPtr's destruction do the dereffing.
     if (!m_scriptExecutionContext->isContextThread()) {
         // Grab a pointer to the script execution here because we're releasing it when we pass it to
         // DerefContextTask::create.
-        ScriptExecutionContext* scriptExecutionContext = m_scriptExecutionContext.get();
-        
-        scriptExecutionContext->postTask(DerefContextTask::create(m_scriptExecutionContext.release()));
+        PassRefPtr<ScriptExecutionContext> passedContext = m_scriptExecutionContext.release();
+        passedContext->postTask({ScriptExecutionContext::Task::CleanupTask, [=] (ScriptExecutionContext* context) {
+            ASSERT_UNUSED(context, context == passedContext);
+            RefPtr<ScriptExecutionContext> scriptExecutionContext(passedContext);
+        }});
     }
 }
 
@@ -187,49 +165,25 @@ void Database::readTransaction(PassRefPtr<SQLTransactionCallback> callback, Pass
     runTransaction(callback, errorCallback, successCallback, true);
 }
 
-static void callTransactionErrorCallback(ScriptExecutionContext*, PassRefPtr<SQLTransactionErrorCallback> callback, PassRefPtr<SQLError> error)
-{
-    callback->handleEvent(error.get());
-}
-
 void Database::runTransaction(PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback,
     PassRefPtr<VoidCallback> successCallback, bool readOnly, const ChangeVersionData* changeVersionData)
 {
-    RefPtr<SQLTransactionErrorCallback> anotherRefToErrorCallback = errorCallback;
-    RefPtr<SQLTransaction> transaction = SQLTransaction::create(this, callback, successCallback, anotherRefToErrorCallback, readOnly);
-
-    RefPtr<SQLTransactionBackend> transactionBackend;
-    transactionBackend = backend()->runTransaction(transaction.release(), readOnly, changeVersionData);
-    if (!transactionBackend && anotherRefToErrorCallback) {
-        RefPtr<SQLError> error = SQLError::create(SQLError::UNKNOWN_ERR, "database has been closed");
-        scriptExecutionContext()->postTask(createCallbackTask(&callTransactionErrorCallback, anotherRefToErrorCallback, error.release()));
-    }
-}
+    RefPtr<SQLTransactionErrorCallback> errorCallbackProtector(errorCallback);
+    RefPtr<SQLTransaction> transaction = SQLTransaction::create(this, callback, successCallback, errorCallbackProtector, readOnly);
 
-class DeliverPendingCallbackTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<DeliverPendingCallbackTask> create(PassRefPtr<SQLTransaction> transaction)
-    {
-        return adoptPtr(new DeliverPendingCallbackTask(transaction));
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_transaction->performPendingCallback();
-    }
-
-private:
-    DeliverPendingCallbackTask(PassRefPtr<SQLTransaction> transaction)
-        : m_transaction(transaction)
-    {
-    }
-
-    RefPtr<SQLTransaction> m_transaction;
-};
+    RefPtr<SQLTransactionBackend> transactionBackend(backend()->runTransaction(transaction.release(), readOnly, changeVersionData));
+    if (!transactionBackend && errorCallbackProtector)
+        scriptExecutionContext()->postTask([=] (ScriptExecutionContext*) {
+            errorCallbackProtector->handleEvent(SQLError::create(SQLError::UNKNOWN_ERR, "database has been closed").get());
+        });
+}
 
 void Database::scheduleTransactionCallback(SQLTransaction* transaction)
 {
-    m_scriptExecutionContext->postTask(DeliverPendingCallbackTask::create(transaction));
+    RefPtr<SQLTransaction> transactionProtector(transaction);
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
+        transactionProtector->performPendingCallback();
+    });
 }
 
 Vector<String> Database::performGetTableNames()
index 1f025ad..744d1a8 100644 (file)
@@ -117,29 +117,6 @@ void DatabaseManager::setIsAvailable(bool available)
     m_databaseIsAvailable = available;
 }
 
-class DatabaseCreationCallbackTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> creationCallback)
-    {
-        return adoptPtr(new DatabaseCreationCallbackTask(database, creationCallback));
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_creationCallback->handleEvent(m_database.get());
-    }
-
-private:
-    DatabaseCreationCallbackTask(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> callback)
-        : m_database(database)
-        , m_creationCallback(callback)
-    {
-    }
-
-    RefPtr<Database> m_database;
-    RefPtr<DatabaseCallback> m_creationCallback;
-};
-
 PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(ScriptExecutionContext* context)
 {
     std::lock_guard<std::mutex> lock(m_mutex);
@@ -334,7 +311,9 @@ PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* conte
 
     if (backend->isNew() && creationCallback.get()) {
         LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database.get());
-        database->m_scriptExecutionContext->postTask(DatabaseCreationCallbackTask::create(database, creationCallback));
+        database->m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
+            creationCallback->handleEvent(database.get());
+        });
     }
 
     ASSERT(database);
index f92c34f..6622bc1 100644 (file)
@@ -158,27 +158,6 @@ void DatabaseSync::markAsDeletedAndClose()
     // FIXME: need to do something similar to closeImmediately(), but in a sync way
 }
 
-class CloseSyncDatabaseOnContextThreadTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<CloseSyncDatabaseOnContextThreadTask> create(PassRefPtr<DatabaseSync> database)
-    {
-        return adoptPtr(new CloseSyncDatabaseOnContextThreadTask(database));
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_database->closeImmediately();
-    }
-
-private:
-    CloseSyncDatabaseOnContextThreadTask(PassRefPtr<DatabaseSync> database)
-        : m_database(database)
-    {
-    }
-
-    RefPtr<DatabaseSync> m_database;
-};
-
 void DatabaseSync::closeImmediately()
 {
     ASSERT(m_scriptExecutionContext->isContextThread());
index 51d006c..3db0c51 100644 (file)
@@ -57,7 +57,7 @@ public:
 
     void clear()
     {
-        ScriptExecutionContext* context;
+        ScriptExecutionContext* scriptExecutionContextPtr;
         T* callback;
         {
             MutexLocker locker(m_mutex);
@@ -70,10 +70,14 @@ public:
                 m_scriptExecutionContext = 0;
                 return;
             }
-            context = m_scriptExecutionContext.release().leakRef();
+            scriptExecutionContextPtr = m_scriptExecutionContext.release().leakRef();
             callback = m_callback.release().leakRef();
         }
-        context->postTask(SafeReleaseTask::create(callback));
+        scriptExecutionContextPtr->postTask({ ScriptExecutionContext::Task::CleanupTask, [=] (ScriptExecutionContext* context) {
+            ASSERT_UNUSED(context, context == scriptExecutionContextPtr && context->isContextThread());
+            callback->deref();
+            scriptExecutionContextPtr->deref();
+        } });
     }
 
     PassRefPtr<T> unwrap()
@@ -88,31 +92,6 @@ public:
     bool hasCallback() const { return m_callback; }
 
 private:
-    class SafeReleaseTask : public ScriptExecutionContext::Task {
-    public:
-        static PassOwnPtr<SafeReleaseTask> create(T* callbackToRelease)
-        {
-            return adoptPtr(new SafeReleaseTask(callbackToRelease));
-        }
-
-        virtual void performTask(ScriptExecutionContext* context)
-        {
-            ASSERT(m_callbackToRelease && context && context->isContextThread());
-            m_callbackToRelease->deref();
-            context->deref();
-        }
-
-        virtual bool isCleanupTask() const { return true; }
-
-    private:
-        explicit SafeReleaseTask(T* callbackToRelease)
-            : m_callbackToRelease(callbackToRelease)
-        {
-        }
-
-        T* m_callbackToRelease;
-    };
-
     Mutex m_mutex;
     RefPtr<T> m_callback;
     RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
index 52e1d6f..54cc744 100644 (file)
@@ -157,49 +157,49 @@ void ThreadableWebSocketChannelClientWrapper::clearClient()
 
 void ThreadableWebSocketChannelClientWrapper::didConnect()
 {
-    m_pendingTasks.append(createCallbackTask(&didConnectCallback, this));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didConnectCallback, this)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didReceiveMessage(const String& message)
 {
-    m_pendingTasks.append(createCallbackTask(&didReceiveMessageCallback, this, message));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didReceiveMessageCallback, this, message)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData(PassOwnPtr<Vector<char>> binaryData)
 {
-    m_pendingTasks.append(createCallbackTask(&didReceiveBinaryDataCallback, this, binaryData));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didReceiveBinaryDataCallback, this, binaryData)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmount(unsigned long bufferedAmount)
 {
-    m_pendingTasks.append(createCallbackTask(&didUpdateBufferedAmountCallback, this, bufferedAmount));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didUpdateBufferedAmountCallback, this, bufferedAmount)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake()
 {
-    m_pendingTasks.append(createCallbackTask(&didStartClosingHandshakeCallback, this));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didStartClosingHandshakeCallback, this)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
 {
-    m_pendingTasks.append(createCallbackTask(&didCloseCallback, this, unhandledBufferedAmount, closingHandshakeCompletion, code, reason));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didCloseCallback, this, unhandledBufferedAmount, closingHandshakeCompletion, code, reason)));
     if (!m_suspended)
         processPendingTasks();
 }
 
 void ThreadableWebSocketChannelClientWrapper::didReceiveMessageError()
 {
-    m_pendingTasks.append(createCallbackTask(&didReceiveMessageErrorCallback, this));
+    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>(createCallbackTask(&didReceiveMessageErrorCallback, this)));
     if (!m_suspended)
         processPendingTasks();
 }
@@ -231,10 +231,10 @@ void ThreadableWebSocketChannelClientWrapper::processPendingTasks()
         m_context->postTask(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::processPendingTasksCallback, this));
         return;
     }
-    Vector<OwnPtr<ScriptExecutionContext::Task>> tasks;
-    tasks.swap(m_pendingTasks);
-    for (Vector<OwnPtr<ScriptExecutionContext::Task>>::const_iterator iter = tasks.begin(); iter != tasks.end(); ++iter)
-        (*iter)->performTask(0);
+
+    Vector<std::unique_ptr<ScriptExecutionContext::Task>> pendingTasks = std::move(m_pendingTasks);
+    for (auto& task : pendingTasks)
+        task->performTask(nullptr);
 }
 
 void ThreadableWebSocketChannelClientWrapper::didConnectCallback(ScriptExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper)
index 29f5495..976c99e 100644 (file)
@@ -37,6 +37,7 @@
 #include "ThreadableWebSocketChannel.h"
 #include "WebSocketChannelClient.h"
 #include "WorkerThreadableWebSocketChannel.h"
+#include <memory>
 #include <wtf/Forward.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -114,7 +115,7 @@ private:
     ThreadableWebSocketChannel::SendResult m_sendRequestResult;
     unsigned long m_bufferedAmount;
     bool m_suspended;
-    Vector<OwnPtr<ScriptExecutionContext::Task>> m_pendingTasks;
+    Vector<std::unique_ptr<ScriptExecutionContext::Task>> m_pendingTasks;
 };
 
 } // namespace WebCore
index 721ba5d..bd6b075 100644 (file)
@@ -359,44 +359,6 @@ WorkerThreadableWebSocketChannel::Bridge::~Bridge()
     disconnect();
 }
 
-class WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<ScriptExecutionContext::Task> create(WorkerThreadableWebSocketChannel::Peer* peer,
-                                                           WorkerLoaderProxy* loaderProxy,
-                                                           PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper)
-    {
-        return adoptPtr(new WorkerGlobalScopeDidInitializeTask(peer, loaderProxy, workerClientWrapper));
-    }
-
-    virtual ~WorkerGlobalScopeDidInitializeTask() { }
-    virtual void performTask(ScriptExecutionContext* context) override
-    {
-        ASSERT_UNUSED(context, context->isWorkerGlobalScope());
-        if (m_workerClientWrapper->failedWebSocketChannelCreation()) {
-            // If Bridge::initialize() quitted earlier, we need to kick mainThreadDestroy() to delete the peer.
-            OwnPtr<WorkerThreadableWebSocketChannel::Peer> peer = adoptPtr(m_peer);
-            m_peer = 0;
-            m_loaderProxy->postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadDestroy, peer.release()));
-        } else
-            m_workerClientWrapper->didCreateWebSocketChannel(m_peer);
-    }
-    virtual bool isCleanupTask() const override { return true; }
-
-private:
-    WorkerGlobalScopeDidInitializeTask(WorkerThreadableWebSocketChannel::Peer* peer,
-                                   WorkerLoaderProxy* loaderProxy,
-                                   PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper)
-        : m_peer(peer)
-        , m_loaderProxy(loaderProxy)
-        , m_workerClientWrapper(workerClientWrapper)
-    {
-    }
-
-    WorkerThreadableWebSocketChannel::Peer* m_peer;
-    WorkerLoaderProxy* m_loaderProxy;
-    RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
-};
-
 void WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize(ScriptExecutionContext* context, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWebSocketChannelClientWrapper> prpClientWrapper, const String& taskMode)
 {
     ASSERT(isMainThread());
@@ -404,12 +366,18 @@ void WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize(ScriptExecut
 
     RefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper = prpClientWrapper;
 
-    Peer* peer = Peer::create(clientWrapper, *loaderProxy, context, taskMode);
-    bool sent = loaderProxy->postTaskForModeToWorkerGlobalScope(
-        WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::create(peer, loaderProxy, clientWrapper), taskMode);
+    Peer* peerPtr = Peer::create(clientWrapper, *loaderProxy, context, taskMode);
+    bool sent = loaderProxy->postTaskForModeToWorkerGlobalScope({ ScriptExecutionContext::Task::CleanupTask, [=] (ScriptExecutionContext* context) {
+        ASSERT_UNUSED(context, context->isWorkerGlobalScope());
+        if (clientWrapper->failedWebSocketChannelCreation()) {
+            // If Bridge::initialize() quitted earlier, we need to kick mainThreadDestroy() to delete the peer.
+            loaderProxy->postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadDestroy, AllowCrossThreadAccess(peerPtr)));
+        } else
+            clientWrapper->didCreateWebSocketChannel(peerPtr);
+    } }, taskMode);
     if (!sent) {
         clientWrapper->clearPeer();
-        delete peer;
+        delete peerPtr;
     }
 }
 
@@ -575,25 +543,21 @@ void WorkerThreadableWebSocketChannel::Bridge::fail(const String& reason)
     m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadFail, AllowCrossThreadAccess(m_peer), reason));
 }
 
-void WorkerThreadableWebSocketChannel::mainThreadDestroy(ScriptExecutionContext* context, PassOwnPtr<Peer> peer)
+void WorkerThreadableWebSocketChannel::mainThreadDestroy(ScriptExecutionContext* context, Peer* peerPtr)
 {
     ASSERT(isMainThread());
     ASSERT_UNUSED(context, context->isDocument());
-    ASSERT_UNUSED(peer, peer);
-
-    // Peer object will be deleted even if the task does not run in the main thread's cleanup period, because
-    // the destructor for the task object (created by createCallbackTask()) will automatically delete the peer.
+    std::unique_ptr<Peer> peer(peerPtr);
 }
 
 void WorkerThreadableWebSocketChannel::Bridge::disconnect()
 {
     clearClientWrapper();
     if (m_peer) {
-        OwnPtr<Peer> peer = adoptPtr(m_peer);
-        m_peer = 0;
-        m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadDestroy, peer.release()));
+        m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadDestroy, AllowCrossThreadAccess(m_peer)));
+        m_peer = nullptr;
     }
-    m_workerGlobalScope = 0;
+    m_workerGlobalScope = nullptr;
 }
 
 void WorkerThreadableWebSocketChannel::mainThreadSuspend(ScriptExecutionContext* context, Peer* peer)
index 90b0ea0..5fba367 100644 (file)
@@ -176,7 +176,7 @@ private:
     static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
     static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const String& reason);
     static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& reason);
-    static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>);
+    static void mainThreadDestroy(ScriptExecutionContext*, Peer*);
     static void mainThreadSuspend(ScriptExecutionContext*, Peer*);
     static void mainThreadResume(ScriptExecutionContext*, Peer*);
 
index c9d4f61..004953e 100644 (file)
@@ -79,21 +79,12 @@ private:
 
 class DeleteCallbackDataTask : public ScriptExecutionContext::Task {
 public:
-    static PassOwnPtr<DeleteCallbackDataTask> create(JSCallbackData* data)
+    DeleteCallbackDataTask(JSCallbackData* data)
+        : ScriptExecutionContext::Task({ ScriptExecutionContext::Task::CleanupTask, [=] (ScriptExecutionContext*) {
+            delete data;
+        } })
     {
-        return adoptPtr(new DeleteCallbackDataTask(data));
     }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        delete m_data;
-    }
-    virtual bool isCleanupTask() const { return true; }
-private:
-
-    DeleteCallbackDataTask(JSCallbackData* data) : m_data(data) {}
-
-    JSCallbackData* m_data;
 };
 
 } // namespace WebCore
index 9cca89b..944b201 100644 (file)
@@ -80,17 +80,12 @@ private:
 };
 
 JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject* globalObject, PassRefPtr<Microtask> task)
-    : m_callback(JSGlobalObjectCallback::create(globalObject, task))
+    : ScriptExecutionContext::Task(nullptr)
 {
-}
-
-JSGlobalObjectTask::~JSGlobalObjectTask()
-{
-}
-
-void JSGlobalObjectTask::performTask(ScriptExecutionContext*)
-{
-    m_callback->call();
+    RefPtr<JSGlobalObjectCallback> callback = JSGlobalObjectCallback::create(globalObject, task);
+    m_task = [=] (ScriptExecutionContext*) {
+        callback->call();
+    };
 }
 
 } // namespace WebCore
index 3cb93f3..87be32d 100644 (file)
 
 namespace WebCore {
 
-class JSGlobalObjectCallback;
-
-class JSGlobalObjectTask final : public ScriptExecutionContext::Task {
+class JSGlobalObjectTask : public ScriptExecutionContext::Task {
 public:
-    static PassOwnPtr<JSGlobalObjectTask> create(JSDOMGlobalObject* globalObject, PassRefPtr<JSC::Microtask> task)
-    {
-        return adoptPtr(new JSGlobalObjectTask(globalObject, task));
-    }
-
-    virtual ~JSGlobalObjectTask();
-
-private:
     JSGlobalObjectTask(JSDOMGlobalObject*, PassRefPtr<JSC::Microtask>);
-
-    virtual void performTask(ScriptExecutionContext*) override;
-
-    RefPtr<JSGlobalObjectCallback> m_callback;
 };
 
 } // namespace WebCore
index 3a07bbc..c6feb1f 100644 (file)
@@ -190,7 +190,7 @@ bool JSDOMWindowBase::javaScriptExperimentsEnabled(const JSGlobalObject* object)
 void JSDOMWindowBase::queueTaskToEventLoop(const JSGlobalObject* object, PassRefPtr<Microtask> task)
 {
     const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object);
-    thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask::create((JSDOMWindowBase*)thisObject, task));
+    thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask((JSDOMWindowBase*)thisObject, task));
 }
 
 void JSDOMWindowBase::willRemoveFromWindowShell()
index a493cb0..88c0716 100644 (file)
@@ -103,7 +103,7 @@ bool JSWorkerGlobalScopeBase::javaScriptExperimentsEnabled(const JSGlobalObject*
 void JSWorkerGlobalScopeBase::queueTaskToEventLoop(const JSGlobalObject* object, PassRefPtr<Microtask> task)
 {
     const JSWorkerGlobalScopeBase* thisObject = static_cast<const JSWorkerGlobalScopeBase*>(object);
-    thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask::create((JSDOMGlobalObject*)thisObject, task));
+    thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask((JSDOMGlobalObject*)thisObject, task));
 }
 
 JSValue toJS(ExecState* exec, JSDOMGlobalObject*, WorkerGlobalScope* workerGlobalScope)
index c070bba..5c5d44d 100644 (file)
@@ -3435,7 +3435,7 @@ sub GenerateCallbackImplementation
     push(@implContent, "    if (!context || context->isContextThread())\n");
     push(@implContent, "        delete m_data;\n");
     push(@implContent, "    else\n");
-    push(@implContent, "        context->postTask(DeleteCallbackDataTask::create(m_data));\n");
+    push(@implContent, "        context->postTask(DeleteCallbackDataTask(m_data));\n");
     push(@implContent, "#ifndef NDEBUG\n");
     push(@implContent, "    m_data = 0;\n");
     push(@implContent, "#endif\n");
index 6cc5f84..af01fc8 100644 (file)
@@ -57,25 +57,19 @@ template<typename T> struct CrossThreadTaskTraits<PassOwnPtr<T>> {
 };
 
 template<typename P1, typename MP1>
-class CrossThreadTask1 : public ScriptExecutionContext::Task {
+class CrossThreadTask1 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1);
     typedef CrossThreadTask1<P1, MP1> CrossThreadTask;
     typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1));
-    }
-
-private:
     CrossThreadTask1(Method method, Param1 parameter1)
         : m_method(method)
         , m_parameter1(parameter1)
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1);
     }
@@ -86,19 +80,13 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2>
-class CrossThreadTask2 : public ScriptExecutionContext::Task {
+class CrossThreadTask2 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2);
     typedef CrossThreadTask2<P1, MP1, P2, MP2> CrossThreadTask;
     typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
     typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2));
-    }
-
-private:
     CrossThreadTask2(Method method, Param1 parameter1, Param2 parameter2)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -106,7 +94,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2);
     }
@@ -118,7 +106,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-class CrossThreadTask3 : public ScriptExecutionContext::Task {
+class CrossThreadTask3 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3);
     typedef CrossThreadTask3<P1, MP1, P2, MP2, P3, MP3> CrossThreadTask;
@@ -126,12 +114,6 @@ public:
     typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
     typedef typename CrossThreadTaskTraits<P3>::ParamType Param3;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3));
-    }
-
-private:
     CrossThreadTask3(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -140,7 +122,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3);
     }
@@ -153,7 +135,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4>
-class CrossThreadTask4 : public ScriptExecutionContext::Task {
+class CrossThreadTask4 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4);
     typedef CrossThreadTask4<P1, MP1, P2, MP2, P3, MP3, P4, MP4> CrossThreadTask;
@@ -162,12 +144,6 @@ public:
     typedef typename CrossThreadTaskTraits<P3>::ParamType Param3;
     typedef typename CrossThreadTaskTraits<P4>::ParamType Param4;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4));
-    }
-
-private:
     CrossThreadTask4(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -177,7 +153,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4);
     }
@@ -191,7 +167,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5>
-class CrossThreadTask5 : public ScriptExecutionContext::Task {
+class CrossThreadTask5 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5);
     typedef CrossThreadTask5<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5> CrossThreadTask;
@@ -201,12 +177,6 @@ public:
     typedef typename CrossThreadTaskTraits<P4>::ParamType Param4;
     typedef typename CrossThreadTaskTraits<P5>::ParamType Param5;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5));
-    }
-
-private:
     CrossThreadTask5(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -217,7 +187,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5);
     }
@@ -232,7 +202,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6>
-class CrossThreadTask6 : public ScriptExecutionContext::Task {
+class CrossThreadTask6 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6);
     typedef CrossThreadTask6<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6> CrossThreadTask;
@@ -243,12 +213,6 @@ public:
     typedef typename CrossThreadTaskTraits<P5>::ParamType Param5;
     typedef typename CrossThreadTaskTraits<P6>::ParamType Param6;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6));
-    }
-
-private:
     CrossThreadTask6(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -260,7 +224,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6);
     }
@@ -276,7 +240,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7>
-class CrossThreadTask7 : public ScriptExecutionContext::Task {
+class CrossThreadTask7 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7);
     typedef CrossThreadTask7<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6, P7, MP7> CrossThreadTask;
@@ -288,12 +252,6 @@ public:
     typedef typename CrossThreadTaskTraits<P6>::ParamType Param6;
     typedef typename CrossThreadTaskTraits<P7>::ParamType Param7;
 
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7));
-    }
-
-private:
     CrossThreadTask7(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7)
         : m_method(method)
         , m_parameter1(parameter1)
@@ -306,7 +264,7 @@ private:
     {
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6, m_parameter7);
     }
@@ -323,7 +281,7 @@ private:
 };
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7, typename P8, typename MP8>
-class CrossThreadTask8 : public ScriptExecutionContext::Task {
+class CrossThreadTask8 {
 public:
     typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8);
     typedef CrossThreadTask8<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6, P7, MP7, P8, MP8> CrossThreadTask;
@@ -336,12 +294,6 @@ public:
     typedef typename CrossThreadTaskTraits<P7>::ParamType Param7;
     typedef typename CrossThreadTaskTraits<P8>::ParamType Param8;
     
-    static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8)
-    {
-        return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7, parameter8));
-    }
-    
-private:
     CrossThreadTask8(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8)
     : m_method(method)
     , m_parameter1(parameter1)
@@ -355,7 +307,7 @@ private:
     {
     }
     
-    virtual void performTask(ScriptExecutionContext* context)
+    void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6, m_parameter7, m_parameter8);
     }
@@ -373,102 +325,134 @@ private:
 };
 
 template<typename P1, typename MP1>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1),
     const P1& parameter1)
 {
-    return CrossThreadTask1<typename CrossThreadCopier<P1>::Type, MP1>::create(
+    auto taskPtr = new CrossThreadTask1<typename CrossThreadCopier<P1>::Type, MP1>(
         method,
         CrossThreadCopier<P1>::copy(parameter1));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2),
     const P1& parameter1, const P2& parameter2)
 {
-    return CrossThreadTask2<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>::create(
+    auto taskPtr = new CrossThreadTask2<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>(
         method,
         CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2, MP3),
     const P1& parameter1, const P2& parameter2, const P3& parameter3)
 {
-    return CrossThreadTask3<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>::create(
+    auto taskPtr = new CrossThreadTask3<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>(
         method,
         CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
         CrossThreadCopier<P3>::copy(parameter3));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4),
     const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4)
 {
-    return CrossThreadTask4<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
-        typename CrossThreadCopier<P4>::Type, MP4>::create(
+    auto taskPtr = new CrossThreadTask4<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
+        typename CrossThreadCopier<P4>::Type, MP4>(
             method,
             CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
             CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5),
     const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5)
 {
-    return CrossThreadTask5<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
-        typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5>::create(
+    auto taskPtr = new CrossThreadTask5<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
+        typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5>(
             method,
             CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
             CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4),
             CrossThreadCopier<P5>::copy(parameter5));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6),
     const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6)
 {
-    return CrossThreadTask6<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
-        typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6>::create(
+    auto taskPtr = new CrossThreadTask6<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
+        typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6>(
             method,
             CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
             CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4),
             CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
+ScriptExecutionContext::Task createCallbackTask(
     void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7),
     const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6, const P7& parameter7)
 {
-    return CrossThreadTask7<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
+    auto taskPtr = new CrossThreadTask7<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
         typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6,
-        typename CrossThreadCopier<P7>::Type, MP7>::create(
+        typename CrossThreadCopier<P7>::Type, MP7>(
             method,
             CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
             CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4),
             CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6),
             CrossThreadCopier<P7>::copy(parameter7));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7, typename P8, typename MP8>
-PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask(
-                                                            void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8),
-                                                            const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6, const P7& parameter7, const P8& parameter8)
+ScriptExecutionContext::Task createCallbackTask(
+    void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8),
+    const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6, const P7& parameter7, const P8& parameter8)
 {
-    return CrossThreadTask8<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
+    auto taskPtr = new CrossThreadTask8<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3,
     typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6,
-    typename CrossThreadCopier<P7>::Type, MP7, typename CrossThreadCopier<P8>::Type, MP8>::create(
-                                                       method,
-                                                       CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
-                                                       CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4),
-                                                       CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6),
-                                                       CrossThreadCopier<P7>::copy(parameter7), CrossThreadCopier<P8>::copy(parameter8));
+    typename CrossThreadCopier<P7>::Type, MP7, typename CrossThreadCopier<P8>::Type, MP8>(
+        method,
+        CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2),
+        CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4),
+        CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6),
+        CrossThreadCopier<P7>::copy(parameter7), CrossThreadCopier<P8>::copy(parameter8));
+    return [=] (ScriptExecutionContext* context) {
+        std::unique_ptr<typename std::remove_pointer<decltype(taskPtr)>::type> task(taskPtr);
+        task->performTask(context);
+    };
 }
 
 } // namespace WebCore
index 30b3309..b7c17ed 100644 (file)
@@ -4875,7 +4875,7 @@ void Document::parseDNSPrefetchControlHeader(const String& dnsPrefetchControl)
 void Document::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask::create(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, message.isolatedCopy()));
         return;
     }
 
@@ -4886,7 +4886,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, PassRefPtr<Inspector::ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask::create(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
@@ -4899,51 +4899,32 @@ SecurityOrigin* Document::topOrigin() const
     return topDocument().securityOrigin();
 }
 
-struct PerformTaskContext {
-    WTF_MAKE_NONCOPYABLE(PerformTaskContext); WTF_MAKE_FAST_ALLOCATED;
-public:
-    PerformTaskContext(WeakPtr<Document> document, PassOwnPtr<ScriptExecutionContext::Task> task)
-        : documentReference(document)
-        , task(task)
-    {
-    }
-
-    WeakPtr<Document> documentReference;
-    OwnPtr<ScriptExecutionContext::Task> task;
-};
-
-void Document::didReceiveTask(void* untypedContext)
+void Document::postTask(Task task)
 {
-    ASSERT(isMainThread());
-
-    OwnPtr<PerformTaskContext> context = adoptPtr(static_cast<PerformTaskContext*>(untypedContext));
-    ASSERT(context);
-
-    Document* document = context->documentReference.get();
-    if (!document)
-        return;
+    Task* taskPtr = std::make_unique<Task>(std::move(task)).release();
+    WeakPtr<Document> documentReference(m_weakFactory.createWeakPtr());
 
-    Page* page = document->page();
-    if ((page && page->defersLoading()) || !document->m_pendingTasks.isEmpty()) {
-        document->m_pendingTasks.append(context->task.release());
-        return;
-    }
+    callOnMainThread([=] {
+        ASSERT(isMainThread());
+        std::unique_ptr<Task> task(taskPtr);
 
-    context->task->performTask(document);
-}
+        Document* document = documentReference.get();
+        if (!document)
+            return;
 
-void Document::postTask(PassOwnPtr<Task> task)
-{
-    callOnMainThread(didReceiveTask, new PerformTaskContext(m_weakFactory.createWeakPtr(), task));
+        Page* page = document->page();
+        if ((page && page->defersLoading()) || !document->m_pendingTasks.isEmpty())
+            document->m_pendingTasks.append(std::move(*task.release()));
+        else
+            task->performTask(document);
+    });
 }
 
 void Document::pendingTasksTimerFired(Timer<Document>&)
 {
-    while (!m_pendingTasks.isEmpty()) {
-        OwnPtr<Task> task = m_pendingTasks[0].release();
-        m_pendingTasks.remove(0);
-        task->performTask(this);
-    }
+    Vector<Task> pendingTasks = std::move(m_pendingTasks);
+    for (auto& task : pendingTasks)
+        task.performTask(this);
 }
 
 void Document::suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension reason)
index 22f035b..655edfc 100644 (file)
@@ -1007,7 +1007,7 @@ public:
     bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
     void parseDNSPrefetchControlHeader(const String&);
 
-    virtual void postTask(PassOwnPtr<Task>) override; // Executes the task on context's thread asynchronously.
+    virtual void postTask(Task) override; // Executes the task on context's thread asynchronously.
 
     void suspendScriptedAnimationControllerCallbacks();
     void resumeScriptedAnimationControllerCallbacks();
@@ -1336,8 +1336,6 @@ private:
 
     void pendingTasksTimerFired(Timer<Document>&);
 
-    static void didReceiveTask(void*);
-    
     template <typename CharacterType>
     void displayBufferModifiedByEncodingInternal(CharacterType*, unsigned) const;
 
@@ -1643,7 +1641,7 @@ private:
 #endif
 
     Timer<Document> m_pendingTasksTimer;
-    Vector<OwnPtr<Task>> m_pendingTasks;
+    Vector<Task> m_pendingTasks;
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 public:
index fc50c64..ca86901 100644 (file)
@@ -55,19 +55,6 @@ using namespace Inspector;
 
 namespace WebCore {
 
-class ProcessMessagesSoonTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<ProcessMessagesSoonTask> create()
-    {
-        return adoptPtr(new ProcessMessagesSoonTask);
-    }
-
-    virtual void performTask(ScriptExecutionContext* context) override
-    {
-        context->dispatchMessagePortEvents();
-    }
-};
-
 class ScriptExecutionContext::PendingException {
     WTF_MAKE_NONCOPYABLE(PendingException);
 public:
@@ -86,11 +73,6 @@ public:
     RefPtr<ScriptCallStack> m_callStack;
 };
 
-void ScriptExecutionContext::AddConsoleMessageTask::performTask(ScriptExecutionContext* context)
-{
-    context->addConsoleMessage(m_source, m_level, m_message);
-}
-
 ScriptExecutionContext::ScriptExecutionContext()
     : m_circularSequentialID(0)
     , m_inDispatchErrorEvent(false)
@@ -150,7 +132,9 @@ ScriptExecutionContext::~ScriptExecutionContext()
 
 void ScriptExecutionContext::processMessagePortMessagesSoon()
 {
-    postTask(ProcessMessagesSoonTask::create());
+    postTask([] (ScriptExecutionContext* context) {
+        context->dispatchMessagePortEvents();
+    });
 }
 
 void ScriptExecutionContext::dispatchMessagePortEvents()
@@ -460,10 +444,6 @@ double ScriptExecutionContext::timerAlignmentInterval() const
     return Settings::defaultDOMTimerAlignmentInterval();
 }
 
-ScriptExecutionContext::Task::~Task()
-{
-}
-
 JSC::VM& ScriptExecutionContext::vm()
 {
      if (isDocument())
index 28f8dbb..7124ffe 100644 (file)
@@ -115,17 +115,35 @@ public:
     void deref() { derefScriptExecutionContext(); }
 
     class Task {
-        WTF_MAKE_NONCOPYABLE(Task);
         WTF_MAKE_FAST_ALLOCATED;
     public:
-        Task() { }
-        virtual ~Task();
-        virtual void performTask(ScriptExecutionContext*) = 0;
-        // Certain tasks get marked specially so that they aren't discarded, and are executed, when the context is shutting down its message queue.
-        virtual bool isCleanupTask() const { return false; }
+        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>
+        Task(T task)
+            : m_task(std::move(task))
+            , m_isCleanupTask(false)
+        {
+        }
+
+        template<typename T, typename = typename std::enable_if<std::is_convertible<T, std::function<void (ScriptExecutionContext*)>>::value>::type>
+        Task(CleanupTaskTag, T task)
+            : m_task(std::move(task))
+            , m_isCleanupTask(true)
+        {
+        }
+
+        Task(Task&&) = default;
+
+        void performTask(ScriptExecutionContext* context) { m_task(context); }
+        bool isCleanupTask() const { return m_isCleanupTask; }
+
+    protected:
+        std::function<void (ScriptExecutionContext*)> m_task;
+        bool m_isCleanupTask;
     };
 
-    virtual void postTask(PassOwnPtr<Task>) = 0; // Executes the task on context's thread asynchronously.
+    virtual void postTask(Task) = 0; // Executes the task on context's thread asynchronously.
 
     // Gets the next id in a circular sequence from 1 to 2^31-1.
     int circularSequentialID();
@@ -157,21 +175,12 @@ public:
 protected:
     class AddConsoleMessageTask : public Task {
     public:
-        static PassOwnPtr<AddConsoleMessageTask> create(MessageSource source, MessageLevel level, const String& message)
-        {
-            return adoptPtr(new AddConsoleMessageTask(source, level, message));
-        }
-        virtual void performTask(ScriptExecutionContext*) override;
-    private:
         AddConsoleMessageTask(MessageSource source, MessageLevel level, const String& message)
-            : m_source(source)
-            , m_level(level)
-            , m_message(message.isolatedCopy())
+            : Task([=] (ScriptExecutionContext* context) {
+                context->addConsoleMessage(source, level, message);
+            })
         {
         }
-        MessageSource m_source;
-        MessageLevel m_level;
-        String m_message;
     };
 
     ActiveDOMObject::ReasonForSuspension reasonForSuspendingActiveDOMObjects() const { return m_reasonForSuspendingActiveDOMObjects; }
index b54105f..da6b96e 100644 (file)
 
 namespace WebCore {
 
-namespace {
-
-class DispatchCallbackTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<DispatchCallbackTask> create(PassRefPtr<StringCallback> callback, const String& data)
-    {
-        return adoptPtr(new DispatchCallbackTask(callback, data));
-    }
-
-    virtual void performTask(ScriptExecutionContext*) override
-    {
-        m_callback->handleEvent(m_data);
-    }
-
-private:
-    DispatchCallbackTask(PassRefPtr<StringCallback> callback, const String& data)
-        : m_callback(callback)
-        , m_data(data)
-    {
-    }
-
-    RefPtr<StringCallback> m_callback;
-    const String m_data;
-};
-
-} // namespace
-
 void StringCallback::scheduleCallback(ScriptExecutionContext* context, const String& data)
 {
-    context->postTask(DispatchCallbackTask::create(this, data));
+    RefPtr<StringCallback> protector(this);
+    context->postTask([=] (ScriptExecutionContext*) {
+        this->handleEvent(data);
+    });
 }
 
 } // namespace WebCore
index 300aa63..54c854b 100644 (file)
@@ -1100,41 +1100,6 @@ void ApplicationCacheGroup::scheduleReachedMaxAppCacheSizeCallback()
     // The timer will delete itself once it fires.
 }
 
-class CallCacheListenerTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<CallCacheListenerTask> create(PassRefPtr<DocumentLoader> loader, ApplicationCacheHost::EventID eventID, int progressTotal, int progressDone)
-    {
-        return adoptPtr(new CallCacheListenerTask(loader, eventID, progressTotal, progressDone));
-    }
-
-    virtual void performTask(ScriptExecutionContext* context) override
-    {
-        
-        ASSERT_UNUSED(context, context->isDocument());
-        Frame* frame = m_documentLoader->frame();
-        if (!frame)
-            return;
-    
-        ASSERT(frame->loader().documentLoader() == m_documentLoader.get());
-
-        m_documentLoader->applicationCacheHost()->notifyDOMApplicationCache(m_eventID, m_progressTotal, m_progressDone);
-    }
-
-private:
-    CallCacheListenerTask(PassRefPtr<DocumentLoader> loader, ApplicationCacheHost::EventID eventID, int progressTotal, int progressDone)
-        : m_documentLoader(loader)
-        , m_eventID(eventID)
-        , m_progressTotal(progressTotal)
-        , m_progressDone(progressDone)
-    {
-    }
-
-    RefPtr<DocumentLoader> m_documentLoader;
-    ApplicationCacheHost::EventID m_eventID;
-    int m_progressTotal;
-    int m_progressDone;
-};
-
 void ApplicationCacheGroup::postListenerTask(ApplicationCacheHost::EventID eventID, int progressTotal, int progressDone, const HashSet<DocumentLoader*>& loaderSet)
 {
     HashSet<DocumentLoader*>::const_iterator loaderSetEnd = loaderSet.end();
@@ -1150,7 +1115,17 @@ void ApplicationCacheGroup::postListenerTask(ApplicationCacheHost::EventID event
     
     ASSERT(frame->loader().documentLoader() == loader);
 
-    frame->document()->postTask(CallCacheListenerTask::create(loader, eventID, progressTotal, progressDone));
+    RefPtr<DocumentLoader> loaderProtector(loader);
+    frame->document()->postTask([=] (ScriptExecutionContext* context) {
+        ASSERT_UNUSED(context, context->isDocument());
+        Frame* frame = loaderProtector->frame();
+        if (!frame)
+            return;
+
+        ASSERT(frame->loader().documentLoader() == loaderProtector);
+
+        loaderProtector->applicationCacheHost()->notifyDOMApplicationCache(eventID, progressTotal, progressDone);
+    });
 }
 
 void ApplicationCacheGroup::setUpdateStatus(UpdateStatus status)
index c59d563..cb18d25 100644 (file)
@@ -80,8 +80,8 @@ public:
     bool matches(const String& name, PassRefPtr<SecurityOrigin> origin, const URL& urlToMatch) const;
 
     // WorkerLoaderProxy
-    virtual void postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task>);
-    virtual bool postTaskForModeToWorkerGlobalScope(PassOwnPtr<ScriptExecutionContext::Task>, const String&);
+    virtual void postTaskToLoader(ScriptExecutionContext::Task);
+    virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task, const String&);
 
     // WorkerReportingProxy
     virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL);
@@ -140,7 +140,7 @@ bool SharedWorkerProxy::matches(const String& name, PassRefPtr<SecurityOrigin> o
     return name == m_name;
 }
 
-void SharedWorkerProxy::postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task> task)
+void SharedWorkerProxy::postTaskToLoader(ScriptExecutionContext::Task task)
 {
     MutexLocker lock(m_workerDocumentsLock);
 
@@ -153,15 +153,15 @@ void SharedWorkerProxy::postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task
     // Just pick an arbitrary active document from the HashSet and pass load requests to it.
     // FIXME: Do we need to deal with the case where the user closes the document mid-load, via a shadow document or some other solution?
     Document* document = *(m_workerDocuments.begin());
-    document->postTask(task);
+    document->postTask(std::move(task));
 }
 
-bool SharedWorkerProxy::postTaskForModeToWorkerGlobalScope(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
+bool SharedWorkerProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task task, const String& mode)
 {
     if (isClosing())
         return false;
     ASSERT(m_thread);
-    m_thread->runLoop().postTaskForMode(task, mode);
+    m_thread->runLoop().postTaskForMode(std::move(task), mode);
     return true;
 }
 
@@ -254,30 +254,19 @@ void SharedWorkerProxy::close()
 
 class SharedWorkerConnectTask : public ScriptExecutionContext::Task {
 public:
-    static PassOwnPtr<SharedWorkerConnectTask> create(std::unique_ptr<MessagePortChannel> channel)
+    SharedWorkerConnectTask(MessagePortChannel* channel)
+        : ScriptExecutionContext::Task([=] (ScriptExecutionContext* context) {
+            RefPtr<MessagePort> port = MessagePort::create(*context);
+            port->entangle(std::unique_ptr<MessagePortChannel>(channel));
+            ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
+            WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
+            // Since close() stops the thread event loop, this should not ever get called while closing.
+            ASSERT(!workerGlobalScope->isClosing());
+            ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScope());
+            workerGlobalScope->dispatchEvent(createConnectEvent(port));
+        })
     {
-        return adoptPtr(new SharedWorkerConnectTask(std::move(channel)));
     }
-
-private:
-    SharedWorkerConnectTask(std::unique_ptr<MessagePortChannel> channel)
-        : m_channel(std::move(channel))
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext* scriptContext)
-    {
-        RefPtr<MessagePort> port = MessagePort::create(*scriptContext);
-        port->entangle(std::move(m_channel));
-        ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isWorkerGlobalScope());
-        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(scriptContext);
-        // Since close() stops the thread event loop, this should not ever get called while closing.
-        ASSERT(!workerGlobalScope->isClosing());
-        ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScope());
-        workerGlobalScope->dispatchEvent(createConnectEvent(port));
-    }
-
-    std::unique_ptr<MessagePortChannel> m_channel;
 };
 
 // Loads the script on behalf of a worker.
@@ -367,7 +356,8 @@ void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy,
         proxy.setThread(thread);
         thread->start();
     }
-    proxy.thread()->runLoop().postTask(SharedWorkerConnectTask::create(std::move(port)));
+
+    proxy.thread()->runLoop().postTask(SharedWorkerConnectTask(port.release()));
 }
 
 bool DefaultSharedWorkerRepository::hasSharedWorkers(Document* document)
@@ -415,7 +405,7 @@ void DefaultSharedWorkerRepository::connectToWorker(PassRefPtr<SharedWorker> wor
     }
     // If proxy is already running, just connect to it - otherwise, kick off a loader to load the script.
     if (proxy->thread())
-        proxy->thread()->runLoop().postTask(SharedWorkerConnectTask::create(std::move(port)));
+        proxy->thread()->runLoop().postTask(SharedWorkerConnectTask(port.release()));
     else {
         RefPtr<SharedWorkerScriptLoader> loader = adoptRef(new SharedWorkerScriptLoader(worker, std::move(port), proxy.release()));
         loader->load(url);
index 745498c..46a0e30 100644 (file)
@@ -46,30 +46,28 @@ WorkerEventQueue::~WorkerEventQueue()
     close();
 }
 
-class WorkerEventQueue::EventDispatcherTask final : public ScriptExecutionContext::Task {
+class WorkerEventQueue::EventDispatcher
+{
 public:
-    static PassOwnPtr<EventDispatcherTask> create(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
+    EventDispatcher(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
+        : m_event(event)
+        , m_eventQueue(eventQueue)
+        , m_isCancelled(false)
     {
-        return adoptPtr(new EventDispatcherTask(event, eventQueue));
     }
 
-    virtual ~EventDispatcherTask()
+    ~EventDispatcher()
     {
         if (m_event)
-            m_eventQueue.m_eventTaskMap.remove(m_event.get());
+            m_eventQueue.m_eventDispatcherMap.remove(m_event.get());
     }
 
-    void dispatchEvent(ScriptExecutionContext*, PassRefPtr<Event> event)
-    {
-        event->target()->dispatchEvent(event);
-    }
-
-    virtual void performTask(ScriptExecutionContext* context) override
+    void dispatch()
     {
         if (m_isCancelled)
             return;
-        m_eventQueue.m_eventTaskMap.remove(m_event.get());
-        dispatchEvent(context, m_event);
+        m_eventQueue.m_eventDispatcherMap.remove(m_event.get());
+        m_event->target()->dispatchEvent(m_event);
         m_event.clear();
     }
 
@@ -80,32 +78,29 @@ public:
     }
 
 private:
-    EventDispatcherTask(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
-        : m_event(event)
-        , m_eventQueue(eventQueue)
-        , m_isCancelled(false)
-    {
-    }
-
     RefPtr<Event> m_event;
     WorkerEventQueue& m_eventQueue;
     bool m_isCancelled;
 };
 
-bool WorkerEventQueue::enqueueEvent(PassRefPtr<Event> prpEvent)
+bool WorkerEventQueue::enqueueEvent(PassRefPtr<Event> event)
 {
     if (m_isClosed)
         return false;
-    RefPtr<Event> event = prpEvent;
-    OwnPtr<EventDispatcherTask> task = EventDispatcherTask::create(event, *this);
-    m_eventTaskMap.add(event.release(), task.get());
-    m_scriptExecutionContext.postTask(task.release());
+
+    EventDispatcher* eventDispatcherPtr = new EventDispatcher(event.get(), *this);
+    m_eventDispatcherMap.add(event, eventDispatcherPtr);
+    m_scriptExecutionContext.postTask([=] (ScriptExecutionContext*) {
+        std::unique_ptr<EventDispatcher> eventDispatcher(eventDispatcherPtr);
+        eventDispatcher->dispatch();
+    });
+
     return true;
 }
 
 bool WorkerEventQueue::cancelEvent(Event& event)
 {
-    EventDispatcherTask* task = m_eventTaskMap.take(&event);
+    EventDispatcher* task = m_eventDispatcherMap.take(&event);
     if (!task)
         return false;
     task->cancel();
@@ -115,11 +110,9 @@ bool WorkerEventQueue::cancelEvent(Event& event)
 void WorkerEventQueue::close()
 {
     m_isClosed = true;
-    for (EventTaskMap::iterator it = m_eventTaskMap.begin(); it != m_eventTaskMap.end(); ++it) {
-        EventDispatcherTask* task = it->value;
-        task->cancel();
-    }
-    m_eventTaskMap.clear();
+    for (auto& dispatcher : m_eventDispatcherMap.values())
+        dispatcher->cancel();
+    m_eventDispatcherMap.clear();
 }
 
 }
index 5fae1d6..1c92844 100644 (file)
@@ -48,9 +48,9 @@ private:
     ScriptExecutionContext& m_scriptExecutionContext;
     bool m_isClosed;
 
-    class EventDispatcherTask;
-    typedef HashMap<RefPtr<Event>, EventDispatcherTask*> EventTaskMap;
-    EventTaskMap m_eventTaskMap;
+    class EventDispatcher;
+    typedef HashMap<RefPtr<Event>, EventDispatcher*> EventDispatcherMap;
+    EventDispatcherMap m_eventDispatcherMap;
 };
 
 }
index 4171c2f..722d6b9 100644 (file)
@@ -64,22 +64,6 @@ using namespace Inspector;
 
 namespace WebCore {
 
-class CloseWorkerGlobalScopeTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<CloseWorkerGlobalScopeTask> create()
-    {
-        return adoptPtr(new CloseWorkerGlobalScopeTask);
-    }
-
-    virtual void performTask(ScriptExecutionContext *context)
-    {
-        // Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop().
-        toWorkerGlobalScope(context)->thread().workerReportingProxy().workerGlobalScopeClosed();
-    }
-
-    virtual bool isCleanupTask() const { return true; }
-};
-
 WorkerGlobalScope::WorkerGlobalScope(const URL& url, const String& userAgent, std::unique_ptr<GroupSettings> settings, WorkerThread& thread, PassRefPtr<SecurityOrigin> topOrigin)
     : m_url(url)
     , m_userAgent(userAgent)
@@ -149,7 +133,12 @@ void WorkerGlobalScope::close()
     // After m_closing is set, all the tasks in the queue continue to be fetched but only
     // tasks with isCleanupTask()==true will be executed.
     m_closing = true;
-    postTask(CloseWorkerGlobalScopeTask::create());
+    postTask({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext* context) {
+        ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
+        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
+        // Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop().
+        workerGlobalScope->thread().workerReportingProxy().workerGlobalScopeClosed();
+    } });
 }
 
 WorkerNavigator* WorkerGlobalScope::navigator() const
@@ -159,9 +148,9 @@ WorkerNavigator* WorkerGlobalScope::navigator() const
     return m_navigator.get();
 }
 
-void WorkerGlobalScope::postTask(PassOwnPtr<Task> task)
+void WorkerGlobalScope::postTask(Task task)
 {
-    thread().runLoop().postTask(task);
+    thread().runLoop().postTask(std::move(task));
 }
 
 int WorkerGlobalScope::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout)
@@ -234,7 +223,7 @@ void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const
 void WorkerGlobalScope::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask::create(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
@@ -245,7 +234,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, PassRefPtr<ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask::create(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, message));
         return;
     }
 
index 19d20ee..0018466 100644 (file)
@@ -78,7 +78,7 @@ namespace WebCore {
 
         using ScriptExecutionContext::hasPendingActivity;
 
-        virtual void postTask(PassOwnPtr<Task>) override; // Executes the task on context's thread asynchronously.
+        virtual void postTask(Task) override; // Executes the task on context's thread asynchronously.
 
         // WorkerGlobalScope
         WorkerGlobalScope* self() { return this; }
index 6293124..df304dc 100644 (file)
@@ -47,12 +47,12 @@ namespace WebCore {
         virtual ~WorkerLoaderProxy() { }
 
         // Posts a task to the thread which runs the loading code (normally, the main thread).
-        virtual void postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task>) = 0;
+        virtual void postTaskToLoader(ScriptExecutionContext::Task) = 0;
 
         // Posts callbacks from loading code to the WorkerGlobalScope. The 'mode' is used to differentiate
         // specific synchronous loading requests so they can be 'nested', per spec.
         // Returns true if the task was posted successfully.
-        virtual bool postTaskForModeToWorkerGlobalScope(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode) = 0;
+        virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task, const String& mode) = 0;
     };
 
 } // namespace WebCore
index bd2439d..13a6ced 100644 (file)
 
 namespace WebCore {
 
-class MessageWorkerGlobalScopeTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<MessageWorkerGlobalScopeTask> create(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
-    {
-        return adoptPtr(new MessageWorkerGlobalScopeTask(message, std::move(channels)));
-    }
-
-private:
-    MessageWorkerGlobalScopeTask(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
-        : m_message(message)
-        , m_channels(std::move(channels))
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext* scriptContext)
-    {
-        ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isWorkerGlobalScope());
-        DedicatedWorkerGlobalScope* context = static_cast<DedicatedWorkerGlobalScope*>(scriptContext);
-        std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*scriptContext, std::move(m_channels));
-        context->dispatchEvent(MessageEvent::create(std::move(ports), m_message));
-        context->thread().workerObjectProxy().confirmMessageFromWorkerObject(context->hasPendingActivity());
-    }
-
-private:
-    RefPtr<SerializedScriptValue> m_message;
-    std::unique_ptr<MessagePortChannelArray> m_channels;
-};
-
-class MessageWorkerTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<MessageWorkerTask> create(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels, WorkerMessagingProxy* messagingProxy)
-    {
-        return adoptPtr(new MessageWorkerTask(message, std::move(channels), messagingProxy));
-    }
-
-private:
-    MessageWorkerTask(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels, WorkerMessagingProxy* messagingProxy)
-        : m_message(message)
-        , m_channels(std::move(channels))
-        , m_messagingProxy(messagingProxy)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext* scriptContext)
-    {
-        Worker* workerObject = m_messagingProxy->workerObject();
-        if (!workerObject || m_messagingProxy->askedToTerminate())
-            return;
-
-        std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*scriptContext, std::move(m_channels));
-        workerObject->dispatchEvent(MessageEvent::create(std::move(ports), m_message));
-    }
-
-private:
-    RefPtr<SerializedScriptValue> m_message;
-    std::unique_ptr<MessagePortChannelArray> m_channels;
-    WorkerMessagingProxy* m_messagingProxy;
-};
-
-class WorkerExceptionTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerExceptionTask> create(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, WorkerMessagingProxy* messagingProxy)
-    {
-        return adoptPtr(new WorkerExceptionTask(errorMessage, lineNumber, columnNumber, sourceURL, messagingProxy));
-    }
-
-private:
-    WorkerExceptionTask(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, WorkerMessagingProxy* messagingProxy)
-        : m_errorMessage(errorMessage.isolatedCopy())
-        , m_lineNumber(lineNumber)
-        , m_columnNumber(columnNumber)
-        , m_sourceURL(sourceURL.isolatedCopy())
-        , m_messagingProxy(messagingProxy)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext* context)
-    {
-        Worker* workerObject = m_messagingProxy->workerObject();
-        if (!workerObject)
-            return;
-
-        // 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(m_errorMessage, m_sourceURL, m_lineNumber, m_columnNumber));
-        if (!errorHandled)
-            context->reportException(m_errorMessage, m_lineNumber, m_columnNumber, m_sourceURL, 0);
-    }
-
-    String m_errorMessage;
-    int m_lineNumber;
-    int m_columnNumber;
-    String m_sourceURL;
-    WorkerMessagingProxy* m_messagingProxy;
-};
-
-class WorkerGlobalScopeDestroyedTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerGlobalScopeDestroyedTask> create(WorkerMessagingProxy* messagingProxy)
-    {
-        return adoptPtr(new WorkerGlobalScopeDestroyedTask(messagingProxy));
-    }
-
-private:
-    WorkerGlobalScopeDestroyedTask(WorkerMessagingProxy* messagingProxy)
-        : m_messagingProxy(messagingProxy)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_messagingProxy->workerGlobalScopeDestroyedInternal();
-    }
-
-    WorkerMessagingProxy* m_messagingProxy;
-};
-
-class WorkerTerminateTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerTerminateTask> create(WorkerMessagingProxy* messagingProxy)
-    {
-        return adoptPtr(new WorkerTerminateTask(messagingProxy));
-    }
-
-private:
-    WorkerTerminateTask(WorkerMessagingProxy* messagingProxy)
-        : m_messagingProxy(messagingProxy)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_messagingProxy->terminateWorkerGlobalScope();
-    }
-
-    WorkerMessagingProxy* m_messagingProxy;
-};
-
-class WorkerThreadActivityReportTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerThreadActivityReportTask> create(WorkerMessagingProxy* messagingProxy, bool confirmingMessage, bool hasPendingActivity)
-    {
-        return adoptPtr(new WorkerThreadActivityReportTask(messagingProxy, confirmingMessage, hasPendingActivity));
-    }
-
-private:
-    WorkerThreadActivityReportTask(WorkerMessagingProxy* messagingProxy, bool confirmingMessage, bool hasPendingActivity)
-        : m_messagingProxy(messagingProxy)
-        , m_confirmingMessage(confirmingMessage)
-        , m_hasPendingActivity(hasPendingActivity)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_messagingProxy->reportPendingActivityInternal(m_confirmingMessage, m_hasPendingActivity);
-    }
-
-    WorkerMessagingProxy* m_messagingProxy;
-    bool m_confirmingMessage;
-    bool m_hasPendingActivity;
-};
-
-class PostMessageToPageInspectorTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<PostMessageToPageInspectorTask> create(WorkerMessagingProxy* messagingProxy, const String& message)
-    {
-        return adoptPtr(new PostMessageToPageInspectorTask(messagingProxy, message));
-    }
-
-private:
-    PostMessageToPageInspectorTask(WorkerMessagingProxy* messagingProxy, const String& message)
-        : m_messagingProxy(messagingProxy)
-        , m_message(message.isolatedCopy())
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-#if ENABLE(INSPECTOR)
-        if (WorkerGlobalScopeProxy::PageInspector* pageInspector = m_messagingProxy->m_pageInspector)
-            pageInspector->dispatchMessageFromWorker(m_message);
-#endif
-    }
-
-    WorkerMessagingProxy* m_messagingProxy;
-    String m_message;
-};
-
-class NotifyNetworkStateChangeTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<NotifyNetworkStateChangeTask> create(bool isOnLine)
-    {
-        return adoptPtr(new NotifyNetworkStateChangeTask(isOnLine));
-    }
-
-private:
-    NotifyNetworkStateChangeTask(bool isOnLine)
-        : m_isOnLine(isOnLine)
-    {
-    }
-
-    virtual void performTask(ScriptExecutionContext *context)
-    {
-        AtomicString eventName = m_isOnLine ? eventNames().onlineEvent : eventNames().offlineEvent;
-        toWorkerGlobalScope(context)->dispatchEvent(Event::create(eventName, false, false));
-    }
-
-    bool m_isOnLine;
-};
-
-
 WorkerGlobalScopeProxy* WorkerGlobalScopeProxy::create(Worker* worker)
 {
     return new WorkerMessagingProxy(worker);
@@ -310,7 +97,15 @@ void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const St
 
 void WorkerMessagingProxy::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
 {
-    m_scriptExecutionContext->postTask(MessageWorkerTask::create(message, std::move(channels), this));
+    MessagePortChannelArray* channelsPtr = channels.release();
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
+        Worker* workerObject = this->workerObject();
+        if (!workerObject || this->askedToTerminate())
+            return;
+
+        std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*context, std::unique_ptr<MessagePortChannelArray>(channelsPtr));
+        workerObject->dispatchEvent(MessageEvent::create(std::move(ports), message));
+    });
 }
 
 void WorkerMessagingProxy::postMessageToWorkerGlobalScope(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
@@ -318,33 +113,55 @@ void WorkerMessagingProxy::postMessageToWorkerGlobalScope(PassRefPtr<SerializedS
     if (m_askedToTerminate)
         return;
 
+    MessagePortChannelArray* channelsPtr = channels.release();
+    ScriptExecutionContext::Task task([=] (ScriptExecutionContext* scriptContext) {
+        ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isWorkerGlobalScope());
+        DedicatedWorkerGlobalScope* context = static_cast<DedicatedWorkerGlobalScope*>(scriptContext);
+        std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*scriptContext, std::unique_ptr<MessagePortChannelArray>(channelsPtr));
+        context->dispatchEvent(MessageEvent::create(std::move(ports), message));
+        context->thread().workerObjectProxy().confirmMessageFromWorkerObject(context->hasPendingActivity());
+    });
+
     if (m_workerThread) {
         ++m_unconfirmedMessageCount;
-        m_workerThread->runLoop().postTask(MessageWorkerGlobalScopeTask::create(message, std::move(channels)));
+        m_workerThread->runLoop().postTask(std::move(task));
     } else
-        m_queuedEarlyTasks.append(MessageWorkerGlobalScopeTask::create(message, std::move(channels)));
+        m_queuedEarlyTasks.append(std::make_unique<ScriptExecutionContext::Task>(std::move(task)));
 }
 
-bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
+bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task task, const String& mode)
 {
     if (m_askedToTerminate)
         return false;
 
     ASSERT(m_workerThread);
-    m_workerThread->runLoop().postTaskForMode(task, mode);
+    m_workerThread->runLoop().postTaskForMode(std::move(task), mode);
     return true;
 }
 
-void WorkerMessagingProxy::postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task> task)
+void WorkerMessagingProxy::postTaskToLoader(ScriptExecutionContext::Task task)
 {
     // FIXME: In case of nested workers, this should go directly to the root Document context.
     ASSERT(m_scriptExecutionContext->isDocument());
-    m_scriptExecutionContext->postTask(task);
+    m_scriptExecutionContext->postTask(std::move(task));
 }
 
 void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    m_scriptExecutionContext->postTask(WorkerExceptionTask::create(errorMessage, lineNumber, columnNumber, sourceURL, this));
+    String errorMessageCopy = errorMessage.isolatedCopy();
+    String sourceURLCopy = sourceURL.isolatedCopy();
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
+        Worker* workerObject = this->workerObject();
+        if (!workerObject)
+            return;
+
+        // 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(errorMessageCopy, sourceURLCopy, lineNumber, columnNumber));
+        if (!errorHandled)
+            context->reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, 0);
+    });
 }
 
 static void postConsoleMessageTask(ScriptExecutionContext* context, WorkerMessagingProxy* messagingProxy, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceURL)
@@ -367,14 +184,13 @@ void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread>
         // Worker.terminate() could be called from JS before the thread was created.
         m_workerThread->stop();
     } else {
-        unsigned taskCount = m_queuedEarlyTasks.size();
         ASSERT(!m_unconfirmedMessageCount);
-        m_unconfirmedMessageCount = taskCount;
+        m_unconfirmedMessageCount = m_queuedEarlyTasks.size();
         m_workerThreadHadPendingActivity = true; // Worker initialization means a pending activity.
 
-        for (unsigned i = 0; i < taskCount; ++i)
-            m_workerThread->runLoop().postTask(m_queuedEarlyTasks[i].release());
-        m_queuedEarlyTasks.clear();
+        auto queuedEarlyTasks = std::move(m_queuedEarlyTasks);
+        for (auto& task : queuedEarlyTasks)
+            m_workerThread->runLoop().postTask(std::move(*task));
     }
 }
 
@@ -392,7 +208,10 @@ void WorkerMessagingProxy::notifyNetworkStateChange(bool isOnline)
     if (!m_workerThread)
         return;
 
-    m_workerThread->runLoop().postTask(NotifyNetworkStateChangeTask::create(isOnline));
+    m_workerThread->runLoop().postTask([=] (ScriptExecutionContext* context) {
+        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
+        workerGlobalScope->dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
+    });
 }
 
 void WorkerMessagingProxy::workerObjectDestroyedInternal(ScriptExecutionContext*, WorkerMessagingProxy* proxy)
@@ -448,14 +267,18 @@ void WorkerMessagingProxy::sendMessageToInspector(const String& message)
 
 void WorkerMessagingProxy::workerGlobalScopeDestroyed()
 {
-    m_scriptExecutionContext->postTask(WorkerGlobalScopeDestroyedTask::create(this));
+    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext*) {
+        workerGlobalScopeDestroyedInternal();
+    });
     // Will execute workerGlobalScopeDestroyedInternal() on context's thread.
 }
 
 void WorkerMessagingProxy::workerGlobalScopeClosed()
 {
     // Executes terminateWorkerGlobalScope() on parent context's thread.
-    m_scriptExecutionContext->postTask(WorkerTerminateTask::create(this));
+    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext*) {
+        terminateWorkerGlobalScope();
+    });
 }
 
 void WorkerMessagingProxy::workerGlobalScopeDestroyedInternal()
@@ -486,19 +309,26 @@ void WorkerMessagingProxy::terminateWorkerGlobalScope()
 #if ENABLE(INSPECTOR)
 void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
 {
-    m_scriptExecutionContext->postTask(PostMessageToPageInspectorTask::create(this, message));
+    String messageCopy = message.isolatedCopy();
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
+        this->m_pageInspector->dispatchMessageFromWorker(messageCopy);
+    });
 }
 #endif
 
 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivity)
 {
-    m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(this, true, hasPendingActivity));
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
+        this->reportPendingActivityInternal(true, hasPendingActivity);
+    });
     // Will execute reportPendingActivityInternal() on context's thread.
 }
 
 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity)
 {
-    m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(this, false, hasPendingActivity));
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
+        this->reportPendingActivityInternal(false, hasPendingActivity);
+    });
     // Will execute reportPendingActivityInternal() on context's thread.
 }
 
index 606d013..02b08d6 100644 (file)
@@ -80,8 +80,8 @@ namespace WebCore {
         // Implementation of WorkerLoaderProxy.
         // These methods are called on different threads to schedule loading
         // requests and to send callbacks back to WorkerGlobalScope.
-        virtual void postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task>) override;
-        virtual bool postTaskForModeToWorkerGlobalScope(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode) override;
+        virtual void postTaskToLoader(ScriptExecutionContext::Task) override;
+        virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task, const String& mode) override;
 
         void workerThreadCreated(PassRefPtr<DedicatedWorkerThread>);
 
@@ -113,7 +113,7 @@ namespace WebCore {
 
         bool m_askedToTerminate;
 
-        Vector<OwnPtr<ScriptExecutionContext::Task>> m_queuedEarlyTasks; // Tasks are queued here until there's a thread object created.
+        Vector<std::unique_ptr<ScriptExecutionContext::Task>> m_queuedEarlyTasks; // Tasks are queued here until there's a thread object created.
 #if ENABLE(INSPECTOR)
         WorkerGlobalScopeProxy::PageInspector* m_pageInspector;
 #endif
index 49e061c..b64c2e6 100644 (file)
@@ -192,34 +192,34 @@ void WorkerRunLoop::terminate()
     m_messageQueue.kill();
 }
 
-void WorkerRunLoop::postTask(PassOwnPtr<ScriptExecutionContext::Task> task)
+void WorkerRunLoop::postTask(ScriptExecutionContext::Task task)
 {
-    postTaskForMode(task, defaultMode());
+    postTaskForMode(std::move(task), defaultMode());
 }
 
-void WorkerRunLoop::postTaskAndTerminate(PassOwnPtr<ScriptExecutionContext::Task> task)
+void WorkerRunLoop::postTaskAndTerminate(ScriptExecutionContext::Task task)
 {
-    m_messageQueue.appendAndKill(Task::create(task, defaultMode().isolatedCopy()));
+    m_messageQueue.appendAndKill(Task::create(std::move(task), defaultMode().isolatedCopy()));
 }
 
-void WorkerRunLoop::postTaskForMode(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
+void WorkerRunLoop::postTaskForMode(ScriptExecutionContext::Task task, const String& mode)
 {
-    m_messageQueue.append(Task::create(task, mode.isolatedCopy()));
+    m_messageQueue.append(Task::create(std::move(task), mode.isolatedCopy()));
 }
 
-std::unique_ptr<WorkerRunLoop::Task> WorkerRunLoop::Task::create(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
+std::unique_ptr<WorkerRunLoop::Task> WorkerRunLoop::Task::create(ScriptExecutionContext::Task task, const String& mode)
 {
-    return std::unique_ptr<Task>(new Task(task, mode));
+    return std::unique_ptr<Task>(new Task(std::move(task), mode));
 }
 
 void WorkerRunLoop::Task::performTask(const WorkerRunLoop& runLoop, ScriptExecutionContext* context)
 {
-    if ((!toWorkerGlobalScope(context)->isClosing() && !runLoop.terminated()) || m_task->isCleanupTask())
-        m_task->performTask(context);
+    if ((!toWorkerGlobalScope(context)->isClosing() && !runLoop.terminated()) || m_task.isCleanupTask())
+        m_task.performTask(context);
 }
 
-WorkerRunLoop::Task::Task(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
-    : m_task(task)
+WorkerRunLoop::Task::Task(ScriptExecutionContext::Task task, const String& mode)
+    : m_task(std::move(task))
     , m_mode(mode.isolatedCopy())
 {
 }
index 10aa81b..f23c30f 100644 (file)
@@ -58,9 +58,9 @@ namespace WebCore {
         void terminate();
         bool terminated() const { return m_messageQueue.killed(); }
 
-        void postTask(PassOwnPtr<ScriptExecutionContext::Task>);
-        void postTaskAndTerminate(PassOwnPtr<ScriptExecutionContext::Task>);
-        void postTaskForMode(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode);
+        void postTask(ScriptExecutionContext::Task);
+        void postTaskAndTerminate(ScriptExecutionContext::Task);
+        void postTaskForMode(ScriptExecutionContext::Task, const String& mode);
 
         unsigned long createUniqueId() { return ++m_uniqueId; }
 
@@ -69,15 +69,15 @@ namespace WebCore {
         class Task {
             WTF_MAKE_NONCOPYABLE(Task); WTF_MAKE_FAST_ALLOCATED;
         public:
-            static std::unique_ptr<Task> create(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode);
+            static std::unique_ptr<Task> create(ScriptExecutionContext::Task, const String& mode);
             ~Task() { }
             const String& mode() const { return m_mode; }
             void performTask(const WorkerRunLoop&, ScriptExecutionContext*);
 
         private:
-            Task(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode);
+            Task(ScriptExecutionContext::Task task, const String& mode);
         
-            OwnPtr<ScriptExecutionContext::Task> m_task;
+            ScriptExecutionContext::Task m_task;
             String m_mode;
         };
 
index cdf6b25..440b06c 100644 (file)
@@ -205,89 +205,63 @@ void WorkerThread::runEventLoop()
     m_runLoop.run(m_workerGlobalScope.get());
 }
 
-class WorkerThreadShutdownFinishTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerThreadShutdownFinishTask> create()
-    {
-        return adoptPtr(new WorkerThreadShutdownFinishTask());
-    }
-
-    virtual void performTask(ScriptExecutionContext *context)
-    {
-        // It's not safe to call clearScript until all the cleanup tasks posted by functions initiated by WorkerThreadShutdownStartTask have completed.
-        toWorkerGlobalScope(context)->clearScript();
-    }
-
-    virtual bool isCleanupTask() const { return true; }
-};
-
-class WorkerThreadShutdownStartTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<WorkerThreadShutdownStartTask> create()
-    {
-        return adoptPtr(new WorkerThreadShutdownStartTask());
-    }
+void WorkerThread::stop()
+{
+    // Mutex protection is necessary because stop() can be called before the context is fully created.
+    MutexLocker lock(m_threadCreationMutex);
 
-    virtual void performTask(ScriptExecutionContext *context)
-    {
-        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
+    // Ensure that tasks are being handled by thread event loop. If script execution weren't forbidden, a while(1) loop in JS could keep the thread alive forever.
+    if (m_workerGlobalScope) {
+        m_workerGlobalScope->script()->scheduleExecutionTermination();
 
 #if ENABLE(SQL_DATABASE)
-        // FIXME: Should we stop the databases as part of stopActiveDOMObjects() below?
-        DatabaseTaskSynchronizer cleanupSync;
-        DatabaseManager::manager().stopDatabases(workerGlobalScope, &cleanupSync);
+        DatabaseManager::manager().interruptAllDatabasesForContext(m_workerGlobalScope.get());
 #endif
-
-        workerGlobalScope->stopActiveDOMObjects();
-
-        workerGlobalScope->notifyObserversOfStop();
-
-        // Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects,
-        // which become dangling once Heap is destroyed.
-        workerGlobalScope->removeAllEventListeners();
+        m_runLoop.postTaskAndTerminate({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext* context ) {
+            WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
 
 #if ENABLE(SQL_DATABASE)
-        // We wait for the database thread to clean up all its stuff so that we
-        // can do more stringent leak checks as we exit.
-        cleanupSync.waitForTaskCompletion();
+            // FIXME: Should we stop the databases as part of stopActiveDOMObjects() below?
+            DatabaseTaskSynchronizer cleanupSync;
+            DatabaseManager::manager().stopDatabases(workerGlobalScope, &cleanupSync);
 #endif
 
-        // Stick a shutdown command at the end of the queue, so that we deal
-        // with all the cleanup tasks the databases post first.
-        workerGlobalScope->postTask(WorkerThreadShutdownFinishTask::create());
-    }
+            workerGlobalScope->stopActiveDOMObjects();
 
-    virtual bool isCleanupTask() const { return true; }
-};
+            workerGlobalScope->notifyObserversOfStop();
 
-void WorkerThread::stop()
-{
-    // Mutex protection is necessary because stop() can be called before the context is fully created.
-    MutexLocker lock(m_threadCreationMutex);
-
-    // Ensure that tasks are being handled by thread event loop. If script execution weren't forbidden, a while(1) loop in JS could keep the thread alive forever.
-    if (m_workerGlobalScope) {
-        m_workerGlobalScope->script()->scheduleExecutionTermination();
+            // Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects,
+            // which become dangling once Heap is destroyed.
+            workerGlobalScope->removeAllEventListeners();
 
 #if ENABLE(SQL_DATABASE)
-        DatabaseManager::manager().interruptAllDatabasesForContext(m_workerGlobalScope.get());
+            // We wait for the database thread to clean up all its stuff so that we
+            // can do more stringent leak checks as we exit.
+            cleanupSync.waitForTaskCompletion();
 #endif
-        m_runLoop.postTaskAndTerminate(WorkerThreadShutdownStartTask::create());
+
+            // Stick a shutdown command at the end of the queue, so that we deal
+            // with all the cleanup tasks the databases post first.
+            workerGlobalScope->postTask({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext* context) {
+                WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
+                // It's not safe to call clearScript until all the cleanup tasks posted by functions initiated by WorkerThreadShutdownStartTask have completed.
+                workerGlobalScope->clearScript();
+            } });
+
+        } });
         return;
     }
     m_runLoop.terminate();
 }
 
-class ReleaseFastMallocFreeMemoryTask : public ScriptExecutionContext::Task {
-    virtual void performTask(ScriptExecutionContext*) override { WTF::releaseFastMallocFreeMemory(); }
-};
-
 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads()
 {
     std::lock_guard<std::mutex> lock(threadSetMutex());
 
     for (auto* workerThread : workerThreads())
-        workerThread->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask));
+        workerThread->runLoop().postTask([] (ScriptExecutionContext*) {
+            WTF::releaseFastMallocFreeMemory();
+        });
 }
 
 } // namespace WebCore