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

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

Issue 2110193002: Do all parsing for try/catch destructuring inside the appropriate scopes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: One less scope Created 4 years, 5 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 | « no previous file | test/mjsunit/regress/regress-5106.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 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 Variable* catch_variable = NULL; 2992 Variable* catch_variable = NULL;
2993 Block* catch_block = NULL; 2993 Block* catch_block = NULL;
2994 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); 2994 TailCallExpressionList tail_call_expressions_in_catch_block(zone());
2995 if (tok == Token::CATCH) { 2995 if (tok == Token::CATCH) {
2996 Consume(Token::CATCH); 2996 Consume(Token::CATCH);
2997 2997
2998 Expect(Token::LPAREN, CHECK_OK); 2998 Expect(Token::LPAREN, CHECK_OK);
2999 catch_scope = NewScope(scope_, CATCH_SCOPE); 2999 catch_scope = NewScope(scope_, CATCH_SCOPE);
3000 catch_scope->set_start_position(scanner()->location().beg_pos); 3000 catch_scope->set_start_position(scanner()->location().beg_pos);
3001 3001
3002 ExpressionClassifier pattern_classifier(this);
3003 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3004 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3005
3006 const AstRawString* name = ast_value_factory()->dot_catch_string();
3007 bool is_simple = pattern->IsVariableProxy();
3008 if (is_simple) {
3009 auto proxy = pattern->AsVariableProxy();
3010 scope_->RemoveUnresolved(proxy);
3011 name = proxy->raw_name();
3012 }
3013
3014 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
3015 Variable::NORMAL);
3016
3017 Expect(Token::RPAREN, CHECK_OK);
3018
3019 { 3002 {
3020 CollectExpressionsInTailPositionToListScope 3003 CollectExpressionsInTailPositionToListScope
3021 collect_tail_call_expressions_scope( 3004 collect_tail_call_expressions_scope(
3022 function_state_, &tail_call_expressions_in_catch_block); 3005 function_state_, &tail_call_expressions_in_catch_block);
3023 BlockState block_state(&scope_, catch_scope); 3006 BlockState block_state(&scope_, catch_scope);
3024 3007
3025 // TODO(adamk): Make a version of ParseBlock that takes a scope and
3026 // a block.
3027 catch_block = 3008 catch_block =
3028 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); 3009 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition);
3010
3011 // Create a block scope to hold any lexical declarations created
3012 // as part of destructuring the catch parameter.
3029 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 3013 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
3030
3031 block_scope->set_start_position(scanner()->location().beg_pos); 3014 block_scope->set_start_position(scanner()->location().beg_pos);
3032 { 3015 {
3033 BlockState block_state(&scope_, block_scope); 3016 BlockState block_state(&scope_, block_scope);
3034 Target target(&this->target_stack_, catch_block); 3017 Target target(&this->target_stack_, catch_block);
3035 3018
3019 ExpressionClassifier pattern_classifier(this);
3020 Expression* pattern =
3021 ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3022 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3023
3024 const AstRawString* name = ast_value_factory()->dot_catch_string();
3025 bool is_simple = pattern->IsVariableProxy();
3026 if (is_simple) {
3027 auto proxy = pattern->AsVariableProxy();
3028 scope_->RemoveUnresolved(proxy);
3029 name = proxy->raw_name();
3030 }
3031 catch_variable = catch_scope->DeclareLocal(
3032 name, VAR, kCreatedInitialized, Variable::NORMAL);
3033
3034 Expect(Token::RPAREN, CHECK_OK);
3035
3036 if (!is_simple) { 3036 if (!is_simple) {
3037 DeclarationDescriptor descriptor; 3037 DeclarationDescriptor descriptor;
3038 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; 3038 descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
3039 descriptor.parser = this; 3039 descriptor.parser = this;
3040 descriptor.scope = scope_; 3040 descriptor.scope = scope_;
3041 descriptor.hoist_scope = nullptr; 3041 descriptor.hoist_scope = nullptr;
3042 descriptor.mode = LET; 3042 descriptor.mode = LET;
3043 descriptor.declaration_pos = pattern->position(); 3043 descriptor.declaration_pos = pattern->position();
3044 descriptor.initialization_pos = pattern->position(); 3044 descriptor.initialization_pos = pattern->position();
3045 3045
3046 DeclarationParsingResult::Declaration decl( 3046 DeclarationParsingResult::Declaration decl(
3047 pattern, pattern->position(), 3047 pattern, pattern->position(),
3048 factory()->NewVariableProxy(catch_variable)); 3048 factory()->NewVariableProxy(catch_variable));
3049 3049
3050 Block* init_block = 3050 Block* init_block =
3051 factory()->NewBlock(nullptr, 8, true, RelocInfo::kNoPosition); 3051 factory()->NewBlock(nullptr, 8, true, RelocInfo::kNoPosition);
3052 PatternRewriter::DeclareAndInitializeVariables( 3052 PatternRewriter::DeclareAndInitializeVariables(
3053 init_block, &descriptor, &decl, nullptr, CHECK_OK); 3053 init_block, &descriptor, &decl, nullptr, CHECK_OK);
3054 catch_block->statements()->Add(init_block, zone()); 3054 catch_block->statements()->Add(init_block, zone());
3055 } 3055 }
3056 3056
3057 // TODO(adamk): This should call ParseBlock in order to properly
3058 // add an additional block scope for the catch body.
neis 2016/06/30 06:47:05 Is this related to the remaining test262 failure?
adamk 2016/06/30 16:02:10 Yes, Kevin will fix this in his patch which fixes
3057 Expect(Token::LBRACE, CHECK_OK); 3059 Expect(Token::LBRACE, CHECK_OK);
3058 while (peek() != Token::RBRACE) { 3060 while (peek() != Token::RBRACE) {
3059 Statement* stat = ParseStatementListItem(CHECK_OK); 3061 Statement* stat = ParseStatementListItem(CHECK_OK);
3060 if (stat && !stat->IsEmpty()) { 3062 if (stat && !stat->IsEmpty()) {
3061 catch_block->statements()->Add(stat, zone()); 3063 catch_block->statements()->Add(stat, zone());
3062 } 3064 }
3063 } 3065 }
3064 Consume(Token::RBRACE); 3066 Consume(Token::RBRACE);
3065 } 3067 }
3066 block_scope->set_end_position(scanner()->location().end_pos); 3068 block_scope->set_end_position(scanner()->location().end_pos);
(...skipping 3976 matching lines...) Expand 10 before | Expand all | Expand 10 after
7043 try_block, target); 7045 try_block, target);
7044 final_loop = target; 7046 final_loop = target;
7045 } 7047 }
7046 7048
7047 return final_loop; 7049 return final_loop;
7048 } 7050 }
7049 7051
7050 7052
7051 } // namespace internal 7053 } // namespace internal
7052 } // namespace v8 7054 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5106.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698