diff options
author | Robin Burchell <robin.burchell@viroteck.net> | 2016-09-30 10:37:28 +0200 |
---|---|---|
committer | Robin Burchell <robin.burchell@viroteck.net> | 2016-09-30 09:24:05 +0000 |
commit | 0d8a2831779ccb15984e2fe80be04e9856668434 (patch) | |
tree | 579c6d3fd062a65bafa7471c1927ab9c10e2808f | |
parent | c9ffed92a0dee0ae00a9632177ea42f85ea8a48c (diff) |
qv4jsonobject: Make use of QVariant::toString in stringification
This covers a whole host of missing cases, notably QUrl stored in a QV4::Value.
Task-number: QTBUG-50592
Change-Id: I8afd772046c7bfbbcf916a7e90a57be5257b9df8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4jsonobject.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 2e5283c639..fa3eeba745 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -38,6 +38,7 @@ #include <qv4objectiterator_p.h> #include <qv4scopedvalue_p.h> #include <qv4runtime_p.h> +#include <qv4variantobject_p.h> #include "qv4string_p.h" #include <qstack.h> @@ -726,6 +727,10 @@ QString Stringify::Str(const QString &key, const Value &v) return std::isfinite(d) ? value->toQString() : QStringLiteral("null"); } + if (const QV4::VariantObject *v = value->as<QV4::VariantObject>()) { + return v->d()->data.toString(); + } + o = value->asReturnedValue(); if (o) { if (!o->as<FunctionObject>()) { diff --git a/tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml b/tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml new file mode 100644 index 0000000000..e739b85ef8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + Image { + id: img + source: "http://example.org/some_nonexistant_image.png" + visible: false + } + + property string source: JSON.stringify(img.source) +} + diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index d65cec843c..1d335f1f6a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -333,6 +333,7 @@ private slots: void qtbug_52340(); void qtbug_54589(); void qtbug_54687(); + void stringify_qtbug_50592(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -8045,6 +8046,15 @@ void tst_qqmlecmascript::qtbug_54687() engine.evaluate("12\n----12"); } +void tst_qqmlecmascript::stringify_qtbug_50592() +{ + QQmlComponent component(&engine, testFileUrl("stringify_qtbug_50592.qml")); + + QScopedPointer<QObject> obj(component.create()); + QVERIFY(obj != 0); + QCOMPARE(obj->property("source").toString(), QString::fromLatin1("http://example.org/some_nonexistant_image.png")); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" |