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 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 if (ok && is_strict(language_mode())) { | 1066 if (ok && is_strict(language_mode())) { |
1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
1068 } | 1068 } |
1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { | 1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { |
1070 // TODO(littledan): Function bindings on the global object that modify | 1070 // TODO(littledan): Function bindings on the global object that modify |
1071 // pre-existing bindings should be made writable, enumerable and | 1071 // pre-existing bindings should be made writable, enumerable and |
1072 // nonconfigurable if possible, whereas this code will leave attributes | 1072 // nonconfigurable if possible, whereas this code will leave attributes |
1073 // unchanged if the property already exists. | 1073 // unchanged if the property already exists. |
1074 InsertSloppyBlockFunctionVarBindings(scope, &ok); | 1074 InsertSloppyBlockFunctionVarBindings(scope, &ok); |
1075 } | 1075 } |
1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy() || | 1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy())) { |
1077 allow_harmony_destructuring())) { | |
1078 CheckConflictingVarDeclarations(scope_, &ok); | 1077 CheckConflictingVarDeclarations(scope_, &ok); |
1079 } | 1078 } |
1080 | 1079 |
1081 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
1082 if (body->length() != 1 || | 1081 if (body->length() != 1 || |
1083 !body->at(0)->IsExpressionStatement() || | 1082 !body->at(0)->IsExpressionStatement() || |
1084 !body->at(0)->AsExpressionStatement()-> | 1083 !body->at(0)->AsExpressionStatement()-> |
1085 expression()->IsFunctionLiteral()) { | 1084 expression()->IsFunctionLiteral()) { |
1086 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 1085 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
1087 ok = false; | 1086 ok = false; |
(...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3142 Token::Value tok = peek(); | 3141 Token::Value tok = peek(); |
3143 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3142 if (tok != Token::CATCH && tok != Token::FINALLY) { |
3144 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3143 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
3145 *ok = false; | 3144 *ok = false; |
3146 return NULL; | 3145 return NULL; |
3147 } | 3146 } |
3148 | 3147 |
3149 Scope* catch_scope = NULL; | 3148 Scope* catch_scope = NULL; |
3150 Variable* catch_variable = NULL; | 3149 Variable* catch_variable = NULL; |
3151 Block* catch_block = NULL; | 3150 Block* catch_block = NULL; |
| 3151 const AstRawString* name = NULL; |
3152 if (tok == Token::CATCH) { | 3152 if (tok == Token::CATCH) { |
3153 Consume(Token::CATCH); | 3153 Consume(Token::CATCH); |
3154 | 3154 |
3155 Expect(Token::LPAREN, CHECK_OK); | 3155 Expect(Token::LPAREN, CHECK_OK); |
3156 catch_scope = NewScope(scope_, CATCH_SCOPE); | 3156 catch_scope = NewScope(scope_, CATCH_SCOPE); |
3157 catch_scope->set_start_position(scanner()->location().beg_pos); | 3157 catch_scope->set_start_position(scanner()->location().beg_pos); |
| 3158 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
3158 | 3159 |
3159 ExpressionClassifier pattern_classifier; | 3160 Expect(Token::RPAREN, CHECK_OK); |
3160 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | |
3161 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | |
3162 | |
3163 const AstRawString* name = ast_value_factory()->dot_catch_string(); | |
3164 bool is_simple = pattern->IsVariableProxy(); | |
3165 if (is_simple) { | |
3166 auto proxy = pattern->AsVariableProxy(); | |
3167 scope_->RemoveUnresolved(proxy); | |
3168 name = proxy->raw_name(); | |
3169 } | |
3170 | 3161 |
3171 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 3162 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, |
3172 Variable::NORMAL); | 3163 Variable::NORMAL); |
3173 | 3164 BlockState block_state(&scope_, catch_scope); |
3174 Expect(Token::RPAREN, CHECK_OK); | 3165 catch_block = ParseBlock(NULL, CHECK_OK); |
3175 | |
3176 { | |
3177 BlockState block_state(&scope_, catch_scope); | |
3178 | |
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 = scope_; | |
3195 descriptor.scope = scope_; | |
3196 descriptor.hoist_scope = nullptr; | |
3197 descriptor.mode = LET; | |
3198 descriptor.is_const = false; | |
3199 descriptor.needs_init = true; | |
3200 descriptor.declaration_pos = pattern->position(); | |
3201 descriptor.init_op = Token::INIT_LET; | |
3202 | |
3203 DeclarationParsingResult::Declaration decl( | |
3204 pattern, pattern->position(), | |
3205 factory()->NewVariableProxy(catch_variable)); | |
3206 | |
3207 PatternRewriter::DeclareAndInitializeVariables( | |
3208 catch_block, &descriptor, &decl, nullptr, CHECK_OK); | |
3209 } | |
3210 | |
3211 Expect(Token::LBRACE, CHECK_OK); | |
3212 while (peek() != Token::RBRACE) { | |
3213 Statement* stat = ParseStatementListItem(CHECK_OK); | |
3214 if (stat && !stat->IsEmpty()) { | |
3215 catch_block->statements()->Add(stat, zone()); | |
3216 } | |
3217 } | |
3218 Consume(Token::RBRACE); | |
3219 } | |
3220 block_scope->set_end_position(scanner()->location().end_pos); | |
3221 block_scope = block_scope->FinalizeBlockScope(); | |
3222 catch_block->set_scope(block_scope); | |
3223 } | |
3224 | 3166 |
3225 catch_scope->set_end_position(scanner()->location().end_pos); | 3167 catch_scope->set_end_position(scanner()->location().end_pos); |
3226 tok = peek(); | 3168 tok = peek(); |
3227 } | 3169 } |
3228 | 3170 |
3229 Block* finally_block = NULL; | 3171 Block* finally_block = NULL; |
3230 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3172 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
3231 if (tok == Token::FINALLY) { | 3173 if (tok == Token::FINALLY) { |
3232 Consume(Token::FINALLY); | 3174 Consume(Token::FINALLY); |
3233 finally_block = ParseBlock(NULL, CHECK_OK); | 3175 finally_block = ParseBlock(NULL, CHECK_OK); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4415 ValidateFormalParameters(&formals_classifier, language_mode, | 4357 ValidateFormalParameters(&formals_classifier, language_mode, |
4416 allow_duplicate_parameters, CHECK_OK); | 4358 allow_duplicate_parameters, CHECK_OK); |
4417 | 4359 |
4418 if (is_strict(language_mode)) { | 4360 if (is_strict(language_mode)) { |
4419 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4361 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4420 CHECK_OK); | 4362 CHECK_OK); |
4421 } | 4363 } |
4422 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { | 4364 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { |
4423 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); | 4365 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); |
4424 } | 4366 } |
4425 if (is_strict(language_mode) || allow_harmony_sloppy() || | 4367 if (is_strict(language_mode) || allow_harmony_sloppy()) { |
4426 allow_harmony_destructuring()) { | |
4427 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4368 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4428 } | 4369 } |
4429 } | 4370 } |
4430 | 4371 |
4431 bool has_duplicate_parameters = | 4372 bool has_duplicate_parameters = |
4432 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4373 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4433 FunctionLiteral::ParameterFlag duplicate_parameters = | 4374 FunctionLiteral::ParameterFlag duplicate_parameters = |
4434 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 4375 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
4435 : FunctionLiteral::kNoDuplicateParameters; | 4376 : FunctionLiteral::kNoDuplicateParameters; |
4436 | 4377 |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6440 | 6381 |
6441 Expression* Parser::SpreadCallNew(Expression* function, | 6382 Expression* Parser::SpreadCallNew(Expression* function, |
6442 ZoneList<v8::internal::Expression*>* args, | 6383 ZoneList<v8::internal::Expression*>* args, |
6443 int pos) { | 6384 int pos) { |
6444 args->InsertAt(0, function, zone()); | 6385 args->InsertAt(0, function, zone()); |
6445 | 6386 |
6446 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6387 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6447 } | 6388 } |
6448 } // namespace internal | 6389 } // namespace internal |
6449 } // namespace v8 | 6390 } // namespace v8 |
OLD | NEW |