diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-17 17:46:33 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-21 12:53:34 +0100 |
commit | 345cb3b6f38bead32cff74dfbe68fa4bfe13b631 (patch) | |
tree | 6a906cb4681c49d826511bdb9b8d5098e016e8d0 /tests | |
parent | 0adc4b6988e51f4700a62d611c61308ada86a422 (diff) |
QmlCompiler: Do not crash on attempts to lookup a function in the scope
Rather, reject the code and let the engine handle it.
Fixes: QTBUG-100980
Change-Id: Ibcd1249ba3550b40121622752b4ca22d1df3ed2a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
(cherry picked from commit 69fefd94e8b0ec2aa379d0b75ccaa2c58e3f0933)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/functionLookup.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 17 |
3 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index c7a2a7ef0e..34c6ea3542 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -62,6 +62,7 @@ set(qml_files extendedTypes.qml failures.qml fileDialog.qml + functionLookup.qml funcWithParams.qml functionReturningVoid.qml globals.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/functionLookup.qml b/tests/auto/qml/qmlcppcodegen/data/functionLookup.qml new file mode 100644 index 0000000000..211f524088 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/functionLookup.qml @@ -0,0 +1,6 @@ +import QtQml + +QtObject { + function foo() { return "a" + 99 } + property var bar: foo +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 555ec27a4d..48e0bb68c9 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -119,6 +119,7 @@ private slots: void notEqualsInt(); void infinities(); void blockComments(); + void functionLookup(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1788,6 +1789,22 @@ void tst_QmlCppCodegen::blockComments() QCOMPARE(o->property("implicitHeight").toDouble(), 8.0); } +void tst_QmlCppCodegen::functionLookup() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/functionLookup.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + const QVariant foo = o->property("bar"); + QCOMPARE(foo.metaType(), QMetaType::fromType<QJSValue>()); + const QJSManagedValue method(engine.toScriptValue(foo), &engine); + QVERIFY(method.isFunction()); + const QJSValue result = method.call(); + QVERIFY(result.isString()); + QCOMPARE(result.toString(), QStringLiteral("a99")); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |