From db695c5b1d07275f208446dad178b1131b20bb0a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 22 Jun 2018 22:59:43 +0200 Subject: Unify the get and getIndexed vtable functions of QV4::Object This finalizes the refactoring of Object's vtable API. Also added the receiver argument to the method as required by the ES7 spec. Change-Id: I36f9989211c47458788fe9f7e929862bcfe7b845 Reviewed-by: Simon Hausmann --- src/qml/types/qqmldelegatemodel.cpp | 51 ++++++++++++++++++------------------- src/qml/types/qqmllistmodel.cpp | 21 +++++++-------- src/qml/types/qqmllistmodel_p_p.h | 2 +- 3 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/qml/types') diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 76b3b5e76c..030f924e2a 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1857,7 +1857,7 @@ int QQmlDelegateModelItemMetaType::parseGroups(const QV4::Value &groups) const QV4::ScopedValue v(scope); uint arrayLength = array->getLength(); for (uint i = 0; i < arrayLength; ++i) { - v = array->getIndexed(i); + v = array->get(i); const QString groupName = v->toQString(); int index = groupNames.indexOf(groupName); if (index != -1) @@ -3383,44 +3383,43 @@ public: quint32 count() const { return d()->changes->count(); } const QQmlChangeSet::Change &at(int index) const { return d()->changes->at(index); } - static QV4::ReturnedValue getIndexed(const QV4::Managed *m, uint index, bool *hasProperty) + static QV4::ReturnedValue get(const QV4::Managed *m, QV4::Identifier id, const QV4::Value *receiver, bool *hasProperty) { - Q_ASSERT(m->as()); - QV4::ExecutionEngine *v4 = static_cast(m)->engine(); - QV4::Scope scope(v4); - QV4::Scoped array(scope, static_cast(m)); - - if (index >= array->count()) { - if (hasProperty) - *hasProperty = false; - return QV4::Primitive::undefinedValue().asReturnedValue(); - } + if (id.isArrayIndex()) { + uint index = id.asArrayIndex(); + Q_ASSERT(m->as()); + QV4::ExecutionEngine *v4 = static_cast(m)->engine(); + QV4::Scope scope(v4); + QV4::Scoped array(scope, static_cast(m)); + + if (index >= array->count()) { + if (hasProperty) + *hasProperty = false; + return QV4::Primitive::undefinedValue().asReturnedValue(); + } - const QQmlChangeSet::Change &change = array->at(index); + const QQmlChangeSet::Change &change = array->at(index); - QV4::ScopedObject changeProto(scope, engineData(v4)->changeProto.value()); - QV4::Scoped object(scope, QQmlDelegateModelGroupChange::create(v4)); - object->setPrototypeOf(changeProto); - object->d()->change = change; + QV4::ScopedObject changeProto(scope, engineData(v4)->changeProto.value()); + QV4::Scoped object(scope, QQmlDelegateModelGroupChange::create(v4)); + object->setPrototypeOf(changeProto); + object->d()->change = change; - if (hasProperty) - *hasProperty = true; - return object.asReturnedValue(); - } + if (hasProperty) + *hasProperty = true; + return object.asReturnedValue(); + } - static QV4::ReturnedValue get(const QV4::Managed *m, QV4::StringOrSymbol *name, bool *hasProperty) - { Q_ASSERT(m->as()); const QQmlDelegateModelGroupChangeArray *array = static_cast(m); - name->makeIdentifier(); - if (name->identifier() == array->engine()->id_length()->identifier()) { + if (id == array->engine()->id_length()->identifier()) { if (hasProperty) *hasProperty = true; return QV4::Encode(array->count()); } - return Object::get(m, name, hasProperty); + return Object::get(m, id, receiver, hasProperty); } }; diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index a8f4708ff6..8ddacdfd9b 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -587,7 +587,7 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector *roles) int arrayLength = a->getLength(); for (int j=0 ; j < arrayLength ; ++j) { - o = a->getIndexed(j); + o = a->get(j); subModel->append(o); } @@ -668,7 +668,7 @@ void ListModel::set(int elementIndex, QV4::Object *object) int arrayLength = a->getLength(); for (int j=0 ; j < arrayLength ; ++j) { - o = a->getIndexed(j); + o = a->get(j); subModel->append(o); } @@ -1422,7 +1422,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d ListModel *subModel = new ListModel(role.subLayout, nullptr); int arrayLength = a->getLength(); for (int j=0 ; j < arrayLength ; ++j) { - o = a->getIndexed(j); + o = a->get(j); subModel->append(o); } roleIndex = setListProperty(role, subModel); @@ -1584,16 +1584,17 @@ bool ModelObject::put(Managed *m, Identifier id, const Value &value, Value *rece return true; } -ReturnedValue ModelObject::get(const Managed *m, StringOrSymbol *n, bool *hasProperty) +ReturnedValue ModelObject::get(const Managed *m, Identifier id, const Value *receiver, bool *hasProperty) { - if (n->isSymbol()) - return Object::get(m, n, hasProperty); - String *name = static_cast(n); + if (!id.isString()) + return Object::get(m, id, receiver, hasProperty); const ModelObject *that = static_cast(m); + Scope scope(that); + ScopedString name(scope, id.asHeapObject()); const ListLayout::Role *role = that->d()->m_model->m_listModel->getExistingRole(name); if (!role) - return QObjectWrapper::get(m, name, hasProperty); + return QObjectWrapper::get(m, id, receiver, hasProperty); if (hasProperty) *hasProperty = true; @@ -2343,7 +2344,7 @@ void QQmlListModel::insert(QQmlV4Function *args) int objectArrayLength = objectArray->getLength(); emitItemsAboutToBeInserted(index, objectArrayLength); for (int i=0 ; i < objectArrayLength ; ++i) { - argObject = objectArray->getIndexed(i); + argObject = objectArray->get(i); if (m_dynamicRoles) { m_modelObjects.insert(index+i, DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); @@ -2455,7 +2456,7 @@ void QQmlListModel::append(QQmlV4Function *args) emitItemsAboutToBeInserted(index, objectArrayLength); for (int i=0 ; i < objectArrayLength ; ++i) { - argObject = objectArray->getIndexed(i); + argObject = objectArray->get(i); if (m_dynamicRoles) { m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index a271d9b4d2..a0fd4a3310 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -174,7 +174,7 @@ struct ModelObject : public QObjectWrapper { struct ModelObject : public QObjectWrapper { static bool put(Managed *m, Identifier id, const Value& value, Value *receiver); - static ReturnedValue get(const Managed *m, StringOrSymbol *name, bool *hasProperty); + static ReturnedValue get(const Managed *m, Identifier id, const Value *receiver, bool *hasProperty); static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); V4_OBJECT2(ModelObject, QObjectWrapper) -- cgit v1.2.3