Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: src/parsing/preparser.cc

Issue 1914423002: [es8] Report proper syntax error for tail call expressions in for-in and for-of bodies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@tco-fix
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/message/syntactic-tail-call-in-for-in.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 Consume(Token::CONTINUE); 686 Consume(Token::CONTINUE);
687 tail_call_position = position(); 687 tail_call_position = position();
688 tok = peek(); 688 tok = peek();
689 } 689 }
690 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 690 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
691 tok != Token::SEMICOLON && 691 tok != Token::SEMICOLON &&
692 tok != Token::RBRACE && 692 tok != Token::RBRACE &&
693 tok != Token::EOS) { 693 tok != Token::EOS) {
694 ParseExpression(true, CHECK_OK); 694 ParseExpression(true, CHECK_OK);
695 if (tail_call_position >= 0) { 695 if (tail_call_position >= 0) {
696 if (!function_state_->collect_expressions_in_tail_position()) { 696 ReturnExprContext return_expr_context =
697 function_state_->return_expr_context();
698 if (return_expr_context != ReturnExprContext::kNormal) {
697 Scanner::Location loc(tail_call_position, tail_call_position + 1); 699 Scanner::Location loc(tail_call_position, tail_call_position + 1);
698 ReportMessageAt(loc, MessageTemplate::kTailCallInTryBlock); 700 MessageTemplate::Template msg =
701 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
702 ? MessageTemplate::kTailCallInTryBlock
703 : MessageTemplate::kTailCallInForInOf;
704 ReportMessageAt(loc, msg);
699 *ok = false; 705 *ok = false;
700 return Statement::Default(); 706 return Statement::Default();
701 } 707 }
702 function_state_->AddExpressionInTailPosition( 708 function_state_->AddExpressionInTailPosition(
703 PreParserExpression::Default(), tail_call_position); 709 PreParserExpression::Default(), tail_call_position);
704 } 710 }
705 } 711 }
706 ExpectSemicolon(CHECK_OK); 712 ExpectSemicolon(CHECK_OK);
707 return Statement::Jump(); 713 return Statement::Jump();
708 } 714 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 849
844 if (mode == ForEachStatement::ITERATE) { 850 if (mode == ForEachStatement::ITERATE) {
845 ExpressionClassifier classifier(this); 851 ExpressionClassifier classifier(this);
846 ParseAssignmentExpression(true, &classifier, CHECK_OK); 852 ParseAssignmentExpression(true, &classifier, CHECK_OK);
847 RewriteNonPattern(&classifier, CHECK_OK); 853 RewriteNonPattern(&classifier, CHECK_OK);
848 } else { 854 } else {
849 ParseExpression(true, CHECK_OK); 855 ParseExpression(true, CHECK_OK);
850 } 856 }
851 857
852 Expect(Token::RPAREN, CHECK_OK); 858 Expect(Token::RPAREN, CHECK_OK);
853 ParseScopedStatement(true, CHECK_OK); 859 {
860 ReturnExprScope no_tail_calls(function_state_,
861 ReturnExprContext::kInsideForInOfBody);
862 ParseScopedStatement(true, CHECK_OK);
863 }
854 return Statement::Default(); 864 return Statement::Default();
855 } 865 }
856 } else { 866 } else {
857 int lhs_beg_pos = peek_position(); 867 int lhs_beg_pos = peek_position();
858 ExpressionClassifier classifier(this); 868 ExpressionClassifier classifier(this);
859 Expression lhs = ParseExpression(false, &classifier, CHECK_OK); 869 Expression lhs = ParseExpression(false, &classifier, CHECK_OK);
860 int lhs_end_pos = scanner()->location().end_pos; 870 int lhs_end_pos = scanner()->location().end_pos;
861 bool is_for_each = CheckInOrOf(&mode, ok); 871 bool is_for_each = CheckInOrOf(&mode, ok);
862 if (!*ok) return Statement::Default(); 872 if (!*ok) return Statement::Default();
863 bool is_destructuring = is_for_each && 873 bool is_destructuring = is_for_each &&
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 // 956 //
947 // Catch :: 957 // Catch ::
948 // 'catch' '(' Identifier ')' Block 958 // 'catch' '(' Identifier ')' Block
949 // 959 //
950 // Finally :: 960 // Finally ::
951 // 'finally' Block 961 // 'finally' Block
952 962
953 Expect(Token::TRY, CHECK_OK); 963 Expect(Token::TRY, CHECK_OK);
954 964
955 { 965 {
956 DontCollectExpressionsInTailPositionScope no_tail_calls(function_state_); 966 ReturnExprScope no_tail_calls(function_state_,
967 ReturnExprContext::kInsideTryBlock);
957 ParseBlock(CHECK_OK); 968 ParseBlock(CHECK_OK);
958 } 969 }
959 970
960 Token::Value tok = peek(); 971 Token::Value tok = peek();
961 if (tok != Token::CATCH && tok != Token::FINALLY) { 972 if (tok != Token::CATCH && tok != Token::FINALLY) {
962 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); 973 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally);
963 *ok = false; 974 *ok = false;
964 return Statement::Default(); 975 return Statement::Default();
965 } 976 }
966 List<TailCallExpression> expressions_in_tail_position_in_catch_block; 977 List<TailCallExpression> expressions_in_tail_position_in_catch_block;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 } 1203 }
1193 Expect(Token::RBRACE, CHECK_OK); 1204 Expect(Token::RBRACE, CHECK_OK);
1194 return PreParserExpression::Default(); 1205 return PreParserExpression::Default();
1195 } 1206 }
1196 1207
1197 #undef CHECK_OK 1208 #undef CHECK_OK
1198 1209
1199 1210
1200 } // namespace internal 1211 } // namespace internal
1201 } // namespace v8 1212 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/message/syntactic-tail-call-in-for-in.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698