aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-02-15 15:16:01 +0100
committerErik Verbruggen <erik.verbruggen@qt.io>2018-02-20 08:44:07 +0000
commit2f784a544ec4dccaa70ee1bcec71c8e6c2bd5d99 (patch)
treefebaa003be903df7dfc9af2c8c3a442a60ba2557 /tests/auto/qml/qqmllanguage
parentb8dbe476f01a38afc921f9693d89f3c72396651a (diff)
Correctly set this object when calling scope/context functions
When a function is called that is in a QML scope or a QML context, set the 'this' object to the QML scope. This is done by introducing two new interpreter instructions, which get the context passed in. Note: this patch is 5.11 specific. 5.9 had a similair issue, but the implementation is quite different, so that was fixed separately. Task-number: QTBUG-66432 Change-Id: Ie43150cdd26360025895df28d31264985abf1c15 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r--tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml10
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp15
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml b/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml
new file mode 100644
index 0000000000..e3c99e70e1
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml
@@ -0,0 +1,10 @@
+import QtQml 2.2
+QtObject {
+ property int x: 42
+ property int y: 0
+ function g(){
+ y = this.x;
+ }
+ property var f: g
+ Component.onCompleted: f()
+}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 03d53b755d..195a9687a8 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -281,6 +281,8 @@ private slots:
void lowercaseTypeNames();
+ void thisInQmlScope();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -4911,6 +4913,19 @@ void tst_qqmllanguage::lowercaseTypeNames()
QCOMPARE(qmlRegisterSingletonType<QObject>("Test", 1, 0, "lowerCaseTypeName", nullptr), -1);
}
+void tst_qqmllanguage::thisInQmlScope()
+{
+ QQmlEngine engine;
+
+ QQmlComponent component(&engine, testFileUrl("thisInQmlScope.qml"));
+ QTRY_VERIFY(component.isReady());
+ VERIFY_ERRORS(0);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->property("x"), QVariant(42));
+ QCOMPARE(o->property("y"), QVariant(42));
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"