Skip to content
Permalink
Browse files
Move Source/WebCore/workers/ code to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=132401

Reviewed by Andreas Kling.

Replace uses of OwnPtr and PassOwnPtr in code under Source/WebCore/workers (and related places)
with std::unique_ptr.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::setTimeout):
(WebCore::JSDOMWindow::setInterval):
* bindings/js/JSWorkerGlobalScopeCustom.cpp:
(WebCore::JSWorkerGlobalScope::setTimeout):
(WebCore::JSWorkerGlobalScope::setInterval):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
* bindings/js/ScheduledAction.h:
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer):
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
(WebCore::DOMTimer::didStop):
* page/DOMTimer.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::setTimeout):
(WebCore::DOMWindow::setInterval):
* page/DOMWindow.h:
* workers/WorkerEventQueue.h:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope):
(WebCore::WorkerGlobalScope::setTimeout):
(WebCore::WorkerGlobalScope::setInterval):
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::clearScript):
* workers/WorkerLoaderProxy.h:
* workers/WorkerMessagingProxy.h:
* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::WorkerRunLoop):
* workers/WorkerRunLoop.h:
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::loadAsynchronously):
(WebCore::WorkerScriptLoader::createResourceRequest):
* workers/WorkerScriptLoader.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::WorkerThread):
(WebCore::WorkerThread::workerThread):
(WebCore::WorkerThreadStartupData::create): Deleted.
* workers/WorkerThread.h:


Canonical link: https://commits.webkit.org/150823@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168578 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
zdobersek committed May 10, 2014
1 parent 011732b commit 6b2ee98399610700950feebf8140efbdea716fda
Showing 20 changed files with 107 additions and 65 deletions.
@@ -1,3 +1,55 @@
2014-05-10 Zan Dobersek <zdobersek@igalia.com>

Move Source/WebCore/workers/ code to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=132401

Reviewed by Andreas Kling.

Replace uses of OwnPtr and PassOwnPtr in code under Source/WebCore/workers (and related places)
with std::unique_ptr.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::setTimeout):
(WebCore::JSDOMWindow::setInterval):
* bindings/js/JSWorkerGlobalScopeCustom.cpp:
(WebCore::JSWorkerGlobalScope::setTimeout):
(WebCore::JSWorkerGlobalScope::setInterval):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
* bindings/js/ScheduledAction.h:
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer):
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
(WebCore::DOMTimer::didStop):
* page/DOMTimer.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::setTimeout):
(WebCore::DOMWindow::setInterval):
* page/DOMWindow.h:
* workers/WorkerEventQueue.h:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope):
(WebCore::WorkerGlobalScope::setTimeout):
(WebCore::WorkerGlobalScope::setInterval):
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::clearScript):
* workers/WorkerLoaderProxy.h:
* workers/WorkerMessagingProxy.h:
* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::WorkerRunLoop):
* workers/WorkerRunLoop.h:
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::loadAsynchronously):
(WebCore::WorkerScriptLoader::createResourceRequest):
* workers/WorkerScriptLoader.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::WorkerThread):
(WebCore::WorkerThread::workerThread):
(WebCore::WorkerThreadStartupData::create): Deleted.
* workers/WorkerThread.h:

2014-05-09 Dean Jackson <dino@apple.com>

-webkit-filter prevents rendering at retina scale
@@ -594,7 +594,7 @@ JSValue JSDOMWindow::postMessage(ExecState* exec)
JSValue JSDOMWindow::setTimeout(ExecState* exec)
{
ContentSecurityPolicy* contentSecurityPolicy = impl().document() ? impl().document()->contentSecurityPolicy() : 0;
OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), contentSecurityPolicy);
std::unique_ptr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), contentSecurityPolicy);
if (exec->hadException())
return jsUndefined();

@@ -604,7 +604,7 @@ JSValue JSDOMWindow::setTimeout(ExecState* exec)
int delay = exec->argument(1).toInt32(exec);

ExceptionCode ec = 0;
int result = impl().setTimeout(action.release(), delay, ec);
int result = impl().setTimeout(std::move(action), delay, ec);
setDOMException(exec, ec);

