| Index: src/parser.cc
|
| diff --git a/src/parser.cc b/src/parser.cc
|
| index f122d9aa5e4b57ff1459cfa48e060c666bd407ff..04ce30f4f383733d32efe87786838ade2e3d0431 100644
|
| --- a/src/parser.cc
|
| +++ b/src/parser.cc
|
| @@ -3786,12 +3786,19 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
|
| Expression* enumerable = ParseExpression(true, CHECK_OK);
|
| Expect(Token::RPAREN, CHECK_OK);
|
|
|
| + // Make a block around the statement in case a lexical binding
|
| + // is introduced, e.g. by a FunctionDeclaration.
|
| + Block* block =
|
| + factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
|
| Statement* body = ParseSubStatement(NULL, CHECK_OK);
|
| - InitializeForEachStatement(loop, expression, enumerable, body);
|
| + block->statements()->Add(body, zone());
|
| + InitializeForEachStatement(loop, expression, enumerable, block);
|
| scope_ = saved_scope;
|
| for_scope->set_end_position(scanner()->location().end_pos);
|
| for_scope = for_scope->FinalizeBlockScope();
|
| - DCHECK(for_scope == NULL);
|
| + if (for_scope != nullptr) {
|
| + block->set_scope(for_scope);
|
| + }
|
| // Parsed for-in loop.
|
| return loop;
|
|
|
| @@ -3861,10 +3868,20 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
|
| // const x = i;
|
| // for (; c; n) b
|
| // }
|
| - DCHECK(init != NULL);
|
| + //
|
| + // or, desugar
|
| + // for (; c; n) b
|
| + // into
|
| + // {
|
| + // for (; c; n) b
|
| + // }
|
| + // just in case b introduces a lexical binding some other way, e.g., if b
|
| + // is a FunctionDeclaration.
|
| Block* block =
|
| factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
|
| - block->statements()->Add(init, zone());
|
| + if (init != nullptr) {
|
| + block->statements()->Add(init, zone());
|
| + }
|
| block->statements()->Add(loop, zone());
|
| block->set_scope(for_scope);
|
| loop->Initialize(NULL, cond, next, body);
|
|
|