| 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 3023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3034 Token::Value tok = peek(); | 3034 Token::Value tok = peek(); |
| 3035 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3035 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 3036 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3036 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
| 3037 *ok = false; | 3037 *ok = false; |
| 3038 return NULL; | 3038 return NULL; |
| 3039 } | 3039 } |
| 3040 | 3040 |
| 3041 Scope* catch_scope = NULL; | 3041 Scope* catch_scope = NULL; |
| 3042 Variable* catch_variable = NULL; | 3042 Variable* catch_variable = NULL; |
| 3043 Block* catch_block = NULL; | 3043 Block* catch_block = NULL; |
| 3044 const AstRawString* name = NULL; | |
| 3045 if (tok == Token::CATCH) { | 3044 if (tok == Token::CATCH) { |
| 3046 Consume(Token::CATCH); | 3045 Consume(Token::CATCH); |
| 3047 | 3046 |
| 3048 Expect(Token::LPAREN, CHECK_OK); | 3047 Expect(Token::LPAREN, CHECK_OK); |
| 3049 catch_scope = NewScope(scope_, CATCH_SCOPE); | 3048 catch_scope = NewScope(scope_, CATCH_SCOPE); |
| 3050 catch_scope->set_start_position(scanner()->location().beg_pos); | 3049 catch_scope->set_start_position(scanner()->location().beg_pos); |
| 3051 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 3050 |
| 3051 ExpressionClassifier pattern_classifier; |
| 3052 Token::Value next = peek(); |
| 3053 Expression* pattern = |
| 3054 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 3055 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| 3056 |
| 3057 if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) { |
| 3058 ReportUnexpectedToken(next); |
| 3059 *ok = false; |
| 3060 return NULL; |
| 3061 } |
| 3052 | 3062 |
| 3053 Expect(Token::RPAREN, CHECK_OK); | 3063 Expect(Token::RPAREN, CHECK_OK); |
| 3054 | 3064 |
| 3055 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 3065 if (pattern->IsVariableProxy()) { |
| 3056 Variable::NORMAL); | 3066 const AstRawString* name = pattern->AsVariableProxy()->raw_name(); |
| 3057 BlockState block_state(&scope_, catch_scope); | 3067 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, |
| 3058 catch_block = ParseBlock(NULL, CHECK_OK); | 3068 Variable::NORMAL); |
| 3069 BlockState block_state(&scope_, catch_scope); |
| 3070 catch_block = ParseBlock(NULL, CHECK_OK); |
| 3071 } else { |
| 3072 Variable* temp = scope_->NewTemporary( |
| 3073 ast_value_factory()->dot_catch_string()); |
| 3074 Scope* destruct_scope = NewScope(catch_scope, BLOCK_SCOPE); |
| 3075 Block* destruct_block = |
| 3076 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); |
| 3077 |
| 3078 DeclarationDescriptor descriptor; |
| 3079 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; |
| 3080 descriptor.parser = this; |
| 3081 descriptor.declaration_scope = destruct_scope->DeclarationScope(); |
| 3082 descriptor.scope = destruct_scope; |
| 3083 descriptor.hoist_scope = nullptr; |
| 3084 descriptor.mode = LET; |
| 3085 descriptor.is_const = false; |
| 3086 descriptor.needs_init = true; |
| 3087 descriptor.declaration_pos = RelocInfo::kNoPosition; |
| 3088 descriptor.initialization_pos = RelocInfo::kNoPosition; |
| 3089 descriptor.init_op = Token::INIT_LET; |
| 3090 Expression* initial_value = factory()->NewVariableProxy(temp); |
| 3091 |
| 3092 BlockState block_state(&scope_, destruct_scope); |
| 3093 DeclarationParsingResult::Declaration decl( |
| 3094 pattern, pattern->position(), initial_value); |
| 3095 PatternRewriter::DeclareAndInitializeVariables( |
| 3096 destruct_block, &descriptor, &decl, nullptr, CHECK_OK); |
| 3097 |
| 3098 catch_block->AddStatement(destruct_block, zone()); |
| 3099 catch_block = ParseBlock(NULL, CHECK_OK); |
| 3100 } |
| 3059 | 3101 |
| 3060 catch_scope->set_end_position(scanner()->location().end_pos); | 3102 catch_scope->set_end_position(scanner()->location().end_pos); |
| 3061 tok = peek(); | 3103 tok = peek(); |
| 3062 } | 3104 } |
| 3063 | 3105 |
| 3064 Block* finally_block = NULL; | 3106 Block* finally_block = NULL; |
| 3065 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3107 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
| 3066 if (tok == Token::FINALLY) { | 3108 if (tok == Token::FINALLY) { |
| 3067 Consume(Token::FINALLY); | 3109 Consume(Token::FINALLY); |
| 3068 finally_block = ParseBlock(NULL, CHECK_OK); | 3110 finally_block = ParseBlock(NULL, CHECK_OK); |
| (...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6071 Expression* Parser::SpreadCallNew(Expression* function, | 6113 Expression* Parser::SpreadCallNew(Expression* function, |
| 6072 ZoneList<v8::internal::Expression*>* args, | 6114 ZoneList<v8::internal::Expression*>* args, |
| 6073 int pos) { | 6115 int pos) { |
| 6074 args->InsertAt(0, function, zone()); | 6116 args->InsertAt(0, function, zone()); |
| 6075 | 6117 |
| 6076 return factory()->NewCallRuntime( | 6118 return factory()->NewCallRuntime( |
| 6077 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6119 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 6078 } | 6120 } |
| 6079 } // namespace internal | 6121 } // namespace internal |
| 6080 } // namespace v8 | 6122 } // namespace v8 |
| OLD | NEW |