qPersistentDispose(m_constructor);
}
-bool QV8SequenceWrapper::isEqual(QV8ObjectResource *lhs, const QVariant &rhs)
-{
- Q_ASSERT(lhs->resourceType() == QV8ObjectResource::SequenceType);
- QV8SequenceResource *r = static_cast<QV8SequenceResource *>(lhs);
- Q_ASSERT(r);
- return r->isEqual(rhs);
-}
-
bool QV8SequenceWrapper::isEqual(QV8ObjectResource *lhs, QV8ObjectResource *rhs)
{
+ Q_ASSERT(lhs && rhs && lhs->resourceType() == QV8ObjectResource::SequenceType && rhs->resourceType() == QV8ObjectResource::SequenceType);
QV8SequenceResource *lr = static_cast<QV8SequenceResource *>(lhs);
QV8SequenceResource *rr = static_cast<QV8SequenceResource *>(rhs);
- Q_ASSERT(lr && rr);
return lr->isEqual(rr);
}
QVariant QV8SequenceWrapper::toVariant(v8::Handle<v8::Array> array, int typeHint, bool *succeeded)
{
*succeeded = true;
- QV8SequenceResource *sr = static_cast<QV8SequenceResource *>(array->GetExternalResource());
- if (sr)
- return sr->toVariant();
-
- // if no typehint is given it's just a sequence of arbitrary variants
uint32_t length = array->Length();
- if (typeHint == -1) {
- QVariantList list;
- for (uint32_t ii = 0; ii < length; ++ii) {
- v8::Local<v8::Value> arrayItem = array->Get(ii);
- list.append(m_engine->toVariant(arrayItem, -1));
- }
-
- return list;
- }
-
- // otherwise, try to build a sequence of the correct type
FOREACH_QML_SEQUENCE_TYPE(SEQUENCE_TO_VARIANT) { /* else */ *succeeded = false; return QVariant(); }
}
#undef SEQUENCE_TO_VARIANT
enum ObjectType { Reference, Copy };
virtual QVariant toVariant() = 0;
- virtual bool isEqual(const QVariant &v) = 0;
virtual bool isEqual(const QV8SequenceResource *v) = 0;
virtual quint32 lengthGetter() = 0;
} \
return QVariant::fromValue<SequenceType>(c); \
} \
- bool isEqual(const QVariant &v) \
- { \
- if (objectType == QV8SequenceResource::Reference) { \
- if (!object) \
- return false; \
- void *a[] = { &c, 0 }; \
- QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
- } \
- return (c == v.value<SequenceType>()); \
- } \
bool isEqual(const QV8SequenceResource *v) \
{ \
/* Note: two different sequences can never be equal (even if they */ \
worker.sendSequence(msco.urlListProperty);
}
+ function testVariantSequence() {
+ msco.variantListProperty = [ "one", true, 3, "four" ];
+ worker.sendSequence(msco.variantListProperty);
+ }
+
WorkerScript {
id: worker
source: "threadScript.js"
Q_PROPERTY (QList<bool> boolListProperty READ boolListProperty WRITE setBoolListProperty NOTIFY boolListPropertyChanged)
Q_PROPERTY (QList<QString> stringListProperty READ stringListProperty WRITE setStringListProperty NOTIFY stringListPropertyChanged)
Q_PROPERTY (QList<QUrl> urlListProperty READ urlListProperty WRITE setUrlListProperty NOTIFY urlListPropertyChanged)
-
Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged)
+
Q_PROPERTY (QList<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
+ Q_PROPERTY (QList<QVariant> variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged)
public:
MySequenceConversionObject()
m_boolList << true << false << true << false;
m_stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
m_urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com");
-
m_qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
+
m_pointList << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
+ m_variantList << QVariant(QLatin1String("one")) << QVariant(true) << QVariant(3);
}
~MySequenceConversionObject() {}
void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); }
QList<QPoint> pointListProperty() const { return m_pointList; }
void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
+ QList<QVariant> variantListProperty() const { return m_variantList; }
+ void setVariantListProperty(const QList<QVariant> &list) { m_variantList = list; emit variantListPropertyChanged(); }
// now for "copy resource" sequences:
Q_INVOKABLE QList<int> generateIntSequence() const { QList<int> retn; retn << 1 << 2 << 3; return retn; }
void urlListPropertyChanged();
void qstringListPropertyChanged();
void pointListPropertyChanged();
+ void variantListPropertyChanged();
private:
QList<int> m_intList;
QList<bool> m_boolList;
QList<QString> m_stringList;
QList<QUrl> m_urlList;
+ QStringList m_qstringList;
- QStringList m_qstringList; // not a supported sequence type, but QStringList support is hardcoded.
QList<QPoint> m_pointList; // not a supported sequence type
+ QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
};
class MyDeleteObject : public QObject
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
+ QMetaObject::invokeMethod(object, "testVariantSequence");
+ QTRY_VERIFY(object->property("finished").toBool());
+ QVERIFY(object->property("success").toBool());
+
delete object;
}