diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-10-03 10:52:38 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-02 01:17:09 +0100 |
commit | c177691118e4e2bace9b5c1f4f57343190e6ad64 (patch) | |
tree | b177efd1493e33dc28c57b5a2980fd020b3c9395 /src/declarative/qml/v8/qv8engine_p.h | |
parent | 9dd6d4e9b8f7c2df6369c336b429bc965a2697d4 (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/v8/qv8engine_p.h')
-rw-r--r-- | src/declarative/qml/v8/qv8engine_p.h | 14 |
1 files changed, 13 insertions, 1 deletions
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) |