summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-06 13:21:18 +0200
committerKent Hansen <khansen@trolltech.com>2009-08-06 13:21:18 +0200
commitbe03a2e9d79e8fa4440f5c6b2760e8b37ff5fa8a (patch)
tree4531f461351e778bcd9b92a298bb76fc8b74e993
parente8043818e92c275884f1a29ed740f8f82b0bc084 (diff)
finish implementation of QVariant.prototype.toString()
Behave like the old back-end.
-rw-r--r--src/script/bridge/qscriptvariant.cpp40
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp1
2 files changed, 24 insertions, 17 deletions
diff --git a/src/script/bridge/qscriptvariant.cpp b/src/script/bridge/qscriptvariant.cpp
index f69a4eac21..87f22d96d1 100644
--- a/src/script/bridge/qscriptvariant.cpp
+++ b/src/script/bridge/qscriptvariant.cpp
@@ -84,21 +84,6 @@ QScriptObjectDelegate::Type QVariantDelegate::type() const
return Variant;
}
-static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString(JSC::ExecState *exec, JSC::JSObject*,
- JSC::JSValue thisValue, const JSC::ArgList&)
-{
- QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
- thisValue = engine->toUsableValue(thisValue);
- if (!thisValue.isObject(&QScriptObject::info))
- return throwError(exec, JSC::TypeError, "This object is not a QVariant");
- QScriptObjectDelegate *delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
- if (!delegate || (delegate->type() != QScriptObjectDelegate::Variant))
- return throwError(exec, JSC::TypeError, "This object is not a QVariant");
- const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
- // ### call valueOf()
- return JSC::jsString(exec, QScript::qtStringToJSCUString(v.toString()));
-}
-
static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf(JSC::ExecState *exec, JSC::JSObject*,
JSC::JSValue thisValue, const JSC::ArgList&)
{
@@ -113,7 +98,6 @@ static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf(JSC::ExecState *exec,
switch (v.type()) {
case QVariant::Invalid:
return JSC::jsUndefined();
-
case QVariant::String:
return JSC::jsString(exec, QScript::qtStringToJSCUString(v.toString()));
@@ -131,12 +115,36 @@ static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf(JSC::ExecState *exec,
case QVariant::UInt:
return JSC::jsNumber(exec, v.toUInt());
+
default:
;
}
return thisValue;
}
+static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString(JSC::ExecState *exec, JSC::JSObject *callee,
+ JSC::JSValue thisValue, const JSC::ArgList &args)
+{
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
+ thisValue = engine->toUsableValue(thisValue);
+ if (!thisValue.isObject(&QScriptObject::info))
+ return throwError(exec, JSC::TypeError, "This object is not a QVariant");
+ QScriptObjectDelegate *delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
+ if (!delegate || (delegate->type() != QScriptObjectDelegate::Variant))
+ return throwError(exec, JSC::TypeError, "This object is not a QVariant");
+ const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
+ JSC::UString result;
+ JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args);
+ if (value && !value.isObject())
+ result = value.toString(exec);
+ if (result.isEmpty()) {
+ result = "QVariant(";
+ result += v.typeName();
+ result += ")";
+ }
+ return JSC::jsString(exec, result);
+}
+
QVariantPrototype::QVariantPrototype(JSC::ExecState* exec, WTF::PassRefPtr<JSC::Structure> structure,
JSC::Structure* prototypeFunctionStructure)
: QScriptObject(structure)
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index fca098346f..896a860261 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -444,7 +444,6 @@ void tst_QScriptEngine::newVariant()
QScriptValue value = object.property("valueOf").call(object);
QVERIFY(value.isObject());
QVERIFY(value.strictlyEquals(object));
- QEXPECT_FAIL("", "QVariant.prototype.toString is not correctly implemented", Continue);
QCOMPARE(object.toString(), QString::fromLatin1("QVariant(QPoint)"));
}
}