aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-01-31 15:23:30 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-03 14:38:11 +0100
commitd60251910eb3700f0f45e2fadf61dd457b094412 (patch)
tree81d3671ff39291fe1393ee73ce81cdad65a6e43c /src
parent5c62a537065b0186bd07cc008a47405607b2ba92 (diff)
[new compiler] Don't allow setting the id property multiple times
Change-Id: Ic7f1938dd048db6c6975d78ad4f69d3c646cece5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qqmlcodegenerator.cpp7
-rw-r--r--src/qml/compiler/qqmlcodegenerator_p.h4
2 files changed, 7 insertions, 4 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp
index 5d3123569f..f3b92fd27f 100644
--- a/src/qml/compiler/qqmlcodegenerator.cpp
+++ b/src/qml/compiler/qqmlcodegenerator.cpp
@@ -946,7 +946,7 @@ void QQmlCodeGenerator::appendBinding(AST::UiQualifiedId *name, int objectIndex,
void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, quint32 propertyNameIndex, AST::Statement *value)
{
if (stringAt(propertyNameIndex) == QStringLiteral("id")) {
- setId(value);
+ setId(nameLocation, value);
return;
}
@@ -1009,7 +1009,7 @@ QmlObject *QQmlCodeGenerator::bindingsTarget() const
return _object;
}
-bool QQmlCodeGenerator::setId(AST::Statement *value)
+bool QQmlCodeGenerator::setId(const AST::SourceLocation &idLocation, AST::Statement *value)
{
AST::SourceLocation loc = value->firstSourceLocation();
QStringRef str;
@@ -1047,6 +1047,9 @@ bool QQmlCodeGenerator::setId(AST::Statement *value)
if (illegalNames.contains(idQString))
COMPILE_EXCEPTION(loc, tr( "ID illegally masks global JavaScript property"));
+ if (_object->idIndex != emptyStringIndex)
+ COMPILE_EXCEPTION(idLocation, tr("Property value set multiple times"));
+
_object->idIndex = registerString(idQString);
_object->locationOfIdProperty.line = loc.startLine;
_object->locationOfIdProperty.column = loc.startColumn;
diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h
index eae359418a..124b46bc9e 100644
--- a/src/qml/compiler/qqmlcodegenerator_p.h
+++ b/src/qml/compiler/qqmlcodegenerator_p.h
@@ -162,7 +162,7 @@ struct QmlObject
Q_DECLARE_TR_FUNCTIONS(QmlObject)
public:
int inheritedTypeNameIndex;
- int idIndex;
+ quint32 idIndex;
int indexOfDefaultProperty;
QV4::CompiledData::Location location;
@@ -293,7 +293,7 @@ public:
QmlObject *bindingsTarget() const;
- bool setId(AST::Statement *value);
+ bool setId(const AST::SourceLocation &idLocation, AST::Statement *value);
// 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.