Chromium Code Reviews| Index: src/parsing/preparser.cc |
| diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc |
| index f1ef8ab60b384b9adac6b9e7e17aec20d8589d0d..a670b3e44be1c0c0b4e5bca533e1096fc38c371e 100644 |
| --- a/src/parsing/preparser.cc |
| +++ b/src/parsing/preparser.cc |
| @@ -693,9 +693,15 @@ PreParser::Statement PreParser::ParseReturnStatement(bool* ok) { |
| tok != Token::EOS) { |
| ParseExpression(true, CHECK_OK); |
| if (tail_call_position >= 0) { |
| - if (!function_state_->collect_expressions_in_tail_position()) { |
| + ReturnExprContext return_expr_context = |
| + function_state_->return_expr_context(); |
| + if (return_expr_context != ReturnExprContext::kNormal) { |
| Scanner::Location loc(tail_call_position, tail_call_position + 1); |
| - ReportMessageAt(loc, MessageTemplate::kTailCallInTryBlock); |
| + MessageTemplate::Template msg = |
| + return_expr_context == ReturnExprContext::kInsideTryBlock |
|
rossberg
2016/04/27 11:12:01
Use a switch here, to be robust against extensions
Igor Sheludko
2016/04/27 11:39:47
I moved this code to ReportIllegalTailCallAt() to
|
| + ? MessageTemplate::kTailCallInTryBlock |
| + : MessageTemplate::kTailCallInForInOf; |
| + ReportMessageAt(loc, msg); |
| *ok = false; |
| return Statement::Default(); |
| } |
| @@ -850,7 +856,11 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
| } |
| Expect(Token::RPAREN, CHECK_OK); |
| - ParseScopedStatement(true, CHECK_OK); |
| + { |
| + ReturnExprScope no_tail_calls(function_state_, |
| + ReturnExprContext::kInsideForInOfBody); |
| + ParseScopedStatement(true, CHECK_OK); |
| + } |
| return Statement::Default(); |
| } |
| } else { |
| @@ -953,7 +963,8 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
| Expect(Token::TRY, CHECK_OK); |
| { |
| - DontCollectExpressionsInTailPositionScope no_tail_calls(function_state_); |
| + ReturnExprScope no_tail_calls(function_state_, |
| + ReturnExprContext::kInsideTryBlock); |
| ParseBlock(CHECK_OK); |
| } |