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 4070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4081 DCHECK(parser_->allow_harmony_default_parameters()); | 4081 DCHECK(parser_->allow_harmony_default_parameters()); |
4082 DCHECK(!assignment->is_compound()); | 4082 DCHECK(!assignment->is_compound()); |
4083 initializer = assignment->value(); | 4083 initializer = assignment->value(); |
4084 expr = assignment->target(); | 4084 expr = assignment->target(); |
4085 | 4085 |
4086 // TODO(adamk): Only call this if necessary. | 4086 // TODO(adamk): Only call this if necessary. |
4087 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, | 4087 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, |
4088 parser_->scope_, parameters->scope); | 4088 parser_->scope_, parameters->scope); |
4089 } | 4089 } |
4090 | 4090 |
4091 AddFormalParameter(parameters, expr, initializer, is_rest); | 4091 // TODO(adamk): params_loc.end_pos is not the correct initializer position, |
| 4092 // but it should be conservative enough to trigger hole checks for variables |
| 4093 // referenced in the initializer (if any). |
| 4094 AddFormalParameter(parameters, expr, initializer, params_loc.end_pos, |
| 4095 is_rest); |
4092 } | 4096 } |
4093 | 4097 |
4094 | 4098 |
4095 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4099 DoExpression* Parser::ParseDoExpression(bool* ok) { |
4096 // AssignmentExpression :: | 4100 // AssignmentExpression :: |
4097 // do '{' StatementList '}' | 4101 // do '{' StatementList '}' |
4098 int pos = peek_position(); | 4102 int pos = peek_position(); |
4099 | 4103 |
4100 Expect(Token::DO, CHECK_OK); | 4104 Expect(Token::DO, CHECK_OK); |
4101 Variable* result = | 4105 Variable* result = |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4543 DeclarationDescriptor descriptor; | 4547 DeclarationDescriptor descriptor; |
4544 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4548 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4545 descriptor.parser = this; | 4549 descriptor.parser = this; |
4546 descriptor.declaration_scope = scope_; | 4550 descriptor.declaration_scope = scope_; |
4547 descriptor.scope = scope_; | 4551 descriptor.scope = scope_; |
4548 descriptor.hoist_scope = nullptr; | 4552 descriptor.hoist_scope = nullptr; |
4549 descriptor.mode = LET; | 4553 descriptor.mode = LET; |
4550 descriptor.is_const = false; | 4554 descriptor.is_const = false; |
4551 descriptor.needs_init = true; | 4555 descriptor.needs_init = true; |
4552 descriptor.declaration_pos = parameter.pattern->position(); | 4556 descriptor.declaration_pos = parameter.pattern->position(); |
| 4557 // The position that will be used by the AssignmentExpression |
| 4558 // which copies from the temp parameter to the pattern. |
| 4559 // |
| 4560 // TODO(adamk): Should this be RelocInfo::kNoPosition, since |
| 4561 // it's just copying from a temp var to the real param var? |
4553 descriptor.initialization_pos = parameter.pattern->position(); | 4562 descriptor.initialization_pos = parameter.pattern->position(); |
| 4563 // The initializer position which will end up in, |
| 4564 // Variable::initializer_position(), used for hole check elimination. |
| 4565 int initializer_position = parameter.pattern->position(); |
4554 Expression* initial_value = | 4566 Expression* initial_value = |
4555 factory()->NewVariableProxy(parameters.scope->parameter(i)); | 4567 factory()->NewVariableProxy(parameters.scope->parameter(i)); |
4556 if (parameter.initializer != nullptr) { | 4568 if (parameter.initializer != nullptr) { |
4557 // IS_UNDEFINED($param) ? initializer : $param | 4569 // IS_UNDEFINED($param) ? initializer : $param |
4558 DCHECK(!parameter.is_rest); | 4570 DCHECK(!parameter.is_rest); |
4559 auto condition = factory()->NewCompareOperation( | 4571 auto condition = factory()->NewCompareOperation( |
4560 Token::EQ_STRICT, | 4572 Token::EQ_STRICT, |
4561 factory()->NewVariableProxy(parameters.scope->parameter(i)), | 4573 factory()->NewVariableProxy(parameters.scope->parameter(i)), |
4562 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 4574 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
4563 RelocInfo::kNoPosition); | 4575 RelocInfo::kNoPosition); |
4564 initial_value = factory()->NewConditional( | 4576 initial_value = factory()->NewConditional( |
4565 condition, parameter.initializer, initial_value, | 4577 condition, parameter.initializer, initial_value, |
4566 RelocInfo::kNoPosition); | 4578 RelocInfo::kNoPosition); |
4567 descriptor.initialization_pos = parameter.initializer->position(); | 4579 descriptor.initialization_pos = parameter.initializer->position(); |
| 4580 initializer_position = parameter.initializer_end_position; |
4568 } else if (parameter.is_rest) { | 4581 } else if (parameter.is_rest) { |
4569 // $rest = []; | 4582 // $rest = []; |
4570 // for (var $argument_index = $rest_index; | 4583 // for (var $argument_index = $rest_index; |
4571 // $argument_index < %_ArgumentsLength(); | 4584 // $argument_index < %_ArgumentsLength(); |
4572 // ++$argument_index) { | 4585 // ++$argument_index) { |
4573 // %AppendElement($rest, %_Arguments($argument_index)); | 4586 // %AppendElement($rest, %_Arguments($argument_index)); |
4574 // } | 4587 // } |
4575 // let <param> = $rest; | 4588 // let <param> = $rest; |
4576 DCHECK(parameter.pattern->IsVariableProxy()); | 4589 DCHECK(parameter.pattern->IsVariableProxy()); |
4577 DCHECK_EQ(i, parameters.params.length() - 1); | 4590 DCHECK_EQ(i, parameters.params.length() - 1); |
4578 | 4591 |
4579 int pos = parameter.pattern->position(); | |
4580 Variable* temp_var = parameters.scope->parameter(i); | 4592 Variable* temp_var = parameters.scope->parameter(i); |
4581 auto empty_values = new (zone()) ZoneList<Expression*>(0, zone()); | 4593 auto empty_values = new (zone()) ZoneList<Expression*>(0, zone()); |
4582 auto empty_array = factory()->NewArrayLiteral( | 4594 auto empty_array = factory()->NewArrayLiteral( |
4583 empty_values, parameters.rest_array_literal_index, | 4595 empty_values, parameters.rest_array_literal_index, |
4584 is_strong(language_mode()), RelocInfo::kNoPosition); | 4596 is_strong(language_mode()), RelocInfo::kNoPosition); |
4585 | 4597 |
4586 auto init_array = factory()->NewAssignment( | 4598 auto init_array = factory()->NewAssignment( |
4587 Token::INIT, factory()->NewVariableProxy(temp_var), empty_array, | 4599 Token::INIT, factory()->NewVariableProxy(temp_var), empty_array, |
4588 RelocInfo::kNoPosition); | 4600 RelocInfo::kNoPosition); |
4589 | 4601 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4633 RelocInfo::kNoPosition), | 4645 RelocInfo::kNoPosition), |
4634 RelocInfo::kNoPosition); | 4646 RelocInfo::kNoPosition); |
4635 | 4647 |
4636 loop->Initialize(init, cond, next, body); | 4648 loop->Initialize(init, cond, next, body); |
4637 | 4649 |
4638 init_block->statements()->Add( | 4650 init_block->statements()->Add( |
4639 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), | 4651 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), |
4640 zone()); | 4652 zone()); |
4641 | 4653 |
4642 init_block->statements()->Add(loop, zone()); | 4654 init_block->statements()->Add(loop, zone()); |
4643 | |
4644 descriptor.initialization_pos = pos; | |
4645 } | 4655 } |
4646 | 4656 |
4647 Scope* param_scope = scope_; | 4657 Scope* param_scope = scope_; |
4648 Block* param_block = init_block; | 4658 Block* param_block = init_block; |
4649 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { | 4659 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
4650 param_scope = NewScope(scope_, BLOCK_SCOPE); | 4660 param_scope = NewScope(scope_, BLOCK_SCOPE); |
4651 param_scope->set_is_declaration_scope(); | 4661 param_scope->set_is_declaration_scope(); |
4652 param_scope->set_start_position(parameter.pattern->position()); | 4662 param_scope->set_start_position(parameter.pattern->position()); |
4653 param_scope->set_end_position(RelocInfo::kNoPosition); | 4663 param_scope->set_end_position(RelocInfo::kNoPosition); |
4654 param_scope->RecordEvalCall(); | 4664 param_scope->RecordEvalCall(); |
4655 param_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4665 param_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
4656 param_block->set_scope(param_scope); | 4666 param_block->set_scope(param_scope); |
4657 descriptor.hoist_scope = scope_; | 4667 descriptor.hoist_scope = scope_; |
4658 } | 4668 } |
4659 | 4669 |
4660 { | 4670 { |
4661 BlockState block_state(&scope_, param_scope); | 4671 BlockState block_state(&scope_, param_scope); |
4662 DeclarationParsingResult::Declaration decl( | 4672 DeclarationParsingResult::Declaration decl( |
4663 parameter.pattern, parameter.pattern->position(), initial_value); | 4673 parameter.pattern, initializer_position, initial_value); |
4664 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 4674 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, |
4665 &decl, nullptr, CHECK_OK); | 4675 &decl, nullptr, CHECK_OK); |
4666 } | 4676 } |
4667 | 4677 |
4668 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { | 4678 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
4669 param_scope = param_scope->FinalizeBlockScope(); | 4679 param_scope = param_scope->FinalizeBlockScope(); |
4670 if (param_scope != nullptr) { | 4680 if (param_scope != nullptr) { |
4671 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 4681 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
4672 } | 4682 } |
4673 init_block->statements()->Add(param_block, zone()); | 4683 init_block->statements()->Add(param_block, zone()); |
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6456 } | 6466 } |
6457 | 6467 |
6458 | 6468 |
6459 void Parser::RaiseLanguageMode(LanguageMode mode) { | 6469 void Parser::RaiseLanguageMode(LanguageMode mode) { |
6460 SetLanguageMode(scope_, | 6470 SetLanguageMode(scope_, |
6461 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 6471 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
6462 } | 6472 } |
6463 | 6473 |
6464 } // namespace internal | 6474 } // namespace internal |
6465 } // namespace v8 | 6475 } // namespace v8 |
OLD | NEW |