diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-30 13:48:05 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-02 16:07:33 +0200 |
commit | 430dfd326cb9d8dab8ebd11e83dd52e6d55c4229 (patch) | |
tree | 0d1dd82ddf8f027a591e93def6ce369237af725a /src/qml/types | |
parent | 3dc090fc1eb0a810d96ffc87e4662f7eb9ac8fd2 (diff) |
Fix ObjectIterator API to be GC safe
Change-Id: I3a9c48d53d8dbadcb9b32c00fcef1f89447c4b8c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 7 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 50 |
2 files changed, 28 insertions, 29 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index f929880f58..b87ed63f2b 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1557,14 +1557,13 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const if (!o) return false; - QV4::ObjectIterator it(o.getPointer(), QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain); + QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain); QV4::ScopedValue propertyName(scope); + QV4::ScopedValue v(scope); while (1) { - QV4::Value value; - propertyName = it.nextPropertyNameAsString(&value); + propertyName = it.nextPropertyNameAsString(v); if (propertyName->isNull()) break; - QV4::ScopedValue v(scope, value); cacheItem->setValue(propertyName->toQStringNoThrow(), m_cacheMetaType->v8Engine->toVariant(v, QVariant::Invalid)); } diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index f5e0e70035..0ff348790c 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -415,13 +415,13 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles QV4::ExecutionEngine *v4 = object->engine(); QV4::Scope scope(v4); - QV4::Scoped<QV4::Object> o(scope); + QV4::ScopedObject o(scope); - QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); + QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); QV4::Scoped<QV4::String> propertyName(scope); + QV4::ScopedValue propertyValue(scope); while (1) { - QV4::Value propertyValue; - propertyName = it.nextPropertyNameAsString(&propertyValue); + propertyName = it.nextPropertyNameAsString(propertyValue); if (!propertyName) break; @@ -429,13 +429,13 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles int roleIndex = -1; // Add the value now - if (QV4::String *s = propertyValue.asString()) { + if (QV4::String *s = propertyValue->asString()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::String); roleIndex = e->setStringProperty(r, s->toQString()); - } else if (propertyValue.isNumber()) { + } else if (propertyValue->isNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Number); - roleIndex = e->setDoubleProperty(r, propertyValue.asDouble()); - } else if (QV4::ArrayObject *a = propertyValue.asArrayObject()) { + roleIndex = e->setDoubleProperty(r, propertyValue->asDouble()); + } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::List); ListModel *subModel = new ListModel(r.subLayout, 0, -1); @@ -446,14 +446,14 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles } roleIndex = e->setListProperty(r, subModel); - } else if (propertyValue.isBoolean()) { + } else if (propertyValue->isBoolean()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Bool); - roleIndex = e->setBoolProperty(r, propertyValue.booleanValue()); - } else if (QV4::DateObject *dd = propertyValue.asDateObject()) { + roleIndex = e->setBoolProperty(r, propertyValue->booleanValue()); + } else if (QV4::DateObject *dd = propertyValue->asDateObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::DateTime); QDateTime dt = dd->toQDateTime(); roleIndex = e->setDateTimeProperty(r, dt); - } else if (QV4::Object *o = propertyValue.asObject()) { + } else if (QV4::Object *o = propertyValue->asObject()) { if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) { QObject *o = wrapper->object(); const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::QObject); @@ -466,7 +466,7 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles roleIndex = e->setVariantMapProperty(role, obj, eng); } } - } else if (propertyValue.isNullOrUndefined()) { + } else if (propertyValue->isNullOrUndefined()) { const ListLayout::Role *r = m_layout->getExistingRole(propertyName.getPointer()); if (r) e->clearProperty(*r); @@ -489,25 +489,25 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng) QV4::Scope scope(v4); QV4::Scoped<QV4::Object> o(scope); - QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); + QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); QV4::Scoped<QV4::String> propertyName(scope); + QV4::ScopedValue propertyValue(scope); while (1) { - QV4::Value propertyValue; - propertyName = it.nextPropertyNameAsString(&propertyValue); + propertyName = it.nextPropertyNameAsString(propertyValue); if (!propertyName) break; // Add the value now - if (QV4::String *s = propertyValue.asString()) { + if (QV4::String *s = propertyValue->asString()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::String); if (r.type == ListLayout::Role::String) e->setStringPropertyFast(r, s->toQString()); - } else if (propertyValue.isNumber()) { + } else if (propertyValue->isNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Number); if (r.type == ListLayout::Role::Number) { - e->setDoublePropertyFast(r, propertyValue.asDouble()); + e->setDoublePropertyFast(r, propertyValue->asDouble()); } - } else if (QV4::ArrayObject *a = propertyValue.asArrayObject()) { + } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::List); if (r.type == ListLayout::Role::List) { ListModel *subModel = new ListModel(r.subLayout, 0, -1); @@ -520,18 +520,18 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng) e->setListPropertyFast(r, subModel); } - } else if (propertyValue.isBoolean()) { + } else if (propertyValue->isBoolean()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Bool); if (r.type == ListLayout::Role::Bool) { - e->setBoolPropertyFast(r, propertyValue.booleanValue()); + e->setBoolPropertyFast(r, propertyValue->booleanValue()); } - } else if (QV4::DateObject *dd = propertyValue.asDateObject()) { + } else if (QV4::DateObject *dd = propertyValue->asDateObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::DateTime); if (r.type == ListLayout::Role::DateTime) { QDateTime dt = dd->toQDateTime();; e->setDateTimePropertyFast(r, dt); } - } else if (propertyValue.isObject()) { + } else if (propertyValue->isObject()) { QV4::ScopedObject o(scope, propertyValue); if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) { QObject *o = wrapper->object(); @@ -543,7 +543,7 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng) if (role.type == ListLayout::Role::VariantMap) e->setVariantMapFast(role, o, eng); } - } else if (propertyValue.isUndefined() || propertyValue.isNull()) { + } else if (propertyValue->isNullOrUndefined()) { const ListLayout::Role *r = m_layout->getExistingRole(propertyName.getPointer()); if (r) e->clearProperty(*r); |