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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 4536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4547 rewriter.Run(); | 4547 rewriter.Run(); |
4548 } | 4548 } |
4549 | 4549 |
4550 | 4550 |
4551 Block* Parser::BuildParameterInitializationBlock( | 4551 Block* Parser::BuildParameterInitializationBlock( |
4552 const ParserFormalParameters& parameters, bool* ok) { | 4552 const ParserFormalParameters& parameters, bool* ok) { |
4553 DCHECK(!parameters.is_simple); | 4553 DCHECK(!parameters.is_simple); |
4554 DCHECK(scope_->is_function_scope()); | 4554 DCHECK(scope_->is_function_scope()); |
4555 Block* init_block = | 4555 Block* init_block = |
4556 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4556 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4557 ZoneList<Scope*>* param_scopes = new (zone()) ZoneList<Scope*>(0, zone()); | |
4558 for (int i = 0; i < parameters.params.length(); ++i) { | 4557 for (int i = 0; i < parameters.params.length(); ++i) { |
4559 auto parameter = parameters.params[i]; | 4558 auto parameter = parameters.params[i]; |
4560 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break; | 4559 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break; |
4561 DeclarationDescriptor descriptor; | 4560 DeclarationDescriptor descriptor; |
4562 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4561 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4563 descriptor.parser = this; | 4562 descriptor.parser = this; |
4564 descriptor.scope = scope_; | 4563 descriptor.scope = scope_; |
4565 descriptor.hoist_scope = nullptr; | 4564 descriptor.hoist_scope = nullptr; |
4566 descriptor.mode = LET; | 4565 descriptor.mode = LET; |
4567 descriptor.declaration_pos = parameter.pattern->position(); | 4566 descriptor.declaration_pos = parameter.pattern->position(); |
(...skipping 21 matching lines...) Expand all Loading... |
4589 RelocInfo::kNoPosition); | 4588 RelocInfo::kNoPosition); |
4590 initial_value = factory()->NewConditional( | 4589 initial_value = factory()->NewConditional( |
4591 condition, parameter.initializer, initial_value, | 4590 condition, parameter.initializer, initial_value, |
4592 RelocInfo::kNoPosition); | 4591 RelocInfo::kNoPosition); |
4593 descriptor.initialization_pos = parameter.initializer->position(); | 4592 descriptor.initialization_pos = parameter.initializer->position(); |
4594 initializer_position = parameter.initializer_end_position; | 4593 initializer_position = parameter.initializer_end_position; |
4595 } | 4594 } |
4596 | 4595 |
4597 Scope* param_scope = scope_; | 4596 Scope* param_scope = scope_; |
4598 Block* param_block = init_block; | 4597 Block* param_block = init_block; |
4599 if (!parameter.is_simple()) { | 4598 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
4600 param_scope = NewScope(scope_, BLOCK_SCOPE); | 4599 param_scope = NewScope(scope_, BLOCK_SCOPE); |
4601 param_scope->set_is_declaration_scope(); | 4600 param_scope->set_is_declaration_scope(); |
4602 param_scope->set_start_position(descriptor.initialization_pos); | 4601 param_scope->set_start_position(descriptor.initialization_pos); |
4603 param_scope->set_end_position(parameter.initializer_end_position); | 4602 param_scope->set_end_position(parameter.initializer_end_position); |
4604 param_scopes->Add(param_scope, zone()); | 4603 param_scope->RecordEvalCall(); |
4605 scope_->PropagateUsageFlagsToScope(param_scope); | |
4606 param_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4604 param_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
4607 param_block->set_scope(param_scope); | 4605 param_block->set_scope(param_scope); |
4608 descriptor.hoist_scope = scope_; | 4606 descriptor.hoist_scope = scope_; |
4609 } | 4607 } |
4610 | 4608 |
4611 { | 4609 { |
4612 BlockState block_state(&scope_, param_scope); | 4610 BlockState block_state(&scope_, param_scope); |
4613 DeclarationParsingResult::Declaration decl( | 4611 DeclarationParsingResult::Declaration decl( |
4614 parameter.pattern, initializer_position, initial_value); | 4612 parameter.pattern, initializer_position, initial_value); |
4615 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 4613 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, |
4616 &decl, nullptr, CHECK_OK); | 4614 &decl, nullptr, CHECK_OK); |
4617 } | 4615 } |
4618 | 4616 |
4619 if (!parameter.is_simple()) { | 4617 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
4620 param_scope = param_scope->FinalizeBlockScope(); | 4618 param_scope = param_scope->FinalizeBlockScope(); |
4621 if (param_scope != nullptr) { | 4619 if (param_scope != nullptr) { |
4622 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 4620 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
4623 } | 4621 } |
4624 init_block->statements()->Add(param_block, zone()); | 4622 init_block->statements()->Add(param_block, zone()); |
4625 } | 4623 } |
4626 } | 4624 } |
4627 for (Scope* param_scope : *param_scopes) { | |
4628 scope_->PropagateUsageFlagsToScope(param_scope); | |
4629 } | |
4630 return init_block; | 4625 return init_block; |
4631 } | 4626 } |
4632 | 4627 |
4633 Block* Parser::BuildRejectPromiseOnException(Block* block) { | 4628 Block* Parser::BuildRejectPromiseOnException(Block* block) { |
4634 // try { <block> } catch (error) { return Promise.reject(error); } | 4629 // try { <block> } catch (error) { return Promise.reject(error); } |
4635 Block* try_block = block; | 4630 Block* try_block = block; |
4636 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); | 4631 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); |
4637 catch_scope->set_is_hidden(); | 4632 catch_scope->set_is_hidden(); |
4638 Variable* catch_variable = | 4633 Variable* catch_variable = |
4639 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 4634 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, |
(...skipping 2325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6965 try_block, target); | 6960 try_block, target); |
6966 final_loop = target; | 6961 final_loop = target; |
6967 } | 6962 } |
6968 | 6963 |
6969 return final_loop; | 6964 return final_loop; |
6970 } | 6965 } |
6971 | 6966 |
6972 | 6967 |
6973 } // namespace internal | 6968 } // namespace internal |
6974 } // namespace v8 | 6969 } // namespace v8 |
OLD | NEW |