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/qml/jsruntime/qv4engine.cpp | |
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/qml/jsruntime/qv4engine.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 21 |
1 files changed, 21 insertions, 0 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(); |