aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-10-03 10:52:38 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-02 01:17:09 +0100
commitc177691118e4e2bace9b5c1f4f57343190e6ad64 (patch)
treeb177efd1493e33dc28c57b5a2980fd020b3c9395 /src/declarative/qml
parent9dd6d4e9b8f7c2df6369c336b429bc965a2697d4 (diff)
Add support for more sequence types
This commit adds support for more sequence types by adding a sequence wrapper. This class enables conversion between v8::Array and C++ sequences of various types (currently just QList<int>, QList<qreal>, QList<bool>, QList<QString>, QList<QUrl> and QStringList), but more types can be added later if required). When a JavaScript object is created from such a sequence, its prototype object is set to the v8::Array prototype object. The indexed setter, indexed getter, length and toString methods are implemented directly or in terms of the underlying sequence resource. Note that currently, sequences of ValueTypes are NOT supported, due to the fact that operations like: someObj.someValueTypeSequence[i].x = 5; would not behave as required. Task-number: QTBUG-20826 Task-number: QTBUG-21770 Change-Id: I36deb448fb0e87a32084a900e70a2604ff369309 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativevaluetype.cpp2
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp55
-rw-r--r--src/declarative/qml/v8/qv8engine_p.h14
-rw-r--r--src/declarative/qml/v8/qv8qobjectwrapper.cpp20
-rw-r--r--src/declarative/qml/v8/qv8sequencewrapper.cpp273
-rw-r--r--src/declarative/qml/v8/qv8sequencewrapper_p.h104
-rw-r--r--src/declarative/qml/v8/qv8sequencewrapper_p_p.h387
-rw-r--r--src/declarative/qml/v8/qv8worker.cpp40
-rw-r--r--src/declarative/qml/v8/v8.pri3
9 files changed, 877 insertions, 21 deletions
diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp
index 9f43d0ef72..9a941e63f9 100644
--- a/src/declarative/qml/qdeclarativevaluetype.cpp
+++ b/src/declarative/qml/qdeclarativevaluetype.cpp
@@ -92,7 +92,7 @@ QDeclarativeValueTypeFactory::~QDeclarativeValueTypeFactory()
bool QDeclarativeValueTypeFactory::isValueType(int idx)
{
- if ((uint)idx < QVariant::UserType)
+ if ((uint)idx < QVariant::UserType && (uint)idx != QVariant::StringList)
return true;
return false;
}
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index 62abbbe59b..d239f30734 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -45,6 +45,7 @@
#include "qv8contextwrapper_p.h"
#include "qv8valuetypewrapper_p.h"
#include "qv8gccallback_p.h"
+#include "qv8sequencewrapper_p.h"
#include "qv8include_p.h"
#include "../../../3rdparty/javascriptcore/DateMath.h"
@@ -82,6 +83,7 @@ static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Ob
switch (lhst) {
case QV8ObjectResource::ValueTypeType:
+ // a value type might be equal to a variant or another value type
if (rhst == QV8ObjectResource::ValueTypeType) {
return lhsr->engine->valueTypeWrapper()->isEqual(lhsr, lhsr->engine->valueTypeWrapper()->toVariant(rhsr));
} else if (rhst == QV8ObjectResource::VariantType) {
@@ -89,6 +91,7 @@ static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Ob
}
break;
case QV8ObjectResource::VariantType:
+ // a variant might be equal to a value type or other variant.
if (rhst == QV8ObjectResource::VariantType) {
return lhsr->engine->variantWrapper()->toVariant(lhsr) ==
lhsr->engine->variantWrapper()->toVariant(rhsr);
@@ -96,6 +99,12 @@ static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Ob
return rhsr->engine->valueTypeWrapper()->isEqual(rhsr, rhsr->engine->variantWrapper()->toVariant(lhsr));
}
break;
+ case QV8ObjectResource::SequenceType:
+ // a sequence might be equal to itself.
+ if (rhst == QV8ObjectResource::SequenceType) {
+ return lhsr->engine->sequenceWrapper()->isEqual(lhsr, rhsr);
+ }
+ break;
default:
break;
}
@@ -135,6 +144,7 @@ QV8Engine::QV8Engine(QJSEngine* qq, QJSEngine::ContextOwnership ownership)
m_listWrapper.init(this);
m_variantWrapper.init(this);
m_valueTypeWrapper.init(this);
+ m_sequenceWrapper.init(this);
QV8GCCallback::registerGcPrologueCallback();
@@ -164,6 +174,7 @@ QV8Engine::~QV8Engine()
invalidateAllValues();
clearExceptions();
+ m_sequenceWrapper.destroy();
m_valueTypeWrapper.destroy();
m_variantWrapper.destroy();
m_listWrapper.destroy();
@@ -226,25 +237,33 @@ QVariant QV8Engine::toVariant(v8::Handle<v8::Value> value, int typeHint)
return m_variantWrapper.toVariant(r);
case QV8ObjectResource::ValueTypeType:
return m_valueTypeWrapper.toVariant(r);
+ case QV8ObjectResource::SequenceType:
+ return m_sequenceWrapper.toVariant(r);
}
}
}
- if (typeHint == qMetaTypeId<QList<QObject *> >() && value->IsArray()) {
+ if (value->IsArray()) {
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
-
- QList<QObject *> list;
- uint32_t length = array->Length();
- for (uint32_t ii = 0; ii < length; ++ii) {
- v8::Local<v8::Value> arrayItem = array->Get(ii);
- if (arrayItem->IsObject()) {
- list << toQObject(arrayItem->ToObject());
- } else {
- list << 0;
+ if (typeHint == qMetaTypeId<QList<QObject *> >()) {
+ QList<QObject *> list;
+ uint32_t length = array->Length();
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ v8::Local<v8::Value> arrayItem = array->Get(ii);
+ if (arrayItem->IsObject()) {
+ list << toQObject(arrayItem->ToObject());
+ } else {
+ list << 0;
+ }
}
+
+ return qVariantFromValue<QList<QObject*> >(list);
}
- return qVariantFromValue<QList<QObject*> >(list);
+ bool succeeded = false;
+ QVariant retn = m_sequenceWrapper.toVariant(array, typeHint, &succeeded);
+ if (succeeded)
+ return retn;
}
return toBasicVariant(value);
@@ -325,8 +344,14 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
return newQObject(*reinterpret_cast<QObject* const *>(ptr));
- case QMetaType::QStringList:
+ case QMetaType::QStringList:
+ {
+ bool succeeded = false;
+ v8::Handle<v8::Value> retn = m_sequenceWrapper.fromVariant(variant, &succeeded);
+ if (succeeded)
+ return retn;
return arrayFromStringList(this, *reinterpret_cast<const QStringList *>(ptr));
+ }
case QMetaType::QVariantList:
return arrayFromVariantList(this, *reinterpret_cast<const QVariantList *>(ptr));
case QMetaType::QVariantMap:
@@ -369,6 +394,11 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
QObject *obj = QDeclarativeMetaType::toQObject(variant, &objOk);
if (objOk)
return newQObject(obj);
+
+ bool succeeded = false;
+ v8::Handle<v8::Value> retn = m_sequenceWrapper.fromVariant(variant, &succeeded);
+ if (succeeded)
+ return retn;
}
// XXX TODO: To be compatible, we still need to handle:
@@ -459,7 +489,6 @@ QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
int length = array->Length();
for (int ii = 0; ii < length; ++ii)
rv << toVariant(array->Get(ii), -1);
-
return rv;
}
if (!value->IsFunction()) {
diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h
index 79a77c2ac1..92e6123ca1 100644
--- a/src/declarative/qml/v8/qv8engine_p.h
+++ b/src/declarative/qml/v8/qv8engine_p.h
@@ -77,6 +77,7 @@
#include "qv8listwrapper_p.h"
#include "qv8variantwrapper_p.h"
#include "qv8valuetypewrapper_p.h"
+#include "qv8sequencewrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -136,7 +137,8 @@ public:
enum ResourceType { ContextType, QObjectType, TypeType, ListType, VariantType,
ValueTypeType, XMLHttpRequestType, DOMNodeType, SQLDatabaseType,
ListModelType, Context2DType, Context2DStyleType, Context2DPixelArrayType,
- ParticleDataType, SignalHandlerType, IncubatorType, VisualDataItemType };
+ ParticleDataType, SignalHandlerType, IncubatorType, VisualDataItemType,
+ SequenceType };
virtual ResourceType resourceType() const = 0;
QV8Engine *engine;
@@ -279,6 +281,7 @@ public:
QV8ListWrapper *listWrapper() { return &m_listWrapper; }
QV8VariantWrapper *variantWrapper() { return &m_variantWrapper; }
QV8ValueTypeWrapper *valueTypeWrapper() { return &m_valueTypeWrapper; }
+ QV8SequenceWrapper *sequenceWrapper() { return &m_sequenceWrapper; }
void *xmlHttpRequestData() { return m_xmlHttpRequestData; }
void *sqlDatabaseData() { return m_sqlDatabaseData; }
@@ -326,6 +329,9 @@ public:
inline v8::Handle<v8::Value> newValueType(QObject *, int coreIndex, QDeclarativeValueType *);
inline v8::Handle<v8::Value> newValueType(const QVariant &, QDeclarativeValueType *);
+ // Create a new sequence type object
+ inline v8::Handle<v8::Value> newSequence(int sequenceType, QObject *, int coreIndex, bool *succeeded);
+
// Create a new QVariant object. This doesn't examine the type of the variant, but always returns
// a QVariant wrapper
inline v8::Handle<v8::Value> newQVariant(const QVariant &);
@@ -415,6 +421,7 @@ protected:
QV8ListWrapper m_listWrapper;
QV8VariantWrapper m_variantWrapper;
QV8ValueTypeWrapper m_valueTypeWrapper;
+ QV8SequenceWrapper m_sequenceWrapper;
v8::Persistent<v8::Function> m_getOwnPropertyNames;
v8::Persistent<v8::Function> m_freezeObject;
@@ -545,6 +552,11 @@ v8::Handle<v8::Value> QV8Engine::newValueType(const QVariant &value, QDeclarativ
return m_valueTypeWrapper.newValueType(value, type);
}
+v8::Handle<v8::Value> QV8Engine::newSequence(int sequenceType, QObject *object, int property, bool *succeeded)
+{
+ return m_sequenceWrapper.newSequence(sequenceType, object, property, succeeded);
+}
+
// XXX Can this be made more optimal? It is called prior to resolving each and every
// unqualified name in QV8ContextWrapper.
bool QV8Engine::startsWithUpper(v8::Handle<v8::String> string)
diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
index c2ee429d5c..40cb021512 100644
--- a/src/declarative/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
@@ -385,7 +385,13 @@ static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object,
QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
if (valueType)
return engine->newValueType(object, property.coreIndex, valueType);
- }
+ } else {
+ // see if it's a sequence type
+ bool succeeded = false;
+ v8::Handle<v8::Value> retn = engine->newSequence(property.propType, object, property.coreIndex, &succeeded);
+ if (succeeded)
+ return retn;
+ }
QVariant var = object->metaObject()->property(property.coreIndex).read(object);
return engine->fromVariant(var);
@@ -425,13 +431,18 @@ static v8::Handle<v8::Value> LoadPropertyDirect(QV8Engine *engine, QObject *obje
void *args[] = { &handle, 0 };
object->qt_metacall(QMetaObject::ReadProperty, property.coreIndex, args);
return handle.toHandle();
- } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)
- && engine->engine()) {
+ } else if (engine->engine() && QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
if (valueType)
return engine->newValueType(object, property.coreIndex, valueType);
- }
+ } else {
+ // see if it's a sequence type
+ bool success = false;
+ v8::Handle<v8::Value> retn = engine->newSequence(property.propType, object, property.coreIndex, &success);
+ if (success)
+ return retn;
+ }
QVariant var = object->metaObject()->property(property.coreIndex).read(object);
return engine->fromVariant(var);
@@ -601,7 +612,6 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QDeclarativ
v = engine->toVariant(value, property->propType);
QDeclarativeContextData *context = engine->callingContext();
-
if (!QDeclarativePropertyPrivate::write(object, *property, v, context)) {
const char *valueType = 0;
if (v.userType() == QVariant::Invalid) valueType = "null";
diff --git a/src/declarative/qml/v8/qv8sequencewrapper.cpp b/src/declarative/qml/v8/qv8sequencewrapper.cpp
new file mode 100644
index 0000000000..61fb993d8c
--- /dev/null
+++ b/src/declarative/qml/v8/qv8sequencewrapper.cpp
@@ -0,0 +1,273 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDeclarative/qdeclarative.h>
+
+#include "qv8sequencewrapper_p.h"
+#include "qv8sequencewrapper_p_p.h"
+#include "qv8engine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QV8SequenceWrapper::QV8SequenceWrapper()
+ : m_engine(0)
+{
+}
+
+QV8SequenceWrapper::~QV8SequenceWrapper()
+{
+}
+
+#define REGISTER_QML_SEQUENCE_METATYPE(unused, unused2, SequenceType, unused3) qRegisterMetaType<SequenceType>();
+void QV8SequenceWrapper::init(QV8Engine *engine)
+{
+ FOREACH_QML_SEQUENCE_TYPE(REGISTER_QML_SEQUENCE_METATYPE)
+
+ m_engine = engine;
+ m_toString = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(ToString)->GetFunction());
+ m_valueOf = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(ValueOf)->GetFunction());
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetIndexedPropertyHandler(IndexedGetter, IndexedSetter, 0, 0, IndexedEnumerator);
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("length"), LengthGetter, 0,
+ v8::Handle<v8::Value>(), v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("toString"), ToStringGetter, 0,
+ m_toString, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("valueOf"), ValueOfGetter, 0,
+ m_valueOf, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->MarkAsUseUserObjectComparison();
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+}
+#undef REGISTER_QML_SEQUENCE_METATYPE
+
+void QV8SequenceWrapper::destroy()
+{
+ qPersistentDispose(m_toString);
+ qPersistentDispose(m_valueOf);
+ 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)
+{
+ QV8SequenceResource *lr = static_cast<QV8SequenceResource *>(lhs);
+ QV8SequenceResource *rr = static_cast<QV8SequenceResource *>(rhs);
+ Q_ASSERT(lr && rr);
+ return lr->isEqual(rr);
+}
+
+quint32 QV8SequenceWrapper::sequenceLength(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::SequenceType);
+ QV8SequenceResource *sr = static_cast<QV8SequenceResource *>(r);
+ Q_ASSERT(sr);
+ return sr->lengthGetter();
+}
+
+#define NEW_REFERENCE_SEQUENCE(ElementType, ElementTypeName, SequenceType, unused) \
+ if (sequenceType == qMetaTypeId<SequenceType>()) { \
+ r = new QV8##ElementTypeName##SequenceResource(m_engine, object, propertyIndex); \
+ } else
+
+v8::Local<v8::Object> QV8SequenceWrapper::newSequence(int sequenceType, QObject *object, int propertyIndex, bool *succeeded)
+{
+ // This function is called when the property is a QObject Q_PROPERTY of
+ // the given sequence type. Internally we store a typed-sequence
+ // (as well as object ptr + property index for updated-read and write-back)
+ // and so access/mutate avoids variant conversion.
+ *succeeded = true;
+ QV8SequenceResource *r = 0;
+ FOREACH_QML_SEQUENCE_TYPE(NEW_REFERENCE_SEQUENCE) { /* else */ *succeeded = false; return v8::Local<v8::Object>(); }
+
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ rv->SetExternalResource(r);
+ rv->SetPrototype(v8::Array::New(1)->GetPrototype());
+ return rv;
+}
+#undef NEW_REFERENCE_SEQUENCE
+
+#define NEW_COPY_SEQUENCE(ElementType, ElementTypeName, SequenceType, unused) \
+ if (sequenceType == qMetaTypeId<SequenceType>()) { \
+ r = new QV8##ElementTypeName##SequenceResource(m_engine, v.value<SequenceType>()); \
+ } else
+
+v8::Local<v8::Object> QV8SequenceWrapper::fromVariant(const QVariant& v, bool *succeeded)
+{
+ // This function is called when assigning a sequence value to a normal JS var
+ // in a JS block. Internally, we store a sequence of the specified type.
+ // Access and mutation is extremely fast since it will not need to modify any
+ // QObject property.
+ int sequenceType = v.userType();
+ *succeeded = true;
+ QV8SequenceResource *r = 0;
+ FOREACH_QML_SEQUENCE_TYPE(NEW_COPY_SEQUENCE) { /* else */ *succeeded = false; return v8::Local<v8::Object>(); }
+
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ rv->SetExternalResource(r);
+ rv->SetPrototype(v8::Array::New(1)->GetPrototype());
+ return rv;
+}
+#undef NEW_COPY_SEQUENCE
+
+QVariant QV8SequenceWrapper::toVariant(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::SequenceType);
+ QV8SequenceResource *resource = static_cast<QV8SequenceResource *>(r);
+ return resource->toVariant();
+}
+
+#define SEQUENCE_TO_VARIANT(ElementType, ElementTypeName, SequenceType, unused) \
+ if (typeHint == qMetaTypeId<SequenceType>()) { \
+ return QV8##ElementTypeName##SequenceResource::toVariant(m_engine, array, length, succeeded); \
+ } else
+
+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
+
+v8::Handle<v8::Value> QV8SequenceWrapper::IndexedSetter(quint32 index, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(info.This());
+ Q_ASSERT(sr);
+ return sr->indexedSetter(index, value);
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::IndexedGetter(quint32 index, const v8::AccessorInfo &info)
+{
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(info.This());
+ Q_ASSERT(sr);
+ return sr->indexedGetter(index);
+}
+
+v8::Handle<v8::Array> QV8SequenceWrapper::IndexedEnumerator(const v8::AccessorInfo &info)
+{
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(info.This());
+ Q_ASSERT(sr);
+ return sr->indexedEnumerator();
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::LengthGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(info.This());
+ Q_ASSERT(sr);
+ return v8::Integer::NewFromUnsigned(sr->lengthGetter());
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::ToStringGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::ValueOfGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::ToString(const v8::Arguments &args)
+{
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(args.This());
+ Q_ASSERT(sr);
+ return sr->toString();
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::ValueOf(const v8::Arguments &args)
+{
+ QV8SequenceResource *sr = v8_resource_cast<QV8SequenceResource>(args.This());
+ Q_ASSERT(sr);
+ v8::Handle<v8::Value> tostringValue = sr->toString();
+ if (!tostringValue.IsEmpty())
+ return tostringValue;
+ return v8::Integer::NewFromUnsigned(sr->lengthGetter());
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ Q_UNUSED(info);
+ return v8::Handle<v8::Value>();
+}
+
+v8::Handle<v8::Value> QV8SequenceWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ Q_UNUSED(info);
+ return value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8sequencewrapper_p.h b/src/declarative/qml/v8/qv8sequencewrapper_p.h
new file mode 100644
index 0000000000..da0f7eacca
--- /dev/null
+++ b/src/declarative/qml/v8/qv8sequencewrapper_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8SEQUENCEWRAPPER_P_H
+#define QV8SEQUENCEWRAPPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qvariant.h>
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8Engine;
+class QV8ObjectResource;
+class QV8SequenceWrapper
+{
+public:
+ QV8SequenceWrapper();
+ ~QV8SequenceWrapper();
+
+ void init(QV8Engine *);
+ void destroy();
+
+ bool isEqual(QV8ObjectResource *lhs, const QVariant &rhs);
+ bool isEqual(QV8ObjectResource *lhs, QV8ObjectResource *rhs);
+ quint32 sequenceLength(QV8ObjectResource *);
+
+ v8::Local<v8::Object> newSequence(int sequenceTypeId, QObject *object, int propertyIndex, bool *succeeded);
+ v8::Local<v8::Object> fromVariant(const QVariant& v, bool *succeeded);
+ QVariant toVariant(QV8ObjectResource *);
+ QVariant toVariant(v8::Handle<v8::Array> array, int typeHint, bool *succeeded);
+
+private:
+ QV8Engine *m_engine;
+
+ v8::Persistent<v8::Function> m_constructor;
+ v8::Persistent<v8::Function> m_toString;
+ v8::Persistent<v8::Function> m_valueOf;
+
+ static v8::Handle<v8::Value> IndexedGetter(quint32 index, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> IndexedSetter(quint32 index, v8::Local<v8::Value> value, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Array> IndexedEnumerator(const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> LengthGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> ToStringGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
+ static v8::Handle<v8::Value> ValueOfGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> ValueOf(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo &info);
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QV8SEQUENCEWRAPPER_P_H
diff --git a/src/declarative/qml/v8/qv8sequencewrapper_p_p.h b/src/declarative/qml/v8/qv8sequencewrapper_p_p.h
new file mode 100644
index 0000000000..f609aff223
--- /dev/null
+++ b/src/declarative/qml/v8/qv8sequencewrapper_p_p.h
@@ -0,0 +1,387 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8SEQUENCEWRAPPER_P_P_H
+#define QV8SEQUENCEWRAPPER_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativemetatype_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+ \class QV8SequenceResource
+ \brief The abstract base class of the external resource used in sequence type objects
+
+ Every sequence type object returned by QV8SequenceWrapper::fromVariant() or
+ QV8SequenceWrapper::newSequence() has a type-specific QV8SequenceResource which
+ contains the type name, the meta type ids of the sequence and sequence element
+ types, as well as either the sequence data (copy) or object pointer and property
+ index (reference) data associated with the sequence.
+ */
+class QV8SequenceResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(SequenceType);
+
+public:
+ virtual ~QV8SequenceResource() {}
+
+ 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;
+ virtual v8::Handle<v8::Value> indexedSetter(quint32 index, v8::Handle<v8::Value> value) = 0;
+ virtual v8::Handle<v8::Value> indexedGetter(quint32 index) = 0;
+ virtual v8::Handle<v8::Array> indexedEnumerator() = 0;
+ virtual v8::Handle<v8::Value> toString() = 0;
+
+ ObjectType objectType;
+ QByteArray typeName;
+ int sequenceMetaTypeId;
+ int elementMetaTypeId;
+
+protected:
+ QV8SequenceResource(QV8Engine *engine, ObjectType type, const QByteArray &name, int sequenceId, int elementId)
+ : QV8ObjectResource(engine), objectType(type), typeName(name), sequenceMetaTypeId(sequenceId), elementMetaTypeId(elementId)
+ {
+ }
+};
+
+static int convertV8ValueToInt(QV8Engine *, v8::Handle<v8::Value> v)
+{
+ return v->Int32Value();
+}
+
+static v8::Handle<v8::Value> convertIntToV8Value(QV8Engine *, int v)
+{
+ return v8::Integer::New(v);
+}
+
+static QString convertIntToString(QV8Engine *, int v)
+{
+ return QString::number(v);
+}
+
+static qreal convertV8ValueToReal(QV8Engine *, v8::Handle<v8::Value> v)
+{
+ return v->NumberValue();
+}
+
+static v8::Handle<v8::Value> convertRealToV8Value(QV8Engine *, qreal v)
+{
+ return v8::Number::New(v);
+}
+
+static QString convertRealToString(QV8Engine *, qreal v)
+{
+ return QString::number(v);
+}
+
+static bool convertV8ValueToBool(QV8Engine *, v8::Handle<v8::Value> v)
+{
+ return v->BooleanValue();
+}
+
+static v8::Handle<v8::Value> convertBoolToV8Value(QV8Engine *, bool v)
+{
+ return v8::Boolean::New(v);
+}
+
+static QString convertBoolToString(QV8Engine *, bool v)
+{
+ if (v)
+ return QLatin1String("true");
+ return QLatin1String("false");
+}
+
+static QString convertV8ValueToString(QV8Engine *e, v8::Handle<v8::Value> v)
+{
+ return e->toString(v->ToString());
+}
+
+static v8::Handle<v8::Value> convertStringToV8Value(QV8Engine *e, const QString &v)
+{
+ return e->toString(v);
+}
+
+static QString convertStringToString(QV8Engine *, const QString &v)
+{
+ return v;
+}
+
+static QString convertV8ValueToQString(QV8Engine *e, v8::Handle<v8::Value> v)
+{
+ return e->toString(v->ToString());
+}
+
+static v8::Handle<v8::Value> convertQStringToV8Value(QV8Engine *e, const QString &v)
+{
+ return e->toString(v);
+}
+
+static QString convertQStringToString(QV8Engine *, const QString &v)
+{
+ return v;
+}
+
+static QUrl convertV8ValueToUrl(QV8Engine *e, v8::Handle<v8::Value> v)
+{
+ return QUrl(e->toString(v->ToString()));
+}
+
+static v8::Handle<v8::Value> convertUrlToV8Value(QV8Engine *e, const QUrl &v)
+{
+ return e->toString(v.toString());
+}
+
+static QString convertUrlToString(QV8Engine *, const QUrl &v)
+{
+ return v.toString();
+}
+
+
+/*
+ \internal
+ \class QV8<Type>SequenceResource
+ \brief The external resource used in sequence type objects
+
+ Every sequence type object returned by QV8SequenceWrapper::newSequence() has
+ a QV8<Type>SequenceResource which contains a property index and a pointer
+ to the object which contains the property.
+
+ Every sequence type object returned by QV8SequenceWrapper::fromVariant() has
+ a QV8<Type>SequenceResource which contains a copy of the sequence value.
+ Operations on the sequence are implemented directly in terms of that sequence data.
+
+ There exists one QV8<Type>SequenceResource instance for every JavaScript Object
+ (sequence) instance returned from QV8SequenceWrapper::newSequence() or
+ QV8SequenceWrapper::fromVariant().
+ */
+
+// F(elementType, elementTypeName, sequenceType, defaultValue)
+#define FOREACH_QML_SEQUENCE_TYPE(F) \
+ F(int, Int, QList<int>, 0) \
+ F(qreal, Real, QList<qreal>, 0.0) \
+ F(bool, Bool, QList<bool>, false) \
+ F(QString, String, QList<QString>, QString()) \
+ F(QString, QString, QStringList, QString()) \
+ F(QUrl, Url, QList<QUrl>, QUrl())
+
+#define QML_SEQUENCE_TYPE_RESOURCE(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue, ConversionToV8fn, ConversionFromV8fn, ToStringfn) \
+ Q_DECLARE_METATYPE(SequenceType) \
+ class QV8##SequenceElementTypeName##SequenceResource : public QV8SequenceResource { \
+ public:\
+ QV8##SequenceElementTypeName##SequenceResource(QV8Engine *engine, QObject *obj, int propIdx) \
+ : QV8SequenceResource(engine, QV8SequenceResource::Reference, #SequenceType, qMetaTypeId<SequenceType>(), qMetaTypeId<SequenceElementType>()) \
+ , object(obj), propertyIndex(propIdx) \
+ { \
+ } \
+ QV8##SequenceElementTypeName##SequenceResource(QV8Engine *engine, const SequenceType &value) \
+ : QV8SequenceResource(engine, QV8SequenceResource::Copy, #SequenceType, qMetaTypeId<SequenceType>(), qMetaTypeId<SequenceElementType>()) \
+ , object(0), propertyIndex(-1), c(value) \
+ { \
+ } \
+ ~QV8##SequenceElementTypeName##SequenceResource() \
+ { \
+ } \
+ static QVariant toVariant(QV8Engine *e, v8::Handle<v8::Array> array, uint32_t length, bool *succeeded) \
+ { \
+ SequenceType list; \
+ for (uint32_t ii = 0; ii < length; ++ii) { \
+ list.append(ConversionFromV8fn(e, array->Get(ii))); \
+ } \
+ *succeeded = true; \
+ return QVariant::fromValue<SequenceType>(list); \
+ } \
+ QVariant toVariant() \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return QVariant(); \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ 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 */ \
+ /* contain the same elements in the same order) in order to */ \
+ /* maintain JavaScript semantics. However, if they both reference */ \
+ /* the same QObject+propertyIndex, they are equal. */ \
+ if (objectType == QV8SequenceResource::Reference && v->objectType == QV8SequenceResource::Reference) { \
+ if (sequenceMetaTypeId == v->sequenceMetaTypeId) { \
+ const QV8##SequenceElementTypeName##SequenceResource *rhs = static_cast<const QV8##SequenceElementTypeName##SequenceResource *>(v); \
+ return (object != 0 && object == rhs->object && propertyIndex == rhs->propertyIndex); \
+ } \
+ } else if (objectType == QV8SequenceResource::Copy && v->objectType == QV8SequenceResource::Copy) { \
+ if (sequenceMetaTypeId == v->sequenceMetaTypeId) { \
+ const QV8##SequenceElementTypeName##SequenceResource *rhs = static_cast<const QV8##SequenceElementTypeName##SequenceResource *>(v); \
+ return (this == rhs); \
+ } \
+ } \
+ return false; \
+ } \
+ quint32 lengthGetter() \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return 0; \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ return c.count(); \
+ } \
+ v8::Handle<v8::Value> indexedSetter(quint32 index, v8::Handle<v8::Value> value) \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return v8::Undefined(); \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ /* modify the sequence */ \
+ SequenceElementType elementValue = ConversionFromV8fn(engine, value); \
+ quint32 count = c.count(); \
+ if (index == count) { \
+ c.append(elementValue); \
+ } else if (index < count) { \
+ c[index] = elementValue; \
+ } else { \
+ /* according to ECMA262r3 we need to insert */ \
+ /* the value at the given index, increasing length to index+1. */ \
+ while (index > count++) { \
+ c.append(DefaultValue); \
+ } \
+ c.append(elementValue); \
+ } \
+ if (objectType == QV8SequenceResource::Reference) { \
+ /* write back. already checked that object is non-null, so skip that check here. */ \
+ int status = -1; \
+ QDeclarativePropertyPrivate::WriteFlags flags = QDeclarativePropertyPrivate::DontRemoveBinding; \
+ void *a[] = { &c, 0, &status, &flags }; \
+ QMetaObject::metacall(object, QMetaObject::WriteProperty, propertyIndex, a); \
+ } \
+ return value; \
+ } \
+ v8::Handle<v8::Value> indexedGetter(quint32 index) \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return v8::Undefined(); \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ quint32 count = c.count(); \
+ if (index < count) \
+ return ConversionToV8fn(engine, c.at(index)); \
+ return v8::Undefined(); \
+ } \
+ v8::Handle<v8::Array> indexedEnumerator() \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return v8::Handle<v8::Array>(); \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ quint32 count = c.count(); \
+ v8::Local<v8::Array> retn = v8::Array::New(count); \
+ for (quint32 i = 0; i < count; ++i) { \
+ retn->Set(i, v8::Integer::NewFromUnsigned(i)); \
+ } \
+ return retn; \
+ } \
+ v8::Handle<v8::Value> toString() \
+ { \
+ if (objectType == QV8SequenceResource::Reference) { \
+ if (!object) \
+ return v8::Undefined(); \
+ void *a[] = { &c, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyIndex, a); \
+ } \
+ QString str; \
+ quint32 count = c.count(); \
+ for (quint32 i = 0; i < count; ++i) { \
+ str += QString(QLatin1String("%1,")).arg(ToStringfn(engine, c[i])); \
+ } \
+ str.chop(1); \
+ return engine->toString(str); \
+ } \
+ private: \
+ QDeclarativeGuard<QObject> object; \
+ int propertyIndex; \
+ SequenceType c; \
+ };
+
+#define GENERATE_QML_SEQUENCE_TYPE_RESOURCE(ElementType, ElementTypeName, SequenceType, DefaultValue) \
+ QML_SEQUENCE_TYPE_RESOURCE(ElementType, ElementTypeName, SequenceType, DefaultValue, convert##ElementTypeName##ToV8Value, convertV8ValueTo##ElementTypeName, convert##ElementTypeName##ToString)
+
+FOREACH_QML_SEQUENCE_TYPE(GENERATE_QML_SEQUENCE_TYPE_RESOURCE)
+#undef GENERATE_QML_SEQUENCE_TYPE_RESOURCE
+#undef QML_SEQUENCE_TYPE_RESOURCE
+
+#endif // QV8SEQUENCEWRAPPER_P_P_H
diff --git a/src/declarative/qml/v8/qv8worker.cpp b/src/declarative/qml/v8/qv8worker.cpp
index d6998849e2..16e5abfb06 100644
--- a/src/declarative/qml/v8/qv8worker.cpp
+++ b/src/declarative/qml/v8/qv8worker.cpp
@@ -74,7 +74,8 @@ enum Type {
WorkerNumber,
WorkerDate,
WorkerRegexp,
- WorkerListModel
+ WorkerListModel,
+ WorkerSequence
};
static inline quint32 valueheader(Type type, quint32 size = 0)
@@ -252,6 +253,31 @@ void QV8Worker::serialize(QByteArray &data, v8::Handle<v8::Value> v, QV8Engine *
// No other QObject's are allowed to be sent
push(data, valueheader(WorkerUndefined));
} else {
+ // we can convert sequences, but not other types with external data.
+ if (v->IsObject()) {
+ v8::Handle<v8::Object> seqObj = v->ToObject();
+ QV8ObjectResource *r = static_cast<QV8ObjectResource *>(seqObj->GetExternalResource());
+ QVariant sequenceVariant = engine->sequenceWrapper()->toVariant(r);
+ if (!sequenceVariant.isNull()) {
+ // valid sequence. we generate a length (sequence length + 1 for the sequence type)
+ uint32_t seqLength = engine->sequenceWrapper()->sequenceLength(r);
+ uint32_t length = seqLength + 1;
+ if (length > 0xFFFFFF) {
+ push(data, valueheader(WorkerUndefined));
+ return;
+ }
+ reserve(data, sizeof(quint32) + length * sizeof(quint32));
+ push(data, valueheader(WorkerSequence, length));
+ serialize(data, v8::Integer::New(sequenceVariant.userType()), engine); // sequence type
+ for (uint32_t ii = 0; ii < seqLength; ++ii) {
+ serialize(data, seqObj->Get(ii), engine); // sequence elements
+ }
+
+ return;
+ }
+ }
+
+ // not a sequence.
push(data, valueheader(WorkerUndefined));
}
}
@@ -330,6 +356,18 @@ v8::Handle<v8::Value> QV8Worker::deserialize(const char *&data, QV8Engine *engin
agent->setV8Engine(engine);
return rv;
}
+ case WorkerSequence:
+ {
+ bool succeeded = false;
+ quint32 length = headersize(header);
+ quint32 seqLength = length - 1;
+ int sequenceType = deserialize(data, engine)->Int32Value();
+ v8::Local<v8::Array> array = v8::Array::New(seqLength);
+ for (quint32 ii = 0; ii < seqLength; ++ii)
+ array->Set(ii, deserialize(data, engine));
+ QVariant seqVariant = engine->sequenceWrapper()->toVariant(array, sequenceType, &succeeded);
+ return engine->sequenceWrapper()->fromVariant(seqVariant, &succeeded);
+ }
}
Q_ASSERT(!"Unreachable");
return v8::Undefined();
diff --git a/src/declarative/qml/v8/v8.pri b/src/declarative/qml/v8/v8.pri
index c4372ab82a..924602ec39 100644
--- a/src/declarative/qml/v8/v8.pri
+++ b/src/declarative/qml/v8/v8.pri
@@ -9,6 +9,8 @@ HEADERS += \
$$PWD/qv8stringwrapper_p.h \
$$PWD/qv8engine_p.h \
$$PWD/qv8gccallback_p.h \
+ $$PWD/qv8sequencewrapper_p.h \
+ $$PWD/qv8sequencewrapper_p_p.h \
$$PWD/qv8contextwrapper_p.h \
$$PWD/qv8qobjectwrapper_p.h \
$$PWD/qv8typewrapper_p.h \
@@ -26,6 +28,7 @@ HEADERS += \
SOURCES += \
$$PWD/qv8stringwrapper.cpp \
$$PWD/qv8engine.cpp \
+ $$PWD/qv8sequencewrapper.cpp \
$$PWD/qv8contextwrapper.cpp \
$$PWD/qv8qobjectwrapper.cpp \
$$PWD/qv8typewrapper.cpp \