diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp index 56e78be2d2c3bbf59c7b936c771c6bf61e9bb490..61863631be8d8f2178aace0500c6f233dd0eddfe 100644 --- a/src/libs/qmljs/qmljsbind.cpp +++ b/src/libs/qmljs/qmljsbind.cpp @@ -35,8 +35,10 @@ using namespace QmlJS; using namespace QmlJS::AST; using namespace QmlJS::Interpreter; -Bind::Bind(Interpreter::Engine *interp) - : _interp(interp), +Bind::Bind(Document::Ptr doc, const Snapshot &snapshot, Interpreter::Engine *interp) + : _doc(doc), + _snapshot(snapshot), + _interp(interp), _interestingMember(0), _currentObjectValue(0), _typeEnvironment(0), @@ -50,14 +52,12 @@ Bind::~Bind() { } -Interpreter::ObjectValue *Bind::operator()(Document::Ptr doc, const Snapshot &snapshot, UiObjectMember *member) +Interpreter::ObjectValue *Bind::operator()(UiObjectMember *member) { - UiProgram *program = doc->qmlProgram(); + UiProgram *program = _doc->qmlProgram(); if (!program) return 0; - _doc = doc; - _snapshot = snapshot; _interestingMember = member; _currentObjectValue = 0; @@ -128,10 +128,13 @@ bool Bind::visit(UiImport *ast) ObjectValue *namespaceObject; if (ast->asToken.isValid()) { // with namespace we insert an object in the type env. to hold the imported types - namespaceObject = _interp->newObject(0); + namespaceObject = _interp->newObject(/*prototype */ 0); + if (!ast->importId) return false; // this should never happen, but better be safe than sorry + _typeEnvironment->setProperty(ast->importId->asString(), namespaceObject); + } else { // without namespace we insert all types directly into the type env. namespaceObject = _typeEnvironment; } @@ -148,7 +151,7 @@ bool Bind::visit(UiImport *ast) if (ast->versionToken.isValid()) { const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length); - int dotIdx = versionString.indexOf('.'); + const int dotIdx = versionString.indexOf(QLatin1Char('.')); if (dotIdx == -1) { // only major (which is probably invalid, but let's handle it anyway) majorVersion = versionString.toInt(); diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h index df59c45d5fc2dfb55e24abda6d6e7ebb07cbd6e8..2eb017126811e7d48b37d527d4a1f7b7e34cd8a0 100644 --- a/src/libs/qmljs/qmljsbind.h +++ b/src/libs/qmljs/qmljsbind.h @@ -39,10 +39,10 @@ namespace QmlJS { class QMLJS_EXPORT Bind: protected AST::Visitor { public: - Bind(Interpreter::Engine *interp); + Bind(Document::Ptr doc, const Snapshot &snapshot, Interpreter::Engine *interp); virtual ~Bind(); - Interpreter::ObjectValue* operator()(Document::Ptr doc, const Snapshot &snapshot, AST::UiObjectMember *member); + Interpreter::ObjectValue* operator()(AST::UiObjectMember *member); protected: void accept(AST::Node *node); diff --git a/src/libs/qmljs/qmljsmetatypesystem.cpp b/src/libs/qmljs/qmljsmetatypesystem.cpp index 03e39bc704f964e3a350012012f504e2e309322f..09c223b29f4bcdb1c69d25f0dc7b9a02218ecc6f 100644 --- a/src/libs/qmljs/qmljsmetatypesystem.cpp +++ b/src/libs/qmljs/qmljsmetatypesystem.cpp @@ -63,7 +63,7 @@ QList<QmlObjectValue *> MetaTypeSystem::staticTypesForImport(const QString &pref { QMap<QString, QmlObjectValue *> objectValuesByName; - foreach (QmlObjectValue *qmlObjectValue, _importedTypes[prefix]) { + foreach (QmlObjectValue *qmlObjectValue, _importedTypes.value(prefix)) { if (qmlObjectValue->majorVersion() < majorVersion || (qmlObjectValue->majorVersion() == majorVersion && qmlObjectValue->minorVersion() <= minorVersion)) { // we got a candidate. diff --git a/src/plugins/qmljseditor/qmlcodecompletion.cpp b/src/plugins/qmljseditor/qmlcodecompletion.cpp index dfd8f3adabdb722212d0a63610220824a182cbb2..e844d179e22a45fe186ad9042a3094600575efe1 100644 --- a/src/plugins/qmljseditor/qmlcodecompletion.cpp +++ b/src/plugins/qmljseditor/qmlcodecompletion.cpp @@ -821,8 +821,8 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) scope->setProperty(QLatin1String("parent"), parentItem); #endif - Bind bind(&interp); - scope = bind(qmlDocument, snapshot, declaringMember); + Bind bind(qmlDocument, snapshot, &interp); + scope = bind(declaringMember); } // Search for the operator that triggered the completion.