diff options
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 15 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 28b344d154..124b246701 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1064,6 +1064,8 @@ ReturnedValue Runtime::method_callQmlScopeObjectProperty(ExecutionEngine *engine return engine->throwTypeError(error); } + auto scopeObj = static_cast<const QmlContext &>(callData->thisObject).d()->qml->scopeObject; + callData->thisObject = QObjectWrapper::wrap(engine, scopeObj); o->call(scope, callData); return scope.result.asReturnedValue(); } @@ -1077,6 +1079,8 @@ ReturnedValue Runtime::method_callQmlContextObjectProperty(ExecutionEngine *engi return engine->throwTypeError(error); } + auto scopeObj = static_cast<const QmlContext &>(callData->thisObject).d()->qml->context->contextData()->contextObject; + callData->thisObject = QObjectWrapper::wrap(engine, scopeObj); o->call(scope, callData); return scope.result.asReturnedValue(); } 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 83151fb6e2..292403bcbb 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -273,6 +273,8 @@ private slots: void lowercaseTypeNames(); + void thisInQmlScope(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -4604,6 +4606,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" |