aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2014-10-30 22:30:01 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-10-31 15:42:42 +0100
commit0704d2be63b484cb579c1507223db3f914b1338a (patch)
tree66d4e616545d7f576125e85cc108c7e2988cecdd /src/qml/qml
parente67948823d6810c2de784859da52a261bf80b550 (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/qml')
-rw-r--r--src/qml/qml/qqmlbinding.cpp3
-rw-r--r--src/qml/qml/qqmlcomponent.cpp6
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp16
-rw-r--r--src/qml/qml/qqmllistwrapper.cpp24
-rw-r--r--src/qml/qml/qqmllocale_p.h3
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp19
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp27
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp28
8 files changed, 52 insertions, 74 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 6033395629..7babcd2f4e 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -171,7 +171,8 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags)
QV4::ScopedFunctionObject f(scope, v4function.value());
Q_ASSERT(f);
if (f->bindingKeyFlag()) {
- QQmlSourceLocation loc = f->as<QV4::QQmlBindingFunction>()->d()->bindingLocation;
+ Q_ASSERT(f->as<QV4::QQmlBindingFunction>());
+ QQmlSourceLocation loc = static_cast<QV4::QQmlBindingFunction *>(f.getPointer())->d()->bindingLocation;
url = loc.sourceFile;
lineNumber = loc.line;
columnNumber = loc.column;
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index c772e16ca9..63a43966b1 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -1500,13 +1500,13 @@ void QmlIncubatorObject::setInitialState(QObject *o)
void QmlIncubatorObject::destroy(Managed *that)
{
- that->as<QmlIncubatorObject>()->d()->~Data();
+ static_cast<QmlIncubatorObject *>(that)->d()->~Data();
}
void QmlIncubatorObject::markObjects(QV4::Managed *that, QV4::ExecutionEngine *e)
{
- QmlIncubatorObject *o = that->as<QmlIncubatorObject>();
- Q_ASSERT(o);
+ QmlIncubatorObject *o = static_cast<QmlIncubatorObject *>(that);
+ Q_ASSERT(that->as<QmlIncubatorObject>());
o->d()->valuemap.mark(e);
o->d()->qmlGlobal.mark(e);
o->d()->statusChanged.mark(e);
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index e78f9cf7a4..0816bc05df 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -97,7 +97,7 @@ ReturnedValue QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url)
QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4)
{
Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, v4->qmlContextObject()->getPointer()->as<QmlContextWrapper>());
+ QV4::Scoped<QmlContextWrapper> c(scope, v4->qmlContextObject(), QV4::Scoped<QmlContextWrapper>::Cast);
return !!c ? c->getContext() : 0;
}
@@ -128,11 +128,10 @@ void QmlContextWrapper::takeContextOwnership(const ValueRef qmlglobal)
ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
{
+ Q_ASSERT(m->as<QmlContextWrapper>());
QV4::ExecutionEngine *v4 = m->engine();
QV4::Scope scope(v4);
- QmlContextWrapper *resource = m->as<QmlContextWrapper>();
- if (!resource)
- return v4->currentContext()->throwTypeError();
+ QmlContextWrapper *resource = static_cast<QmlContextWrapper *>(m);
// In V8 the JS global object would come _before_ the QML global object,
// so simulate that here.
@@ -273,15 +272,12 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty
void QmlContextWrapper::put(Managed *m, String *name, const ValueRef value)
{
+ Q_ASSERT(m->as<QmlContextWrapper>());
ExecutionEngine *v4 = m->engine();
QV4::Scope scope(v4);
if (scope.hasException())
return;
- QV4::Scoped<QmlContextWrapper> wrapper(scope, m->as<QmlContextWrapper>());
- if (!wrapper) {
- v4->currentContext()->throwTypeError();
- return;
- }
+ QV4::Scoped<QmlContextWrapper> wrapper(scope, static_cast<QmlContextWrapper *>(m));
PropertyAttributes attrs;
Property *pd = wrapper->__getOwnProperty__(name, &attrs);
@@ -372,7 +368,7 @@ void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const C
return;
QV4::Scope scope(engine);
- QV4::Scoped<QmlContextWrapper> contextWrapper(scope, engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>());
+ QV4::Scoped<QmlContextWrapper> contextWrapper(scope, engine->qmlContextObject(), QV4::Scoped<QmlContextWrapper>::Cast);
QQmlContextData *qmlContext = contextWrapper->getContext();
const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp
index 9a51767ef1..13e5e49b55 100644
--- a/src/qml/qml/qqmllistwrapper.cpp
+++ b/src/qml/qml/qqmllistwrapper.cpp
@@ -98,10 +98,9 @@ QVariant QmlListWrapper::toVariant() const
ReturnedValue QmlListWrapper::get(Managed *m, String *name, bool *hasProperty)
{
+ Q_ASSERT(m->as<QmlListWrapper>());
QV4::ExecutionEngine *v4 = m->engine();
- QmlListWrapper *w = m->as<QmlListWrapper>();
- if (!w)
- return v4->currentContext()->throwTypeError();
+ QmlListWrapper *w = static_cast<QmlListWrapper *>(m);
if (name->equals(v4->id_length) && !w->d()->object.isNull()) {
quint32 count = w->d()->property.count ? w->d()->property.count(&w->d()->property) : 0;
@@ -119,19 +118,15 @@ ReturnedValue QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProper
{
Q_UNUSED(hasProperty);
- QV4::ExecutionEngine *e = m->engine();
- QmlListWrapper *w = m->as<QmlListWrapper>();
- if (!w) {
- if (hasProperty)
- *hasProperty = false;
- return e->currentContext()->throwTypeError();
- }
+ Q_ASSERT(m->as<QmlListWrapper>());
+ QV4::ExecutionEngine *v4 = m->engine();
+ QmlListWrapper *w = static_cast<QmlListWrapper *>(m);
quint32 count = w->d()->property.count ? w->d()->property.count(&w->d()->property) : 0;
if (index < count && w->d()->property.at) {
if (hasProperty)
*hasProperty = true;
- return QV4::QObjectWrapper::wrap(e, w->d()->property.at(&w->d()->property, index));
+ return QV4::QObjectWrapper::wrap(v4, w->d()->property.at(&w->d()->property, index));
}
if (hasProperty)
@@ -149,15 +144,16 @@ void QmlListWrapper::put(Managed *m, String *name, const ValueRef value)
void QmlListWrapper::destroy(Managed *that)
{
- QmlListWrapper *w = that->as<QmlListWrapper>();
- w->d()->~Data();
+ Q_ASSERT(that->as<QmlListWrapper>());
+ static_cast<QmlListWrapper *>(that)->d()->~Data();
}
void QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, String *&name, uint *index, Property *p, PropertyAttributes *attrs)
{
name = (String *)0;
*index = UINT_MAX;
- QmlListWrapper *w = m->as<QmlListWrapper>();
+ Q_ASSERT(m->as<QmlListWrapper>());
+ QmlListWrapper *w = static_cast<QmlListWrapper *>(m);
quint32 count = w->d()->property.count ? w->d()->property.count(&w->d()->property) : 0;
if (it->arrayIndex < count) {
*index = it->arrayIndex;
diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h
index 24cb3a8c42..a29b86fbea 100644
--- a/src/qml/qml/qqmllocale_p.h
+++ b/src/qml/qml/qqmllocale_p.h
@@ -134,7 +134,8 @@ struct QQmlLocaleData : public QV4::Object
V4_OBJECT(Object)
static QLocale *getThisLocale(QV4::CallContext *ctx) {
- QQmlLocaleData *thisObject = ctx->d()->callData->thisObject.asObject()->as<QQmlLocaleData>();
+ QV4::Object *o = ctx->d()->callData->thisObject.asObject();
+ QQmlLocaleData *thisObject = o ? o->as<QQmlLocaleData>() : 0;
if (!thisObject) {
ctx->throwTypeError();
return 0;
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index 627b701512..d8f282c030 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -125,13 +125,12 @@ ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCach
ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
{
+ Q_ASSERT(m->as<QmlTypeWrapper>());
+
QV4::ExecutionEngine *v4 = m->engine();
QV4::Scope scope(v4);
- Scoped<QmlTypeWrapper> w(scope, m->as<QmlTypeWrapper>());
- if (!w)
- return v4->currentContext()->throwTypeError();
-
+ Scoped<QmlTypeWrapper> w(scope, static_cast<QmlTypeWrapper *>(m));
if (hasProperty)
*hasProperty = true;
@@ -235,14 +234,11 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
void QmlTypeWrapper::put(Managed *m, String *name, const ValueRef value)
{
- QmlTypeWrapper *w = m->as<QmlTypeWrapper>();
+ Q_ASSERT(m->as<QmlTypeWrapper>());
+ QmlTypeWrapper *w = static_cast<QmlTypeWrapper *>(m);
QV4::ExecutionEngine *v4 = m->engine();
if (v4->hasException)
return;
- if (!w) {
- v4->currentContext()->throwTypeError();
- return;
- }
QV4::Scope scope(v4);
QV8Engine *v8engine = v4->v8Engine;
@@ -290,8 +286,9 @@ void QmlTypeWrapper::destroy(Managed *that)
bool QmlTypeWrapper::isEqualTo(Managed *a, Managed *b)
{
- QV4::QmlTypeWrapper *qmlTypeWrapperA = a->asObject()->as<QV4::QmlTypeWrapper>();
- if (QV4::QmlTypeWrapper *qmlTypeWrapperB = b->asObject()->as<QV4::QmlTypeWrapper>())
+ Q_ASSERT(a->as<QV4::QmlTypeWrapper>());
+ QV4::QmlTypeWrapper *qmlTypeWrapperA = static_cast<QV4::QmlTypeWrapper *>(a);
+ if (QV4::QmlTypeWrapper *qmlTypeWrapperB = b->as<QV4::QmlTypeWrapper>())
return qmlTypeWrapperA->toVariant() == qmlTypeWrapperB->toVariant();
else if (QV4::QObjectWrapper *qobjectWrapper = b->as<QV4::QObjectWrapper>())
return qmlTypeWrapperA->toVariant().value<QObject*>() == qobjectWrapper->object();
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 0599745d95..b0125b4c13 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -180,7 +180,8 @@ QVariant QmlValueTypeWrapper::toVariant() const
void QmlValueTypeWrapper::destroy(Managed *that)
{
- QmlValueTypeWrapper *w = that->as<QmlValueTypeWrapper>();
+ Q_ASSERT(that->as<QmlValueTypeWrapper>());
+ QmlValueTypeWrapper *w = static_cast<QmlValueTypeWrapper *>(that);
if (w->d()->objectType == Reference)
static_cast<QmlValueTypeReference *>(w)->d()->~Data();
else
@@ -189,8 +190,8 @@ void QmlValueTypeWrapper::destroy(Managed *that)
bool QmlValueTypeWrapper::isEqualTo(Managed *m, Managed *other)
{
- QV4::QmlValueTypeWrapper *lv = m->as<QmlValueTypeWrapper>();
- Q_ASSERT(lv);
+ Q_ASSERT(m && m->as<QmlValueTypeWrapper>() && other);
+ QV4::QmlValueTypeWrapper *lv = static_cast<QmlValueTypeWrapper *>(m);
if (QV4::VariantObject *rv = other->as<VariantObject>())
return lv->isEqual(rv->d()->data);
@@ -203,12 +204,8 @@ bool QmlValueTypeWrapper::isEqualTo(Managed *m, Managed *other)
PropertyAttributes QmlValueTypeWrapper::query(const Managed *m, String *name)
{
- const QmlValueTypeWrapper *r = m->as<const QmlValueTypeWrapper>();
- QV4::ExecutionEngine *v4 = m->engine();
- if (!r) {
- v4->currentContext()->throwTypeError();
- return PropertyAttributes();
- }
+ Q_ASSERT(m->as<const QmlValueTypeWrapper>());
+ const QmlValueTypeWrapper *r = static_cast<const QmlValueTypeWrapper *>(m);
QQmlPropertyData local;
QQmlPropertyData *result = 0;
@@ -267,10 +264,9 @@ ReturnedValue QmlValueTypeWrapper::method_toString(CallContext *ctx)
ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
{
- QmlValueTypeWrapper *r = m->as<QmlValueTypeWrapper>();
+ Q_ASSERT(m->as<QmlValueTypeWrapper>());
+ QmlValueTypeWrapper *r = static_cast<QmlValueTypeWrapper *>(m);
QV4::ExecutionEngine *v4 = m->engine();
- if (!r)
- return v4->currentContext()->throwTypeError();
// Note: readReferenceValue() can change the reference->type.
if (r->d()->objectType == QmlValueTypeWrapper::Reference) {
@@ -329,16 +325,13 @@ ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProper
void QmlValueTypeWrapper::put(Managed *m, String *name, const ValueRef value)
{
+ Q_ASSERT(m->as<QmlValueTypeWrapper>());
ExecutionEngine *v4 = m->engine();
Scope scope(v4);
if (scope.hasException())
return;
- Scoped<QmlValueTypeWrapper> r(scope, m->as<QmlValueTypeWrapper>());
- if (!r) {
- v4->currentContext()->throwTypeError();
- return;
- }
+ Scoped<QmlValueTypeWrapper> r(scope, static_cast<QmlValueTypeWrapper *>(m));
QByteArray propName = name->toQString().toUtf8();
if (r->d()->objectType == QmlValueTypeWrapper::Reference) {
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index e374e471e3..0730cbc363 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -203,7 +203,7 @@ public:
// JS API
static void destroy(Managed *that) {
- that->as<NamedNodeMap>()->d()->~Data();
+ static_cast<NamedNodeMap *>(that)->d()->~Data();
}
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
@@ -234,7 +234,7 @@ public:
// JS API
static void destroy(Managed *that) {
- that->as<NodeList>()->d()->~Data();
+ static_cast<NodeList *>(that)->d()->~Data();
}
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
@@ -324,7 +324,7 @@ struct Node : public Object
// JS API
static void destroy(Managed *that) {
- that->as<Node>()->d()->~Data();
+ static_cast<Node *>(that)->d()->~Data();
}
// C++ API
@@ -916,10 +916,9 @@ ReturnedValue NamedNodeMap::getIndexed(Managed *m, uint index, bool *hasProperty
ReturnedValue NamedNodeMap::get(Managed *m, String *name, bool *hasProperty)
{
- NamedNodeMap *r = m->as<NamedNodeMap>();
+ Q_ASSERT(m->as<NamedNodeMap>());
+ NamedNodeMap *r = static_cast<NamedNodeMap *>(m);
QV4::ExecutionEngine *v4 = m->engine();
- if (!r)
- return v4->currentContext()->throwTypeError();
name->makeIdentifier();
if (name->equals(v4->id_length))
@@ -949,13 +948,9 @@ ReturnedValue NamedNodeMap::create(QV8Engine *engine, NodeImpl *data, const QLis
ReturnedValue NodeList::getIndexed(Managed *m, uint index, bool *hasProperty)
{
+ Q_ASSERT(m->as<NodeList>());
QV4::ExecutionEngine *v4 = m->engine();
- NodeList *r = m->as<NodeList>();
- if (!r) {
- if (hasProperty)
- *hasProperty = false;
- return v4->currentContext()->throwTypeError();
- }
+ NodeList *r = static_cast<NodeList *>(m);
QV8Engine *engine = v4->v8Engine;
@@ -971,10 +966,9 @@ ReturnedValue NodeList::getIndexed(Managed *m, uint index, bool *hasProperty)
ReturnedValue NodeList::get(Managed *m, String *name, bool *hasProperty)
{
+ Q_ASSERT(m->as<NodeList>());
QV4::ExecutionEngine *v4 = m->engine();
- NodeList *r = m->as<NodeList>();
- if (!r)
- return v4->currentContext()->throwTypeError();
+ NodeList *r = static_cast<NodeList *>(m);
name->makeIdentifier();
@@ -1608,7 +1602,7 @@ struct QQmlXMLHttpRequestWrapper : public Object
V4_OBJECT(Object)
static void destroy(Managed *that) {
- that->as<QQmlXMLHttpRequestWrapper>()->d()->~Data();
+ static_cast<QQmlXMLHttpRequestWrapper *>(that)->d()->~Data();
}
};
@@ -1638,7 +1632,7 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject
};
V4_OBJECT(FunctionObject)
static void markObjects(Managed *that, ExecutionEngine *e) {
- QQmlXMLHttpRequestCtor *c = that->as<QQmlXMLHttpRequestCtor>();
+ QQmlXMLHttpRequestCtor *c = static_cast<QQmlXMLHttpRequestCtor *>(that);
if (c->d()->proto)
c->d()->proto->mark(e);
FunctionObject::markObjects(that, e);