QmlCompiler: Do not crash when trying to iterate non-iterables
Amends commit a173d50a9e
.
Change-Id: I2774cd483e073c69f2ceff345436fbdd2a9ac692
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
This commit is contained in:
parent
c296e67c11
commit
8a22282f6a
|
@ -2327,6 +2327,10 @@ void QQmlJSCodeGenerator::generate_GetIterator(int iterator)
|
|||
reject(u"iterator on non-list type"_s);
|
||||
|
||||
const QQmlJSRegisterContent iteratorType = m_state.accumulatorOut();
|
||||
if (!iteratorType.isProperty()) {
|
||||
reject(u"using non-iterator as iterator"_s);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString identifier = QString::number(iteratorType.baseLookupIndex());
|
||||
const QString iteratorName = m_state.accumulatorVariableOut + u"Iterator" + identifier;
|
||||
|
@ -2359,8 +2363,12 @@ void QQmlJSCodeGenerator::generate_IteratorNext(int value, int offset)
|
|||
|
||||
Q_ASSERT(value == m_state.changedRegisterIndex());
|
||||
const QQmlJSRegisterContent iteratorContent = m_state.accumulatorIn();
|
||||
const QQmlJSScope::ConstPtr iteratorType = iteratorContent.storedType();
|
||||
if (!iteratorContent.isProperty()) {
|
||||
reject(u"using non-iterator as iterator"_s);
|
||||
return;
|
||||
}
|
||||
|
||||
const QQmlJSScope::ConstPtr iteratorType = iteratorContent.storedType();
|
||||
const QString iteratorTypeName = iteratorType->internalName();
|
||||
const QString listName = m_state.accumulatorVariableIn
|
||||
+ u"List" + QString::number(iteratorContent.baseLookupIndex());
|
||||
|
|
|
@ -92,4 +92,11 @@ QtObject {
|
|||
|
||||
// Cannot generate code for getters
|
||||
property rect r3: ({ get x() { return 42; }, y: 4 })
|
||||
|
||||
property int nonIterable: {
|
||||
var result = 1;
|
||||
for (var a in Component)
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue