| Index: src/parser.cc
|
| diff --git a/src/parser.cc b/src/parser.cc
|
| index 9334a33195a1e21f474055863bc28dd47fa2cb93..691f9fb83f43e3905f24e7676d406711cc334201 100644
|
| --- a/src/parser.cc
|
| +++ b/src/parser.cc
|
| @@ -3041,21 +3041,63 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
|
| Scope* catch_scope = NULL;
|
| Variable* catch_variable = NULL;
|
| Block* catch_block = NULL;
|
| - const AstRawString* name = NULL;
|
| if (tok == Token::CATCH) {
|
| Consume(Token::CATCH);
|
|
|
| Expect(Token::LPAREN, CHECK_OK);
|
| catch_scope = NewScope(scope_, CATCH_SCOPE);
|
| catch_scope->set_start_position(scanner()->location().beg_pos);
|
| - name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
|
| +
|
| + ExpressionClassifier pattern_classifier;
|
| + Token::Value next = peek();
|
| + Expression* pattern =
|
| + ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
|
| + ValidateBindingPattern(&pattern_classifier, CHECK_OK);
|
| +
|
| + if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) {
|
| + ReportUnexpectedToken(next);
|
| + *ok = false;
|
| + return NULL;
|
| + }
|
|
|
| Expect(Token::RPAREN, CHECK_OK);
|
|
|
| - catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
|
| - Variable::NORMAL);
|
| - BlockState block_state(&scope_, catch_scope);
|
| - catch_block = ParseBlock(NULL, CHECK_OK);
|
| + if (pattern->IsVariableProxy()) {
|
| + const AstRawString* name = pattern->AsVariableProxy()->raw_name();
|
| + catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
|
| + Variable::NORMAL);
|
| + BlockState block_state(&scope_, catch_scope);
|
| + catch_block = ParseBlock(NULL, CHECK_OK);
|
| + } else {
|
| + Variable* temp = scope_->NewTemporary(
|
| + ast_value_factory()->dot_catch_string());
|
| + Scope* destruct_scope = NewScope(catch_scope, BLOCK_SCOPE);
|
| + Block* destruct_block =
|
| + factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition);
|
| +
|
| + DeclarationDescriptor descriptor;
|
| + descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
|
| + descriptor.parser = this;
|
| + descriptor.declaration_scope = destruct_scope->DeclarationScope();
|
| + descriptor.scope = destruct_scope;
|
| + descriptor.hoist_scope = nullptr;
|
| + descriptor.mode = LET;
|
| + descriptor.is_const = false;
|
| + descriptor.needs_init = true;
|
| + descriptor.declaration_pos = RelocInfo::kNoPosition;
|
| + descriptor.initialization_pos = RelocInfo::kNoPosition;
|
| + descriptor.init_op = Token::INIT_LET;
|
| + Expression* initial_value = factory()->NewVariableProxy(temp);
|
| +
|
| + BlockState block_state(&scope_, destruct_scope);
|
| + DeclarationParsingResult::Declaration decl(
|
| + pattern, pattern->position(), initial_value);
|
| + PatternRewriter::DeclareAndInitializeVariables(
|
| + destruct_block, &descriptor, &decl, nullptr, CHECK_OK);
|
| +
|
| + catch_block->AddStatement(destruct_block, zone());
|
| + catch_block = ParseBlock(NULL, CHECK_OK);
|
| + }
|
|
|
| catch_scope->set_end_position(scanner()->location().end_pos);
|
| tok = peek();
|
|
|