aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-07 12:23:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-07 14:40:41 +0100
commit7f0faa7fb56435ab515a6178892c420b595a899f (patch)
treec50c52602ea4bf77af5f98b2df8749b3d29863ed /tests
parent5f6436e474624997b284547e4ee117fb49d29e79 (diff)
Fix exception thrown in slot without Qml Engine
Don't crash when an exception is thrown in a JS slot but we don't have a Qml engine. Change-Id: I1530d5c1c8cb9b9b33b9fdd0d45639fd4a0516f7 Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index ba99b34935..44c113ba13 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -47,6 +47,7 @@
#include <qgraphicsitem.h>
#include <qstandarditemmodel.h>
#include <QtCore/qnumeric.h>
+#include <qqmlengine.h>
#include <stdlib.h>
#ifdef Q_CC_MSVC
@@ -87,6 +88,7 @@ private slots:
void newQObject();
void newQObject_ownership();
void newQObject_deletedEngine();
+ void exceptionInSlot();
void globalObjectProperties();
void globalObjectEquals();
void globalObjectProperties_enumerate();
@@ -150,6 +152,9 @@ private slots:
void arrayPop_QTBUG_35979();
void regexpLastMatch();
+
+signals:
+ void testSignal();
};
tst_QJSEngine::tst_QJSEngine()
@@ -512,6 +517,25 @@ void tst_QJSEngine::newQObject_deletedEngine()
QTRY_VERIFY(spy.count());
}
+void tst_QJSEngine::exceptionInSlot()
+{
+ QJSEngine engine;
+ QJSValue wrappedThis = engine.newQObject(this);
+ QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
+ engine.globalObject().setProperty("testCase", wrappedThis);
+ engine.evaluate(
+ "var called = false\n"
+ "function throwingSlot() {\n"
+ " called = true\n"
+ " throw 42;\n"
+ "}\n"
+ "testCase.testSignal.connect(throwingSlot)\n"
+ );
+ QCOMPARE(engine.globalObject().property("called").toBool(), false);
+ emit testSignal();
+ QCOMPARE(engine.globalObject().property("called").toBool(), true);
+}
+
void tst_QJSEngine::globalObjectProperties()
{
// See ECMA-262 Section 15.1, "The Global Object".