Fix the remaining test failures in the jsonbinding autotest
authorLars Knoll <lars.knoll@digia.com>
Mon, 17 Jun 2013 11:47:24 +0000 (13:47 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 17 Jun 2013 11:52:24 +0000 (13:52 +0200)
Skip properties that are function objects when converting a V4 Object to a
QJsonObject. For arrays the function object gets replaced with null.
Fix the test case for arrays to have the correct expected output.

Change-Id: I3ee63935d038e0922e33ac6e64e9c31ecfbd4a7e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4/qv4jsonobject.cpp
tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp

index 1d83a0d..34f4809 100644 (file)
@@ -992,7 +992,8 @@ QJsonObject JsonObject::toJsonObject(QV4::Object *o, V4ObjectSet &visitedObjects
             break;
 
         QString key = name.toQString();
-        result.insert(key, toJsonValue(v, visitedObjects));
+        if (!v.asFunctionObject())
+            result.insert(key, toJsonValue(v, visitedObjects));
     }
 
     visitedObjects.remove(o);
@@ -1030,7 +1031,7 @@ QJsonArray JsonObject::toJsonArray(ArrayObject *a, V4ObjectSet &visitedObjects)
     quint32 length = a->arrayLength();
     for (quint32 i = 0; i < length; ++i) {
         Value v = a->getIndexed(i);
-        result.append(toJsonValue(v, visitedObjects));
+        result.append(toJsonValue(v.asFunctionObject() ? QV4::Value::nullValue() : v, visitedObjects));
     }
 
     visitedObjects.remove(a);
index e6b056f..aaeecb9 100644 (file)
@@ -428,7 +428,7 @@ void tst_qjsonbinding::writeProperty_javascriptExpression_data()
     QTest::newRow("object = object with function property")
             << "object" << "{ foo: function() {} }" << "{}";
     QTest::newRow("array = array with function property")
-            << "array" << "[function() {}]" << "[]";
+            << "array" << "[function() {}]" << "[null]";
 
     // Inherited properties should not be included.
     QTest::newRow("value = object with inherited property")