ScheduledAction.cpp [plain text]
#include "config.h"
#include "ScheduledAction.h"
#include "CString.h"
#include "Chrome.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "Page.h"
#include "kjs_proxy.h"
#include "kjs_window.h"
using namespace KJS;
namespace WebCore {
ScheduledAction::ScheduledAction(JSValue* func, const List& args)
: m_func(func)
{
List::const_iterator end = args.end();
for (List::const_iterator it = args.begin(); it != end; ++it)
m_args.append(*it);
}
void ScheduledAction::execute(Window* window)
{
RefPtr<Frame> frame = window->impl()->frame();
if (!frame)
return;
if (!frame->scriptProxy()->isEnabled())
return;
KJSProxy* scriptProxy = frame->scriptProxy();
Window* globalObject = scriptProxy->globalObject();
scriptProxy->setProcessingTimerCallback(true);
if (JSValue* func = m_func.get()) {
JSLock lock;
if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
ExecState* exec = window->globalExec();
ASSERT(window == globalObject);
List args;
size_t size = m_args.size();
for (size_t i = 0; i < size; ++i)
args.append(m_args[i]);
globalObject->startTimeoutCheck();
static_cast<JSObject*>(func)->call(exec, window, args);
globalObject->stopTimeoutCheck();
if (exec->hadException()) {
JSObject* exception = exec->exception()->toObject(exec);
exec->clearException();
String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
int lineNumber = exception->get(exec, "line")->toInt32(exec);
if (Interpreter::shouldPrintExceptions())
printf("(timer):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
}
}
} else
frame->loader()->executeScript(m_code);
if (Document* doc = frame->document())
doc->updateRendering();
scriptProxy->setProcessingTimerCallback(false);
}
}