From 6f55f3dbbb2cdae33a8b0d00b7bf2ada7fe79a04 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Thu, 8 Jan 2015 16:33:34 +0100 Subject: Fix empty arrays in QML 1 Commit bb0239e added a regression, where empty arrays would produce errors in QML 1. Task-number: QTBUG-43656 Change-Id: I6d416b2387a1dfd3588c000368fc1223d08399bd Reviewed-by: Simon Hausmann --- src/declarative/qml/qdeclarativeengine.cpp | 2 ++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 52e5074..8885f40 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -2145,6 +2145,8 @@ QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val if (val.isArray()) { int length = val.property(QLatin1String("length")).toInt32(); + if (!length) + containsQObjects = true; for (int ii = 0; ii < length; ++ii) { if (val.property(ii).isQObject()) { containsQObjects = true; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index ac548b1..2ad3c66 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -457,6 +457,12 @@ void tst_qdeclarativeecmascript::arrayExpressions() QCOMPARE(list2.at(1), QVariant(2)); QCOMPARE(list2.at(2), QVariant(QString("foo"))); QCOMPARE(list2.at(3), QVariant(QString("bar"))); + + MyExpression expr3(&context, "[]"); + result = expr3.evaluate(); + QCOMPARE(result.userType(), qMetaTypeId >()); + QList list3 = qvariant_cast >(result); + QCOMPARE(list3.count(), 0); } // Tests that modifying a context property will reevaluate expressions -- cgit v0.12