diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-12 14:14:40 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-20 20:01:25 +0000 |
commit | ad55f5fd249296de8871545f6d4cf463bd5ed1c9 (patch) | |
tree | e00145261f0b2825f382405c044929c0717a0163 /src | |
parent | 04d3a95dea37cbc79348147eebac9916cc8b4c79 (diff) |
Move the qmlSingletonWrapper method out of the contextwrapper
One more step towards removing the class alltogether.
Change-Id: Ic9f6794eb3c5c6605ee43ad23a6d432ebbf321a1
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 21 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 21 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper_p.h | 2 |
5 files changed, 23 insertions, 25 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 7424dc4e4c..caf07e8b0b 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -759,6 +759,27 @@ QObject *ExecutionEngine::qmlScopeObject() const return qmlContextObject()->scopeObject; } +ReturnedValue ExecutionEngine::qmlSingletonWrapper(String *name) +{ + QQmlContextData *ctx = callingQmlContext(); + if (!ctx->imports) + return Encode::undefined(); + // Search for attached properties, enums and imported scripts + QQmlTypeNameCache::Result r = ctx->imports->query(name); + + Q_ASSERT(r.isValid()); + Q_ASSERT(r.type); + Q_ASSERT(r.type->isSingleton()); + + QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); + QQmlEngine *e = qmlEngine(); + siinfo->init(e); + + if (QObject *qobjectSingleton = siinfo->qobjectApi(e)) + return QV4::QObjectWrapper::wrap(this, qobjectSingleton); + return QJSValuePrivate::convertedToValue(this, siinfo->scriptApi(e)); +} + QQmlContextData *ExecutionEngine::callingQmlContext() const { Heap::QmlContextWrapper *w = qmlContextObject(); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 9f44745e4c..90564a9652 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -390,6 +390,7 @@ public: Heap::QmlContext *qmlContext() const; QV4::Heap::QmlContextWrapper *qmlContextObject() const; QObject *qmlScopeObject() const; + ReturnedValue qmlSingletonWrapper(String *name); QQmlContextData *callingQmlContext() const; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index b8ea6d7a87..9316223696 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1460,8 +1460,7 @@ QV4::ReturnedValue Runtime::getQmlSingleton(QV4::NoThrowEngine *engine, int name { Scope scope(engine); ScopedString name(scope, engine->currentContext()->compilationUnit->runtimeStrings[nameIndex]); - Scoped<QmlContextWrapper> wrapper(scope, engine->qmlContextObject()); - return wrapper->qmlSingletonWrapper(engine, name); + return engine->qmlSingletonWrapper(name); } void Runtime::convertThisToObject(ExecutionEngine *engine) diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index be06c596c2..4fee3d8fef 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -323,25 +323,4 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value) Object::put(m, name, value); } -ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name) -{ - if (!d()->context->imports) - return Encode::undefined(); - // Search for attached properties, enums and imported scripts - QQmlTypeNameCache::Result r = d()->context->imports->query(name); - - Q_ASSERT(r.isValid()); - Q_ASSERT(r.type); - Q_ASSERT(r.type->isSingleton()); - Q_ASSERT(v4); - - QQmlEngine *e = v4->qmlEngine(); - QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); - siinfo->init(e); - - if (QObject *qobjectSingleton = siinfo->qobjectApi(e)) - return QV4::QObjectWrapper::wrap(engine(), qobjectSingleton); - return QJSValuePrivate::convertedToValue(engine(), siinfo->scriptApi(e)); -} - QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index d7a4a10468..cbba35f5d1 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -98,8 +98,6 @@ struct Q_QML_EXPORT QmlContextWrapper : Object static ReturnedValue get(const Managed *m, String *name, bool *hasProperty); static void put(Managed *m, String *name, const Value &value); - - ReturnedValue qmlSingletonWrapper(ExecutionEngine *e, String *name); }; } |