diff options
author | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2009-08-03 18:06:34 (GMT) |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2009-08-03 18:18:05 (GMT) |
commit | e2852e547216562751a5d05ebdfbd001113cc9b6 (patch) | |
tree | 9be1efb141753fdbe3b6887c6049544f64b674f4 | |
parent | f3a7266cb4793f933ea8c7d2c73c736e022b754a (diff) | |
download | Qt-e2852e547216562751a5d05ebdfbd001113cc9b6.zip Qt-e2852e547216562751a5d05ebdfbd001113cc9b6.tar.gz Qt-e2852e547216562751a5d05ebdfbd001113cc9b6.tar.bz2 |
Implement QScriptEngine::abortEvaluation()
We store the abort-state in the TimeoutChecker, since that's
where we'll mostly access it, but the abort result is stored
in the QScriptEngine's d-pointer.
-rw-r--r-- | src/script/api/qscriptengine.cpp | 18 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 1 |
3 files changed, 16 insertions, 4 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index f60d0af..97d8061 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -417,9 +417,12 @@ public: TimeoutCheckerProxy(const JSC::TimeoutChecker& originalChecker) : JSC::TimeoutChecker(originalChecker) , m_shouldProcessEvents(false) + , m_shouldAbortEvaluation(false) {} void setShouldProcessEvents(bool shouldProcess) { m_shouldProcessEvents = shouldProcess; } + void setShouldAbort(bool shouldAbort) { m_shouldAbortEvaluation = shouldAbort; } + bool shouldAbort() { return m_shouldAbortEvaluation; } virtual bool didTimeOut(JSC::ExecState* exec) { @@ -429,11 +432,12 @@ public: if (m_shouldProcessEvents) QCoreApplication::processEvents(); - return false; + return m_shouldAbortEvaluation; } private: bool m_shouldProcessEvents; + bool m_shouldAbortEvaluation; }; static int toDigit(char c) @@ -2278,6 +2282,12 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file JSC::JSValue exceptionValue; JSC::JSValue result = exec->interpreter()->execute(evalNode.get(), exec, thisObject, exec->scopeChain(), &exceptionValue); + if (dynamic_cast<QScript::TimeoutCheckerProxy*>(d->globalData->timeoutChecker)->shouldAbort()) { + if (d->abortResult.isError()) + exec->setException(d->scriptValueToJSCValue(d->abortResult)); + return d->abortResult; + } + if (exceptionValue) { exec->setException(exceptionValue); return d->scriptValueFromJSCValue(exceptionValue); @@ -3541,8 +3551,10 @@ bool QScriptEngine::isEvaluating() const */ void QScriptEngine::abortEvaluation(const QScriptValue &result) { - qWarning("QScriptEngine::abortEvaluation() not implemented"); - Q_UNUSED(result); + Q_D(QScriptEngine); + + dynamic_cast<QScript::TimeoutCheckerProxy*>(d->globalData->timeoutChecker)->setShouldAbort(true); + d->abortResult = result; } #ifndef QT_NO_QOBJECT diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index f6d7700..cb56cae 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -225,6 +225,7 @@ public: QHash<JSC::JSCell*, QBasicAtomicInt> keepAliveValues; QHash<int, QScriptTypeInfo*> m_typeInfos; int processEventsInterval; + QScriptValue abortResult; QSet<QString> importedExtensions; QSet<QString> extensionsBeingImported; diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 04d7d21..0b16980 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -2531,7 +2531,6 @@ static QScriptValue myFunctionAbortingEvaluation(QScriptContext *, QScriptEngine void tst_QScriptEngine::abortEvaluation() { - QSKIP("Not implemented", SkipAll); QScriptEngine eng; eng.abortEvaluation(); |