aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp13
-rw-r--r--tests/auto/qml/qqmlcontext/data/qtbug_53431.qml7
-rw-r--r--tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp14
3 files changed, 32 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index 0d84c3bb64..e3770a7ec5 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -99,14 +99,23 @@ ReturnedValue QmlContextWrapper::get(const Managed *m, String *name, bool *hasPr
QV4::ExecutionEngine *v4 = resource->engine();
QV4::Scope scope(v4);
+ // In V8 the JS global object would come _before_ the QML global object,
+ // so simulate that here.
+ bool hasProp;
+ QV4::ScopedValue result(scope, v4->globalObject->get(name, &hasProp));
+ if (hasProp) {
+ if (hasProperty)
+ *hasProperty = hasProp;
+ return result->asReturnedValue();
+ }
+
if (resource->d()->isNullWrapper)
return Object::get(m, name, hasProperty);
if (v4->callingQmlContext() != resource->d()->context)
return Object::get(m, name, hasProperty);
- bool hasProp;
- QV4::ScopedValue result(scope, Object::get(m, name, &hasProp));
+ result = Object::get(m, name, &hasProp);
if (hasProp) {
if (hasProperty)
*hasProperty = hasProp;
diff --git a/tests/auto/qml/qqmlcontext/data/qtbug_53431.qml b/tests/auto/qml/qqmlcontext/data/qtbug_53431.qml
new file mode 100644
index 0000000000..2ceee2bade
--- /dev/null
+++ b/tests/auto/qml/qqmlcontext/data/qtbug_53431.qml
@@ -0,0 +1,7 @@
+import QtQml 2.0
+QtObject {
+ property int value: {
+ console.log("lookup in global object")
+ return 1
+ }
+}
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
index 18ef7ac31d..d338e6f5ad 100644
--- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
+++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
@@ -61,6 +61,7 @@ private slots:
void refreshExpressions();
void refreshExpressionsCrash();
void refreshExpressionsRootContext();
+ void skipExpressionRefresh_qtbug_53431();
void qtbug_22535();
void evalAfterInvalidate();
@@ -642,6 +643,19 @@ void tst_qqmlcontext::refreshExpressionsRootContext()
delete o1;
}
+void tst_qqmlcontext::skipExpressionRefresh_qtbug_53431()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("qtbug_53431.qml"));
+ QScopedPointer<QObject> object(component.create(0));
+ QVERIFY(!object.isNull());
+ QCOMPARE(object->property("value").toInt(), 1);
+ object->setProperty("value", 10);
+ QCOMPARE(object->property("value").toInt(), 10);
+ engine.rootContext()->setContextProperty("randomContextProperty", 42);
+ QCOMPARE(object->property("value").toInt(), 10);
+}
+
void tst_qqmlcontext::qtbug_22535()
{
QQmlEngine engine;