From 0d8a2831779ccb15984e2fe80be04e9856668434 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 30 Sep 2016 10:37:28 +0200 Subject: 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 --- src/qml/jsruntime/qv4jsonobject.cpp | 5 +++++ tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml | 12 ++++++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/auto/qml/qqmlecmascript/data/stringify_qtbug_50592.qml 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 #include #include +#include #include "qv4string_p.h" #include @@ -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()) { + return v->d()->data.toString(); + } + o = value->asReturnedValue(); if (o) { if (!o->as()) { 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 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 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" -- cgit v1.2.3