return jsNumber(result);
@@ -613,7 +613,7 @@ JSValue JSDOMWindow::setTimeout(ExecState* exec)
JSValue JSDOMWindow::setInterval(ExecState* exec)
{
ContentSecurityPolicy* contentSecurityPolicy = impl().document() ? impl().document()->contentSecurityPolicy() : 0;
OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), contentSecurityPolicy);
std::unique_ptr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), contentSecurityPolicy);
if (exec->hadException())
return jsUndefined();
int delay = exec->argument(1).toInt32(exec);
@@ -622,7 +622,7 @@ JSValue JSDOMWindow::setInterval(ExecState* exec)
return jsNumber(0);

ExceptionCode ec = 0;
int result = impl().setInterval(action.release(), delay, ec);
int result = impl().setInterval(std::move(action), delay, ec);
setDOMException(exec, ec);

return jsNumber(result);
@@ -87,24 +87,24 @@ JSValue JSWorkerGlobalScope::importScripts(ExecState* exec)

JSValue JSWorkerGlobalScope::setTimeout(ExecState* exec)
{
OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), impl().contentSecurityPolicy());
std::unique_ptr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), impl().contentSecurityPolicy());
if (exec->hadException())
return jsUndefined();
if (!action)
return jsNumber(0);
int delay = exec->argument(1).toInt32(exec);
return jsNumber(impl().setTimeout(action.release(), delay));
return jsNumber(impl().setTimeout(std::move(action), delay));
}

JSValue JSWorkerGlobalScope::setInterval(ExecState* exec)
{
OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), impl().contentSecurityPolicy());
std::unique_ptr<ScheduledAction> action = ScheduledAction::create(exec, globalObject()->world(), impl().contentSecurityPolicy());
if (exec->hadException())
return jsUndefined();
if (!action)
return jsNumber(0);
int delay = exec->argument(1).toInt32(exec);
return jsNumber(impl().setInterval(action.release(), delay));
return jsNumber(impl().setInterval(std::move(action), delay));
}

} // namespace WebCore
@@ -46,7 +46,7 @@ using namespace JSC;

namespace WebCore {

PassOwnPtr<ScheduledAction> ScheduledAction::create(ExecState* exec, DOMWrapperWorld& isolatedWorld, ContentSecurityPolicy* policy)
std::unique_ptr<ScheduledAction> ScheduledAction::create(ExecState* exec, DOMWrapperWorld& isolatedWorld, ContentSecurityPolicy* policy)
{
JSValue v = exec->argument(0);
CallData callData;
@@ -56,10 +56,10 @@ PassOwnPtr<ScheduledAction> ScheduledAction::create(ExecState* exec, DOMWrapperW
String string = v.toString(exec)->value(exec);
if (exec->hadException())
return nullptr;
return adoptPtr(new ScheduledAction(string, isolatedWorld));
return std::unique_ptr<ScheduledAction>(new ScheduledAction(string, isolatedWorld));
}

return adoptPtr(new ScheduledAction(exec, v, isolatedWorld));
return std::unique_ptr<ScheduledAction>(new ScheduledAction(exec, v, isolatedWorld));
}

ScheduledAction::ScheduledAction(ExecState* exec, JSValue function, DOMWrapperWorld& isolatedWorld)
@@ -23,8 +23,8 @@
#include "JSDOMBinding.h"
#include <heap/Strong.h>
#include <heap/StrongInlines.h>
#include <memory>
#include <runtime/JSCell.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

@@ -46,7 +46,7 @@ namespace WebCore {
class ScheduledAction {
WTF_MAKE_NONCOPYABLE(ScheduledAction); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<ScheduledAction> create(JSC::ExecState*, DOMWrapperWorld& isolatedWorld, ContentSecurityPolicy*);
static std::unique_ptr<ScheduledAction> create(JSC::ExecState*, DOMWrapperWorld& isolatedWorld, ContentSecurityPolicy*);

void execute(ScriptExecutionContext*);

@@ -58,10 +58,10 @@ static inline bool shouldForwardUserGesture(int interval, int nestingLevel)
&& nestingLevel == 1; // Gestures should not be forwarded to nested timers.
}

DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int interval, bool singleShot)
DOMTimer::DOMTimer(ScriptExecutionContext* context, std::unique_ptr<ScheduledAction> action, int interval, bool singleShot)
: SuspendableTimer(context)
, m_nestingLevel(timerNestingLevel + 1)
, m_action(action)
, m_action(std::move(action))
, m_originalInterval(interval)
, m_shouldForwardUserGesture(shouldForwardUserGesture(interval, m_nestingLevel))
{
@@ -83,12 +83,12 @@ DOMTimer::~DOMTimer()
scriptExecutionContext()->removeTimeout(m_timeoutId);
}

int DOMTimer::install(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int timeout, bool singleShot)
int DOMTimer::install(ScriptExecutionContext* context, std::unique_ptr<ScheduledAction> action, int timeout, bool singleShot)
{
// DOMTimer constructor links the new timer into a list of ActiveDOMObjects held by the 'context'.
// The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(),
// or if it is a one-time timer and it has fired (DOMTimer::fired).
DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot);
DOMTimer* timer = new DOMTimer(context, std::move(action), timeout, singleShot);
#if PLATFORM(IOS)
if (context->isDocument()) {
Document& document = toDocument(*context);
@@ -157,7 +157,7 @@ void DOMTimer::fired()
}

// Delete timer before executing the action for one-shot timers.
OwnPtr<ScheduledAction> action = m_action.release();
ScheduledAction* action = m_action.release();

// No access to member variables after this point.
delete this;
@@ -207,7 +207,7 @@ void DOMTimer::didStop()
// Need to release JS objects potentially protected by ScheduledAction
// because they can form circular references back to the ScriptExecutionContext
// which will cause a memory leak.
m_action.clear();
m_action = nullptr;
}

