From b7731f69f1e8c1410f860f74481222b4b3752505 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 17 Jun 2013 13:47:24 +0200 Subject: [PATCH] Fix the remaining test failures in the jsonbinding autotest 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 --- src/qml/qml/v4/qv4jsonobject.cpp | 5 +++-- tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qml/qml/v4/qv4jsonobject.cpp b/src/qml/qml/v4/qv4jsonobject.cpp index 1d83a0d..34f4809 100644 --- a/src/qml/qml/v4/qv4jsonobject.cpp +++ b/src/qml/qml/v4/qv4jsonobject.cpp @@ -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); diff --git a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp index e6b056f..aaeecb9 100644 --- a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp +++ b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp @@ -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") -- 2.7.4