aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-09-26 14:25:36 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-30 10:37:05 +0200
commit20fb62f6040ad8415828092a2b09bd374433505f (patch)
treedab84177a83c9e8c9e2d95c8025fd4f7aed2116e /tests
parent54c1fa834aae16fc98fe2f9a3d2a93adc93254df (diff)
Modify JS Object to QVariant conversion
Previously, JS Objects would be converted to a QVariantMap where each value in the map was a QVariant from toVariant(propertyValue). Unfortunately, this would result in a crash if the object had a reference to another object which had a reference to the original object, due to the circular reference. This commit changes the conversion code to use QV8Engine::variantMapFromJS() instead, which avoids cyclic references. Task-number: QTBUG-21626 Change-Id: I129048c8704ae0d1095a02d0ce4c0fe5850b1b20 Reviewed-on: http://codereview.qt-project.org/5490 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/objectConversion.qml16
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp16
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/objectConversion.qml b/tests/auto/declarative/qdeclarativeecmascript/data/objectConversion.qml
new file mode 100644
index 0000000000..67fc342db3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/objectConversion.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 360
+ height: 360
+
+ function circularObject() {
+ var a = {}
+ var b = {}
+
+ a.test = 100;
+ a.c = b;
+ b.c = a;
+ return a;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 537965ccf8..9200e0f5f2 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -152,6 +152,7 @@ private slots:
void propertyChangeSlots();
void elementAssign();
void objectPassThroughSignals();
+ void objectConversion();
void booleanConversion();
void handleReferenceManagement();
void stringArg();
@@ -3314,6 +3315,21 @@ void tst_qdeclarativeecmascript::objectPassThroughSignals()
delete object;
}
+// QTBUG-21626
+void tst_qdeclarativeecmascript::objectConversion()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("objectConversion.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVariant retn;
+ QMetaObject::invokeMethod(object, "circularObject", Q_RETURN_ARG(QVariant, retn));
+ QCOMPARE(retn.value<QVariantMap>().value("test"), QVariant(100));
+
+ delete object;
+}
+
+
// QTBUG-20242
void tst_qdeclarativeecmascript::booleanConversion()
{