void DOMTimer::adjustMinimumTimerInterval(double oldMinimumTimerInterval)
@@ -28,8 +28,7 @@
#define DOMTimer_h

#include "SuspendableTimer.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <memory>

namespace WebCore {

@@ -40,7 +39,7 @@ namespace WebCore {
virtual ~DOMTimer();
// Creates a new timer owned by specified ScriptExecutionContext, starts it
// and returns its Id.
static int install(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int timeout, bool singleShot);
static int install(ScriptExecutionContext*, std::unique_ptr<ScheduledAction>, int timeout, bool singleShot);
static void removeById(ScriptExecutionContext*, int timeoutId);

// Adjust to a change in the ScriptExecutionContext's minimum timer interval.
@@ -49,7 +48,7 @@ namespace WebCore {
void adjustMinimumTimerInterval(double oldMinimumTimerInterval);

private:
DOMTimer(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int interval, bool singleShot);
DOMTimer(ScriptExecutionContext*, std::unique_ptr<ScheduledAction>, int interval, bool singleShot);
virtual void fired() override;

// ActiveDOMObject
@@ -65,7 +64,7 @@ namespace WebCore {

int m_timeoutId;
int m_nestingLevel;
OwnPtr<ScheduledAction> m_action;
std::unique_ptr<ScheduledAction> m_action;
int m_originalInterval;
bool m_shouldForwardUserGesture;
};
@@ -1513,14 +1513,14 @@ void DOMWindow::resizeTo(float width, float height) const
page->chrome().setWindowRect(adjustWindowRect(page, update));
}

int DOMWindow::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec)
int DOMWindow::setTimeout(std::unique_ptr<ScheduledAction> action, int timeout, ExceptionCode& ec)
{
ScriptExecutionContext* context = scriptExecutionContext();
if (!context) {
ec = INVALID_ACCESS_ERR;
return -1;
}
return DOMTimer::install(context, action, timeout, true);
return DOMTimer::install(context, std::move(action), timeout, true);
}

void DOMWindow::clearTimeout(int timeoutId)
@@ -1547,14 +1547,14 @@ void DOMWindow::clearTimeout(int timeoutId)
DOMTimer::removeById(context, timeoutId);
}

int DOMWindow::setInterval(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec)
int DOMWindow::setInterval(std::unique_ptr<ScheduledAction> action, int timeout, ExceptionCode& ec)
{
ScriptExecutionContext* context = scriptExecutionContext();
if (!context) {
ec = INVALID_ACCESS_ERR;
return -1;
}
return DOMTimer::install(context, action, timeout, false);
return DOMTimer::install(context, std::move(action), timeout, false);
}

void DOMWindow::clearInterval(int timeoutId)
@@ -33,6 +33,7 @@
#include "URL.h"
#include "Supplementable.h"
#include <functional>
#include <memory>

namespace Inspector {
class ScriptCallStack;
@@ -253,9 +254,9 @@ namespace WebCore {
void resizeTo(float width, float height) const;

// Timers
int setTimeout(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
int setTimeout(std::unique_ptr<ScheduledAction>, int timeout, ExceptionCode&);
void clearTimeout(int timeoutId);
int setInterval(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
int setInterval(std::unique_ptr<ScheduledAction>, int timeout, ExceptionCode&);
void clearInterval(int timeoutId);

// WebKit animation extensions
@@ -29,7 +29,6 @@

#include "EventQueue.h"
#include <wtf/HashMap.h>
#include <wtf/PassOwnPtr.h>

namespace WebCore {

@@ -67,7 +67,7 @@ WorkerGlobalScope::WorkerGlobalScope(const URL& url, const String& userAgent, st
: m_url(url)
, m_userAgent(userAgent)
, m_groupSettings(std::move(settings))
, m_script(adoptPtr(new WorkerScriptController(this)))
, m_script(std::make_unique<WorkerScriptController>(this))
, m_thread(thread)
#if ENABLE(INSPECTOR)
, m_workerInspectorController(std::make_unique<WorkerInspectorController>(*this))
@@ -152,19 +152,19 @@ void WorkerGlobalScope::postTask(Task task)
thread().runLoop().postTask(std::move(task));
}

int WorkerGlobalScope::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout)
int WorkerGlobalScope::setTimeout(std::unique_ptr<ScheduledAction> action, int timeout)
{
return DOMTimer::install(scriptExecutionContext(), action, timeout, true);
return DOMTimer::install(scriptExecutionContext(), std::move(action), timeout, true);
}

void WorkerGlobalScope::clearTimeout(int timeoutId)
{
DOMTimer::removeById(scriptExecutionContext(), timeoutId);
}

int WorkerGlobalScope::setInterval(PassOwnPtr<ScheduledAction> action, int timeout)
int WorkerGlobalScope::setInterval(std::unique_ptr<ScheduledAction> action, int timeout)
{
return DOMTimer::install(scriptExecutionContext(), action, timeout, false);
return DOMTimer::install(scriptExecutionContext(), std::move(action), timeout, false);
}

void WorkerGlobalScope::clearInterval(int timeoutId)
@@ -35,9 +35,9 @@
#include "ScriptExecutionContext.h"
#include "WorkerEventQueue.h"
#include "WorkerScriptController.h"
#include <memory>
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
@@ -72,7 +72,7 @@ namespace WebCore {
virtual void disableEval(const String& errorMessage) override;

WorkerScriptController* script() { return m_script.get(); }
void clearScript() { m_script.clear(); }
void clearScript() { m_script = nullptr; }

WorkerThread& thread() const { return m_thread; }

@@ -94,9 +94,9 @@ namespace WebCore {
WorkerNavigator* navigator() const;

// Timers
int setTimeout(PassOwnPtr<ScheduledAction>, int timeout);
int setTimeout(std::unique_ptr<ScheduledAction>, int timeout);
void clearTimeout(int timeoutId);
int setInterval(PassOwnPtr<ScheduledAction>, int timeout);
int setInterval(std::unique_ptr<ScheduledAction>, int timeout);
void clearInterval(int timeoutId);

virtual bool isContextThread() const override;
@@ -167,7 +167,7 @@ namespace WebCore {
mutable RefPtr<WorkerLocation> m_location;
mutable RefPtr<WorkerNavigator> m_navigator;

OwnPtr<WorkerScriptController> m_script;
std::unique_ptr<WorkerScriptController> m_script;
WorkerThread& m_thread;

#if ENABLE(INSPECTOR)
@@ -33,7 +33,6 @@

#include "ScriptExecutionContext.h"
#include <wtf/Forward.h>
#include <wtf/PassOwnPtr.h>

namespace WebCore {

@@ -34,7 +34,6 @@
#include <memory>
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>

0 comments on commit 6b2ee98

Please sign in to comment.