aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine/tst_qjsengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 796d9e9c34..c20937f9a1 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -219,6 +219,11 @@ private slots:
void protoChanges_QTBUG68369();
void multilineStrings();
+ void throwError();
+
+public:
+ Q_INVOKABLE QJSValue throwingCppMethod();
+
signals:
void testSignal();
};
@@ -4291,6 +4296,36 @@ void tst_QJSEngine::multilineStrings()
}
+void tst_QJSEngine::throwError()
+{
+ QJSEngine engine;
+ QJSValue wrappedThis = engine.newQObject(this);
+ QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
+ engine.globalObject().setProperty("testCase", wrappedThis);
+
+ QJSValue result = engine.evaluate(
+ "function test(){\n"
+ "try {\n"
+ " return testCase.throwingCppMethod();\n"
+ "} catch (error) {\n"
+ " return error;\n"
+ "}\n"
+ "return \"not reached!\";\n"
+ "}\n"
+ "test();"
+ );
+ QVERIFY(result.isError());
+ QCOMPARE(result.property("lineNumber").toString(), "3");
+ QCOMPARE(result.property("message").toString(), "blub");
+ QVERIFY(!result.property("stack").isUndefined());
+}
+
+QJSValue tst_QJSEngine::throwingCppMethod()
+{
+ qjsEngine(this)->throwError("blub");
+ return QJSValue(47);
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"