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

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

Issue 2151433005: Slight cleanup of TryCatch parsing/variable declaration (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/harmony/async-function-stacktrace.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 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after
2988 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); 2988 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
2989 2989
2990 // Create a block scope to hold any lexical declarations created 2990 // Create a block scope to hold any lexical declarations created
2991 // as part of destructuring the catch parameter. 2991 // as part of destructuring the catch parameter.
2992 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 2992 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
2993 block_scope->set_start_position(scanner()->location().beg_pos); 2993 block_scope->set_start_position(scanner()->location().beg_pos);
2994 { 2994 {
2995 BlockState block_state(&scope_, block_scope); 2995 BlockState block_state(&scope_, block_scope);
2996 Target target(&this->target_stack_, catch_block); 2996 Target target(&this->target_stack_, catch_block);
2997 2997
2998 ExpressionClassifier pattern_classifier(this);
2999 Expression* pattern =
3000 ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3001 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3002
3003 const AstRawString* name = ast_value_factory()->dot_catch_string(); 2998 const AstRawString* name = ast_value_factory()->dot_catch_string();
3004 bool is_simple = pattern->IsVariableProxy(); 2999 Expression* pattern = nullptr;
3005 if (is_simple) { 3000 if (peek_any_identifier()) {
3006 auto proxy = pattern->AsVariableProxy(); 3001 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
3007 scope_->RemoveUnresolved(proxy); 3002 } else {
3008 name = proxy->raw_name(); 3003 ExpressionClassifier pattern_classifier(this);
3004 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3005 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3009 } 3006 }
3010 catch_variable = catch_scope->DeclareLocal( 3007 catch_variable = catch_scope->DeclareLocal(
3011 name, VAR, kCreatedInitialized, Variable::NORMAL); 3008 name, VAR, kCreatedInitialized, Variable::NORMAL);
3012 3009
3013 Expect(Token::RPAREN, CHECK_OK); 3010 Expect(Token::RPAREN, CHECK_OK);
3014 3011
3015 ZoneList<const AstRawString*> bound_names(1, zone()); 3012 ZoneList<const AstRawString*> bound_names(1, zone());
3016 3013 if (pattern != nullptr) {
3017 if (!is_simple) {
3018 DeclarationDescriptor descriptor; 3014 DeclarationDescriptor descriptor;
3019 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; 3015 descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
3020 descriptor.parser = this; 3016 descriptor.parser = this;
3021 descriptor.scope = scope_; 3017 descriptor.scope = scope_;
3022 descriptor.hoist_scope = nullptr; 3018 descriptor.hoist_scope = nullptr;
3023 descriptor.mode = LET; 3019 descriptor.mode = LET;
3024 descriptor.declaration_pos = pattern->position(); 3020 descriptor.declaration_pos = pattern->position();
3025 descriptor.initialization_pos = pattern->position(); 3021 descriptor.initialization_pos = pattern->position();
3026 3022
3027 // Initializer position for variables declared by the pattern. 3023 // Initializer position for variables declared by the pattern.
(...skipping 4022 matching lines...) Expand 10 before | Expand all | Expand 10 after
7050 7046
7051 #ifdef DEBUG 7047 #ifdef DEBUG
7052 void Parser::Print(AstNode* node) { 7048 void Parser::Print(AstNode* node) {
7053 ast_value_factory()->Internalize(Isolate::Current()); 7049 ast_value_factory()->Internalize(Isolate::Current());
7054 node->Print(Isolate::Current()); 7050 node->Print(Isolate::Current());
7055 } 7051 }
7056 #endif // DEBUG 7052 #endif // DEBUG
7057 7053
7058 } // namespace internal 7054 } // namespace internal
7059 } // namespace v8 7055 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/async-function-stacktrace.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698