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

Side by Side Diff: src/parsing/parser-base.h

Issue 2694003002: Raise SyntaxError on let [ starting an ExpressionStatement (Closed)
Patch Set: Created 3 years, 10 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/messages.h ('k') | test/mjsunit/for.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 4978 matching lines...) Expand 10 before | Expand all | Expand 10 after
4989 int pos = peek_position(); 4989 int pos = peek_position();
4990 4990
4991 switch (peek()) { 4991 switch (peek()) {
4992 case Token::FUNCTION: 4992 case Token::FUNCTION:
4993 case Token::LBRACE: 4993 case Token::LBRACE:
4994 UNREACHABLE(); // Always handled by the callers. 4994 UNREACHABLE(); // Always handled by the callers.
4995 case Token::CLASS: 4995 case Token::CLASS:
4996 ReportUnexpectedToken(Next()); 4996 ReportUnexpectedToken(Next());
4997 *ok = false; 4997 *ok = false;
4998 return impl()->NullStatement(); 4998 return impl()->NullStatement();
4999 case Token::LET:
5000 if (PeekAhead() != Token::LBRACK) break;
5001 impl()->ReportMessageAt(scanner()->peek_location(),
5002 MessageTemplate::kUnexpectedTokenLetLBrack);
5003 *ok = false;
5004 return impl()->NullStatement();
4999 default: 5005 default:
5000 break; 5006 break;
5001 } 5007 }
5002 5008
5003 bool starts_with_identifier = peek_any_identifier(); 5009 bool starts_with_identifier = peek_any_identifier();
5004 ExpressionT expr = ParseExpression(true, CHECK_OK); 5010 ExpressionT expr = ParseExpression(true, CHECK_OK);
5005 if (peek() == Token::COLON && starts_with_identifier && 5011 if (peek() == Token::COLON && starts_with_identifier &&
5006 impl()->IsIdentifier(expr)) { 5012 impl()->IsIdentifier(expr)) {
5007 // The whole expression was a single identifier, and not, e.g., 5013 // The whole expression was a single identifier, and not, e.g.,
5008 // something starting with an identifier or a parenthesized identifier. 5014 // something starting with an identifier or a parenthesized identifier.
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
5439 5445
5440 // Create an in-between scope for let-bound iteration variables. 5446 // Create an in-between scope for let-bound iteration variables.
5441 BlockState for_state(zone(), &scope_state_); 5447 BlockState for_state(zone(), &scope_state_);
5442 Expect(Token::FOR, CHECK_OK); 5448 Expect(Token::FOR, CHECK_OK);
5443 Expect(Token::LPAREN, CHECK_OK); 5449 Expect(Token::LPAREN, CHECK_OK);
5444 for_state.set_start_position(scanner()->location().beg_pos); 5450 for_state.set_start_position(scanner()->location().beg_pos);
5445 for_state.set_is_hidden(); 5451 for_state.set_is_hidden();
5446 5452
5447 StatementT init = impl()->NullStatement(); 5453 StatementT init = impl()->NullStatement();
5448 5454
5455 // "let [" is forbidden in the initializer of the for loop.
5456 if (peek() == Token::LET && PeekAhead() == Token::LBRACK) {
5457 impl()->ReportMessageAt(scanner()->peek_location(),
5458 MessageTemplate::kUnexpectedTokenLetLBrack);
5459 *ok = false;
5460 return init;
5461 }
Dan Ehrenberg 2017/02/13 19:26:57 I'm not sure I agree with your reading of the spec
vabr (Chromium) 2017/02/13 20:14:46 The test failures are due to not restricting this
vabr (Chromium) 2017/02/13 20:29:20 Hm, now I see how I misunderstood your comment and
5449 if (peek() == Token::VAR || peek() == Token::CONST || 5462 if (peek() == Token::VAR || peek() == Token::CONST ||
5450 (peek() == Token::LET && IsNextLetKeyword())) { 5463 (peek() == Token::LET && IsNextLetKeyword())) {
5451 // The initializer contains declarations. 5464 // The initializer contains declarations.
5452 ParseVariableDeclarations(kForStatement, &for_info.parsing_result, nullptr, 5465 ParseVariableDeclarations(kForStatement, &for_info.parsing_result, nullptr,
5453 CHECK_OK); 5466 CHECK_OK);
5454 bound_names_are_lexical = 5467 bound_names_are_lexical =
5455 IsLexicalVariableMode(for_info.parsing_result.descriptor.mode); 5468 IsLexicalVariableMode(for_info.parsing_result.descriptor.mode);
5456 for_info.position = scanner()->location().beg_pos; 5469 for_info.position = scanner()->location().beg_pos;
5457 5470
5458 if (CheckInOrOf(&for_info.mode)) { 5471 if (CheckInOrOf(&for_info.mode)) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
5767 } 5780 }
5768 5781
5769 #undef CHECK_OK 5782 #undef CHECK_OK
5770 #undef CHECK_OK_CUSTOM 5783 #undef CHECK_OK_CUSTOM
5771 #undef CHECK_OK_VOID 5784 #undef CHECK_OK_VOID
5772 5785
5773 } // namespace internal 5786 } // namespace internal
5774 } // namespace v8 5787 } // namespace v8
5775 5788
5776 #endif // V8_PARSING_PARSER_BASE_H 5789 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/messages.h ('k') | test/mjsunit/for.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698