diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-04-30 05:48:13 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-04-30 05:50:21 (GMT) |
commit | deb92c796c727c6ad0eaf28929cda6d000c1b3c1 (patch) | |
tree | 2c9cc6efb5500e7e90fb44e115ea5b2483d0381a | |
parent | e4b865ef512e338cf495226dc98540f45fba1d9f (diff) | |
download | Qt-deb92c796c727c6ad0eaf28929cda6d000c1b3c1.zip Qt-deb92c796c727c6ad0eaf28929cda6d000c1b3c1.tar.gz Qt-deb92c796c727c6ad0eaf28929cda6d000c1b3c1.tar.bz2 |
Fix assignment of value types to javascript var.
Make sure the scriptclass is used.
Task-number: QTBUG-10329
Reviewed-by: Aaron Kennedy
3 files changed, 32 insertions, 4 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 3f4a735..4d23e8f 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1075,7 +1075,7 @@ QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngi qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); qsreal z = ctxt->argument(2).toNumber(); - return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QVector3D(x, y, z))); } QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) @@ -1198,7 +1198,7 @@ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine if (w < 0 || h < 0) return engine->nullValue(); - return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QRectF(x, y, w, h))); } QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) @@ -1207,7 +1207,7 @@ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngin return ctxt->throwError("Qt.point(): Invalid arguments"); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); - return qScriptValueFromValue(engine, qVariantFromValue(QPointF(x, y))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y))); } QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) @@ -1216,7 +1216,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine return ctxt->throwError("Qt.size(): Invalid arguments"); qsreal w = ctxt->argument(0).toNumber(); qsreal h = ctxt->argument(1).toNumber(); - return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h))); } QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine) diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml new file mode 100644 index 0000000..e4715ab --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +QtObject { + property int x; + property int y; + property int z; + + Component.onCompleted: { + var vec3 = Qt.vector3d(1, 2, 3); + x = vec3.x; + y = vec3.y; + z = vec3.z; + } +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index c18fbf5..95b9baa 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -84,6 +84,7 @@ private slots: void enums(); void conflictingBindings(); void returnValues(); + void varAssignment(); private: QDeclarativeEngine engine; @@ -911,6 +912,19 @@ void tst_qdeclarativevaluetypes::returnValues() delete object; } +void tst_qdeclarativevaluetypes::varAssignment() +{ + QDeclarativeComponent component(&engine, TEST_FILE("varAssignment.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("x").toInt(), 1); + QCOMPARE(object->property("y").toInt(), 2); + QCOMPARE(object->property("z").toInt(), 3); + + delete object; +} + QTEST_MAIN(tst_qdeclarativevaluetypes) #include "tst_qdeclarativevaluetypes.moc" |