summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/js/ScheduledAction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/bindings/js/ScheduledAction.cpp')
-rw-r--r--WebCore/bindings/js/ScheduledAction.cpp108
1 files changed, 80 insertions, 28 deletions
diff --git a/WebCore/bindings/js/ScheduledAction.cpp b/WebCore/bindings/js/ScheduledAction.cpp
index 8d13cd2..8627474 100644
--- a/WebCore/bindings/js/ScheduledAction.cpp
+++ b/WebCore/bindings/js/ScheduledAction.cpp
@@ -3,6 +3,7 @@
* Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ * Copyright (C) 2009 Google 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
@@ -24,59 +25,110 @@
#include "ScheduledAction.h"
#include "CString.h"
-#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
+#include "JSDOMBinding.h"
#include "JSDOMWindow.h"
+#ifdef ANDROID_FIX // these are generated files, need to check ENABLE(WORKERS)
+#if ENABLE(WORKERS)
+#include "JSWorkerContext.h"
+#endif
+#endif
#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, JSValue* function, const ArgList& args)
+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(JSDOMWindowShell* windowShell)
+void ScheduledAction::execute(ScriptExecutionContext* context)
{
- RefPtr<Frame> frame = windowShell->window()->impl()->frame();
- if (!frame)
- return;
+ 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);
- if (!frame->script()->isEnabled())
+ CallData callData;
+ CallType callType = m_function.get().getCallData(callData);
+ if (callType == CallTypeNone)
return;
- frame->script()->setProcessingTimerCallback(true);
+ ExecState* exec = globalObject->globalExec();
- JSLock lock(false);
+ 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)
+{
+ // In a Worker, the execution should always happen on a worker thread.
+ ASSERT(workerContext->thread()->threadID() == currentThread());
+
+ WorkerScriptController* scriptController = workerContext->script();
if (m_function) {
- CallData callData;
- CallType callType = m_function->getCallData(callData);
- if (callType != CallTypeNone) {
- JSDOMWindow* window = windowShell->window();
- ExecState* exec = window->globalExec();
-
- ArgList args;
- size_t size = m_args.size();
- for (size_t i = 0; i < size; ++i)
- args.append(m_args[i]);
-
- window->startTimeoutCheck();
- call(exec, m_function, callType, callData, windowShell, args);
- window->stopTimeoutCheck();
- if (exec->hadException())
- frame->domWindow()->console()->reportCurrentException(exec);
- }
- } else
+ 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);
// Update our document's rendering following the execution of the timeout callback.