From e2852e547216562751a5d05ebdfbd001113cc9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 3 Aug 2009 20:06:34 +0200 Subject: 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. --- src/script/api/qscriptengine.cpp | 18 +++++++++++++++--- src/script/api/qscriptengine_p.h | 1 + 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(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(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 keepAliveValues; QHash m_typeInfos; int processEventsInterval; + QScriptValue abortResult; QSet importedExtensions; QSet 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(); -- cgit v0.12