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())) { |
1077 CheckConflictingVarDeclarations(scope_, &ok); | 1078 CheckConflictingVarDeclarations(scope_, &ok); |
1078 } | 1079 } |
1079 | 1080 |
1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 1081 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
1081 if (body->length() != 1 || | 1082 if (body->length() != 1 || |
1082 !body->at(0)->IsExpressionStatement() || | 1083 !body->at(0)->IsExpressionStatement() || |
1083 !body->at(0)->AsExpressionStatement()-> | 1084 !body->at(0)->AsExpressionStatement()-> |
1084 expression()->IsFunctionLiteral()) { | 1085 expression()->IsFunctionLiteral()) { |
1085 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 1086 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
1086 ok = false; | 1087 ok = false; |
(...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3141 Token::Value tok = peek(); | 3142 Token::Value tok = peek(); |
3142 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3143 if (tok != Token::CATCH && tok != Token::FINALLY) { |
3143 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3144 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
3144 *ok = false; | 3145 *ok = false; |
3145 return NULL; | 3146 return NULL; |
3146 } | 3147 } |
3147 | 3148 |
3148 Scope* catch_scope = NULL; | 3149 Scope* catch_scope = NULL; |
3149 Variable* catch_variable = NULL; | 3150 Variable* catch_variable = NULL; |
3150 Block* catch_block = NULL; | 3151 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 ExpressionClassifier pattern_classifier; |
| 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 |
| 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 = 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 } |
3166 | 3224 |
3167 catch_scope->set_end_position(scanner()->location().end_pos); | 3225 catch_scope->set_end_position(scanner()->location().end_pos); |
3168 tok = peek(); | 3226 tok = peek(); |
3169 } | 3227 } |
3170 | 3228 |
3171 Block* finally_block = NULL; | 3229 Block* finally_block = NULL; |
3172 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3230 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
3173 if (tok == Token::FINALLY) { | 3231 if (tok == Token::FINALLY) { |
3174 Consume(Token::FINALLY); | 3232 Consume(Token::FINALLY); |
3175 finally_block = ParseBlock(NULL, CHECK_OK); | 3233 finally_block = ParseBlock(NULL, CHECK_OK); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4357 ValidateFormalParameters(&formals_classifier, language_mode, | 4415 ValidateFormalParameters(&formals_classifier, language_mode, |
4358 allow_duplicate_parameters, CHECK_OK); | 4416 allow_duplicate_parameters, CHECK_OK); |
4359 | 4417 |
4360 if (is_strict(language_mode)) { | 4418 if (is_strict(language_mode)) { |
4361 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4419 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4362 CHECK_OK); | 4420 CHECK_OK); |
4363 } | 4421 } |
4364 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { | 4422 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { |
4365 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); | 4423 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); |
4366 } | 4424 } |
4367 if (is_strict(language_mode) || allow_harmony_sloppy()) { | 4425 if (is_strict(language_mode) || allow_harmony_sloppy() || |
| 4426 allow_harmony_destructuring()) { |
4368 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4427 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4369 } | 4428 } |
4370 } | 4429 } |
4371 | 4430 |
4372 bool has_duplicate_parameters = | 4431 bool has_duplicate_parameters = |
4373 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4432 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4374 FunctionLiteral::ParameterFlag duplicate_parameters = | 4433 FunctionLiteral::ParameterFlag duplicate_parameters = |
4375 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 4434 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
4376 : FunctionLiteral::kNoDuplicateParameters; | 4435 : FunctionLiteral::kNoDuplicateParameters; |
4377 | 4436 |
(...skipping 2003 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 |