aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2016-04-29 09:55:49 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2016-05-01 09:08:52 +0000
commit1650377af7dfb01a0641d4e21bf1ba33e6a7320f (patch)
tree3a4d704484b49905149d0f26d0937af6e14e39e9
parent3b0cb49ef0cff2e7ae4ba295d035b87f09fdea4f (diff)
Fix crash when trying to call a property of the scope or context object
For calls on properties of the scope or context object the thisObject parameter in the callData is a reference to the QmlContext, not a real object - therefore the toString conversion fails. Task-number: QTBUG-52340 Change-Id: I08d01cc5c05920c2fac46ddd40fa41e630bcade3 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp5
-rw-r--r--tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml13
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp12
3 files changed, 27 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index a988313f5f..d8ae7d4e92 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -953,10 +953,9 @@ ReturnedValue Runtime::callQmlScopeObjectProperty(ExecutionEngine *engine, int p
Scope scope(engine);
ScopedFunctionObject o(scope, getQmlScopeObjectProperty(engine, callData->thisObject, propertyIndex));
if (!o) {
- QString error = QStringLiteral("Property '%1' of object %2 is not a function").arg(propertyIndex).arg(callData->thisObject.toQStringNoThrow());
+ QString error = QStringLiteral("Property '%1' of scope object is not a function").arg(propertyIndex);
return engine->throwTypeError(error);
}
-
return o->call(callData);
}
@@ -965,7 +964,7 @@ ReturnedValue Runtime::callQmlContextObjectProperty(ExecutionEngine *engine, int
Scope scope(engine);
ScopedFunctionObject o(scope, getQmlContextObjectProperty(engine, callData->thisObject, propertyIndex));
if (!o) {
- QString error = QStringLiteral("Property '%1' of object %2 is not a function").arg(propertyIndex).arg(callData->thisObject.toQStringNoThrow());
+ QString error = QStringLiteral("Property '%1' of context object is not a function").arg(propertyIndex);
return engine->throwTypeError(error);
}
diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml
new file mode 100644
index 0000000000..03f90c15c8
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml
@@ -0,0 +1,13 @@
+import QtQml 2.0
+
+QtObject {
+ property bool someProperty: true
+ function testCall() {
+ try {
+ someProperty(); // should throw
+ return false
+ } catch (e) {
+ return true
+ }
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 60fc8d0b90..08ebfbbbcf 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -327,6 +327,7 @@ private slots:
void writeUnregisteredQObjectProperty();
void switchExpression();
void qtbug_46022();
+ void qtbug_52340();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7910,6 +7911,17 @@ void tst_qqmlecmascript::qtbug_46022()
QCOMPARE(obj->property("test2").toBool(), true);
}
+void tst_qqmlecmascript::qtbug_52340()
+{
+ QQmlComponent component(&engine, testFileUrl("qtbug_52340.qml"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+ QVariant returnValue;
+ QVERIFY(QMetaObject::invokeMethod(object.data(), "testCall", Q_RETURN_ARG(QVariant, returnValue)));
+ QVERIFY(returnValue.isValid());
+ QVERIFY(returnValue.toBool());
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"