diff options
Diffstat (limited to 'src/qml/jsruntime/qv4qobjectwrapper_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 104 |
1 files changed, 90 insertions, 14 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 9c5862b80e..504f6a69b8 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -78,25 +78,78 @@ namespace Heap { struct QQmlValueTypeWrapper; struct Q_QML_EXPORT QObjectWrapper : Object { - QObjectWrapper(QObject *object); - QPointer<QObject> object; + void init(QObject *object) + { + Object::init(); + qObj.init(object); + } + + void destroy() { + qObj.destroy(); + Object::destroy(); + } + + QObject *object() const { return qObj.data(); } + +private: + QQmlQPointer<QObject> qObj; }; struct QObjectMethod : FunctionObject { - QObjectMethod(QV4::ExecutionContext *scope); - QPointer<QObject> object; - QQmlRefPointer<QQmlPropertyCache> propertyCache; - int index; + void init(QV4::ExecutionContext *scope); + void destroy() + { + setPropertyCache(nullptr); + qObj.destroy(); + FunctionObject::destroy(); + } + + QQmlPropertyCache *propertyCache() const { return _propertyCache; } + void setPropertyCache(QQmlPropertyCache *c) { + if (c) + c->addref(); + if (_propertyCache) + _propertyCache->release(); + _propertyCache = c; + } Pointer<QQmlValueTypeWrapper> valueTypeWrapper; const QMetaObject *metaObject(); + QObject *object() const { return qObj.data(); } + void setObject(QObject *o) { qObj = o; } + +private: + QQmlQPointer<QObject> qObj; + QQmlPropertyCache *_propertyCache; + +public: + int index; +}; + +struct QMetaObjectWrapper : FunctionObject { + const QMetaObject* metaObject; + QQmlPropertyData *constructors; + int constructorCount; + + void init(const QMetaObject* metaObject); + void destroy(); + void ensureConstructorsCache(); }; struct QmlSignalHandler : Object { - QmlSignalHandler(QObject *object, int signalIndex); - QPointer<QObject> object; + void init(QObject *object, int signalIndex); + void destroy() { + qObj.destroy(); + Object::destroy(); + } int signalIndex; + + QObject *object() const { return qObj.data(); } + void setObject(QObject *o) { qObj = o; } + +private: + QQmlQPointer<QObject> qObj; }; } @@ -104,12 +157,13 @@ struct QmlSignalHandler : Object { struct Q_QML_EXPORT QObjectWrapper : public Object { V4_OBJECT2(QObjectWrapper, Object) + V4_NEEDS_DESTROY enum RevisionMode { IgnoreRevision, CheckRevision }; static void initializeBindings(ExecutionEngine *engine); - QObject *object() const { return d()->object.data(); } + QObject *object() const { return d()->object(); } ReturnedValue getQmlProperty(QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false) const; static ReturnedValue getQmlProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, QObject *object, String *name, RevisionMode revisionMode, bool *hasProperty = 0); @@ -147,7 +201,7 @@ protected: static ReturnedValue method_disconnect(CallContext *ctx); private: - static ReturnedValue wrap_slowPath(ExecutionEngine *engine, QObject *object); + Q_NEVER_INLINE static ReturnedValue wrap_slowPath(ExecutionEngine *engine, QObject *object); }; inline ReturnedValue QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object) @@ -179,16 +233,38 @@ struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index); int methodIndex() const { return d()->index; } - QObject *object() const { return d()->object.data(); } + QObject *object() const { return d()->object(); } QV4::ReturnedValue method_toString(QV4::ExecutionContext *ctx) const; QV4::ReturnedValue method_destroy(QV4::ExecutionContext *ctx, const Value *args, int argc) const; - static ReturnedValue call(const Managed *, CallData *callData); + static void call(const Managed *, Scope &scope, CallData *callData); - ReturnedValue callInternal(CallData *callData) const; + void callInternal(CallData *callData, Scope &scope) const; static void markObjects(Heap::Base *that, QV4::ExecutionEngine *e); + + static QPair<QObject *, int> extractQtMethod(const QV4::FunctionObject *function); +}; + + +struct Q_QML_EXPORT QMetaObjectWrapper : public QV4::FunctionObject +{ + V4_OBJECT2(QMetaObjectWrapper, QV4::FunctionObject) + V4_NEEDS_DESTROY + + static ReturnedValue create(ExecutionEngine *engine, const QMetaObject* metaObject); + static void construct(const Managed *, Scope &scope, CallData *callData); + static bool isEqualTo(Managed *a, Managed *b); + + const QMetaObject *metaObject() const { return d()->metaObject; } + +private: + void init(ExecutionEngine *engine); + ReturnedValue constructInternal(CallData *callData) const; + ReturnedValue callConstructor(const QQmlPropertyData &data, QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; + ReturnedValue callOverloadedConstructor(QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; + }; struct Q_QML_EXPORT QmlSignalHandler : public QV4::Object @@ -198,7 +274,7 @@ struct Q_QML_EXPORT QmlSignalHandler : public QV4::Object V4_NEEDS_DESTROY int signalIndex() const { return d()->signalIndex; } - QObject *object() const { return d()->object.data(); } + QObject *object() const { return d()->object(); } static void initProto(ExecutionEngine *v4); }; |