From 6d4d98bc593289d4418a1ab83f00dca0608da23e Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Thu, 3 Oct 2013 10:30:53 +0200 Subject: [PATCH] V4: fix Array.indexOf() for QStringList Autotest is included. Task-number: QTBUG-33542 Change-Id: I46c3a81006019c6613a3d35aa018217f85a15d0b Reviewed-by: Simon Hausmann Reviewed-by: Liang Qi --- src/qml/jsruntime/qv4object.cpp | 2 +- .../qml/qqmlecmascript/data/sequenceConversion.indexes.qml | 13 +++++++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 4fadec7..cca7d2b 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -1133,7 +1133,7 @@ ReturnedValue Object::arrayIndexOf(const ValueRef v, uint fromIndex, uint endInd Scope scope(engine()); ScopedValue value(scope); - if (o->protoHasArray() || o->arrayAttributes) { + if (!(flags & SimpleArray) || o->protoHasArray() || o->arrayAttributes) { // lets be safe and slow for (uint i = fromIndex; i < endIndex; ++i) { bool exists; diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml index 962e8dd..a3f306f 100644 --- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml @@ -72,4 +72,17 @@ Item { if (!verifyExpected(msco.intListProperty, 4)) success = false; } + + function indexOf() { + if (msco.qstringListProperty.length != 4) + success = false; + if (msco.qstringListProperty.indexOf("first") != 0) + success = false; + if (msco.qstringListProperty.indexOf("second") != 1) + success = false; + if (msco.qstringListProperty.indexOf("third") != 2) + success = false; + if (msco.qstringListProperty.indexOf("fourth") != 3) + success = false; + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 3aa8fd4..6b19c13 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5433,6 +5433,8 @@ void tst_qqmlecmascript::sequenceConversionIndexes() QTest::ignoreMessage(QtWarningMsg, qPrintable(w3)); QMetaObject::invokeMethod(object, "indexedAccess"); QVERIFY(object->property("success").toBool()); + QMetaObject::invokeMethod(object, "indexOf"); + QVERIFY(object->property("success").toBool()); delete object; } -- 2.7.4