aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/testtypes.cpp
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2012-07-18 13:20:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-08 00:34:22 +0200
commitec519529087cc3005d55242569dcbca3dcee91bf (patch)
tree9fb83a2396c62e5231b11aaff013e94ed7f239dc /tests/auto/qml/qqmlecmascript/testtypes.cpp
parent8bb5677f45935a03f1ed439e8a01ca71e9f1152c (diff)
Support JS Array.sort() function for sequence wrappers.
The V8 natve sort implementation calls some functions that are incompatible with the way sequence wrappers work. In particular, it calls an internal length() function which does not pass through the length accessor provided by sequence wrappers, so the sort function always thinks the array is zero length. Instead, clone the array prototype and override the sort function with one that is specific to sequence wrappers. Task-number: QTBUG-25269 Change-Id: Ic83b9ee0bd3a0707e512f28057f0f99b432fded4 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/testtypes.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index b02e9963ab..77670f74da 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -190,6 +190,46 @@ void MyWorkerObject::doIt()
new MyWorkerObjectThread(this);
}
+class MyStringClass : public QObject
+{
+ Q_OBJECT
+public:
+ Q_INVOKABLE QStringList strings(QStringList stringList) const
+ {
+ return stringList;
+ }
+ Q_INVOKABLE QList<int> integers(QVariant v) const
+ {
+ QList<int> intList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ int iv = vList[i].toInt();
+ intList.append(iv);
+ }
+ return intList;
+ }
+ Q_INVOKABLE QList<qreal> reals(QVariant v) const
+ {
+ QList<qreal> realList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ qreal fv = vList[i].toReal();
+ realList.append(fv);
+ }
+ return realList;
+ }
+ Q_INVOKABLE QList<bool> bools(QVariant v) const
+ {
+ QList<bool> boolList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ bool bv = vList[i].toBool();
+ boolList.append(bv);
+ }
+ return boolList;
+ }
+};
+
void registerTypes()
{
qmlRegisterType<MyQmlObject>("Qt.test", 1,0, "MyQmlObjectAlias");
@@ -253,6 +293,8 @@ void registerTypes()
qmlRegisterType<FallbackBindingsTypeObject>("Qt.test.fallbackBindingsObject", 1, 0, "FallbackBindingsType");
qmlRegisterType<FallbackBindingsTypeDerived>("Qt.test.fallbackBindingsDerived", 1, 0, "FallbackBindingsType");
+
+ qmlRegisterType<MyStringClass>("Qt.test", 1, 0, "MyStringClass");
}
#include "testtypes.moc"