diff options
-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" |