diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-09-10 17:13:10 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2014-09-17 08:13:11 +0200 |
commit | 3dbe05f6bf3fd51ce8097c35f6c7f12b39acb0f6 (patch) | |
tree | 444ed433aa02085357b589b19b28f4bc1c243320 /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | |
parent | cfe1a8152c948a4586ffa1fe79b47f9a0e88beb5 (diff) |
Fix mapping of JS objects/arrays to C++
[ChangeLog][QtQml][Important Behavior Changes] When a JavaScript object/array
is passed to C++ through a QVariant, the engine no longer immediately converts
the object recursively into a QVariantMap or QVariantList but instead stores
a QJSValue in the QVariant. This prevents a loss of data when the JS object
contains non-primitive types such as function objects for example. Code that
expects the variant type to be exactly QVariant::Map or QVariant::List may
need to be adapted. Registered conversion functions however ensure that code
that merely calls toMap() or toList() continues to work.
Task-number: QTBUG-40431
Change-Id: I1dbc1d5f8e78ad28bb62db3681b9a0b34557e7f5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index c246647325..196f6b96f9 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -746,13 +746,13 @@ void tst_qqmlecmascript::arrayExpressions() MyExpression expr(&context, "[a, b, c, 10]"); QVariant result = expr.evaluate(); - QCOMPARE(result.userType(), qMetaTypeId<QVariantList>()); - QVariantList list = qvariant_cast<QVariantList>(result); - QCOMPARE(list.count(), 4); - QCOMPARE(list.at(0).value<QObject*>(), &obj1); - QCOMPARE(list.at(1).value<QObject*>(), &obj2); - QCOMPARE(list.at(2).value<QObject*>(), &obj3); - QCOMPARE(list.at(3).value<int>(), 10); + QCOMPARE(result.userType(), qMetaTypeId<QJSValue>()); + QJSValue list = qvariant_cast<QJSValue>(result); + QCOMPARE(list.property("length").toInt(), 4); + QCOMPARE(list.property(0).toQObject(), &obj1); + QCOMPARE(list.property(1).toQObject(), &obj2); + QCOMPARE(list.property(2).toQObject(), &obj3); + QCOMPARE(list.property(3).toInt(), 10); } // Tests that modifying a context property will reevaluate expressions @@ -4811,7 +4811,7 @@ void tst_qqmlecmascript::propertyVarCpp() QCOMPARE(object->property("varProperty2"), QVariant(QLatin1String("randomString"))); QCOMPARE(object->property("varProperty2").userType(), (int)QVariant::String); // now enforce behaviour when accessing JavaScript objects from cpp. - QCOMPARE(object->property("jsobject").userType(), (int)QVariant::Map); + QCOMPARE(object->property("jsobject").userType(), qMetaTypeId<QJSValue>()); delete object; } @@ -5166,7 +5166,7 @@ void tst_qqmlecmascript::objectConversion() QVERIFY(object != 0); QVariant retn; QMetaObject::invokeMethod(object, "circularObject", Q_RETURN_ARG(QVariant, retn)); - QCOMPARE(retn.value<QVariantMap>().value("test"), QVariant(100)); + QCOMPARE(retn.value<QJSValue>().property("test").toInt(), int(100)); delete object; } @@ -5434,7 +5434,7 @@ void tst_qqmlecmascript::sequenceConversionWrite() QVERIFY(seq != 0); // we haven't registered QList<QPoint> as a sequence type, so writing shouldn't work. - QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QVariantList to an unregistered type"); + QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QJSValue to an unregistered type"); QTest::ignoreMessage(QtWarningMsg, warningOne.toLatin1().constData()); QMetaObject::invokeMethod(object, "performTest"); |