From e1a0c7c01d494f7db194e3b5245368ba1d95c6c8 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 26 Jun 2009 12:41:17 +0200 Subject: qtscript meta-object binding: enum properties are not deletable --- src/script/qscriptextqobject.cpp | 6 +++--- tests/auto/qscriptqobject/tst_qscriptqobject.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/script/qscriptextqobject.cpp b/src/script/qscriptextqobject.cpp index a3cb4e6..88fd007 100644 --- a/src/script/qscriptextqobject.cpp +++ b/src/script/qscriptextqobject.cpp @@ -2053,12 +2053,12 @@ bool ExtQMetaObjectData::resolve(const QScriptValueImpl &object, for (int i = 0; i < meta->enumeratorCount(); ++i) { QMetaEnum e = meta->enumerator(i); - for (int j = 0; j < e.keyCount(); ++j) { const char *key = e.key(j); - if (! qstrcmp (key, name.constData())) { - member->native(nameId, e.value(j), QScriptValue::ReadOnly); + member->native(nameId, e.value(j), + QScriptValue::ReadOnly + | QScriptValue::Undeletable); *base = object; return true; } diff --git a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp index fa519de..d8db7b7 100644 --- a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp +++ b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp @@ -1954,7 +1954,7 @@ void tst_QScriptExtQObject::classEnums() QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.AllAbility").toInt32()), MyQObject::AllAbility); - QScriptValue::PropertyFlags expectedEnumFlags = QScriptValue::ReadOnly; + QScriptValue::PropertyFlags expectedEnumFlags = QScriptValue::ReadOnly | QScriptValue::Undeletable; QCOMPARE(myClass.propertyFlags("FooPolicy"), expectedEnumFlags); QCOMPARE(myClass.propertyFlags("BarPolicy"), expectedEnumFlags); QCOMPARE(myClass.propertyFlags("BazPolicy"), expectedEnumFlags); @@ -2005,6 +2005,15 @@ void tst_QScriptExtQObject::classEnums() QCOMPARE(m_myObject->qtFunctionActuals().size(), 0); QCOMPARE(ret.isNumber(), true); } + + // enum properties are not deletable or writable + QVERIFY(!m_engine->evaluate("delete MyQObject.BazPolicy").toBool()); + myClass.setProperty("BazPolicy", QScriptValue()); + QCOMPARE(static_cast(myClass.property("BazPolicy").toInt32()), + MyQObject::BazPolicy); + myClass.setProperty("BazPolicy", MyQObject::FooPolicy); + QCOMPARE(static_cast(myClass.property("BazPolicy").toInt32()), + MyQObject::BazPolicy); } QT_BEGIN_NAMESPACE -- cgit v0.12