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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index b1541f616afe133554881e99aec4f71a9f5e45e0..a104678f9fb0f43a9ea6a75d9bf8c0d127536973 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -496,15 +496,11 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// VariableDeclarations ::
// ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[',']
//
- // The ES6 Draft Rev3 specifies the following grammar for const declarations
- //
// ConstDeclaration ::
// const ConstBinding (',' ConstBinding)* ';'
- // ConstBinding ::
- // Identifier '=' AssignmentExpression
//
- // TODO(ES6):
// ConstBinding ::
+ // Identifier '=' AssignmentExpression
// BindingPattern '=' AssignmentExpression
bool require_initializer = false;
bool is_strict_const = false;
@@ -980,6 +976,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
//
// Catch ::
// 'catch' '(' Identifier ')' Block
+ // 'catch' '(' BindingPattern ')' Block
//
// Finally ::
// 'finally' Block
@@ -997,11 +994,29 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
if (tok == Token::CATCH) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
- ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
+
+ ExpressionClassifier pattern_classifier;
+ Token::Value next = peek();
+ PreParserExpression pattern =
+ ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
+ ValidateBindingPattern(&pattern_classifier, CHECK_OK);
+
+ if (!allow_harmony_destructuring() && !pattern.IsIdentifier()) {
+ ReportUnexpectedToken(next);
+ *ok = false;
+ return Statement::Default();
+ }
+
Expect(Token::RPAREN, CHECK_OK);
- {
- Scope* with_scope = NewScope(scope_, WITH_SCOPE);
- BlockState block_state(&scope_, with_scope);
+
+ if (pattern.IsIdentifier()) {
+ Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
+ BlockState block_state(&scope_, catch_scope);
+ ParseBlock(CHECK_OK);
+ } else {
+ Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
+ Scope* destruct_scope = NewScope(catch_scope, BLOCK_SCOPE);
+ BlockState block_state(&scope_, destruct_scope);
ParseBlock(CHECK_OK);
}
tok = peek();
« 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