diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-10 22:55:55 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 07:17:29 +0000 |
commit | fd183d3db9d1eba4f7dd3e978192a247bf7dba85 (patch) | |
tree | c8359248c07cb4467e4c8b844a07a0d4ba8abaab | |
parent | e203a868470ab2e435111127f00530f4d8cc581d (diff) |
Give for loops a proper block scope for it's lexically declared vars
Change-Id: I71c40d1d061ac3c1c623dbbf8f7967c9ec35c082
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 2 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 7 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 5 |
4 files changed, 10 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index fc7ca911e8..687731c32b 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2687,6 +2687,8 @@ bool Codegen::visit(ForStatement *ast) RegisterScope scope(this); + ControlFlowBlock controlFlow(this, ast); + if (ast->initialiser) statement(ast->initialiser); else if (ast->declarations) diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 31663e2162..c2256537c4 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -320,6 +320,8 @@ bool ScanFunctions::visit(DoWhileStatement *ast) { } bool ScanFunctions::visit(ForStatement *ast) { + enterEnvironment(ast, ContextType::Block); + _context->name = QLatin1String("For"); Node::accept(ast->initialiser, this); Node::accept(ast->declarations, this); Node::accept(ast->condition, this); @@ -331,6 +333,11 @@ bool ScanFunctions::visit(ForStatement *ast) { return false; } +void ScanFunctions::endVisit(ForStatement *) +{ + leaveEnvironment(); +} + bool ScanFunctions::visit(ForEachStatement *ast) { enterEnvironment(ast, ContextType::Block); _context->name = QLatin1String("Foreach"); diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h index 4d52548637..b9b41781c4 100644 --- a/src/qml/compiler/qv4compilerscanfunctions_p.h +++ b/src/qml/compiler/qv4compilerscanfunctions_p.h @@ -125,6 +125,7 @@ protected: bool visit(AST::DoWhileStatement *ast) override; bool visit(AST::ForStatement *ast) override; + void endVisit(AST::ForStatement *) override; bool visit(AST::ForEachStatement *ast) override; void endVisit(AST::ForEachStatement *) override; diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index dfa5d38ed8..bcf845c8a8 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -5969,7 +5969,6 @@ language/statements/const/global-use-before-initialization-in-prior-statement.js language/statements/const/syntax/const-invalid-assignment-next-expression-for.js fails language/statements/const/syntax/const-invalid-assignment-statement-body-for-in.js fails language/statements/const/syntax/const-invalid-assignment-statement-body-for-of.js fails -language/statements/const/syntax/const-outer-inner-let-bindings.js fails language/statements/do-while/tco-body.js strictFails language/statements/empty/cptn-value.js fails language/statements/for-in/head-const-bound-names-fordecl-tdz.js fails @@ -6417,13 +6416,10 @@ language/statements/for/dstr-var-obj-ptrn-id-init-fn-name-class.js fails language/statements/for/dstr-var-obj-ptrn-id-init-fn-name-cover.js fails language/statements/for/dstr-var-obj-ptrn-id-init-fn-name-fn.js fails language/statements/for/dstr-var-obj-ptrn-id-init-fn-name-gen.js fails -language/statements/for/head-let-destructuring.js fails language/statements/for/head-lhs-let.js sloppyFails language/statements/for/let-identifier-with-newline.js sloppyFails language/statements/for/scope-body-lex-boundary.js fails language/statements/for/scope-body-lex-open.js fails -language/statements/for/scope-head-lex-close.js fails -language/statements/for/scope-head-lex-open.js fails language/statements/for/tco-const-body.js strictFails language/statements/for/tco-let-body.js strictFails language/statements/for/tco-lhs-body.js strictFails @@ -6633,7 +6629,6 @@ language/statements/let/syntax/let-closure-inside-initialization.js fails language/statements/let/syntax/let-closure-inside-next-expression.js fails language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-multi-let-binding.js fails language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-single-let-binding.js fails -language/statements/let/syntax/let-outer-inner-let-bindings.js fails language/statements/let/syntax/let.js fails language/statements/return/tco.js strictFails language/statements/switch/scope-lex-close-case.js fails |