From 6ed436a0bcbba1c04068c1dc48f7c74882bbf62e Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 17 Aug 2009 17:49:39 +0200 Subject: adopt variant-to-string conversion of the original qtscript back-end --- src/script/bridge/qscriptvariant.cpp | 13 ++++++++----- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/script/bridge/qscriptvariant.cpp b/src/script/bridge/qscriptvariant.cpp index 7bc1122..d352a98 100644 --- a/src/script/bridge/qscriptvariant.cpp +++ b/src/script/bridge/qscriptvariant.cpp @@ -134,12 +134,15 @@ static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString(JSC::ExecState *exec, const QVariant &v = static_cast(delegate)->value(); JSC::UString result; JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args); - if (value && !value.isObject()) + if (value.isObject()) { + result = QScript::qtStringToJSCUString(v.toString()); + if (result.isEmpty()) { + result = "QVariant("; + result += v.typeName(); + result += ")"; + } + } else { result = value.toString(exec); - if (result.isEmpty()) { - result = "QVariant("; - result += v.typeName(); - result += ")"; } return JSC::jsString(exec, result); } diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index a11b7b7..37f1c8a 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -435,6 +435,18 @@ void tst_QScriptValue::toString() QCOMPARE(str.toString(), QString("ciao")); QCOMPARE(qscriptvalue_cast(str), QString("ciao")); } + + // variant should use internal valueOf(), then fall back to QVariant::toString(), + // then fall back to "QVariant(typename)" + QScriptValue variant = eng.newVariant(123); + QVERIFY(variant.isVariant()); + QCOMPARE(variant.toString(), QString::fromLatin1("123")); + variant = eng.newVariant(QByteArray("hello")); + QVERIFY(variant.isVariant()); + QCOMPARE(variant.toString(), QString::fromLatin1("hello")); + variant = eng.newVariant(QVariant(QPoint(10, 20))); + QVERIFY(variant.isVariant()); + QCOMPARE(variant.toString(), QString::fromLatin1("QVariant(QPoint)")); } void tst_QScriptValue::toNumber() -- cgit v0.12