diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-09-17 17:23:49 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 14:26:59 +0200 |
commit | c5a8d5b331352e9a1a0a4be7571add641b22238c (patch) | |
tree | 10619b0b49fd1df82437a93147282daf01c3f193 /src/qml/compiler | |
parent | 9702c226edbb58aede140af91b13136b7cd810d8 (diff) |
[new compiler] Improve error handling and sanity checking for object ids
Disallow properties called id.foo.bar as well as id: Object {}
Change-Id: I3e31875a5863b5b4d4f9f7dd6c74d337eea3dfb2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 27 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 2 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 1739d2c22b..f3a9b0213d 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -219,7 +219,10 @@ bool QQmlCodeGenerator::visit(AST::UiScriptBinding *node) bool QQmlCodeGenerator::visit(AST::UiArrayBinding *node) { QmlObject *object = 0; - AST::UiQualifiedId *name = resolveQualifiedId(node->qualifiedId, &object); + AST::UiQualifiedId *name = node->qualifiedId; + if (!resolveQualifiedId(&name, &object)) + return false; + qSwap(_object, object); AST::UiArrayMemberList *member = node->members; @@ -729,7 +732,8 @@ void QQmlCodeGenerator::setBindingValue(QV4::CompiledData::Binding *binding, AST void QQmlCodeGenerator::appendBinding(AST::UiQualifiedId *name, AST::Statement *value) { QmlObject *object = 0; - name = resolveQualifiedId(name, &object); + if (!resolveQualifiedId(&name, &object)) + return; qSwap(_object, object); appendBinding(name->identifierToken, registerString(name->name.toString()), value); qSwap(_object, object); @@ -738,7 +742,8 @@ void QQmlCodeGenerator::appendBinding(AST::UiQualifiedId *name, AST::Statement * void QQmlCodeGenerator::appendBinding(AST::UiQualifiedId *name, int objectIndex) { QmlObject *object = 0; - name = resolveQualifiedId(name, &object); + if (!resolveQualifiedId(&name, &object)) + return; qSwap(_object, object); appendBinding(name->identifierToken, registerString(name->name.toString()), objectIndex); qSwap(_object, object); @@ -767,6 +772,12 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, i { if (!sanityCheckPropertyName(nameLocation, propertyNameIndex, isListItem)) return; + + if (stringAt(propertyNameIndex) == QStringLiteral("id")) { + recordError(nameLocation, tr("Invalid component id specification")); + return; + } + Binding *binding = New<Binding>(); binding->propertyNameIndex = propertyNameIndex; binding->location.line = nameLocation.startLine; @@ -820,8 +831,13 @@ bool QQmlCodeGenerator::setId(AST::Statement *value) return true; } -AST::UiQualifiedId *QQmlCodeGenerator::resolveQualifiedId(AST::UiQualifiedId *name, QmlObject **object) +bool QQmlCodeGenerator::resolveQualifiedId(AST::UiQualifiedId **nameToResolve, QmlObject **object) { + AST::UiQualifiedId *name = *nameToResolve; + + if (name->name == QStringLiteral("id") && name->next) + COMPILE_EXCEPTION(name->identifierToken, tr( "Invalid use of id property")); + *object = _object; while (name->next) { Binding *binding = New<Binding>(); @@ -843,7 +859,8 @@ AST::UiQualifiedId *QQmlCodeGenerator::resolveQualifiedId(AST::UiQualifiedId *na name = name->next; } - return name; + *nameToResolve = name; + return true; } bool QQmlCodeGenerator::sanityCheckPropertyName(const AST::SourceLocation &nameLocation, int nameIndex, bool isListItem) diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 4562e88d34..0fecd84684 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -230,7 +230,7 @@ public: // resolves qualified name (font.pixelSize for example) and returns the last name along // with the object any right-hand-side of a binding should apply to. - AST::UiQualifiedId *resolveQualifiedId(AST::UiQualifiedId *name, QmlObject **object); + bool resolveQualifiedId(AST::UiQualifiedId **nameToResolve, QmlObject **object); bool sanityCheckPropertyName(const AST::SourceLocation &nameLocation, int nameIndex, bool isListItem = false); |