[new compiler] Don't allow setting the id property multiple times

Change-Id: Ic7f1938dd048db6c6975d78ad4f69d3c646cece5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Simon Hausmann 2014-01-31 15:23:30 +01:00 committed by The Qt Project
parent 5c62a53706
commit d60251910e
2 changed files with 7 additions and 4 deletions

View File

@ -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;

View File

@ -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.