diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2014-10-30 22:30:01 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-10-31 15:42:42 +0100 |
commit | 0704d2be63b484cb579c1507223db3f914b1338a (patch) | |
tree | 66d4e616545d7f576125e85cc108c7e2988cecdd /src/qml/jsruntime | |
parent | e67948823d6810c2de784859da52a261bf80b550 (diff) |
Get rid of !this and similar constructs
The C++ standard doesn't allow calling member functions
on a mull object. Fix all such places, by moving the checks
to the caller where required.
Change-Id: I10fb22acaf0324d8ffd3a6d8e19152e5d32f56bb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4arraydata.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4arraydata_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4identifier_p.h | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4managed_p.h | 16 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4variantobject.cpp | 4 |
9 files changed, 43 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp index 12254c6384..35bd6e5501 100644 --- a/src/qml/jsruntime/qv4arraydata.cpp +++ b/src/qml/jsruntime/qv4arraydata.cpp @@ -571,21 +571,21 @@ bool SparseArrayData::putArray(Object *o, uint index, Value *values, uint n) uint ArrayData::append(Object *obj, ArrayObject *otherObj, uint n) { - Q_ASSERT(!obj->arrayData()->hasAttributes()); + Q_ASSERT(!obj->arrayData() || !obj->arrayData()->hasAttributes()); if (!n) return obj->getLength(); ArrayData *other = otherObj->arrayData(); - if (other->isSparse()) + if (other && other->isSparse()) obj->initSparseArray(); else obj->arrayCreate(); uint oldSize = obj->getLength(); - if (other->isSparse()) { + if (other && other->isSparse()) { SparseArrayData *os = static_cast<SparseArrayData *>(other); if (otherObj->hasAccessorProperty() && other->hasAttributes()) { Scope scope(obj->engine()); diff --git a/src/qml/jsruntime/qv4arraydata_p.h b/src/qml/jsruntime/qv4arraydata_p.h index c2deb3e385..b69d200665 100644 --- a/src/qml/jsruntime/qv4arraydata_p.h +++ b/src/qml/jsruntime/qv4arraydata_p.h @@ -113,14 +113,14 @@ struct Q_QML_EXPORT ArrayData : public Managed Value *arrayData() { return &d()->arrayData[0]; } const ArrayVTable *vtable() const { return reinterpret_cast<const ArrayVTable *>(internalClass()->vtable); } - bool isSparse() const { return this && type() == Sparse; } + bool isSparse() const { return type() == Sparse; } uint length() const { return vtable()->length(this); } bool hasAttributes() const { - return this && attrs(); + return attrs(); } PropertyAttributes attributes(int i) const { Q_ASSERT(this); diff --git a/src/qml/jsruntime/qv4identifier_p.h b/src/qml/jsruntime/qv4identifier_p.h index 9ca6714b90..afed5c646f 100644 --- a/src/qml/jsruntime/qv4identifier_p.h +++ b/src/qml/jsruntime/qv4identifier_p.h @@ -56,9 +56,9 @@ struct IdentifierHashEntry { int value; void *pointer; }; - int get(int *) const { return this ? value : -1; } - bool get(bool *) const { return this != 0; } - void *get(void **) const { return this ? pointer : 0; } + static int get(const IdentifierHashEntry *This, int *) { return This ? This->value : -1; } + static bool get(const IdentifierHashEntry *This, bool *) { return This != 0; } + static void *get(const IdentifierHashEntry *This, void **) { return This ? This->pointer : 0; } }; struct IdentifierHashData @@ -181,13 +181,13 @@ void IdentifierHash<T>::add(const QString &str, const T &value) template<typename T> inline T IdentifierHash<T>::value(const QString &str) const { - return lookup(str)->get((T*)0); + return IdentifierHashEntry::get(lookup(str), (T*)0); } template<typename T> inline T IdentifierHash<T>::value(String *str) const { - return lookup(str)->get((T*)0); + return IdentifierHashEntry::get(lookup(str), (T*)0); } @@ -197,7 +197,7 @@ QString IdentifierHash<T>::findId(T value) const IdentifierHashEntry *e = d->entries; IdentifierHashEntry *end = e + d->alloc; while (e < end) { - if (e->identifier && e->get((T*)0) == value) + if (e->identifier && IdentifierHashEntry::get(e, (T*)0) == value) return e->identifier->string; ++e; } diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index ce0ee973e8..e679017b7e 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -269,9 +269,7 @@ public: template <typename T> T *as() { - // ### FIXME: - if (!this || !internalClass()) - return 0; + Q_ASSERT(internalClass()); #if !defined(QT_NO_QOBJECT_CHECK) static_cast<T *>(this)->qt_check_for_QMANAGED_macro(static_cast<T *>(this)); #endif @@ -285,9 +283,7 @@ public: } template <typename T> const T *as() const { - // ### FIXME: - if (!this) - return 0; + Q_ASSERT(internalClass()); #if !defined(QT_NO_QOBJECT_CHECK) static_cast<T *>(this)->qt_check_for_QMANAGED_macro(static_cast<T *>(const_cast<Managed *>(this))); #endif @@ -362,23 +358,23 @@ inline Managed *value_cast(const Value &v) { template<typename T> inline T *managed_cast(Managed *m) { - return m->as<T>(); + return m ? m->as<T>() : 0; } template<> inline String *managed_cast(Managed *m) { - return m->asString(); + return m ? m->asString() : 0; } template<> inline Object *managed_cast(Managed *m) { - return m->asObject(); + return m ? m->asObject() : 0; } template<> inline FunctionObject *managed_cast(Managed *m) { - return m->asFunctionObject(); + return m ? m->asFunctionObject() : 0; } } diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 32379f7f1e..f2c30e618f 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -650,9 +650,13 @@ void QObjectWrapper::setProperty(ExecutionContext *ctx, int propertyIndex, const bool QObjectWrapper::isEqualTo(Managed *a, Managed *b) { - QV4::QObjectWrapper *qobjectWrapper = a->as<QV4::QObjectWrapper>(); - if (QV4::QmlTypeWrapper *qmlTypeWrapper = b->asObject()->as<QV4::QmlTypeWrapper>()) - return qmlTypeWrapper->toVariant().value<QObject*>() == qobjectWrapper->object(); + Q_ASSERT(a->as<QV4::QObjectWrapper>()); + QV4::QObjectWrapper *qobjectWrapper = static_cast<QV4::QObjectWrapper *>(a); + QV4::Object *o = b->asObject(); + if (o) { + if (QV4::QmlTypeWrapper *qmlTypeWrapper = o->as<QV4::QmlTypeWrapper>()) + return qmlTypeWrapper->toVariant().value<QObject*>() == qobjectWrapper->object(); + } return false; } diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 048ff935bf..f72f25bd58 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1276,7 +1276,8 @@ ReturnedValue Runtime::regexpLiteral(ExecutionContext *ctx, int id) ReturnedValue Runtime::getQmlIdArray(NoThrowContext *ctx) { - return ctx->engine()->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->idObjectsArray(); + Q_ASSERT(ctx->engine()->qmlContextObject()->getPointer()->as<QmlContextWrapper>()); + return static_cast<QmlContextWrapper *>(ctx->engine()->qmlContextObject()->getPointer())->idObjectsArray(); } ReturnedValue Runtime::getQmlContextObject(NoThrowContext *ctx) @@ -1290,7 +1291,7 @@ ReturnedValue Runtime::getQmlContextObject(NoThrowContext *ctx) ReturnedValue Runtime::getQmlScopeObject(NoThrowContext *ctx) { Scope scope(ctx); - QV4::Scoped<QmlContextWrapper> c(scope, ctx->engine()->qmlContextObject()->getPointer()->as<QmlContextWrapper>()); + QV4::Scoped<QmlContextWrapper> c(scope, ctx->engine()->qmlContextObject(), Scoped<QmlContextWrapper>::Cast); return QObjectWrapper::wrap(ctx->d()->engine, c->getScopeObject()); } @@ -1308,7 +1309,7 @@ ReturnedValue Runtime::getQmlQObjectProperty(ExecutionContext *ctx, const ValueR QV4::ReturnedValue Runtime::getQmlAttachedProperty(ExecutionContext *ctx, int attachedPropertiesId, int propertyIndex) { Scope scope(ctx); - QV4::Scoped<QmlContextWrapper> c(scope, ctx->engine()->qmlContextObject()->getPointer()->as<QmlContextWrapper>()); + QV4::Scoped<QmlContextWrapper> c(scope, ctx->engine()->qmlContextObject(), Scoped<QmlContextWrapper>::Cast); QObject *scopeObject = c->getScopeObject(); QObject *attachedObject = qmlAttachedPropertiesObjectById(attachedPropertiesId, scopeObject); @@ -1349,7 +1350,7 @@ ReturnedValue Runtime::getQmlImportedScripts(NoThrowContext *ctx) QV4::ReturnedValue Runtime::getQmlSingleton(QV4::NoThrowContext *ctx, String *name) { - return ctx->engine()->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->qmlSingletonWrapper(ctx->engine()->v8Engine, name); + return static_cast<QmlContextWrapper *>(ctx->engine()->qmlContextObject()->getPointer())->qmlSingletonWrapper(ctx->engine()->v8Engine, name); } void Runtime::convertThisToObject(ExecutionContext *ctx) diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 9e9a6e60c9..b1b4d5da8d 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -288,6 +288,16 @@ struct Scoped #endif } + template<typename X> + Scoped(const Scope &scope, Returned<X> *x, _Cast) + { + ptr = scope.engine->jsStackTop++; + setPointer(managed_cast<T>(x->getPointer())); +#ifndef QT_NO_DEBUG + ++scope.size; +#endif + } + Scoped(const Scope &scope, const ReturnedValue &v) { ptr = scope.engine->jsStackTop++; diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index a45f4cabc5..7a0a643a7e 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -331,6 +331,8 @@ public: bool containerIsEqualTo(Managed *other) { + if (!other) + return false; QQmlSequence<Container> *otherSequence = other->as<QQmlSequence<Container> >(); if (!otherSequence) return false; diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp index 68b08fb3ca..3cde96992e 100644 --- a/src/qml/jsruntime/qv4variantobject.cpp +++ b/src/qml/jsruntime/qv4variantobject.cpp @@ -92,8 +92,8 @@ void VariantObject::destroy(Managed *that) bool VariantObject::isEqualTo(Managed *m, Managed *other) { - QV4::VariantObject *lv = m->as<QV4::VariantObject>(); - assert(lv); + Q_ASSERT(m->as<QV4::VariantObject>()); + QV4::VariantObject *lv = static_cast<QV4::VariantObject *>(m); if (QV4::VariantObject *rv = other->as<QV4::VariantObject>()) return lv->d()->data == rv->d()->data; |