aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-07 12:23:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-11 08:56:13 +0200
commit45dbc9f1bb72f9661b43d632d82d634ef52f662e (patch)
tree334d80d5cac0fa62dc339595ac37a14de7a5cea3 /src
parent8fbb94cfc614a16700e599ec590c104360215447 (diff)
Remove more direct usages of Managed pointers
Change-Id: I32f61b7919797eef51a8705695787175b76244c4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp14
-rw-r--r--src/qml/jsruntime/qv4sequenceobject_p.h2
-rw-r--r--src/qml/qml/v8/qv8engine.cpp6
-rw-r--r--src/qml/types/qqmllistmodel.cpp58
-rw-r--r--src/qml/types/qqmllistmodel_p_p.h4
5 files changed, 44 insertions, 40 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 8d3dd97e83..c535dbea09 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -455,7 +455,7 @@ public:
QVariant toVariant() const
{ return QVariant::fromValue<Container>(m_container); }
- static QVariant toVariant(QV4::ArrayObject *array)
+ static QVariant toVariant(QV4::ArrayObjectRef array)
{
QV4::Scope scope(array->engine());
Container result;
@@ -544,12 +544,13 @@ void SequencePrototype::init()
QV4::ReturnedValue SequencePrototype::method_sort(QV4::SimpleCallContext *ctx)
{
- QV4::Object *o = ctx->callData->thisObject.asObject();
+ QV4::Scope scope(ctx);
+ QV4::ScopedObject o(scope, ctx->callData->thisObject);
if (!o || !o->isListType())
ctx->throwTypeError();
if (ctx->callData->argc >= 2)
- return ctx->callData->thisObject.asReturnedValue();
+ return o.asReturnedValue();
#define CALL_SORT(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \
@@ -559,7 +560,7 @@ QV4::ReturnedValue SequencePrototype::method_sort(QV4::SimpleCallContext *ctx)
FOREACH_QML_SEQUENCE_TYPE(CALL_SORT)
#undef CALL_SORT
- return ctx->callData->thisObject.asReturnedValue();
+ return o.asReturnedValue();
}
#define IS_SEQUENCE(unused1, unused2, SequenceType, unused3) \
@@ -615,7 +616,7 @@ ReturnedValue SequencePrototype::fromVariant(QV4::ExecutionEngine *engine, const
return list->toVariant(); \
else
-QVariant SequencePrototype::toVariant(QV4::Object *object)
+QVariant SequencePrototype::toVariant(ObjectRef object)
{
Q_ASSERT(object->isListType());
FOREACH_QML_SEQUENCE_TYPE(SEQUENCE_TO_VARIANT) { /* else */ return QVariant(); }
@@ -636,8 +637,7 @@ QVariant SequencePrototype::toVariant(const QV4::ValueRef array, int typeHint, b
return QVariant();
}
QV4::Scope scope(array->engine());
- // ### GC
- QV4::ArrayObject *a = array->asArrayObject();
+ QV4::ScopedArrayObject a(scope, array);
FOREACH_QML_SEQUENCE_TYPE(SEQUENCE_TO_VARIANT) { /* else */ *succeeded = false; return QVariant(); }
}
diff --git a/src/qml/jsruntime/qv4sequenceobject_p.h b/src/qml/jsruntime/qv4sequenceobject_p.h
index d2a7054425..3bbb86f231 100644
--- a/src/qml/jsruntime/qv4sequenceobject_p.h
+++ b/src/qml/jsruntime/qv4sequenceobject_p.h
@@ -80,7 +80,7 @@ struct SequencePrototype : public QV4::Object
static ReturnedValue newSequence(QV4::ExecutionEngine *engine, int sequenceTypeId, QObject *object, int propertyIndex, bool *succeeded);
static ReturnedValue fromVariant(QV4::ExecutionEngine *engine, const QVariant& v, bool *succeeded);
static int metaTypeForSequence(ObjectRef object);
- static QVariant toVariant(QV4::Object *object);
+ static QVariant toVariant(QV4::ObjectRef object);
static QVariant toVariant(const ValueRef array, int typeHint, bool *succeeded);
};
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 7cf769a219..149896b545 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -150,7 +150,7 @@ QVariant QV8Engine::toVariant(const QV4::ValueRef value, int typeHint)
} else if (QV4::QmlListWrapper *l = object->as<QV4::QmlListWrapper>()) {
return l->toVariant();
} else if (object->isListType())
- return QV4::SequencePrototype::toVariant(object.getPointer());
+ return QV4::SequencePrototype::toVariant(object);
}
if (value->asArrayObject()) {
@@ -858,9 +858,9 @@ bool QV8Engine::metaTypeFromJS(const QV4::ValueRef value, int type, void *data)
// We have T t, T* is requested, so return &t.
*reinterpret_cast<void* *>(data) = var.data();
return true;
- } else if (QV4::Object *o = value->asObject()) {
+ } else if (value->isObject()) {
// Look in the prototype chain.
- QV4::Object *proto = o->prototype();
+ QV4::ScopedObject proto(scope, value->objectValue()->prototype());
while (proto) {
bool canCast = false;
if (QV4::VariantObject *vo = proto->as<QV4::VariantObject>()) {
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index 0ff348790c..4fee073180 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -104,9 +104,9 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::Da
return createRole(key, type);
}
-const ListLayout::Role &ListLayout::getRoleOrCreate(const QV4::String *key, Role::DataType type)
+const ListLayout::Role &ListLayout::getRoleOrCreate(const QV4::StringRef key, Role::DataType type)
{
- QStringHash<Role *>::Node *node = roleHash.findNode(key);
+ QStringHash<Role *>::Node *node = roleHash.findNode(key.getPointer());
if (node) {
const Role &r = *node->value;
if (type != r.type)
@@ -239,10 +239,10 @@ const ListLayout::Role *ListLayout::getExistingRole(const QString &key)
return r;
}
-const ListLayout::Role *ListLayout::getExistingRole(const QV4::String *key)
+const ListLayout::Role *ListLayout::getExistingRole(const QV4::StringRef key)
{
Role *r = 0;
- QStringHash<Role *>::Node *node = roleHash.findNode(key);
+ QStringHash<Role *>::Node *node = roleHash.findNode(key.getPointer());
if (node)
r = node->value;
return r;
@@ -430,13 +430,13 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles
// Add the value now
if (QV4::String *s = propertyValue->asString()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::String);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String);
roleIndex = e->setStringProperty(r, s->toQString());
} else if (propertyValue->isNumber()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Number);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number);
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);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List);
ListModel *subModel = new ListModel(r.subLayout, 0, -1);
int arrayLength = a->arrayLength();
@@ -447,27 +447,27 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles
roleIndex = e->setListProperty(r, subModel);
} else if (propertyValue->isBoolean()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Bool);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Bool);
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);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::DateTime);
QDateTime dt = dd->toQDateTime();
roleIndex = e->setDateTimeProperty(r, dt);
} 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);
+ const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
if (role.type == ListLayout::Role::QObject)
roleIndex = e->setQObjectProperty(role, o);
} else {
- const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::VariantMap);
+ const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap);
if (role.type == ListLayout::Role::VariantMap) {
QV4::ScopedObject obj(scope, o);
roleIndex = e->setVariantMapProperty(role, obj, eng);
}
}
} else if (propertyValue->isNullOrUndefined()) {
- const ListLayout::Role *r = m_layout->getExistingRole(propertyName.getPointer());
+ const ListLayout::Role *r = m_layout->getExistingRole(propertyName);
if (r)
e->clearProperty(*r);
}
@@ -487,28 +487,31 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng)
QV4::ExecutionEngine *v4 = object->engine();
QV4::Scope scope(v4);
- QV4::Scoped<QV4::Object> o(scope);
QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly);
QV4::Scoped<QV4::String> propertyName(scope);
QV4::ScopedValue propertyValue(scope);
+ QV4::ScopedObject o(scope);
+ QV4::ScopedArrayObject a(scope);
+ QV4::Scoped<QV4::DateObject> date(scope);
while (1) {
propertyName = it.nextPropertyNameAsString(propertyValue);
if (!propertyName)
break;
// Add the value now
- if (QV4::String *s = propertyValue->asString()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::String);
+ if (propertyValue->isString()) {
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String);
if (r.type == ListLayout::Role::String)
- e->setStringPropertyFast(r, s->toQString());
+ e->setStringPropertyFast(r, propertyValue->stringValue()->toQString());
} else if (propertyValue->isNumber()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Number);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number);
if (r.type == ListLayout::Role::Number) {
e->setDoublePropertyFast(r, propertyValue->asDouble());
}
- } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::List);
+ } else if (propertyValue->asArrayObject()) {
+ a = propertyValue;
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List);
if (r.type == ListLayout::Role::List) {
ListModel *subModel = new ListModel(r.subLayout, 0, -1);
@@ -521,30 +524,31 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng)
e->setListPropertyFast(r, subModel);
}
} else if (propertyValue->isBoolean()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::Bool);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Bool);
if (r.type == ListLayout::Role::Bool) {
e->setBoolPropertyFast(r, propertyValue->booleanValue());
}
- } else if (QV4::DateObject *dd = propertyValue->asDateObject()) {
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::DateTime);
+ } else if (propertyValue->asDateObject()) {
+ date = propertyValue;
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::DateTime);
if (r.type == ListLayout::Role::DateTime) {
- QDateTime dt = dd->toQDateTime();;
+ QDateTime dt = date->toQDateTime();;
e->setDateTimePropertyFast(r, dt);
}
} else if (propertyValue->isObject()) {
- QV4::ScopedObject o(scope, propertyValue);
+ o = propertyValue;
if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
QObject *o = wrapper->object();
- const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::QObject);
+ const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
if (r.type == ListLayout::Role::QObject)
e->setQObjectPropertyFast(r, o);
} else {
- const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName.getPointer(), ListLayout::Role::VariantMap);
+ const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap);
if (role.type == ListLayout::Role::VariantMap)
e->setVariantMapFast(role, o, eng);
}
} else if (propertyValue->isNullOrUndefined()) {
- const ListLayout::Role *r = m_layout->getExistingRole(propertyName.getPointer());
+ const ListLayout::Role *r = m_layout->getExistingRole(propertyName);
if (r)
e->clearProperty(*r);
}
diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h
index 3b15af2d23..924d89c52d 100644
--- a/src/qml/types/qqmllistmodel_p_p.h
+++ b/src/qml/types/qqmllistmodel_p_p.h
@@ -209,12 +209,12 @@ public:
};
const Role *getRoleOrCreate(const QString &key, const QVariant &data);
- const Role &getRoleOrCreate(const QV4::String *key, Role::DataType type);
+ const Role &getRoleOrCreate(const QV4::StringRef key, Role::DataType type);
const Role &getRoleOrCreate(const QString &key, Role::DataType type);
const Role &getExistingRole(int index) { return *roles.at(index); }
const Role *getExistingRole(const QString &key);
- const Role *getExistingRole(const QV4::String *key);
+ const Role *getExistingRole(const QV4::StringRef key);
int roleCount() const { return roles.count(); }