From ea9fcbda2822bb4b41500065908ac4d718ea0884 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 4 Nov 2019 13:12:03 +0100 Subject: QQmlVMEMetaObject: Scope MemberData for allocating write If we need to allocate in order to write a property of the object, we need to make sure that the member data is not garbage collected during that allocation. Change-Id: I885cdc547588c1b20450e1586765cd0266b4c4f0 Reviewed-by: Simon Hausmann Reviewed-by: Fabian Kosmale (cherry picked from commit 21844350df530a65071e8679d5e047adf553e0f7) Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlvmemetaobject.cpp | 55 +++++++-------------------------------- src/qml/qml/qqmlvmemetaobject_p.h | 18 ++++++++----- 2 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 6bc469c836..15fb181516 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -388,57 +388,20 @@ void QQmlVMEMetaObject::writeProperty(int id, double v) void QQmlVMEMetaObject::writeProperty(int id, const QString& v) { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newString(v)); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QDate& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); -} - -void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) -{ - QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, engine->newVariantObject(QVariant::fromValue(v))); + if (md) { + QV4::Scope scope(engine); + QV4::Scoped(scope, md)->set(engine, id, engine->newString(v)); + } } void QQmlVMEMetaObject::writeProperty(int id, QObject* v) { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); - if (md) - md->set(engine, id, QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(engine, v))); + if (md) { + QV4::Scope scope(engine); + QV4::Scoped(scope, md)->set(engine, id, QV4::Value::fromReturnedValue( + QV4::QObjectWrapper::wrap(engine, v))); + } QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); if (v && !guard) { diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index dbcc9d2884..35bc35ce4b 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -196,12 +196,18 @@ public: void writeProperty(int id, bool v); void writeProperty(int id, double v); void writeProperty(int id, const QString& v); - void writeProperty(int id, const QPointF& v); - void writeProperty(int id, const QSizeF& v); - void writeProperty(int id, const QUrl& v); - void writeProperty(int id, const QDate& v); - void writeProperty(int id, const QDateTime& v); - void writeProperty(int id, const QRectF& v); + + template + void writeProperty(int id, const VariantCompatible &v) + { + QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); + if (md) { + QV4::Scope scope(engine); + QV4::Scoped(scope, md)->set(engine, id, engine->newVariantObject( + QVariant::fromValue(v))); + } + } + void writeProperty(int id, QObject *v); void ensureQObjectWrapper(); -- cgit v1.2.3