OLD | NEW |
---|---|
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/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3141 Token::Value tok = peek(); | 3141 Token::Value tok = peek(); |
3142 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3142 if (tok != Token::CATCH && tok != Token::FINALLY) { |
3143 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3143 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
3144 *ok = false; | 3144 *ok = false; |
3145 return NULL; | 3145 return NULL; |
3146 } | 3146 } |
3147 | 3147 |
3148 Scope* catch_scope = NULL; | 3148 Scope* catch_scope = NULL; |
3149 Variable* catch_variable = NULL; | 3149 Variable* catch_variable = NULL; |
3150 Block* catch_block = NULL; | 3150 Block* catch_block = NULL; |
3151 const AstRawString* name = NULL; | |
3152 if (tok == Token::CATCH) { | 3151 if (tok == Token::CATCH) { |
3153 Consume(Token::CATCH); | 3152 Consume(Token::CATCH); |
3154 | 3153 |
3155 Expect(Token::LPAREN, CHECK_OK); | 3154 Expect(Token::LPAREN, CHECK_OK); |
3156 catch_scope = NewScope(scope_, CATCH_SCOPE); | 3155 catch_scope = NewScope(scope_, CATCH_SCOPE); |
3157 catch_scope->set_start_position(scanner()->location().beg_pos); | 3156 catch_scope->set_start_position(scanner()->location().beg_pos); |
3158 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 3157 |
3158 ExpressionClassifier pattern_classifier; | |
3159 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | |
3160 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | |
3161 | |
3162 bool is_simple = false; | |
rossberg
2015/11/03 12:00:50
Nit: why not `is_simple = pattern->IsVariableProxy
adamk
2015/11/03 20:35:20
Done.
| |
3163 const AstRawString* name = ast_value_factory()->dot_catch_string(); | |
3164 if (pattern->IsVariableProxy()) { | |
3165 is_simple = true; | |
3166 auto proxy = pattern->AsVariableProxy(); | |
3167 scope_->RemoveUnresolved(proxy); | |
3168 name = proxy->raw_name(); | |
3169 } | |
3170 | |
3171 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | |
3172 Variable::NORMAL); | |
3159 | 3173 |
3160 Expect(Token::RPAREN, CHECK_OK); | 3174 Expect(Token::RPAREN, CHECK_OK); |
3161 | 3175 |
3162 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 3176 { |
3163 Variable::NORMAL); | 3177 BlockState block_state(&scope_, catch_scope); |
3164 BlockState block_state(&scope_, catch_scope); | 3178 |
3165 catch_block = ParseBlock(NULL, CHECK_OK); | 3179 // TODO(adamk): Make a version of ParseScopedBlock that takes a scope and |
3180 // a block. | |
3181 catch_block = | |
3182 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); | |
3183 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | |
3184 | |
3185 block_scope->set_start_position(scanner()->location().beg_pos); | |
3186 { | |
3187 BlockState block_state(&scope_, block_scope); | |
3188 Target target(&this->target_stack_, catch_block); | |
3189 | |
3190 if (!is_simple) { | |
3191 DeclarationDescriptor descriptor; | |
3192 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; | |
3193 descriptor.parser = this; | |
3194 descriptor.declaration_scope = | |
3195 scope_->DeclarationScope(); // is this right? | |
rossberg
2015/11/03 12:00:50
Judging from how it's set in the other cases, this
adamk
2015/11/03 20:35:20
There's definitely some refactoring to be done her
| |
3196 descriptor.scope = scope_; | |
3197 descriptor.hoist_scope = nullptr; | |
3198 descriptor.mode = LET; | |
3199 descriptor.is_const = false; | |
3200 descriptor.needs_init = true; | |
3201 descriptor.declaration_pos = pattern->position(); | |
3202 descriptor.init_op = Token::INIT_LET; | |
3203 | |
3204 DeclarationParsingResult::Declaration decl( | |
3205 pattern, pattern->position(), | |
3206 factory()->NewVariableProxy(catch_variable)); | |
3207 | |
3208 PatternRewriter::DeclareAndInitializeVariables( | |
3209 catch_block, &descriptor, &decl, nullptr, CHECK_OK); | |
3210 } | |
3211 | |
3212 Expect(Token::LBRACE, CHECK_OK); | |
3213 while (peek() != Token::RBRACE) { | |
3214 Statement* stat = ParseStatementListItem(CHECK_OK); | |
3215 if (stat && !stat->IsEmpty()) { | |
3216 catch_block->statements()->Add(stat, zone()); | |
3217 } | |
3218 } | |
3219 Consume(Token::RBRACE); | |
3220 } | |
3221 block_scope->set_end_position(scanner()->location().end_pos); | |
3222 block_scope = block_scope->FinalizeBlockScope(); | |
3223 catch_block->set_scope(block_scope); | |
3224 } | |
3166 | 3225 |
3167 catch_scope->set_end_position(scanner()->location().end_pos); | 3226 catch_scope->set_end_position(scanner()->location().end_pos); |
3168 tok = peek(); | 3227 tok = peek(); |
3169 } | 3228 } |
3170 | 3229 |
3171 Block* finally_block = NULL; | 3230 Block* finally_block = NULL; |
3172 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3231 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
3173 if (tok == Token::FINALLY) { | 3232 if (tok == Token::FINALLY) { |
3174 Consume(Token::FINALLY); | 3233 Consume(Token::FINALLY); |
3175 finally_block = ParseBlock(NULL, CHECK_OK); | 3234 finally_block = ParseBlock(NULL, CHECK_OK); |
(...skipping 3205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6381 | 6440 |
6382 Expression* Parser::SpreadCallNew(Expression* function, | 6441 Expression* Parser::SpreadCallNew(Expression* function, |
6383 ZoneList<v8::internal::Expression*>* args, | 6442 ZoneList<v8::internal::Expression*>* args, |
6384 int pos) { | 6443 int pos) { |
6385 args->InsertAt(0, function, zone()); | 6444 args->InsertAt(0, function, zone()); |
6386 | 6445 |
6387 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6446 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6388 } | 6447 } |
6389 } // namespace internal | 6448 } // namespace internal |
6390 } // namespace v8 | 6449 } // namespace v8 |
OLD | NEW |