diff options
-rw-r--r-- | src/script/bridge/qscriptvariant.cpp | 40 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 1 |
2 files changed, 24 insertions, 17 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) diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index fca0983..896a860 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)")); } } |