summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-08-31 07:37:30 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-08-31 07:37:30 (GMT)
commiteb0307cac2f6c35094ffcf7de782881cb440cf2f (patch)
tree95dc6c5441111dda2987cd296fe2a65ed19ee4fd
parent6a40104d587211dc740232fed908e29f0b58e2d9 (diff)
downloadQt-eb0307cac2f6c35094ffcf7de782881cb440cf2f.zip
Qt-eb0307cac2f6c35094ffcf7de782881cb440cf2f.tar.gz
Qt-eb0307cac2f6c35094ffcf7de782881cb440cf2f.tar.bz2
Ignore non-scriptable properties in QML
QTBUG-13043
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp14
-rw-r--r--src/declarative/qml/qdeclarativepropertycache.cpp38
-rw-r--r--src/declarative/qml/qmetaobjectbuilder.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/nonscriptable.qml19
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h5
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp12
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.qml6
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.qml5
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/testtypes.h4
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp2
-rw-r--r--tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp12
13 files changed, 104 insertions, 19 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 5bfe5b2..7847303 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -1362,7 +1362,7 @@ bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeParser::Property *prop,
return p.name() != 0;
} else {
int idx = mo->indexOfProperty(prop->name.constData());
- return idx != -1;
+ return idx != -1 && mo->property(idx).isScriptable();
}
}
@@ -1427,6 +1427,11 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
if (prop->index != -1) {
p = metaObject->property(prop->index);
Q_ASSERT(p.name());
+
+ if (!p.isScriptable()) {
+ prop->index = -1;
+ p = QMetaProperty();
+ }
}
}
@@ -1813,6 +1818,8 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type,
if (idx == -1)
COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
QMetaProperty p = type->metaObject()->property(idx);
+ if (!p.isScriptable())
+ COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
prop->index = idx;
prop->type = p.userType();
prop->isValueTypeSubProperty = true;
@@ -2406,7 +2413,6 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
builder.addSignal(p.name + "Changed()");
QMetaPropertyBuilder propBuilder =
builder.addProperty(p.name, type, builder.methodCount() - 1);
- propBuilder.setScriptable(true);
propBuilder.setWritable(!readonly);
}
@@ -2572,6 +2578,9 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder,
COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location"));
QMetaProperty aliasProperty = idObject->metaObject()->property(propIdx);
+ if (!aliasProperty.isScriptable())
+ COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location"));
+
writable = aliasProperty.isWritable();
if (aliasProperty.isEnumType())
@@ -2608,7 +2617,6 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder,
builder.addSignal(prop.name + "Changed()");
QMetaPropertyBuilder propBuilder =
builder.addProperty(prop.name, typeName.constData(), builder.methodCount() - 1);
- propBuilder.setScriptable(true);
propBuilder.setWritable(writable);
return true;
}
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp
index 839d79f..1121a8d 100644
--- a/src/declarative/qml/qdeclarativepropertycache.cpp
+++ b/src/declarative/qml/qdeclarativepropertycache.cpp
@@ -134,8 +134,9 @@ QDeclarativePropertyCache::~QDeclarativePropertyCache()
void QDeclarativePropertyCache::clear()
{
- for (int ii = 0; ii < indexCache.count(); ++ii)
- indexCache.at(ii)->release();
+ for (int ii = 0; ii < indexCache.count(); ++ii) {
+ if (indexCache.at(ii)) indexCache.at(ii)->release();
+ }
for (StringCache::ConstIterator iter = stringCache.begin();
iter != stringCache.end(); ++iter)
@@ -156,10 +157,23 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj
Q_ASSERT(metaObject);
QDeclarativePropertyCache::Data rv;
- int idx = metaObject->indexOfProperty(property.toUtf8());
- if (idx != -1) {
- rv.load(metaObject->property(idx));
- return rv;
+ {
+ const QMetaObject *cmo = metaObject;
+ while (cmo) {
+ int idx = metaObject->indexOfProperty(property.toUtf8());
+ if (idx != -1) {
+ QMetaProperty p = metaObject->property(idx);
+ if (p.isScriptable()) {
+ rv.load(metaObject->property(idx));
+ return rv;
+ } else {
+ while (cmo && cmo->propertyOffset() >= idx)
+ cmo = cmo->superClass();
+ }
+ } else {
+ cmo = 0;
+ }
+ }
}
int methodCount = metaObject->methodCount();
@@ -189,8 +203,9 @@ QDeclarativePropertyCache *QDeclarativePropertyCache::copy() const
cache->stringCache = stringCache;
cache->identifierCache = identifierCache;
- for (int ii = 0; ii < indexCache.count(); ++ii)
- indexCache.at(ii)->addref();
+ for (int ii = 0; ii < indexCache.count(); ++ii) {
+ if (indexCache.at(ii)) indexCache.at(ii)->addref();
+ }
for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
(*iter)->addref();
for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter)
@@ -210,6 +225,9 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
indexCache.resize(propCount);
for (int ii = propOffset; ii < propCount; ++ii) {
QMetaProperty p = metaObject->property(ii);
+ if (!p.isScriptable())
+ continue;
+
QString propName = QString::fromUtf8(p.name());
RData *data = new RData;
@@ -275,6 +293,10 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb
indexCache.resize(propCount);
for (int ii = propCount - 1; ii >= 0; --ii) {
QMetaProperty p = metaObject->property(ii);
+ if (!p.isScriptable()) {
+ indexCache[ii] = 0;
+ continue;
+ }
QString propName = QString::fromUtf8(p.name());
RData *data = new RData;
diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp
index 0954248..58f8811 100644
--- a/src/declarative/qml/qmetaobjectbuilder.cpp
+++ b/src/declarative/qml/qmetaobjectbuilder.cpp
@@ -205,7 +205,7 @@ public:
(const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1)
: name(_name),
type(QMetaObject::normalizedType(_type.constData())),
- flags(Readable | Writable), notifySignal(-1)
+ flags(Readable | Writable | Scriptable), notifySignal(-1)
{
if (notifierIdx >= 0) {
flags |= Notify;
@@ -2187,7 +2187,7 @@ bool QMetaPropertyBuilder::isDesignable() const
/*!
Returns true if the property is scriptable; otherwise returns false.
- This default value is false.
+ This default value is true.
\sa setScriptable(), isDesignable(), isStored()
*/
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/nonscriptable.qml b/tests/auto/declarative/qdeclarativeecmascript/data/nonscriptable.qml
new file mode 100644
index 0000000..024d82e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/nonscriptable.qml
@@ -0,0 +1,19 @@
+import Qt.test 1.0
+import Qt 4.7
+
+MyQmlObject {
+ id: root
+
+ property bool readOk: false;
+ property bool writeOk: false
+
+ Component.onCompleted: {
+ readOk = (root.nonscriptable == undefined);
+
+ try {
+ root.nonscriptable = 10
+ } catch (e) {
+ writeOk = true;
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index 37d6dbd..7d7e3d9 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -92,6 +92,7 @@ class MyQmlObject : public QObject
Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
+ Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false);
public:
MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13) {}
@@ -144,6 +145,10 @@ public:
void setRegExp(const QRegExp &regExp) { m_regExp = regExp; }
int console() const { return 11; }
+
+ int nonscriptable() const { return 0; }
+ void setNonscriptable(int) {}
+
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c);
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index a6d2dac..c01d756 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -157,6 +157,7 @@ private slots:
void qtbug_10696();
void qtbug_11606();
void qtbug_11600();
+ void nonscriptable();
void include();
@@ -2530,6 +2531,17 @@ void tst_qdeclarativeecmascript::qtbug_11600()
delete o;
}
+// Reading and writing non-scriptable properties should fail
+void tst_qdeclarativeecmascript::nonscriptable()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("nonscriptable.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+ QCOMPARE(o->property("readOk").toBool(), true);
+ QCOMPARE(o->property("writeOk").toBool(), true);
+ delete o;
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.errors.txt
new file mode 100644
index 0000000..93652a7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.errors.txt
@@ -0,0 +1 @@
+5:23:Invalid alias location
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.qml
new file mode 100644
index 0000000..2a09648
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.7.qml
@@ -0,0 +1,6 @@
+import Test 1.0
+
+MyTypeObject {
+ id: root
+ property alias a: root.nonScriptable
+}
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.errors.txt
new file mode 100644
index 0000000..cdfa4b2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.errors.txt
@@ -0,0 +1 @@
+4:5:Cannot assign to non-existent property "nonScriptable"
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.qml b/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.qml
new file mode 100644
index 0000000..bd59bc8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/nonScriptableProperty.qml
@@ -0,0 +1,5 @@
+import Test 1.0
+
+MyQmlObject {
+ nonScriptable: 11
+}
diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
index 19790f1..ac55bae 100644
--- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h
+++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
@@ -112,6 +112,7 @@ class MyQmlObject : public QObject, public MyInterface
Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType)
Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject)
Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
+ Q_PROPERTY(int nonScriptable READ nonScriptable WRITE setNonScriptable SCRIPTABLE false);
Q_INTERFACES(MyInterface)
public:
@@ -150,6 +151,9 @@ public:
int propertyWithNotify() const { return m_propertyWithNotify; }
void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); }
+
+ int nonScriptable() const { return 0; }
+ void setNonScriptable(int) {}
public slots:
void basicSlot() { qWarning("MyQmlObject::basicSlot"); }
void basicSlotWithArgs(int v) { qWarning("MyQmlObject::basicSlotWithArgs(%d)", v); }
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index b43fbf4..fc78663 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -343,6 +343,7 @@ void tst_qdeclarativelanguage::errors_data()
QTest::newRow("invalidAlias.4") << "invalidAlias.4.qml" << "invalidAlias.4.errors.txt" << false;
QTest::newRow("invalidAlias.5") << "invalidAlias.5.qml" << "invalidAlias.5.errors.txt" << false;
QTest::newRow("invalidAlias.6") << "invalidAlias.6.qml" << "invalidAlias.6.errors.txt" << false;
+ QTest::newRow("invalidAlias.7") << "invalidAlias.7.qml" << "invalidAlias.7.errors.txt" << false;
QTest::newRow("invalidAttachedProperty.1") << "invalidAttachedProperty.1.qml" << "invalidAttachedProperty.1.errors.txt" << false;
QTest::newRow("invalidAttachedProperty.2") << "invalidAttachedProperty.2.qml" << "invalidAttachedProperty.2.errors.txt" << false;
@@ -373,6 +374,7 @@ void tst_qdeclarativelanguage::errors_data()
QTest::newRow("assignToNamespace") << "assignToNamespace.qml" << "assignToNamespace.errors.txt" << false;
QTest::newRow("invalidOn") << "invalidOn.qml" << "invalidOn.errors.txt" << false;
QTest::newRow("invalidProperty") << "invalidProperty.qml" << "invalidProperty.errors.txt" << false;
+ QTest::newRow("nonScriptableProperty") << "nonScriptableProperty.qml" << "nonScriptableProperty.errors.txt" << false;
}
diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
index 8ba9d45..0f6d531 100644
--- a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
+++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
@@ -558,7 +558,7 @@ void tst_QMetaObjectBuilder::property()
QVERIFY(prop1.isWritable());
QVERIFY(!prop1.isResettable());
QVERIFY(!prop1.isDesignable());
- QVERIFY(!prop1.isScriptable());
+ QVERIFY(prop1.isScriptable());
QVERIFY(!prop1.isStored());
QVERIFY(!prop1.isEditable());
QVERIFY(!prop1.isUser());
@@ -577,7 +577,7 @@ void tst_QMetaObjectBuilder::property()
QVERIFY(prop2.isWritable());
QVERIFY(!prop2.isResettable());
QVERIFY(!prop2.isDesignable());
- QVERIFY(!prop2.isScriptable());
+ QVERIFY(prop2.isScriptable());
QVERIFY(!prop2.isStored());
QVERIFY(!prop2.isEditable());
QVERIFY(!prop2.isUser());
@@ -599,7 +599,7 @@ void tst_QMetaObjectBuilder::property()
prop1.setWritable(false);
prop1.setResettable(true);
prop1.setDesignable(true);
- prop1.setScriptable(true);
+ prop1.setScriptable(false);
prop1.setStored(true);
prop1.setEditable(true);
prop1.setUser(true);
@@ -614,7 +614,7 @@ void tst_QMetaObjectBuilder::property()
QVERIFY(!prop1.isWritable());
QVERIFY(prop1.isResettable());
QVERIFY(prop1.isDesignable());
- QVERIFY(prop1.isScriptable());
+ QVERIFY(!prop1.isScriptable());
QVERIFY(prop1.isStored());
QVERIFY(prop1.isEditable());
QVERIFY(prop1.isUser());
@@ -627,7 +627,7 @@ void tst_QMetaObjectBuilder::property()
QCOMPARE(prop2.type(), QByteArray("int"));
QVERIFY(!prop2.isResettable());
QVERIFY(!prop2.isDesignable());
- QVERIFY(!prop2.isScriptable());
+ QVERIFY(prop2.isScriptable());
QVERIFY(!prop2.isStored());
QVERIFY(!prop2.isEditable());
QVERIFY(!prop2.isUser());
@@ -643,7 +643,7 @@ void tst_QMetaObjectBuilder::property()
QCOMPARE(prop2.type(), QByteArray("int"));
QVERIFY(!prop2.isResettable());
QVERIFY(!prop2.isDesignable());
- QVERIFY(!prop2.isScriptable());
+ QVERIFY(prop2.isScriptable());
QVERIFY(!prop2.isStored());
QVERIFY(!prop2.isEditable());
QVERIFY(!prop2.isUser());