diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-08-08 14:53:45 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-09 05:57:33 +0200 |
commit | f09517bd9c907698a05ee92ccf158a06db3340b8 (patch) | |
tree | c8bae3c214f06c1293d3f0706960f7139dc999db /src | |
parent | 9c2ab7af355d0132af771f8784e42c13d1f49183 (diff) |
Ensure that copy sequences can be passed as arguments
Previously, automatic conversion from JS array to sequence copy
resource was not performed in the case where the array was passed as
a parameter to a QObject function invocation. This commit adds code
to check if the parameter type is a sequence type - and if so, and if
the value is a variantlist, we convert it to a sequence of the
appropriate type.
Change-Id: I3cc3e2f95604bc71d1d8d237e1acffa1e03b78ba
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8sequencewrapper.cpp | 11 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8sequencewrapper_p.h | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 5fce03aa0f..01ab252d7b 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -2160,13 +2160,17 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle<v8::Val type = -1; QQmlEnginePrivate *ep = engine->engine() ? QQmlEnginePrivate::get(engine->engine()) : 0; - QVariant v = engine->toVariant(value, -1); + QVariant v = engine->toVariant(value, -1); // why -1 instead of callType? if (v.userType() == callType) { *qvariantPtr = v; } else if (v.canConvert(callType)) { *qvariantPtr = v; qvariantPtr->convert(callType); + } else if (engine->sequenceWrapper()->isSequenceType(callType) && v.userType() == qMetaTypeId<QVariantList>()) { + // convert the JS array to a sequence of the correct type. + QVariant seqV = engine->toVariant(value, callType); + *qvariantPtr = seqV; } else { QQmlMetaObject mo = ep ? ep->rawMetaObjectForType(callType) : QQmlMetaObject(); if (!mo.isNull()) { diff --git a/src/qml/qml/v8/qv8sequencewrapper.cpp b/src/qml/qml/v8/qv8sequencewrapper.cpp index c4b4e662f5..03aeb85d73 100644 --- a/src/qml/qml/v8/qv8sequencewrapper.cpp +++ b/src/qml/qml/v8/qv8sequencewrapper.cpp @@ -110,6 +110,17 @@ void QV8SequenceWrapper::destroy() qPersistentDispose(m_constructor); } +#define IS_SEQUENCE(unused1, unused2, SequenceType, unused3) \ + if (sequenceTypeId == qMetaTypeId<SequenceType>()) { \ + return true; \ + } else + +bool QV8SequenceWrapper::isSequenceType(int sequenceTypeId) const +{ + FOREACH_QML_SEQUENCE_TYPE(IS_SEQUENCE) { /* else */ return false; } +} +#undef IS_SEQUENCE + bool QV8SequenceWrapper::isEqual(QV8ObjectResource *lhs, QV8ObjectResource *rhs) { Q_ASSERT(lhs && rhs && lhs->resourceType() == QV8ObjectResource::SequenceType && rhs->resourceType() == QV8ObjectResource::SequenceType); diff --git a/src/qml/qml/v8/qv8sequencewrapper_p.h b/src/qml/qml/v8/qv8sequencewrapper_p.h index 141d6f4428..111cea9085 100644 --- a/src/qml/qml/v8/qv8sequencewrapper_p.h +++ b/src/qml/qml/v8/qv8sequencewrapper_p.h @@ -71,6 +71,8 @@ public: void init(QV8Engine *); void destroy(); + bool isSequenceType(int sequenceTypeId) const; + bool isEqual(QV8ObjectResource *lhs, const QVariant &rhs); bool isEqual(QV8ObjectResource *lhs, QV8ObjectResource *rhs); quint32 sequenceLength(QV8ObjectResource *); |