diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-03-16 18:45:52 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-04-26 21:37:23 +0000 |
commit | 67ce06f2c0642fa0a9a4eb4f2239cb99a62d2040 (patch) | |
tree | 4033a1053fb7a1cc39a3938f2fa69388ed8a3476 /src | |
parent | f034d7c36906fedcc6e2846445ae5bf6c23e8ee5 (diff) |
Don't error on duplicate property names in object literals
This has been relaxed from ES5. In ES8 this is actually allowed
even in strict mode. According to the spec we are to evaluate all
rhs expressions, but assign the last one used in the object literal.
The spec probably required this relaxation to be able to handle
computed property names.
Change-Id: Ia1b02010b7541946029951b36e5457a07fdee818
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 2b6bda1de3..229af2844b 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1844,29 +1844,17 @@ bool Codegen::visit(ObjectLiteral *ast) for (PropertyDefinitionList *it = ast->properties; it; it = it->next) { QString name = it->assignment->name->asString(); + ObjectPropertyValue &v = valueMap[name]; if (PropertyNameAndValue *nv = AST::cast<AST::PropertyNameAndValue *>(it->assignment)) { Reference value = expression(nv->value); if (hasError) return false; - ObjectPropertyValue &v = valueMap[name]; - if (v.hasGetter() || v.hasSetter() || (_context->isStrict && v.rvalue.isValid())) { - throwSyntaxError(nv->lastSourceLocation(), - QStringLiteral("Illegal duplicate key '%1' in object literal").arg(name)); - return false; - } - v.rvalue = value.storeOnStack(); + v.getter = v.setter = -1; } else if (PropertyGetterSetter *gs = AST::cast<AST::PropertyGetterSetter *>(it->assignment)) { const int function = defineFunction(name, gs, gs->formals, gs->functionBody); - ObjectPropertyValue &v = valueMap[name]; - if (v.rvalue.isValid() || - (gs->type == PropertyGetterSetter::Getter && v.hasGetter()) || - (gs->type == PropertyGetterSetter::Setter && v.hasSetter())) { - throwSyntaxError(gs->lastSourceLocation(), - QStringLiteral("Illegal duplicate key '%1' in object literal").arg(name)); - return false; - } + v.rvalue = Reference(); if (gs->type == PropertyGetterSetter::Getter) v.getter = function; else |