From 0704d2be63b484cb579c1507223db3f914b1338a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 30 Oct 2014 22:30:01 +0100 Subject: 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 --- src/qml/qml/qqmlcontextwrapper.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/qml/qml/qqmlcontextwrapper.cpp') 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 c(scope, v4->qmlContextObject()->getPointer()->as()); + QV4::Scoped c(scope, v4->qmlContextObject(), QV4::Scoped::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()); QV4::ExecutionEngine *v4 = m->engine(); QV4::Scope scope(v4); - QmlContextWrapper *resource = m->as(); - if (!resource) - return v4->currentContext()->throwTypeError(); + QmlContextWrapper *resource = static_cast(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()); ExecutionEngine *v4 = m->engine(); QV4::Scope scope(v4); if (scope.hasException()) return; - QV4::Scoped wrapper(scope, m->as()); - if (!wrapper) { - v4->currentContext()->throwTypeError(); - return; - } + QV4::Scoped wrapper(scope, static_cast(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 contextWrapper(scope, engine->qmlContextObject()->getPointer()->as()); + QV4::Scoped contextWrapper(scope, engine->qmlContextObject(), QV4::Scoped::Cast); QQmlContextData *qmlContext = contextWrapper->getContext(); const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable(); -- cgit v1.2.3