summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-27 12:28:21 +0200
committerKent Hansen <khansen@trolltech.com>2009-08-27 13:33:35 +0200
commita5c4c8453ac68f847b1bc3b4e01f710b757e7e1b (patch)
treeef689c4d9619665b224c374d5d18816ba4484034
parent2c18dd72d51efffa64ed54f058c64f6e4fc5c597 (diff)
fix whacky behavior of QScriptValue::toString() for QVariant
For some types, an empty string is the correct and complete conversion of the type. If the result is an empty string, use QVariant::canConvert() to determine if that is indeed correct, before falling back to the "string-conversion-not-available" path.
-rw-r--r--src/script/bridge/qscriptvariant.cpp2
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp2
2 files changed, 3 insertions, 1 deletions
diff --git a/src/script/bridge/qscriptvariant.cpp b/src/script/bridge/qscriptvariant.cpp
index c4a152aae3..ab75a02684 100644
--- a/src/script/bridge/qscriptvariant.cpp
+++ b/src/script/bridge/qscriptvariant.cpp
@@ -137,7 +137,7 @@ static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString(JSC::ExecState *exec,
JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args);
if (value.isObject()) {
result = v.toString();
- if (result.isEmpty()) {
+ if (result.isEmpty() && !v.canConvert(QVariant::String)) {
result = "QVariant(";
result += v.typeName();
result += ")";
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index f9ce79f27b..1c09693d34 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -447,6 +447,8 @@ void tst_QScriptValue::toString()
variant = eng.newVariant(QVariant(QPoint(10, 20)));
QVERIFY(variant.isVariant());
QCOMPARE(variant.toString(), QString::fromLatin1("QVariant(QPoint)"));
+ variant = eng.newVariant(QUrl());
+ QVERIFY(variant.toString().isEmpty());
}
void tst_QScriptValue::toNumber()