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

Side by Side Diff: src/preparser.cc

Issue 1315483004: [es6] Implement destructuring for `catch` (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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/parser.cc ('k') | no next file » | 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // *var is untouched; in particular, it is the caller's responsibility 489 // *var is untouched; in particular, it is the caller's responsibility
490 // to initialize it properly. This mechanism is also used for the parsing 490 // to initialize it properly. This mechanism is also used for the parsing
491 // of 'for-in' loops. 491 // of 'for-in' loops.
492 PreParser::Statement PreParser::ParseVariableDeclarations( 492 PreParser::Statement PreParser::ParseVariableDeclarations(
493 VariableDeclarationContext var_context, int* num_decl, 493 VariableDeclarationContext var_context, int* num_decl,
494 Scanner::Location* first_initializer_loc, Scanner::Location* bindings_loc, 494 Scanner::Location* first_initializer_loc, Scanner::Location* bindings_loc,
495 bool* ok) { 495 bool* ok) {
496 // VariableDeclarations :: 496 // VariableDeclarations ::
497 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] 497 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[',']
498 // 498 //
499 // The ES6 Draft Rev3 specifies the following grammar for const declarations
500 //
501 // ConstDeclaration :: 499 // ConstDeclaration ::
502 // const ConstBinding (',' ConstBinding)* ';' 500 // const ConstBinding (',' ConstBinding)* ';'
501 //
503 // ConstBinding :: 502 // ConstBinding ::
504 // Identifier '=' AssignmentExpression 503 // Identifier '=' AssignmentExpression
505 //
506 // TODO(ES6):
507 // ConstBinding ::
508 // BindingPattern '=' AssignmentExpression 504 // BindingPattern '=' AssignmentExpression
509 bool require_initializer = false; 505 bool require_initializer = false;
510 bool is_strict_const = false; 506 bool is_strict_const = false;
511 if (peek() == Token::VAR) { 507 if (peek() == Token::VAR) {
512 if (is_strong(language_mode())) { 508 if (is_strong(language_mode())) {
513 Scanner::Location location = scanner()->peek_location(); 509 Scanner::Location location = scanner()->peek_location();
514 ReportMessageAt(location, MessageTemplate::kStrongVar); 510 ReportMessageAt(location, MessageTemplate::kStrongVar);
515 *ok = false; 511 *ok = false;
516 return Statement::Default(); 512 return Statement::Default();
517 } 513 }
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 969
974 970
975 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { 971 PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
976 // TryStatement :: 972 // TryStatement ::
977 // 'try' Block Catch 973 // 'try' Block Catch
978 // 'try' Block Finally 974 // 'try' Block Finally
979 // 'try' Block Catch Finally 975 // 'try' Block Catch Finally
980 // 976 //
981 // Catch :: 977 // Catch ::
982 // 'catch' '(' Identifier ')' Block 978 // 'catch' '(' Identifier ')' Block
979 // 'catch' '(' BindingPattern ')' Block
983 // 980 //
984 // Finally :: 981 // Finally ::
985 // 'finally' Block 982 // 'finally' Block
986 983
987 Expect(Token::TRY, CHECK_OK); 984 Expect(Token::TRY, CHECK_OK);
988 985
989 ParseBlock(CHECK_OK); 986 ParseBlock(CHECK_OK);
990 987
991 Token::Value tok = peek(); 988 Token::Value tok = peek();
992 if (tok != Token::CATCH && tok != Token::FINALLY) { 989 if (tok != Token::CATCH && tok != Token::FINALLY) {
993 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); 990 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally);
994 *ok = false; 991 *ok = false;
995 return Statement::Default(); 992 return Statement::Default();
996 } 993 }
997 if (tok == Token::CATCH) { 994 if (tok == Token::CATCH) {
998 Consume(Token::CATCH); 995 Consume(Token::CATCH);
999 Expect(Token::LPAREN, CHECK_OK); 996 Expect(Token::LPAREN, CHECK_OK);
1000 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 997
998 ExpressionClassifier pattern_classifier;
999 Token::Value next = peek();
1000 PreParserExpression pattern =
1001 ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
1002 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
1003
1004 if (!allow_harmony_destructuring() && !pattern.IsIdentifier()) {
1005 ReportUnexpectedToken(next);
1006 *ok = false;
1007 return Statement::Default();
1008 }
1009
1001 Expect(Token::RPAREN, CHECK_OK); 1010 Expect(Token::RPAREN, CHECK_OK);
1002 { 1011
1003 Scope* with_scope = NewScope(scope_, WITH_SCOPE); 1012 if (pattern.IsIdentifier()) {
1004 BlockState block_state(&scope_, with_scope); 1013 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
1014 BlockState block_state(&scope_, catch_scope);
1015 ParseBlock(CHECK_OK);
1016 } else {
1017 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
1018 Scope* destruct_scope = NewScope(catch_scope, BLOCK_SCOPE);
1019 BlockState block_state(&scope_, destruct_scope);
1005 ParseBlock(CHECK_OK); 1020 ParseBlock(CHECK_OK);
1006 } 1021 }
1007 tok = peek(); 1022 tok = peek();
1008 } 1023 }
1009 if (tok == Token::FINALLY) { 1024 if (tok == Token::FINALLY) {
1010 Consume(Token::FINALLY); 1025 Consume(Token::FINALLY);
1011 ParseBlock(CHECK_OK); 1026 ParseBlock(CHECK_OK);
1012 } 1027 }
1013 return Statement::Default(); 1028 return Statement::Default();
1014 } 1029 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 1219
1205 DCHECK(!spread_pos.IsValid()); 1220 DCHECK(!spread_pos.IsValid());
1206 1221
1207 return Expression::Default(); 1222 return Expression::Default();
1208 } 1223 }
1209 1224
1210 #undef CHECK_OK 1225 #undef CHECK_OK
1211 1226
1212 1227
1213 } } // v8::internal 1228 } } // v8::internal
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698