Move the qmlSingletonWrapper method out of the contextwrapper
authorLars Knoll <lars.knoll@theqtcompany.com>
Wed, 12 Aug 2015 12:14:40 +0000 (14:14 +0200)
committerLars Knoll <lars.knoll@theqtcompany.com>
Thu, 20 Aug 2015 20:01:25 +0000 (20:01 +0000)
One more step towards removing the class alltogether.

Change-Id: Ic9f6794eb3c5c6605ee43ad23a6d432ebbf321a1
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4engine_p.h
src/qml/jsruntime/qv4runtime.cpp
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/qqmlcontextwrapper_p.h

index 7424dc4..caf07e8 100644 (file)
@@ -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();
index 9f44745..90564a9 100644 (file)
@@ -390,6 +390,7 @@ public:
     Heap::QmlContext *qmlContext() const;
     QV4::Heap::QmlContextWrapper *qmlContextObject() const;
     QObject *qmlScopeObject() const;
+    ReturnedValue qmlSingletonWrapper(String *name);
     QQmlContextData *callingQmlContext() const;
 
 
index b8ea6d7..9316223 100644 (file)
@@ -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)
index be06c59..4fee3d8 100644 (file)
@@ -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
index d7a4a10..cbba35f 100644 (file)
@@ -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);
 };
 
 }