summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-06 11:21:18 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-08-06 11:21:18 (GMT)
commitbe03a2e9d79e8fa4440f5c6b2760e8b37ff5fa8a (patch)
tree4531f461351e778bcd9b92a298bb76fc8b74e993 /src
parente8043818e92c275884f1a29ed740f8f82b0bc084 (diff)
downloadQt-be03a2e9d79e8fa4440f5c6b2760e8b37ff5fa8a.zip
Qt-be03a2e9d79e8fa4440f5c6b2760e8b37ff5fa8a.tar.gz
Qt-be03a2e9d79e8fa4440f5c6b2760e8b37ff5fa8a.tar.bz2
finish implementation of QVariant.prototype.toString()
Behave like the old back-end.
Diffstat (limited to 'src')
-rw-r--r--src/script/bridge/qscriptvariant.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/script/bridge/qscriptvariant.cpp b/src/script/bridge/qscriptvariant.cpp
index f69a4ea..87f22d9 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)