| 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/v8.h" | 5 #include "src/v8.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 3865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3876 duplicate_loc, ok); | 3876 duplicate_loc, ok); |
| 3877 if (!*ok) return; | 3877 if (!*ok) return; |
| 3878 // LHS of comma expression should be unparenthesized. | 3878 // LHS of comma expression should be unparenthesized. |
| 3879 expr = right; | 3879 expr = right; |
| 3880 } | 3880 } |
| 3881 | 3881 |
| 3882 // Only the right-most expression may be a rest parameter. | 3882 // Only the right-most expression may be a rest parameter. |
| 3883 DCHECK(!parameters->has_rest); | 3883 DCHECK(!parameters->has_rest); |
| 3884 | 3884 |
| 3885 bool is_rest = expr->IsSpread(); | 3885 bool is_rest = expr->IsSpread(); |
| 3886 if (is_rest) expr = expr->AsSpread()->expression(); | 3886 if (is_rest) { |
| 3887 expr = expr->AsSpread()->expression(); |
| 3888 parameters->has_rest = true; |
| 3889 } |
| 3890 if (parameters->is_simple) { |
| 3891 parameters->is_simple = !is_rest && expr->IsVariableProxy(); |
| 3892 } |
| 3887 | 3893 |
| 3888 if (expr->IsVariableProxy()) { | 3894 if (expr->IsVariableProxy()) { |
| 3889 // When the formal parameter was originally seen, it was parsed as a | 3895 // When the formal parameter was originally seen, it was parsed as a |
| 3890 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3896 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
| 3891 // parse-time side-effect for parameters that are single-names (not | 3897 // parse-time side-effect for parameters that are single-names (not |
| 3892 // patterns; for patterns that happens uniformly in | 3898 // patterns; for patterns that happens uniformly in |
| 3893 // PatternRewriter::VisitVariableProxy). | 3899 // PatternRewriter::VisitVariableProxy). |
| 3894 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3900 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
| 3895 } | 3901 } |
| 3896 | 3902 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4292 RelocInfo::kNoPosition); | 4298 RelocInfo::kNoPosition); |
| 4293 IfStatement* if_statement = factory()->NewIfStatement( | 4299 IfStatement* if_statement = factory()->NewIfStatement( |
| 4294 condition, factory()->NewExpressionStatement(throw_type_error, | 4300 condition, factory()->NewExpressionStatement(throw_type_error, |
| 4295 RelocInfo::kNoPosition), | 4301 RelocInfo::kNoPosition), |
| 4296 factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 4302 factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
| 4297 RelocInfo::kNoPosition); | 4303 RelocInfo::kNoPosition); |
| 4298 return if_statement; | 4304 return if_statement; |
| 4299 } | 4305 } |
| 4300 | 4306 |
| 4301 | 4307 |
| 4302 bool Parser::IsSimpleParameterList(const ParserFormalParameters& parameters) { | |
| 4303 for (auto parameter : parameters.params) { | |
| 4304 if (parameter.pattern != nullptr) return false; | |
| 4305 } | |
| 4306 return true; | |
| 4307 } | |
| 4308 | |
| 4309 | |
| 4310 Block* Parser::BuildParameterInitializationBlock( | 4308 Block* Parser::BuildParameterInitializationBlock( |
| 4311 const ParserFormalParameters& parameters, bool* ok) { | 4309 const ParserFormalParameters& parameters, bool* ok) { |
| 4312 DCHECK(!IsSimpleParameterList(parameters)); | 4310 DCHECK(!parameters.is_simple); |
| 4313 DCHECK(scope_->is_function_scope()); | 4311 DCHECK(scope_->is_function_scope()); |
| 4314 Block* init_block = | 4312 Block* init_block = |
| 4315 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4313 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
| 4316 for (auto parameter : parameters.params) { | 4314 for (auto parameter : parameters.params) { |
| 4317 if (parameter.pattern == nullptr) continue; | 4315 if (parameter.pattern == nullptr) continue; |
| 4318 DeclarationDescriptor descriptor; | 4316 DeclarationDescriptor descriptor; |
| 4319 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4317 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
| 4320 descriptor.parser = this; | 4318 descriptor.parser = this; |
| 4321 descriptor.declaration_scope = scope_; | 4319 descriptor.declaration_scope = scope_; |
| 4322 descriptor.scope = scope_; | 4320 descriptor.scope = scope_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4333 &decl, nullptr, CHECK_OK); | 4331 &decl, nullptr, CHECK_OK); |
| 4334 } | 4332 } |
| 4335 return init_block; | 4333 return init_block; |
| 4336 } | 4334 } |
| 4337 | 4335 |
| 4338 | 4336 |
| 4339 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4337 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
| 4340 const AstRawString* function_name, int pos, | 4338 const AstRawString* function_name, int pos, |
| 4341 const ParserFormalParameters& parameters, Variable* fvar, | 4339 const ParserFormalParameters& parameters, Variable* fvar, |
| 4342 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 4340 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
| 4343 bool is_simple_parameter_list = IsSimpleParameterList(parameters); | |
| 4344 // Everything inside an eagerly parsed function will be parsed eagerly | 4341 // Everything inside an eagerly parsed function will be parsed eagerly |
| 4345 // (see comment above). | 4342 // (see comment above). |
| 4346 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 4343 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 4347 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); | 4344 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); |
| 4348 if (fvar != NULL) { | 4345 if (fvar != NULL) { |
| 4349 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); | 4346 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); |
| 4350 fproxy->BindTo(fvar); | 4347 fproxy->BindTo(fvar); |
| 4351 result->Add(factory()->NewExpressionStatement( | 4348 result->Add(factory()->NewExpressionStatement( |
| 4352 factory()->NewAssignment(fvar_init_op, | 4349 factory()->NewAssignment(fvar_init_op, |
| 4353 fproxy, | 4350 fproxy, |
| 4354 factory()->NewThisFunction(pos), | 4351 factory()->NewThisFunction(pos), |
| 4355 RelocInfo::kNoPosition), | 4352 RelocInfo::kNoPosition), |
| 4356 RelocInfo::kNoPosition), zone()); | 4353 RelocInfo::kNoPosition), zone()); |
| 4357 } | 4354 } |
| 4358 | 4355 |
| 4359 | 4356 |
| 4360 // For concise constructors, check that they are constructed, | 4357 // For concise constructors, check that they are constructed, |
| 4361 // not called. | 4358 // not called. |
| 4362 if (i::IsConstructor(kind)) { | 4359 if (i::IsConstructor(kind)) { |
| 4363 AddAssertIsConstruct(result, pos); | 4360 AddAssertIsConstruct(result, pos); |
| 4364 } | 4361 } |
| 4365 | 4362 |
| 4366 ZoneList<Statement*>* body = result; | 4363 ZoneList<Statement*>* body = result; |
| 4367 Scope* inner_scope = nullptr; | 4364 Scope* inner_scope = nullptr; |
| 4368 Block* inner_block = nullptr; | 4365 Block* inner_block = nullptr; |
| 4369 if (!is_simple_parameter_list) { | 4366 if (!parameters.is_simple) { |
| 4370 inner_scope = NewScope(scope_, BLOCK_SCOPE); | 4367 inner_scope = NewScope(scope_, BLOCK_SCOPE); |
| 4371 inner_scope->set_is_declaration_scope(); | 4368 inner_scope->set_is_declaration_scope(); |
| 4372 inner_scope->set_start_position(scanner()->location().beg_pos); | 4369 inner_scope->set_start_position(scanner()->location().beg_pos); |
| 4373 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4370 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
| 4374 inner_block->set_scope(inner_scope); | 4371 inner_block->set_scope(inner_scope); |
| 4375 body = inner_block->statements(); | 4372 body = inner_block->statements(); |
| 4376 } | 4373 } |
| 4377 | 4374 |
| 4378 { | 4375 { |
| 4379 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_); | 4376 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4416 factory()->NewReturnStatement( | 4413 factory()->NewReturnStatement( |
| 4417 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4414 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), |
| 4418 RelocInfo::kNoPosition), | 4415 RelocInfo::kNoPosition), |
| 4419 zone()); | 4416 zone()); |
| 4420 } | 4417 } |
| 4421 } | 4418 } |
| 4422 | 4419 |
| 4423 Expect(Token::RBRACE, CHECK_OK); | 4420 Expect(Token::RBRACE, CHECK_OK); |
| 4424 scope_->set_end_position(scanner()->location().end_pos); | 4421 scope_->set_end_position(scanner()->location().end_pos); |
| 4425 | 4422 |
| 4426 if (!is_simple_parameter_list) { | 4423 if (!parameters.is_simple) { |
| 4427 DCHECK_NOT_NULL(inner_scope); | 4424 DCHECK_NOT_NULL(inner_scope); |
| 4428 DCHECK_EQ(body, inner_block->statements()); | 4425 DCHECK_EQ(body, inner_block->statements()); |
| 4429 scope_->SetLanguageMode(inner_scope->language_mode()); | 4426 scope_->SetLanguageMode(inner_scope->language_mode()); |
| 4430 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); | 4427 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); |
| 4431 DCHECK_NOT_NULL(init_block); | 4428 DCHECK_NOT_NULL(init_block); |
| 4432 | 4429 |
| 4433 inner_scope->set_end_position(scanner()->location().end_pos); | 4430 inner_scope->set_end_position(scanner()->location().end_pos); |
| 4434 inner_scope = inner_scope->FinalizeBlockScope(); | 4431 inner_scope = inner_scope->FinalizeBlockScope(); |
| 4435 if (inner_scope != nullptr) { | 4432 if (inner_scope != nullptr) { |
| 4436 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); | 4433 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); |
| (...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5983 Expression* Parser::SpreadCallNew(Expression* function, | 5980 Expression* Parser::SpreadCallNew(Expression* function, |
| 5984 ZoneList<v8::internal::Expression*>* args, | 5981 ZoneList<v8::internal::Expression*>* args, |
| 5985 int pos) { | 5982 int pos) { |
| 5986 args->InsertAt(0, function, zone()); | 5983 args->InsertAt(0, function, zone()); |
| 5987 | 5984 |
| 5988 return factory()->NewCallRuntime( | 5985 return factory()->NewCallRuntime( |
| 5989 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5986 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5990 } | 5987 } |
| 5991 } // namespace internal | 5988 } // namespace internal |
| 5992 } // namespace v8 | 5989 } // namespace v8 |
| OLD | NEW |