aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-31 13:05:37 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-05-31 15:46:27 +0200
commite14b9dbee1260f799d1d2e175d106dbed79b6c49 (patch)
tree127bd9fb574a5d62155e93ead4fdcffc3314e664 /src
parent0ced7dfd6991cd33222e7c5a3c05e56d2c67e9d5 (diff)
Start converting casting of Managed to subtypes to a better scheme
There is now a template based as<Foo>() method available in Managed, that'll allow casting to the proper subclass. It uses the pointer to the vtable and compares it to the classes static vtable for type checking. Like this we can avoid that Managed has to know about all subclasses. Change-Id: Ic966bbe00d85224b8d96cc0ff00f69a6ac67129e Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp31
-rw-r--r--src/qml/qml/qqmlcontextwrapper_p.h15
-rw-r--r--src/qml/qml/qqmllistwrapper.cpp6
-rw-r--r--src/qml/qml/qqmllistwrapper_p.h2
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp4
-rw-r--r--src/qml/qml/qqmltypewrapper_p.h3
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp12
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper_p.h4
-rw-r--r--src/qml/qml/v4/qv4managed_p.h58
-rw-r--r--src/qml/qml/v4/qv4sequenceobject.cpp75
-rw-r--r--src/qml/qml/v4/qv4value_p.h5
-rw-r--r--src/qml/qml/v4/qv4variantobject.cpp2
-rw-r--r--src/qml/qml/v8/qv8engine.cpp12
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp3
-rw-r--r--src/qml/types/qquickworkerscript.cpp2
15 files changed, 114 insertions, 120 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index b7a236b2b8..c7ac48902d 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -55,25 +55,6 @@
QT_BEGIN_NAMESPACE
-namespace QV4 {
-
-struct QmlContextNullWrapper : QmlContextWrapper
-{
- QmlContextNullWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false)
- : QmlContextWrapper(engine, context, scopeObject, ownsContext)
- {
- vtbl = &static_vtbl;
- }
-
- using Object::get;
- static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value);
-
-private:
- const static ManagedVTable static_vtbl;
-};
-
-}
-
using namespace QV4;
DEFINE_MANAGED_VTABLE(QmlContextWrapper);
@@ -123,14 +104,14 @@ QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4)
if (!qmlglobal)
return 0;
- QmlContextWrapper *c = qmlglobal->asQmlContext();
+ QmlContextWrapper *c = qmlglobal->as<QmlContextWrapper>();
return c ? c->getContext() : 0;
}
QQmlContextData *QmlContextWrapper::getContext(const Value &value)
{
Object *o = value.asObject();
- QmlContextWrapper *c = o ? o->asQmlContext() : 0;
+ QmlContextWrapper *c = o ? o->as<QmlContextWrapper>() : 0;
if (!c)
return 0;
@@ -140,7 +121,7 @@ QQmlContextData *QmlContextWrapper::getContext(const Value &value)
void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal)
{
Object *o = qmlglobal.asObject();
- QmlContextWrapper *c = o ? o->asQmlContext() : 0;
+ QmlContextWrapper *c = o ? o->as<QmlContextWrapper>() : 0;
assert(c);
c->ownsContext = true;
}
@@ -148,7 +129,7 @@ void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal)
Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty)
{
- QmlContextWrapper *resource = m->asQmlContext();
+ QmlContextWrapper *resource = m->as<QmlContextWrapper>();
if (!resource)
ctx->throwTypeError();
@@ -284,7 +265,7 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo
void QmlContextWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value)
{
- QmlContextWrapper *wrapper = m->asQmlContext();
+ QmlContextWrapper *wrapper = m->as<QmlContextWrapper>();
if (!wrapper)
ctx->throwTypeError();
@@ -350,7 +331,7 @@ void QmlContextWrapper::destroy(Managed *that)
void QmlContextNullWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value)
{
- QmlContextWrapper *w = m->asQmlContext();
+ QmlContextWrapper *w = m->as<QmlContextWrapper>();
if (w && w->readOnly) {
QString error = QLatin1String("Invalid write to global property \"") + name->toQString() +
QLatin1Char('"');
diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h
index a8df7ba2b6..41026eed32 100644
--- a/src/qml/qml/qqmlcontextwrapper_p.h
+++ b/src/qml/qml/qqmlcontextwrapper_p.h
@@ -66,6 +66,7 @@ namespace QV4 {
struct Q_QML_EXPORT QmlContextWrapper : Object
{
+ Q_MANAGED
QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false);
~QmlContextWrapper();
@@ -92,9 +93,19 @@ struct Q_QML_EXPORT QmlContextWrapper : Object
QQmlGuardedContextData context;
QQmlGuard<QObject> scopeObject;
+};
-private:
- const static ManagedVTable static_vtbl;
+struct QmlContextNullWrapper : QmlContextWrapper
+{
+ Q_MANAGED
+ QmlContextNullWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false)
+ : QmlContextWrapper(engine, context, scopeObject, ownsContext)
+ {
+ vtbl = &static_vtbl;
+ }
+
+ using Object::get;
+ static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value);
};
}
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp
index ff878c0d9c..e8bc053ec1 100644
--- a/src/qml/qml/qqmllistwrapper.cpp
+++ b/src/qml/qml/qqmllistwrapper.cpp
@@ -100,7 +100,7 @@ QVariant QmlListWrapper::toVariant() const
Value QmlListWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty)
{
- QmlListWrapper *w = m->asQmlListWrapper();
+ QmlListWrapper *w = m->as<QmlListWrapper>();
if (!w)
ctx->throwTypeError();
@@ -114,7 +114,7 @@ Value QmlListWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool
Value QmlListWrapper::getIndexed(Managed *m, ExecutionContext *ctx, uint index, bool *hasProperty)
{
- QmlListWrapper *w = m->asQmlListWrapper();
+ QmlListWrapper *w = m->as<QmlListWrapper>();
if (!w)
ctx->throwTypeError();
@@ -136,7 +136,7 @@ void QmlListWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const
void QmlListWrapper::destroy(Managed *that)
{
- QmlListWrapper *w = that->asQmlListWrapper();
+ QmlListWrapper *w = that->as<QmlListWrapper>();
w->~QmlListWrapper();
}
diff --git a/src/qml/qml/qqmllistwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h
index 6cbcef1093..5e8a84b87a 100644
--- a/src/qml/qml/qqmllistwrapper_p.h
+++ b/src/qml/qml/qqmllistwrapper_p.h
@@ -68,6 +68,7 @@ namespace QV4 {
struct Q_QML_EXPORT QmlListWrapper : Object
{
+ Q_MANAGED
protected:
QmlListWrapper(QV8Engine *engine);
~QmlListWrapper();
@@ -90,7 +91,6 @@ private:
QQmlListProperty<QObject> property;
int propertyType;
- static const ManagedVTable static_vtbl;
};
}
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index cdc9265004..1c2fd1f479 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -117,7 +117,7 @@ Value QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, co
Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty)
{
- QmlTypeWrapper *w = m->asQmlTypeWrapper();
+ QmlTypeWrapper *w = m->as<QmlTypeWrapper>();
if (!w)
ctx->throwTypeError();
@@ -229,7 +229,7 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool
void QmlTypeWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value)
{
- QmlTypeWrapper *w = m->asQmlTypeWrapper();
+ QmlTypeWrapper *w = m->as<QmlTypeWrapper>();
if (!w)
ctx->throwTypeError();
diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h
index dc86991605..c81b4cc0c9 100644
--- a/src/qml/qml/qqmltypewrapper_p.h
+++ b/src/qml/qml/qqmltypewrapper_p.h
@@ -68,6 +68,7 @@ namespace QV4 {
struct Q_QML_EXPORT QmlTypeWrapper : Object
{
+ Q_MANAGED
private:
QmlTypeWrapper(QV8Engine *engine);
~QmlTypeWrapper();
@@ -93,8 +94,6 @@ private:
QQmlType *type;
QQmlTypeNameCache *typeNamespace;
const void *importNamespace;
-
- const static ManagedVTable static_vtbl;
};
}
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index ddc22daa5e..03e4639ae8 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -181,7 +181,7 @@ QVariant QmlValueTypeWrapper::toVariant() const
void QmlValueTypeWrapper::destroy(Managed *that)
{
- QmlValueTypeWrapper *w = that->asQmlValueTypeWrapper();
+ QmlValueTypeWrapper *w = that->as<QmlValueTypeWrapper>();
assert(w);
if (w->objectType == Reference)
static_cast<QmlValueTypeReference *>(w)->~QmlValueTypeReference();
@@ -191,13 +191,13 @@ void QmlValueTypeWrapper::destroy(Managed *that)
bool QmlValueTypeWrapper::isEqualTo(Managed *m, Managed *other)
{
- QV4::QmlValueTypeWrapper *lv = m->asQmlValueTypeWrapper();
+ QV4::QmlValueTypeWrapper *lv = m->as<QmlValueTypeWrapper>();
assert(lv);
if (QV4::VariantObject *rv = other->asVariantObject())
return lv->isEqual(rv->data);
- if (QV4::QmlValueTypeWrapper *v = other->asQmlValueTypeWrapper())
+ if (QV4::QmlValueTypeWrapper *v = other->as<QmlValueTypeWrapper>())
return lv->isEqual(v->toVariant());
return false;
@@ -227,7 +227,7 @@ Value QmlValueTypeWrapper::method_toString(SimpleCallContext *ctx)
Object *o = ctx->thisObject.asObject();
if (!o)
ctx->throwTypeError();
- QmlValueTypeWrapper *w = o->asQmlValueTypeWrapper();
+ QmlValueTypeWrapper *w = o->as<QmlValueTypeWrapper>();
if (!w)
ctx->throwTypeError();
@@ -248,7 +248,7 @@ Value QmlValueTypeWrapper::method_toString(SimpleCallContext *ctx)
Value QmlValueTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty)
{
- QmlValueTypeWrapper *r = m->asQmlValueTypeWrapper();
+ QmlValueTypeWrapper *r = m->as<QmlValueTypeWrapper>();
if (!r)
ctx->throwTypeError();
@@ -311,7 +311,7 @@ Value QmlValueTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
void QmlValueTypeWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value)
{
- QmlValueTypeWrapper *r = m->asQmlValueTypeWrapper();
+ QmlValueTypeWrapper *r = m->as<QmlValueTypeWrapper>();
if (!r)
ctx->throwTypeError();
diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h
index c75556a71b..4841bcc523 100644
--- a/src/qml/qml/qqmlvaluetypewrapper_p.h
+++ b/src/qml/qml/qqmlvaluetypewrapper_p.h
@@ -68,6 +68,7 @@ namespace QV4 {
struct Q_QML_EXPORT QmlValueTypeWrapper : Object
{
+ Q_MANAGED
protected:
enum ObjectType { Reference, Copy };
QmlValueTypeWrapper(QV8Engine *engine, ObjectType type);
@@ -93,9 +94,6 @@ public:
ObjectType objectType;
mutable QQmlValueType *type;
-private:
- const static ManagedVTable static_vtbl;
-
static void initProto(ExecutionEngine *v4);
static PersistentValue proto;
};
diff --git a/src/qml/qml/v4/qv4managed_p.h b/src/qml/qml/v4/qv4managed_p.h
index f9641e6689..a942377163 100644
--- a/src/qml/qml/v4/qv4managed_p.h
+++ b/src/qml/qml/v4/qv4managed_p.h
@@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE
class QQmlLocaleData;
class QQuickJSContext2D;
-template <typename, int> class QQmlSequence;
namespace QV4 {
@@ -81,10 +80,22 @@ struct ExecutionEngine;
struct VariantObject;
struct QObjectWrapper;
struct QtObject;
-struct QmlContextWrapper;
-struct QmlTypeWrapper;
-struct QmlValueTypeWrapper;
-struct QmlListWrapper;
+
+#define Q_MANAGED_CHECK \
+ template <typename T> inline void qt_check_for_QMANAGED_macro(const T &_q_argument) const \
+ { int i = qYouForgotTheQ_MANAGED_Macro(this, &_q_argument); i = i + 1; }
+
+template <typename T>
+inline int qYouForgotTheQ_MANAGED_Macro(T, T) { return 0; }
+
+template <typename T1, typename T2>
+inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
+
+#define Q_MANAGED \
+ public: \
+ Q_MANAGED_CHECK \
+ static const ManagedVTable static_vtbl;
+
struct ManagedVTable
{
@@ -178,13 +189,7 @@ public:
Type_QmlLocale,
Type_QQuickJSContext2D,
- // QML sequence types
- Type_QmlIntList,
- Type_QmlRealList,
- Type_QmlBoolList,
- Type_QmlStringList,
- Type_QmlQStringList,
- Type_QmlUrlList,
+ Type_QmlSequence,
// Wrapped QVariant
Type_QVariant,
@@ -201,6 +206,22 @@ public:
String *asString() { return reinterpret_cast<String *>(this); }
Object *asObject() { return reinterpret_cast<Object *>(this); }
+
+ template <typename T>
+ T *as() {
+#if !defined(QT_NO_QOBJECT_CHECK)
+ reinterpret_cast<T *>(this)->qt_check_for_QMANAGED_macro(*reinterpret_cast<T *>(this));
+#endif
+ return vtbl == &T::static_vtbl ? static_cast<T *>(this) : 0;
+ }
+ template <typename T>
+ const T *as() const {
+#if !defined(QT_NO_QOBJECT_CHECK)
+ reinterpret_cast<T *>(this)->qt_check_for_QMANAGED_macro(*reinterpret_cast<T *>(const_cast<Managed *>(this)));
+#endif
+ return vtbl == &T::static_vtbl ? static_cast<const T *>(this) : 0;
+ }
+
ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
FunctionObject *asFunctionObject() { return type == Type_FunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
BooleanObject *asBooleanObject() { return type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }
@@ -220,20 +241,9 @@ public:
QQuickJSContext2D *asQQuickJSContext2D() { return type == Type_QQuickJSContext2D ? reinterpret_cast<QQuickJSContext2D *>(this) : 0; }
VariantObject *asVariantObject() { return type == Type_QVariant ? reinterpret_cast<VariantObject *>(this) : 0; }
- QQmlSequence<QList<int>, Type_QmlIntList> *asQmlIntList() { return type == Type_QmlIntList ? reinterpret_cast<QQmlSequence<QList<int>, Type_QmlIntList> *>(this): 0; }
- QQmlSequence<QList<qreal>, Type_QmlRealList> *asQmlRealList() { return type == Type_QmlRealList ? reinterpret_cast<QQmlSequence<QList<qreal>, Type_QmlRealList> *>(this): 0; }
- QQmlSequence<QList<bool>, Type_QmlBoolList> *asQmlBoolList() { return type == Type_QmlBoolList ? reinterpret_cast<QQmlSequence<QList<bool>, Type_QmlBoolList> *>(this): 0; }
- QQmlSequence<QList<QString>, Type_QmlStringList> *asQmlStringList() { return type == Type_QmlStringList ? reinterpret_cast<QQmlSequence<QList<QString>, Type_QmlStringList> *>(this): 0; }
- QQmlSequence<QStringList, Type_QmlQStringList> *asQmlQStringList() { return type == Type_QmlQStringList ? reinterpret_cast<QQmlSequence<QStringList, Type_QmlQStringList> *>(this): 0; }
- QQmlSequence<QList<QUrl>, Type_QmlUrlList> *asQmlUrlList() { return type == Type_QmlUrlList ? reinterpret_cast<QQmlSequence<QList<QUrl>, Type_QmlUrlList> *>(this): 0; }
-
QtObject *asQtObject() { return type == Type_QtObject ? reinterpret_cast<QtObject *>(this) : 0; }
- QmlContextWrapper *asQmlContext() { return type == Type_QmlContext ? reinterpret_cast<QmlContextWrapper *>(this) : 0; }
- QmlTypeWrapper *asQmlTypeWrapper() { return type == Type_QmlTypeWrapper ? reinterpret_cast<QmlTypeWrapper *>(this) : 0; }
- QmlValueTypeWrapper *asQmlValueTypeWrapper() { return type == Type_QmlValueTypeWrapper ? reinterpret_cast<QmlValueTypeWrapper *>(this) : 0; }
- QmlListWrapper *asQmlListWrapper() { return type == Type_QmlListWrapper ? reinterpret_cast<QmlListWrapper *>(this) : 0; }
- bool isListType() const { return type >= Type_QmlIntList && type <= Type_QmlUrlList; }
+ bool isListType() const { return type == Type_QmlSequence; }
bool isArrayObject() const { return type == Type_ArrayObject; }
bool isStringObject() const { return type == Type_StringObject; }
diff --git a/src/qml/qml/v4/qv4sequenceobject.cpp b/src/qml/qml/v4/qv4sequenceobject.cpp
index c0fa872204..5a1c5b923d 100644
--- a/src/qml/qml/v4/qv4sequenceobject.cpp
+++ b/src/qml/qml/v4/qv4sequenceobject.cpp
@@ -155,9 +155,10 @@ template <> bool convertValueToElement(const QV4::Value &value)
return value.toBoolean();
}
-template <typename Container, int ManagedType>
+template <typename Container>
class QQmlSequence : public QQmlSequenceBase
{
+ Q_MANAGED
public:
QQmlSequence(QV4::ExecutionEngine *engine, const Container &container)
: QQmlSequenceBase(engine)
@@ -166,7 +167,7 @@ public:
, m_propertyIndex(-1)
, m_isReference(false)
{
- type = ManagedType;
+ type = Type_QmlSequence;
vtbl = &static_vtbl;
prototype = engine->sequencePrototype;
initClass(engine);
@@ -178,7 +179,7 @@ public:
, m_propertyIndex(propertyIndex)
, m_isReference(true)
{
- type = ManagedType;
+ type = Type_QmlSequence;
vtbl = &static_vtbl;
prototype = engine->sequencePrototype;
loadReference();
@@ -432,38 +433,36 @@ private:
bool m_isReference;
static QV4::Value getIndexed(QV4::Managed *that, QV4::ExecutionContext *ctx, uint index, bool *hasProperty)
- { return static_cast<QQmlSequence<Container, ManagedType> *>(that)->containerGetIndexed(ctx, index, hasProperty); }
+ { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(ctx, index, hasProperty); }
static void putIndexed(Managed *that, QV4::ExecutionContext *ctx, uint index, const QV4::Value &value)
- { static_cast<QQmlSequence<Container, ManagedType> *>(that)->containerPutIndexed(ctx, index, value); }
+ { static_cast<QQmlSequence<Container> *>(that)->containerPutIndexed(ctx, index, value); }
static QV4::PropertyAttributes queryIndexed(QV4::Managed *that, QV4::ExecutionContext *ctx, uint index)
- { return static_cast<QQmlSequence<Container, ManagedType> *>(that)->containerQueryIndexed(ctx, index); }
+ { return static_cast<QQmlSequence<Container> *>(that)->containerQueryIndexed(ctx, index); }
static bool deleteIndexedProperty(QV4::Managed *that, QV4::ExecutionContext *ctx, uint index)
- { return static_cast<QQmlSequence<Container, ManagedType> *>(that)->containerDeleteIndexedProperty(ctx, index); }
+ { return static_cast<QQmlSequence<Container> *>(that)->containerDeleteIndexedProperty(ctx, index); }
static void destroy(Managed *that)
{
- static_cast<QQmlSequence<Container, ManagedType> *>(that)->~QQmlSequence<Container, ManagedType>();
+ static_cast<QQmlSequence<Container> *>(that)->~QQmlSequence<Container>();
}
-
- static const QV4::ManagedVTable static_vtbl;
};
-typedef QQmlSequence<QStringList, QV4::Managed::Type_QmlQStringList> QQmlQStringList;
+typedef QQmlSequence<QStringList> QQmlQStringList;
template<>
DEFINE_MANAGED_VTABLE(QQmlQStringList);
-typedef QQmlSequence<QList<QString>, QV4::Managed::Type_QmlStringList> QQmlStringList;
+typedef QQmlSequence<QList<QString> > QQmlStringList;
template<>
DEFINE_MANAGED_VTABLE(QQmlStringList);
-typedef QQmlSequence<QList<int>, QV4::Managed::Type_QmlIntList> QQmlIntList;
+typedef QQmlSequence<QList<int> > QQmlIntList;
template<>
DEFINE_MANAGED_VTABLE(QQmlIntList);
-typedef QQmlSequence<QList<QUrl>, QV4::Managed::Type_QmlUrlList> QQmlUrlList;
+typedef QQmlSequence<QList<QUrl> > QQmlUrlList;
template<>
DEFINE_MANAGED_VTABLE(QQmlUrlList);
-typedef QQmlSequence<QList<bool>, QV4::Managed::Type_QmlBoolList> QQmlBoolList;
+typedef QQmlSequence<QList<bool> > QQmlBoolList;
template<>
DEFINE_MANAGED_VTABLE(QQmlBoolList);
-typedef QQmlSequence<QList<qreal>, QV4::Managed::Type_QmlRealList> QQmlRealList;
+typedef QQmlSequence<QList<qreal> > QQmlRealList;
template<>
DEFINE_MANAGED_VTABLE(QQmlRealList);
@@ -482,17 +481,17 @@ QV4::Value SequencePrototype::method_sort(QV4::SimpleCallContext *ctx)
if (!o || !o->isListType())
ctx->throwTypeError();
- if (ctx->argumentCount < 2) {
+ if (ctx->argumentCount >= 2)
+ return ctx->thisObject;
+
#define CALL_SORT(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
- case QV4::Managed::Type_Qml##SequenceElementTypeName##List: o->asQml##SequenceElementTypeName##List()->sort(ctx); break;
+ if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \
+ s->sort(ctx); \
+ } else
- switch (o->internalType()) {
- FOREACH_QML_SEQUENCE_TYPE(CALL_SORT)
- default: break;
- }
+ FOREACH_QML_SEQUENCE_TYPE(CALL_SORT)
#undef CALL_SORT
- }
return ctx->thisObject;
}
@@ -502,14 +501,14 @@ QV4::Value QQmlSequenceBase::method_get_length(QV4::SimpleCallContext* ctx) QV4_
if (!o)
ctx->throwTypeError();
#define CALL_LENGTH_GETTER(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
- case QV4::Managed::Type_Qml##SequenceElementTypeName##List: return o->asQml##SequenceElementTypeName##List()->lengthGetter(ctx);
-
- switch (o->internalType()) {
- FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_GETTER)
- default: QV4::Value::undefinedValue();
- }
+ if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \
+ return s->lengthGetter(ctx); \
+ } else
+ FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_GETTER)
#undef CALL_LENGTH_GETTER
+
+ return QV4::Value::undefinedValue();
}
QV4::Value QQmlSequenceBase::method_set_length(QV4::SimpleCallContext* ctx)
@@ -518,12 +517,11 @@ QV4::Value QQmlSequenceBase::method_set_length(QV4::SimpleCallContext* ctx)
if (!o)
ctx->throwTypeError();
#define CALL_LENGTH_SETTER(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
- case QV4::Managed::Type_Qml##SequenceElementTypeName##List: o->asQml##SequenceElementTypeName##List()->lengthSetter(ctx); break;
+ if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \
+ s->lengthSetter(ctx); \
+ } else
- switch (o->internalType()) {
- FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_SETTER)
- default: break;
- }
+ FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_SETTER)
#undef CALL_LENGTH_SETTER
return QV4::Value::undefinedValue();
@@ -576,7 +574,7 @@ QV4::Value SequencePrototype::fromVariant(QV4::ExecutionEngine *engine, const QV
#undef NEW_COPY_SEQUENCE
#define SEQUENCE_TO_VARIANT(ElementType, ElementTypeName, SequenceType, unused) \
- if (QQml##ElementTypeName##List *list = object->asQml##ElementTypeName##List()) \
+ if (QQml##ElementTypeName##List *list = object->as<QQml##ElementTypeName##List>()) \
return list->toVariant(); \
else
@@ -606,13 +604,14 @@ QVariant SequencePrototype::toVariant(const QV4::Value &array, int typeHint, boo
#undef SEQUENCE_TO_VARIANT
#define MAP_META_TYPE(ElementType, ElementTypeName, SequenceType, unused) \
- case QV4::Managed::Type_Qml##ElementTypeName##List: return qMetaTypeId<SequenceType>();
+ if (object->as<QQml##ElementTypeName##List>()) { \
+ return qMetaTypeId<SequenceType>(); \
+ } else
int SequencePrototype::metaTypeForSequence(QV4::Object *object)
{
- switch (object->internalType()) {
FOREACH_QML_SEQUENCE_TYPE(MAP_META_TYPE)
- default:
+ /*else*/ {
return -1;
}
}
diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h
index 45604740e6..af6f6ab64d 100644
--- a/src/qml/qml/v4/qv4value_p.h
+++ b/src/qml/qml/v4/qv4value_p.h
@@ -271,7 +271,6 @@ struct Q_QML_EXPORT Value
ErrorObject *asErrorObject() const;
VariantObject *asVariantObject() const;
QObjectWrapper *asQObjectWrapper() const;
- QmlValueTypeWrapper *asQmlValueType() const;
uint asArrayIndex() const;
uint asArrayLength(bool *ok) const;
@@ -554,10 +553,6 @@ inline QObjectWrapper *Value::asQObjectWrapper() const
return isObject() ? managed()->asQObjectWrapper() : 0;
}
-inline QmlValueTypeWrapper *Value::asQmlValueType() const
-{
- return isObject() ? managed()->asQmlValueTypeWrapper() : 0;
-}
// ###
inline Value Managed::construct(ExecutionContext *context, Value *args, int argc) {
return vtbl->construct(this, context, args, argc);
diff --git a/src/qml/qml/v4/qv4variantobject.cpp b/src/qml/qml/v4/qv4variantobject.cpp
index c962b21f51..2348a93a6f 100644
--- a/src/qml/qml/v4/qv4variantobject.cpp
+++ b/src/qml/qml/v4/qv4variantobject.cpp
@@ -89,7 +89,7 @@ bool VariantObject::isEqualTo(Managed *m, Managed *other)
if (QV4::VariantObject *rv = other->asVariantObject())
return lv->data == rv->data;
- if (QV4::QmlValueTypeWrapper *v = other->asQmlValueTypeWrapper())
+ if (QV4::QmlValueTypeWrapper *v = other->as<QmlValueTypeWrapper>())
return v->isEqual(lv->data);
return false;
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 1d8de37102..ec56f73845 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -168,13 +168,13 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint)
return QVariant::fromValue(jsonObjectFromJS(value));
} else if (QV4::QObjectWrapper *wrapper = object->asQObjectWrapper()) {
return qVariantFromValue<QObject *>(wrapper->object);
- } else if (QV4::QmlContextWrapper *wrapper = object->asQmlContext()) {
+ } else if (QV4::QmlContextWrapper *wrapper = object->as<QV4::QmlContextWrapper>()) {
return QVariant();
- } else if (QV4::QmlTypeWrapper *w = object->asQmlTypeWrapper()) {
+ } else if (QV4::QmlTypeWrapper *w = object->as<QV4::QmlTypeWrapper>()) {
return w->toVariant();
- } else if (QV4::QmlValueTypeWrapper *v = object->asQmlValueTypeWrapper()) {
+ } else if (QV4::QmlValueTypeWrapper *v = object->as<QV4::QmlValueTypeWrapper>()) {
return v->toVariant();
- } else if (QV4::QmlListWrapper *l = object->asQmlListWrapper()) {
+ } else if (QV4::QmlListWrapper *l = object->as<QV4::QmlListWrapper>()) {
return l->toVariant();
} else if (object->isListType())
return QV4::SequencePrototype::toVariant(object);
@@ -1248,12 +1248,12 @@ QV4::Value QV8Engine::newValueType(const QVariant &value, QQmlValueType *type)
bool QV8Engine::isValueType(const QV4::Value &value) const
{
- return value.isObject() ? value.objectValue()->asQmlValueTypeWrapper() : 0;
+ return value.isObject() ? value.objectValue()->as<QV4::QmlValueTypeWrapper>() : 0;
}
QVariant QV8Engine::toValueType(const QV4::Value &obj)
{
- return obj.isObject() ? obj.objectValue()->asQmlValueTypeWrapper()->toVariant() : QVariant();
+ return obj.isObject() ? obj.objectValue()->as<QV4::QmlValueTypeWrapper>()->toVariant() : QVariant();
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index b06b2ba40a..b8f13d51a1 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -52,6 +52,7 @@
#include <private/qqmlexpression_p.h>
#include <private/qqmlglobal_p.h>
#include <private/qqmltypewrapper_p.h>
+#include <private/qqmlvaluetypewrapper_p.h>
#include <private/qqmlcontextwrapper_p.h>
#include <private/qqmllistwrapper_p.h>
@@ -1435,7 +1436,7 @@ static int MatchScore(v8::Handle<v8::Value> actual, int conversionType)
}
}
- if (QV4::QmlValueTypeWrapper *w = obj->asQmlValueTypeWrapper()) {
+ if (QV4::QmlValueTypeWrapper *w = obj->as<QV4::QmlValueTypeWrapper>()) {
if (engine->toVariant(actual->v4Value(), -1).userType() == conversionType)
return 0;
return 10;
diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp
index 95eabb0f4d..daaa9e2767 100644
--- a/src/qml/types/qquickworkerscript.cpp
+++ b/src/qml/types/qquickworkerscript.cpp
@@ -298,7 +298,7 @@ QV4::Value QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script)
script->object = QV4::QmlContextWrapper::urlScope(workerEngine, script->source);
- QV4::QmlContextWrapper *w = script->object.value().asObject()->asQmlContext();
+ QV4::QmlContextWrapper *w = script->object.value().asObject()->as<QV4::QmlContextNullWrapper>();
w->setReadOnly(false);
QV4::Object *api = v4->newObject();