diff options
Diffstat (limited to 'src/qml/qml/qqmltypewrapper_p.h')
-rw-r--r-- | src/qml/qml/qqmltypewrapper_p.h | 86 |
1 files changed, 74 insertions, 12 deletions
diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index 717efaf20e..fa859dd118 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -19,7 +19,8 @@ #include <QtCore/qpointer.h> #include <private/qv4value_p.h> -#include <private/qv4object_p.h> +#include <private/qv4functionobject_p.h> +#include <private/qv4qmetaobjectwrapper_p.h> QT_BEGIN_NAMESPACE @@ -32,26 +33,65 @@ namespace QV4 { namespace Heap { -struct QQmlTypeWrapper : Object { - enum TypeNameMode { - IncludeEnums, - ExcludeEnums +struct QQmlTypeWrapper : FunctionObject { + + enum TypeNameMode : quint8 { + ExcludeEnums = 0x0, + IncludeEnums = 0x1, + TypeNameModeMask = 0x1, + }; + + enum Kind : quint8 { + Type = 0x0, + Namespace = 0x2, + KindMask = 0x2 }; void init(TypeNameMode m, QObject *o, const QQmlTypePrivate *type); void init(TypeNameMode m, QObject *o, QQmlTypeNameCache *type, const QQmlImportRef *import); void destroy(); - TypeNameMode mode; - QV4QPointer<QObject> object; + + const QMetaObject *metaObject() const { return type().metaObject(); } + QMetaType metaType() const { return type().typeId(); } QQmlType type() const; + TypeNameMode typeNameMode() const { return TypeNameMode(flags & TypeNameModeMask); } + Kind kind() const { return Kind(flags & KindMask); } + + const QQmlPropertyData *ensureConstructorsCache( + const QMetaObject *metaObject, QMetaType metaType) + { + Q_ASSERT(kind() == Type); + if (!t.constructors && metaObject) { + t.constructors = QMetaObjectWrapper::createConstructors(metaObject, metaType); + warnIfUncreatable(); + } + return t.constructors; + } + void warnIfUncreatable() const; + + QQmlTypeNameCache::Result queryNamespace( + const QV4::String *name, QQmlEnginePrivate *enginePrivate) const; - const QQmlTypePrivate *typePrivate; - QQmlTypeNameCache *typeNamespace; - const QQmlImportRef *importNamespace; + QV4QPointer<QObject> object; + + union { + struct { + const QQmlTypePrivate *typePrivate; + const QQmlPropertyData *constructors; + } t; + struct { + QQmlTypeNameCache *typeNamespace; + const QQmlImportRef *importNamespace; + } n; + }; + + quint8 flags; }; +using QQmlTypeConstructor = QQmlTypeWrapper; + struct QQmlScopedEnumWrapper : Object { void init() { Object::init(); } void destroy(); @@ -62,9 +102,10 @@ struct QQmlScopedEnumWrapper : Object { } -struct Q_QML_EXPORT QQmlTypeWrapper : Object +struct Q_QML_EXPORT QQmlTypeWrapper : FunctionObject { - V4_OBJECT2(QQmlTypeWrapper, Object) + V4_OBJECT2(QQmlTypeWrapper, FunctionObject) + V4_PROTOTYPE(typeWrapperPrototype) V4_NEEDS_DESTROY bool isSingleton() const; @@ -74,6 +115,8 @@ struct Q_QML_EXPORT QQmlTypeWrapper : Object QVariant toVariant() const; + static void initProto(ExecutionEngine *v4); + static ReturnedValue create(ExecutionEngine *, QObject *, const QQmlType &, Heap::QQmlTypeWrapper::TypeNameMode = Heap::QQmlTypeWrapper::IncludeEnums); static ReturnedValue create(ExecutionEngine *, QObject *, const QQmlRefPointer<QQmlTypeNameCache> &, const QQmlImportRef *, @@ -95,6 +138,25 @@ protected: static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p); static bool virtualIsEqualTo(Managed *that, Managed *o); static ReturnedValue virtualInstanceOf(const Object *typeObject, const Value &var); + +private: + static ReturnedValue method_hasInstance( + const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_toString( + const FunctionObject *b, const Value *thisObject, const Value *, int); +}; + +struct QQmlTypeConstructor : QQmlTypeWrapper +{ + V4_OBJECT2(QQmlTypeConstructor, QQmlTypeWrapper) + + static ReturnedValue virtualCallAsConstructor( + const FunctionObject *f, const Value *argv, int argc, const Value *) + { + Q_ASSERT(f->as<QQmlTypeWrapper>()); + return QMetaObjectWrapper::construct( + static_cast<const QQmlTypeWrapper *>(f)->d(), argv, argc); + } }; struct Q_QML_EXPORT QQmlScopedEnumWrapper : Object |