aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-08-06 09:28:47 +0200
committerLars Knoll <lars.knoll@qt.io>2017-08-08 18:58:54 +0000
commit4d8aaeddfb81f8f97eaccd4e8d18c17f82c0f596 (patch)
tree8e76da501527d9bcd4611ea2207d68613715ad60 /src
parent22eb1fc012ab1e9b96de293290c78087fe958a8a (diff)
Parse foo["bar"] as a member expression
Change-Id: I9295ca7957783ed85c07e1522d05e300781361e3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4codegen.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index d30fa40e7f..38a8678f0f 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -635,6 +635,17 @@ bool Codegen::visit(ArrayMemberExpression *ast)
if (hasError)
return false;
base = base.storeOnStack();
+ if (AST::StringLiteral *str = AST::cast<AST::StringLiteral *>(ast->expression)) {
+ QString s = str->value.toString();
+ uint arrayIndex = QV4::String::toArrayIndex(s);
+ if (arrayIndex == UINT_MAX) {
+ _expr.setResult(Reference::fromMember(base, str->value.toString()));
+ return false;
+ }
+ Reference index = Reference::fromConst(this, QV4::Encode(arrayIndex));
+ _expr.setResult(Reference::fromSubscript(base, index));
+ return false;
+ }
Reference index = expression(ast->expression);
_expr.setResult(Reference::fromSubscript(base, index));
return false;