diff options
author | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2009-08-03 18:03:35 (GMT) |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2009-08-03 18:18:04 (GMT) |
commit | f3a7266cb4793f933ea8c7d2c73c736e022b754a (patch) | |
tree | 86bad1ad184030d724af095c2479c4026008a698 /src/script/api/qscriptengine.cpp | |
parent | 9b5ab52a37aeb8cb2f139d76421594fa7418e729 (diff) | |
download | Qt-f3a7266cb4793f933ea8c7d2c73c736e022b754a.zip Qt-f3a7266cb4793f933ea8c7d2c73c736e022b754a.tar.gz Qt-f3a7266cb4793f933ea8c7d2c73c736e022b754a.tar.bz2 |
Implement QScriptEngine::setProcessEventsInterval()
We're using a wrapper around TimeoutChecker, where we
re-implement didTimeout() to call processEvents().
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index f80c605..f60d0af 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -68,6 +68,7 @@ #include "ObjectPrototype.h" #include "SourceCode.h" #include "FunctionPrototype.h" +#include "TimeoutChecker.h" #include "JSFunction.h" #include "Parser.h" #include "Operations.h" @@ -410,6 +411,31 @@ private: JSC::JSGlobalObject *originalGlobalObject; }; +class TimeoutCheckerProxy : public JSC::TimeoutChecker +{ +public: + TimeoutCheckerProxy(const JSC::TimeoutChecker& originalChecker) + : JSC::TimeoutChecker(originalChecker) + , m_shouldProcessEvents(false) + {} + + void setShouldProcessEvents(bool shouldProcess) { m_shouldProcessEvents = shouldProcess; } + + virtual bool didTimeOut(JSC::ExecState* exec) + { + if (JSC::TimeoutChecker::didTimeOut(exec)) + return true; + + if (m_shouldProcessEvents) + QCoreApplication::processEvents(); + + return false; + } + +private: + bool m_shouldProcessEvents; +}; + static int toDigit(char c) { if ((c >= '0') && (c <= '9')) @@ -931,6 +957,10 @@ QScriptEnginePrivate::QScriptEnginePrivate() : idGenerator(1) globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "disconnect"), QScript::functionDisconnect)); globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "connect"), QScript::functionConnect)); + JSC::TimeoutChecker* originalChecker = globalData->timeoutChecker; + globalData->timeoutChecker = new QScript::TimeoutCheckerProxy(*originalChecker); + delete originalChecker; + currentFrame = exec; originalGlobalObjectProxy = 0; @@ -3458,12 +3488,12 @@ void QScriptEngine::collectGarbage() void QScriptEngine::setProcessEventsInterval(int interval) { Q_D(QScriptEngine); - qWarning("QScriptEngine::setProcessEventsInterval() not implemented"); - // is it possible with JSC? - // JSC has some code for detecting timeouts but not for getting - // a callback at fixed intervals. - // ### we can install a JSC "debugger client" d->processEventsInterval = interval; + + if (interval > 0) + d->globalData->timeoutChecker->setCheckInterval(interval); + + dynamic_cast<QScript::TimeoutCheckerProxy*>(d->globalData->timeoutChecker)->setShouldProcessEvents(interval > 0); } /*! |