From 88601712c6c480ab4876eaf7756f0bc8c3f66548 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Mon, 30 Aug 2010 14:12:06 +0200
Subject: [PATCH] QmlJS: Make ScopeChain more const-correct.

We don't want people modifying the shared component chain on a
const Context *.
---
 src/libs/qmljs/qmljsinterpreter.cpp | 10 +++++-----
 src/libs/qmljs/qmljsinterpreter.h   |  6 +++---
 src/libs/qmljs/qmljslink.cpp        |  9 +++++----
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index eedcf519e8b..ddf0ed993bc 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -1370,10 +1370,10 @@ void ScopeChain::QmlComponentChain::clear()
     document = Document::Ptr(0);
 }
 
-void ScopeChain::QmlComponentChain::add(QList<const ObjectValue *> *list) const
+void ScopeChain::QmlComponentChain::collect(QList<const ObjectValue *> *list) const
 {
-    foreach (QmlComponentChain *parent, instantiatingComponents)
-        parent->add(list);
+    foreach (const QmlComponentChain *parent, instantiatingComponents)
+        parent->collect(list);
 
     if (!document)
         return;
@@ -1393,8 +1393,8 @@ void ScopeChain::update()
     // the root scope in js files doesn't see instantiating components
     if (jsScopes.count() != 1 || !qmlScopeObjects.isEmpty()) {
         if (qmlComponentScope) {
-            foreach (QmlComponentChain *parent, qmlComponentScope->instantiatingComponents)
-                parent->add(&_all);
+            foreach (const QmlComponentChain *parent, qmlComponentScope->instantiatingComponents)
+                parent->collect(&_all);
         }
     }
 
diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h
index 67222cd3b02..208ed034e00 100644
--- a/src/libs/qmljs/qmljsinterpreter.h
+++ b/src/libs/qmljs/qmljsinterpreter.h
@@ -249,15 +249,15 @@ public:
         QmlComponentChain();
         ~QmlComponentChain();
 
-        QList<QmlComponentChain *> instantiatingComponents;
+        QList<const QmlComponentChain *> instantiatingComponents;
         Document::Ptr document;
 
-        void add(QList<const ObjectValue *> *list) const;
+        void collect(QList<const ObjectValue *> *list) const;
         void clear();
     };
 
     const ObjectValue *globalScope;
-    QSharedPointer<QmlComponentChain> qmlComponentScope;
+    QSharedPointer<const QmlComponentChain> qmlComponentScope;
     QList<const ObjectValue *> qmlScopeObjects;
     const ObjectValue *qmlTypes;
     QList<const ObjectValue *> jsScopes;
diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp
index ffc8edf3804..71ed751a9e3 100644
--- a/src/libs/qmljs/qmljslink.cpp
+++ b/src/libs/qmljs/qmljslink.cpp
@@ -83,10 +83,11 @@ void Link::initializeScopeChain()
     Bind *bind = _doc->bind();
     QHash<Document *, ScopeChain::QmlComponentChain *> componentScopes;
 
-    scopeChain.qmlComponentScope = QSharedPointer<ScopeChain::QmlComponentChain>(new ScopeChain::QmlComponentChain());
+    ScopeChain::QmlComponentChain *chain = new ScopeChain::QmlComponentChain;
+    scopeChain.qmlComponentScope = QSharedPointer<const ScopeChain::QmlComponentChain>(chain);
     if (_doc->qmlProgram()) {
-        componentScopes.insert(_doc.data(), scopeChain.qmlComponentScope.data());
-        makeComponentChain(_doc, scopeChain.qmlComponentScope.data(), &componentScopes);
+        componentScopes.insert(_doc.data(), chain);
+        makeComponentChain(_doc, chain, &componentScopes);
 
         if (const ObjectValue *typeEnvironment = _context->typeEnvironment(_doc.data()))
             scopeChain.qmlTypes = typeEnvironment;
@@ -97,7 +98,7 @@ void Link::initializeScopeChain()
                 if (_doc->fileName() == fileImport.name) {
                     ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain;
                     componentScopes.insert(otherDoc.data(), component);
-                    scopeChain.qmlComponentScope->instantiatingComponents += component;
+                    chain->instantiatingComponents += component;
                     makeComponentChain(otherDoc, component, &componentScopes);
                 }
             }
-- 
GitLab