summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp')
-rw-r--r--tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp38
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"