ScheduledAction.cpp [plain text]
#include "config.h"
#include "ScheduledAction.h"
#include "CString.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "JSDOMBinding.h"
#include "JSDOMWindow.h"
#include "JSWorkerContext.h"
#include "ScriptController.h"
#include "ScriptExecutionContext.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "WorkerContext.h"
#include "WorkerThread.h"
#include <runtime/JSLock.h>
using namespace JSC;
namespace WebCore {
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) {
m_args.append((*it).jsValue(exec));
}
}
void ScheduledAction::execute(ScriptExecutionContext* context)
{
if (context->isDocument())
execute(static_cast<Document*>(context));
#if ENABLE(WORKERS)
else {
ASSERT(context->isWorkerContext());
execute(static_cast<WorkerContext*>(context));
}
#else
ASSERT(context->isDocument());
#endif
}
void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSValuePtr thisValue)
{
ASSERT(m_function);
JSLock lock(false);
CallData callData;
CallType callType = m_function.get().getCallData(callData);
if (callType == CallTypeNone)
return;
ExecState* exec = globalObject->globalExec();
ArgList args;
size_t size = m_args.size();
for (size_t i = 0; i < size; ++i)
args.append(m_args[i]);
globalObject->startTimeoutCheck();
call(exec, m_function, callType, callData, thisValue, args);
globalObject->stopTimeoutCheck();
if (exec->hadException())
reportCurrentException(exec);
}
#if ENABLE(WORKERS)
void ScheduledAction::execute(WorkerContext* workerContext)
{
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());
if (!window)
return;
RefPtr<Frame> frame = window->impl()->frame();
if (!frame || !frame->script()->isEnabled())
return;
frame->script()->setProcessingTimerCallback(true);
if (m_function)
executeFunctionInContext(window, window->shell());
else
frame->loader()->executeScript(m_code);
if (Document* document = frame->document())
document->updateRendering();
frame->script()->setProcessingTimerCallback(false);
}
}