Commit f21bf405 authored by weinig@apple.com's avatar weinig@apple.com

2009-04-28 Sam Weinig <sam@webkit.org>

        Reviewed by Beth Dakin.

        Consolidate ScheduleAction creation into ScheduledAction::create.
        Autogenerate JSWorkerContext.clearTimeout and clearInterval.

        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::JSDOMWindow::setTimeout):
        (WebCore::JSDOMWindow::setInterval):
        * bindings/js/JSWorkerContextCustom.cpp:
        (WebCore::JSWorkerContext::setTimeout):
        (WebCore::JSWorkerContext::setInterval):
        * bindings/js/ScheduledAction.cpp:
        (WebCore::ScheduledAction::create):
        (WebCore::ScheduledAction::ScheduledAction):
        (WebCore::ScheduledAction::execute):
        * bindings/js/ScheduledAction.h:
        * workers/WorkerContext.cpp:
        (WebCore::DOMWindow::setTimeout):
        (WebCore::DOMWindow::clearTimeout):
        (WebCore::DOMWindow::setInterval):
        (WebCore::DOMWindow::clearInterval):
        * workers/WorkerContext.h:
        * workers/WorkerContext.idl:



git-svn-id: svn://svn.chromium.org/blink/trunk@42958 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b5f45f1d
2009-04-28 Sam Weinig <sam@webkit.org>
Reviewed by Beth Dakin.
Consolidate ScheduleAction creation into ScheduledAction::create.
Autogenerate JSWorkerContext.clearTimeout and clearInterval.
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::setTimeout):
(WebCore::JSDOMWindow::setInterval):
* bindings/js/JSWorkerContextCustom.cpp:
(WebCore::JSWorkerContext::setTimeout):
(WebCore::JSWorkerContext::setInterval):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
(WebCore::ScheduledAction::ScheduledAction):
(WebCore::ScheduledAction::execute):
* bindings/js/ScheduledAction.h:
* workers/WorkerContext.cpp:
(WebCore::DOMWindow::setTimeout):
(WebCore::DOMWindow::clearTimeout):
(WebCore::DOMWindow::setInterval):
(WebCore::DOMWindow::clearInterval):
* workers/WorkerContext.h:
* workers/WorkerContext.idl:
2009-04-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin Adler
......@@ -495,22 +495,9 @@ JSValuePtr JSDOMWindow::postMessage(ExecState* exec, const ArgList& args)
return jsUndefined();
}
static ScheduledAction* createScheduledAction(ExecState* exec, const ArgList& args)
{
JSValuePtr v = args.at(exec, 0);
if (v.isString())
return new ScheduledAction(asString(v)->value());
CallData callData;
if (v.getCallData(callData) == CallTypeNone)
return 0;
ArgList argsTail;
args.getSlice(2, argsTail);
return new ScheduledAction(exec, v, argsTail);
}
JSValuePtr JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args)
{
ScheduledAction* action = createScheduledAction(exec, args);
ScheduledAction* action = ScheduledAction::create(exec, args);
if (!action)
return jsUndefined();
int delay = args.at(exec, 1).toInt32(exec);
......@@ -519,7 +506,7 @@ JSValuePtr JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args)
JSValuePtr JSDOMWindow::setInterval(ExecState* exec, const ArgList& args)
{
ScheduledAction* action = createScheduledAction(exec, args);
ScheduledAction* action = ScheduledAction::create(exec, args);
if (!action)
return jsUndefined();
int delay = args.at(exec, 1).toInt32(exec);
......
......@@ -121,40 +121,22 @@ JSValuePtr JSWorkerContext::removeEventListener(ExecState* exec, const ArgList&
return jsUndefined();
}
static JSValuePtr setTimeoutOrInterval(ExecState* exec, WorkerContext* workerContext, const ArgList& args, bool singleShot)
{
JSValuePtr v = args.at(exec, 0);
int delay = args.at(exec, 1).toInt32(exec);
if (v.isString())
return jsNumber(exec, workerContext->installTimeout(new ScheduledAction(asString(v)->value()), delay, singleShot));
CallData callData;
if (v.getCallData(callData) == CallTypeNone)
return jsUndefined();
ArgList argsTail;
args.getSlice(2, argsTail);
return jsNumber(exec, workerContext->installTimeout(new ScheduledAction(exec, v, argsTail), delay, singleShot));
}
JSValuePtr JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
{
return setTimeoutOrInterval(exec, impl(), args, true);
}
JSValuePtr JSWorkerContext::clearTimeout(ExecState* exec, const ArgList& args)
{
impl()->removeTimeout(args.at(exec, 0).toInt32(exec));
ScheduledAction* action = ScheduledAction::create(exec, args);
if (!action)
return jsUndefined();
int delay = args.at(exec, 1).toInt32(exec);
return jsNumber(exec, impl()->setTimeout(action, delay));
}
JSValuePtr JSWorkerContext::setInterval(ExecState* exec, const ArgList& args)
{
return setTimeoutOrInterval(exec, impl(), args, false);
}
JSValuePtr JSWorkerContext::clearInterval(ExecState* exec, const ArgList& args)
{
impl()->removeTimeout(args.at(exec, 0).toInt32(exec));
ScheduledAction* action = ScheduledAction::create(exec, args);
if (!action)
return jsUndefined();
int delay = args.at(exec, 1).toInt32(exec);
return jsNumber(exec, impl()->setInterval(action, delay));
}
} // namespace WebCore
......
/*
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
* Copyright (C) 2009 Google Inc. All rights reseved.
*
......@@ -47,13 +47,25 @@ using namespace JSC;
namespace WebCore {
ScheduledAction* ScheduledAction::create(ExecState* exec, const ArgList& args)
{
JSValuePtr v = args.at(exec, 0);
if (v.isString())
return new ScheduledAction(asString(v)->value());
CallData callData;
if (v.getCallData(callData) == CallTypeNone)
return 0;
ArgList argsTail;
args.getSlice(2, argsTail);
return new ScheduledAction(exec, v, argsTail);
}
ScheduledAction::ScheduledAction(ExecState* exec, JSValuePtr function, const ArgList& args)
: m_function(function)
{
ArgList::const_iterator end = args.end();
for (ArgList::const_iterator it = args.begin(); it != end; ++it) {
for (ArgList::const_iterator it = args.begin(); it != end; ++it)
m_args.append((*it).jsValue(exec));
}
}
void ScheduledAction::execute(ScriptExecutionContext* context)
......@@ -95,24 +107,6 @@ void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSV
reportCurrentException(exec);
}
#if ENABLE(WORKERS)
void ScheduledAction::execute(WorkerContext* workerContext)
{
// In a Worker, the execution should always happen on a worker thread.
ASSERT(workerContext->thread()->threadID() == currentThread());
WorkerScriptController* scriptController = workerContext->script();
if (m_function) {
JSWorkerContext* contextWrapper = scriptController->workerContextWrapper();
executeFunctionInContext(contextWrapper, contextWrapper);
} else {
ScriptSourceCode code(m_code, workerContext->url());
scriptController->evaluate(code);
}
}
#endif // ENABLE(WORKERS)
void ScheduledAction::execute(Document* document)
{
JSDOMWindow* window = toJSDOMWindow(document->frame());
......@@ -134,4 +128,22 @@ void ScheduledAction::execute(Document* document)
frame->script()->setProcessingTimerCallback(false);
}
#if ENABLE(WORKERS)
void ScheduledAction::execute(WorkerContext* workerContext)
{
// In a Worker, the execution should always happen on a worker thread.
ASSERT(workerContext->thread()->threadID() == currentThread());
WorkerScriptController* scriptController = workerContext->script();
if (m_function) {
JSWorkerContext* contextWrapper = scriptController->workerContextWrapper();
executeFunctionInContext(contextWrapper, contextWrapper);
} else {
ScriptSourceCode code(m_code, workerContext->url());
scriptController->evaluate(code);
}
}
#endif // ENABLE(WORKERS)
} // namespace WebCore
/*
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -40,15 +40,17 @@ namespace WebCore {
*/
class ScheduledAction {
public:
static ScheduledAction* create(JSC::ExecState*, const JSC::ArgList&);
void execute(ScriptExecutionContext*);
private:
ScheduledAction(JSC::ExecState* exec, JSC::JSValuePtr function, const JSC::ArgList&);
ScheduledAction(const String& code)
: m_code(code)
{
}
void execute(ScriptExecutionContext*);
private:
void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValuePtr thisValue);
void execute(Document*);
#if ENABLE(WORKERS)
......
......@@ -201,12 +201,22 @@ void WorkerContext::postTask(PassRefPtr<Task> task)
thread()->runLoop().postTask(task);
}
int WorkerContext::installTimeout(ScheduledAction* action, int timeout, bool singleShot)
int WorkerContext::setTimeout(ScheduledAction* action, int timeout)
{
return DOMTimer::install(scriptExecutionContext(), action, timeout, singleShot);
return DOMTimer::install(scriptExecutionContext(), action, timeout, true);
}
void WorkerContext::removeTimeout(int timeoutId)
void WorkerContext::clearTimeout(int timeoutId)
{
DOMTimer::removeById(scriptExecutionContext(), timeoutId);
}
int WorkerContext::setInterval(ScheduledAction* action, int timeout)
{
return DOMTimer::install(scriptExecutionContext(), action, timeout, false);
}
void WorkerContext::clearInterval(int timeoutId)
{
DOMTimer::removeById(scriptExecutionContext(), timeoutId);
}
......
......@@ -83,8 +83,11 @@ namespace WebCore {
void postMessage(const String& message);
virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously.
int installTimeout(ScheduledAction*, int timeout, bool singleShot);
void removeTimeout(int timeoutId);
// Timers
int setTimeout(ScheduledAction*, int timeout);
void clearTimeout(int timeoutId);
int setInterval(ScheduledAction*, int timeout);
void clearInterval(int timeoutId);
void dispatchMessage(const String&);
......
......@@ -53,11 +53,11 @@ module threads {
// Timers
[Custom] long setTimeout(in TimeoutHandler handler, in long timeout);
// [Custom] long setTimeout(in DOMString code, in long timeout);
[Custom] void clearTimeout(in long handle);
void clearTimeout(in long handle);
[Custom] long setInterval(in TimeoutHandler handler, in long timeout);
// [Custom] long setInterval(in DOMString code, in long timeout);
[Custom] void clearInterval(in long handle);
void clearInterval(in long handle);
// EventTarget interface
[Custom] void addEventListener(in DOMString type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment