diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-24 08:44:10 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-25 18:35:05 +0100 |
commit | cd16d2d965cf2b7f8a11b2e1d0f33bc783bd54eb (patch) | |
tree | 584ecebcfc09eefe26e3b1d57ea7ab9efd258248 | |
parent | 655996fd0e7b30f29cc081bf667fed0a78380179 (diff) |
QtQml: Clean up QQmlTypeWrapper
We can enforce that it always receives some kind of type and that the
type doesn't disappear before it's deleted. We also don't have to cast a
Heap::Base to get its engine.
Change-Id: I7f95df64c254d6f4482a02782666e7cccea11ee8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 41 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper_p.h | 4 |
2 files changed, 31 insertions, 14 deletions
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 75f3a19c2f..412c1d6419 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -23,15 +23,32 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(QQmlTypeWrapper); DEFINE_OBJECT_VTABLE(QQmlScopedEnumWrapper); -void Heap::QQmlTypeWrapper::init() + +void Heap::QQmlTypeWrapper::init(TypeNameMode m, QObject *o, const QQmlTypePrivate *type) +{ + Q_ASSERT(type); + Object::init(); + mode = m; + object.init(o); + typePrivate = type; + QQmlType::refHandle(typePrivate); +} + +void Heap::QQmlTypeWrapper::init( + TypeNameMode m, QObject *o, QQmlTypeNameCache *type, const QQmlImportRef *import) { + Q_ASSERT(type); Object::init(); - mode = IncludeEnums; - object.init(); + mode = m; + object.init(o); + typeNamespace = type; + typeNamespace->addref(); + importNamespace = import; } void Heap::QQmlTypeWrapper::destroy() { + Q_ASSERT(typePrivate || typeNamespace); QQmlType::derefHandle(typePrivate); typePrivate = nullptr; if (typeNamespace) @@ -127,25 +144,23 @@ ReturnedValue QQmlTypeWrapper::create(QV4::ExecutionEngine *engine, QObject *o, Q_ASSERT(t.isValid()); Scope scope(engine); - Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>()); - w->d()->mode = mode; w->d()->object = o; - w->d()->typePrivate = t.priv(); - QQmlType::refHandle(w->d()->typePrivate); + Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>( + mode, o, t.priv())); return w.asReturnedValue(); } // Returns a type wrapper for importNamespace (of t) on o. This allows nested resolution of a type in a // namespace. -ReturnedValue QQmlTypeWrapper::create(QV4::ExecutionEngine *engine, QObject *o, const QQmlRefPointer<QQmlTypeNameCache> &t, const QQmlImportRef *importNamespace, - Heap::QQmlTypeWrapper::TypeNameMode mode) +ReturnedValue QQmlTypeWrapper::create( + QV4::ExecutionEngine *engine, QObject *o, const QQmlRefPointer<QQmlTypeNameCache> &t, + const QQmlImportRef *importNamespace, Heap::QQmlTypeWrapper::TypeNameMode mode) { Q_ASSERT(t); Q_ASSERT(importNamespace); Scope scope(engine); - Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>()); - w->d()->mode = mode; w->d()->object = o; w->d()->typeNamespace = t.data(); w->d()->importNamespace = importNamespace; - t->addref(); + Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>( + mode, o, t.data(), importNamespace)); return w.asReturnedValue(); } @@ -178,7 +193,7 @@ ReturnedValue QQmlTypeWrapper::virtualGet(const Managed *m, PropertyKey id, cons if (!id.isString()) return Object::virtualGet(m, id, receiver, hasProperty); - QV4::ExecutionEngine *v4 = static_cast<const QQmlTypeWrapper *>(m)->engine(); + QV4::ExecutionEngine *v4 = m->engine(); QV4::Scope scope(v4); ScopedString name(scope, id.asStringOrSymbol()); diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index 63e170a3d5..717efaf20e 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -38,7 +38,9 @@ struct QQmlTypeWrapper : Object { ExcludeEnums }; - void init(); + 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; |