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 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3150 Token::Value tok = peek(); | 3151 Token::Value tok = peek(); |
3151 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3152 if (tok != Token::CATCH && tok != Token::FINALLY) { |
3152 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3153 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
3153 *ok = false; | 3154 *ok = false; |
3154 return NULL; | 3155 return NULL; |
3155 } | 3156 } |
3156 | 3157 |
3157 Scope* catch_scope = NULL; | 3158 Scope* catch_scope = NULL; |
3158 Variable* catch_variable = NULL; | 3159 Variable* catch_variable = NULL; |
3159 Block* catch_block = NULL; | 3160 Block* catch_block = NULL; |
3160 const AstRawString* name = NULL; | |
3161 if (tok == Token::CATCH) { | 3161 if (tok == Token::CATCH) { |
3162 Consume(Token::CATCH); | 3162 Consume(Token::CATCH); |
3163 | 3163 |
3164 Expect(Token::LPAREN, CHECK_OK); | 3164 Expect(Token::LPAREN, CHECK_OK); |
3165 catch_scope = NewScope(scope_, CATCH_SCOPE); | 3165 catch_scope = NewScope(scope_, CATCH_SCOPE); |
3166 catch_scope->set_start_position(scanner()->location().beg_pos); | 3166 catch_scope->set_start_position(scanner()->location().beg_pos); |
3167 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 3167 |
| 3168 ExpressionClassifier pattern_classifier; |
| 3169 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 3170 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| 3171 |
| 3172 const AstRawString* name = ast_value_factory()->dot_catch_string(); |
| 3173 bool is_simple = pattern->IsVariableProxy(); |
| 3174 if (is_simple) { |
| 3175 auto proxy = pattern->AsVariableProxy(); |
| 3176 scope_->RemoveUnresolved(proxy); |
| 3177 name = proxy->raw_name(); |
| 3178 } |
| 3179 |
| 3180 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, |
| 3181 Variable::NORMAL); |
3168 | 3182 |
3169 Expect(Token::RPAREN, CHECK_OK); | 3183 Expect(Token::RPAREN, CHECK_OK); |
3170 | 3184 |
3171 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 3185 { |
3172 Variable::NORMAL); | 3186 BlockState block_state(&scope_, catch_scope); |
3173 BlockState block_state(&scope_, catch_scope); | 3187 |
3174 catch_block = ParseBlock(NULL, CHECK_OK); | 3188 // TODO(adamk): Make a version of ParseScopedBlock that takes a scope and |
| 3189 // a block. |
| 3190 catch_block = |
| 3191 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); |
| 3192 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
| 3193 |
| 3194 block_scope->set_start_position(scanner()->location().beg_pos); |
| 3195 { |
| 3196 BlockState block_state(&scope_, block_scope); |
| 3197 Target target(&this->target_stack_, catch_block); |
| 3198 |
| 3199 if (!is_simple) { |
| 3200 DeclarationDescriptor descriptor; |
| 3201 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; |
| 3202 descriptor.parser = this; |
| 3203 descriptor.declaration_scope = scope_; |
| 3204 descriptor.scope = scope_; |
| 3205 descriptor.hoist_scope = nullptr; |
| 3206 descriptor.mode = LET; |
| 3207 descriptor.is_const = false; |
| 3208 descriptor.needs_init = true; |
| 3209 descriptor.declaration_pos = pattern->position(); |
| 3210 descriptor.initialization_pos = pattern->position(); |
| 3211 descriptor.init_op = Token::INIT_LET; |
| 3212 |
| 3213 DeclarationParsingResult::Declaration decl( |
| 3214 pattern, pattern->position(), |
| 3215 factory()->NewVariableProxy(catch_variable)); |
| 3216 |
| 3217 PatternRewriter::DeclareAndInitializeVariables( |
| 3218 catch_block, &descriptor, &decl, nullptr, CHECK_OK); |
| 3219 } |
| 3220 |
| 3221 Expect(Token::LBRACE, CHECK_OK); |
| 3222 while (peek() != Token::RBRACE) { |
| 3223 Statement* stat = ParseStatementListItem(CHECK_OK); |
| 3224 if (stat && !stat->IsEmpty()) { |
| 3225 catch_block->statements()->Add(stat, zone()); |
| 3226 } |
| 3227 } |
| 3228 Consume(Token::RBRACE); |
| 3229 } |
| 3230 block_scope->set_end_position(scanner()->location().end_pos); |
| 3231 block_scope = block_scope->FinalizeBlockScope(); |
| 3232 catch_block->set_scope(block_scope); |
| 3233 } |
3175 | 3234 |
3176 catch_scope->set_end_position(scanner()->location().end_pos); | 3235 catch_scope->set_end_position(scanner()->location().end_pos); |
3177 tok = peek(); | 3236 tok = peek(); |
3178 } | 3237 } |
3179 | 3238 |
3180 Block* finally_block = NULL; | 3239 Block* finally_block = NULL; |
3181 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3240 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
3182 if (tok == Token::FINALLY) { | 3241 if (tok == Token::FINALLY) { |
3183 Consume(Token::FINALLY); | 3242 Consume(Token::FINALLY); |
3184 finally_block = ParseBlock(NULL, CHECK_OK); | 3243 finally_block = ParseBlock(NULL, CHECK_OK); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4366 ValidateFormalParameters(&formals_classifier, language_mode, | 4425 ValidateFormalParameters(&formals_classifier, language_mode, |
4367 allow_duplicate_parameters, CHECK_OK); | 4426 allow_duplicate_parameters, CHECK_OK); |
4368 | 4427 |
4369 if (is_strict(language_mode)) { | 4428 if (is_strict(language_mode)) { |
4370 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4429 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4371 CHECK_OK); | 4430 CHECK_OK); |
4372 } | 4431 } |
4373 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { | 4432 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { |
4374 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); | 4433 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); |
4375 } | 4434 } |
4376 if (is_strict(language_mode) || allow_harmony_sloppy()) { | 4435 if (is_strict(language_mode) || allow_harmony_sloppy() || |
| 4436 allow_harmony_destructuring()) { |
4377 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4437 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4378 } | 4438 } |
4379 } | 4439 } |
4380 | 4440 |
4381 bool has_duplicate_parameters = | 4441 bool has_duplicate_parameters = |
4382 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4442 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4383 FunctionLiteral::ParameterFlag duplicate_parameters = | 4443 FunctionLiteral::ParameterFlag duplicate_parameters = |
4384 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 4444 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
4385 : FunctionLiteral::kNoDuplicateParameters; | 4445 : FunctionLiteral::kNoDuplicateParameters; |
4386 | 4446 |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6390 | 6450 |
6391 Expression* Parser::SpreadCallNew(Expression* function, | 6451 Expression* Parser::SpreadCallNew(Expression* function, |
6392 ZoneList<v8::internal::Expression*>* args, | 6452 ZoneList<v8::internal::Expression*>* args, |
6393 int pos) { | 6453 int pos) { |
6394 args->InsertAt(0, function, zone()); | 6454 args->InsertAt(0, function, zone()); |
6395 | 6455 |
6396 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6456 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6397 } | 6457 } |
6398 } // namespace internal | 6458 } // namespace internal |
6399 } // namespace v8 | 6459 } // namespace v8 |
OLD | NEW |