diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-10-19 10:40:38 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-10-19 11:40:35 (GMT) |
commit | 7a647e8c9efbbd46184bc4714159c82ae26be958 (patch) | |
tree | 1334c6e793b3cc84c669bbb78b1de26a1574ed18 /tests/auto | |
parent | f9e46cdb2d9a42d52f90fe50a53a76c03065b9ce (diff) | |
download | Qt-7a647e8c9efbbd46184bc4714159c82ae26be958.zip Qt-7a647e8c9efbbd46184bc4714159c82ae26be958.tar.gz Qt-7a647e8c9efbbd46184bc4714159c82ae26be958.tar.bz2 |
Regression fix. Fix the hasUncaughtException() flag in debugger's event.
The QScriptEngine::hasUncaughtException() flag should be set to true if
returning from a JS function was caused by an exception. According to
documentation, the flag had to be accessible from the
QScriptEngineAgent::functionExit event.
New autotest was added.
Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 283e489..82c8ccd 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -109,6 +109,7 @@ private slots: void extension_invoctaion(); void extension(); void isEvaluatingInExtension(); + void hasUncaughtException(); private: double m_testProperty; @@ -2182,5 +2183,42 @@ void tst_QScriptEngineAgent::isEvaluatingInExtension() QVERIFY(spy->wasEvaluating); } +class NewSpy :public QScriptEngineAgent +{ + bool m_result; +public: + NewSpy(QScriptEngine* eng) : QScriptEngineAgent(eng), m_result(false) {} + void functionExit (qint64, const QScriptValue &scriptValue) + { + if (engine()->hasUncaughtException()) m_result = true; + } + + bool isPass() { return m_result; } + void reset() { m_result = false; } +}; + +void tst_QScriptEngineAgent::hasUncaughtException() +{ + QScriptEngine eng; + NewSpy* spy = new NewSpy(&eng); + eng.setAgent(spy); + QScriptValue scriptValue; + + // Check unhandled exception. + eng.evaluate("function init () {Unknown.doSth ();}"); + scriptValue = QScriptValue(eng.globalObject().property("init")).call(); + QVERIFY(eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); + spy->reset(); + + // Check catched exception. + eng.evaluate("function innerFoo() { throw new Error('ciao') }"); + eng.evaluate("function foo() {try { innerFoo() } catch (e) {} }"); + scriptValue = QScriptValue(eng.globalObject().property("foo")).call(); + QVERIFY(!eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); +} + + QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" |