summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-04-09 08:39:08 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-04-09 08:39:08 (GMT)
commit2c8785e698d68edde74e6db2a3dd1715e17baee8 (patch)
tree987c44c7a3630a4b38b7101bb7e0c8e8cfe46a9c
parentcf6f2eb2ccd1675d890904d12c9717e4570b123b (diff)
downloadQt-2c8785e698d68edde74e6db2a3dd1715e17baee8.zip
Qt-2c8785e698d68edde74e6db2a3dd1715e17baee8.tar.gz
Qt-2c8785e698d68edde74e6db2a3dd1715e17baee8.tar.bz2
Disallow writes to read-only value type properties
QTBUG-9685
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror3.qml7
-rw-r--r--tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror4.qml10
-rw-r--r--tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp18
4 files changed, 38 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index d2b2024..bd664fe 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -1866,6 +1866,10 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr
}
}
+ if (!obj->metaObject()->property(prop->index).isWritable()) {
+ COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler", "Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
+ }
+
COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type],
prop->value, obj, ctxt.incr()));
obj->addValueTypeProperty(prop);
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror3.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror3.qml
new file mode 100644
index 0000000..b8e3f0d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror3.qml
@@ -0,0 +1,7 @@
+import Test 1.0
+
+MyTypeObject {
+ sizereadonly.width: 13
+ sizereadonly.height: 88
+}
+
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror4.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror4.qml
new file mode 100644
index 0000000..8ae2ef8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror4.qml
@@ -0,0 +1,10 @@
+import Test 1.0
+import Qt 4.6
+
+MyTypeObject {
+ Component.onCompleted: {
+ sizereadonly.width = 13;
+ }
+}
+
+
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
index c74199f..e653abf 100644
--- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
+++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
@@ -216,10 +216,26 @@ void tst_qdeclarativevaluetypes::sizereadonly()
{
QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_writeerror2.qml"));
- QEXPECT_FAIL("", "QTBUG-9685", Abort);
QVERIFY(component.isError());
QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property"));
}
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_writeerror3.qml"));
+ QVERIFY(component.isError());
+ QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property"));
+ }
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_writeerror4.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object);
+
+ QCOMPARE(object->property("sizereadonly").toSize(), QSize(1912, 1913));
+
+ delete object;
+ }
}
void tst_qdeclarativevaluetypes::rect()