From: Lars Knoll Date: Fri, 7 Jun 2013 12:06:36 +0000 (+0200) Subject: Fix various errors in the qjsvalue auto test X-Git-Tag: upstream/5.2.1~669^2~297 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21f5744d45ffc07af7978a9f5b382e99f78c2d31;p=platform%2Fupstream%2Fqtdeclarative.git Fix various errors in the qjsvalue auto test Fix creation of Array's from a QStringList Properly implement toVariant() Fix VariantObject::toString() Fix conversion of variant lists to JS values Remove an XFAIL Allow comparison of QJSValue objects created from different engines. There's no reason why we can't simply do this with v4. Change-Id: I8d8c597dbb032926501508d60bd80622ec964d67 Reviewed-by: Simon Hausmann --- diff --git a/src/qml/qml/v4/qv4object.cpp b/src/qml/qml/v4/qv4object.cpp index b6bc353..1559993 100644 --- a/src/qml/qml/v4/qv4object.cpp +++ b/src/qml/qml/v4/qv4object.cpp @@ -1267,6 +1267,8 @@ void Object::markArrayObjects() const ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list) : Object(engine) { + init(engine); + // Converts a QStringList to JS. // The result is a new Array object with length equal to the length // of the QStringList, and the elements being the QStringList's diff --git a/src/qml/qml/v4/qv4runtime.cpp b/src/qml/qml/v4/qv4runtime.cpp index 1444938..7aa4ad7 100644 --- a/src/qml/qml/v4/qv4runtime.cpp +++ b/src/qml/qml/v4/qv4runtime.cpp @@ -754,8 +754,6 @@ Bool __qmljs_strict_equal(const Value &x, const Value &y) return false; if (x.isString()) return x.stringValue()->isEqualTo(y.stringValue()); - if (x.isObject()) - return x.objectValue()->isEqualTo(y.objectValue()); return false; } diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h index 193b77c..6cb8c48 100644 --- a/src/qml/qml/v4/qv4value_p.h +++ b/src/qml/qml/v4/qv4value_p.h @@ -151,6 +151,13 @@ struct Q_QML_EXPORT Value inline bool isObject() const { return tag == Object_Type; } #endif inline bool isConvertibleToInt() const { return (tag & ConvertibleToInt) == ConvertibleToInt; } + inline bool isInt32() const { + if (tag == _Integer_Type) + return true; + if (isDouble() && (int)dbl == dbl) + return true; + return false; + } Bool booleanValue() const { return int_32; diff --git a/src/qml/qml/v4/qv4variantobject.cpp b/src/qml/qml/v4/qv4variantobject.cpp index 6b7deed..ddd6002 100644 --- a/src/qml/qml/v4/qv4variantobject.cpp +++ b/src/qml/qml/v4/qv4variantobject.cpp @@ -43,6 +43,7 @@ #include "qv4functionobject_p.h" #include "qv4objectproto_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -63,8 +64,22 @@ VariantObject::VariantObject(ExecutionEngine *engine, const QVariant &value) QVariant VariantObject::toVariant(const QV4::Value &v) { - VariantObject *o = v.as(); - return o ? o->data : QVariant(); + if (Object *o = v.asObject()) + return o->engine()->v8Engine->variantFromJS(v); + + if (v.isString()) + return QVariant(v.stringValue()->toQString()); + if (v.isBoolean()) + return QVariant(v.booleanValue()); + if (v.isNumber()) { + if (v.isInt32()) + return QVariant(v.toInt32()); + return QVariant(v.asDouble()); + } + if (v.isNull()) + return QVariant(QMetaType::VoidStar, 0); + assert (v.isUndefined() || v.isEmpty()); + return QVariant(); } bool VariantObject::isScarce() const @@ -147,7 +162,7 @@ QV4::Value VariantPrototype::method_toString(SimpleCallContext *ctx) if (!o) return Value::undefinedValue(); QString result = o->data.toString(); - if (result.isEmpty()) + if (result.isEmpty() && !o->data.canConvert(QVariant::String)) result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(o->data.typeName())); return Value::fromString(ctx->engine->newString(result)); } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index cd1d48e..fcd5268 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -515,6 +515,7 @@ QV4::Value QV8Engine::variantListToJS(const QVariantList &lst) a->arrayReserve(lst.size()); for (int i = 0; i < lst.size(); i++) a->arrayData[i].value = variantToJS(lst.at(i)); + a->arrayDataLen = lst.size(); a->setArrayLengthUnchecked(lst.size()); return QV4::Value::fromObject(a); } @@ -538,7 +539,7 @@ QVariantList QV8Engine::variantListFromJS(QV4::ArrayObject *a, quint32 length = a->arrayLength(); for (quint32 i = 0; i < length; ++i) { - QV4::Value v = a->getIndexed(m_v4Engine->current, i); + QV4::Value v = a->getIndexed(i); result.append(variantFromJS(v, visitedObjects)); } diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index fa0456f..2ee344a 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -2070,7 +2070,6 @@ void tst_QJSValue::equals() { QJSValue var1 = eng.toScriptValue(QVariant(QPoint(1, 2))); QJSValue var2 = eng.toScriptValue(QVariant(QPoint(1, 2))); - QEXPECT_FAIL("", "FIXME: QVariant comparison does not work with v8", Continue); QVERIFY(var1.equals(var2)); } { @@ -2078,12 +2077,6 @@ void tst_QJSValue::equals() QJSValue var2 = eng.toScriptValue(QVariant(QPoint(3, 4))); QVERIFY(!var1.equals(var2)); } - - QJSEngine otherEngine; - QTest::ignoreMessage(QtWarningMsg, "QJSValue::equals: " - "cannot compare to a value created in " - "a different engine"); - QCOMPARE(date1.equals(otherEngine.toScriptValue(123)), false); } void tst_QJSValue::strictlyEquals() @@ -2221,12 +2214,6 @@ void tst_QJSValue::strictlyEquals() QJSValue var2 = eng.toScriptValue(QVariant(QPoint(3, 4))); QVERIFY(!var1.strictlyEquals(var2)); } - - QJSEngine otherEngine; - QTest::ignoreMessage(QtWarningMsg, "QJSValue::strictlyEquals: " - "cannot compare to a value created in " - "a different engine"); - QCOMPARE(date1.strictlyEquals(otherEngine.toScriptValue(123)), false); } Q_DECLARE_METATYPE(int*)