| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/ast/ast.h" | 5 #include "src/ast/ast.h" |
| 6 #include "src/messages.h" | 6 #include "src/messages.h" |
| 7 #include "src/parsing/parameter-initializer-rewriter.h" | 7 #include "src/parsing/parameter-initializer-rewriter.h" |
| 8 #include "src/parsing/parser.h" | 8 #include "src/parsing/parser.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 descriptor_->scope->RemoveUnresolved(pattern); | 132 descriptor_->scope->RemoveUnresolved(pattern); |
| 133 | 133 |
| 134 // Declare variable. | 134 // Declare variable. |
| 135 // Note that we *always* must treat the initial value via a separate init | 135 // Note that we *always* must treat the initial value via a separate init |
| 136 // assignment for variables and constants because the value must be assigned | 136 // assignment for variables and constants because the value must be assigned |
| 137 // when the variable is encountered in the source. But the variable/constant | 137 // when the variable is encountered in the source. But the variable/constant |
| 138 // is declared (and set to 'undefined') upon entering the function within | 138 // is declared (and set to 'undefined') upon entering the function within |
| 139 // which the variable or constant is declared. Only function variables have | 139 // which the variable or constant is declared. Only function variables have |
| 140 // an initial value in the declaration (because they are initialized upon | 140 // an initial value in the declaration (because they are initialized upon |
| 141 // entering the function). | 141 // entering the function). |
| 142 // | |
| 143 // If we have a legacy const declaration, in an inner scope, the proxy | |
| 144 // is always bound to the declared variable (independent of possibly | |
| 145 // surrounding 'with' statements). | |
| 146 // For let/const declarations in harmony mode, we can also immediately | |
| 147 // pre-resolve the proxy because it resides in the same scope as the | |
| 148 // declaration. | |
| 149 const AstRawString* name = pattern->raw_name(); | 142 const AstRawString* name = pattern->raw_name(); |
| 150 VariableProxy* proxy = descriptor_->scope->NewUnresolved( | 143 VariableProxy* proxy = descriptor_->scope->NewUnresolved( |
| 151 factory(), name, parser_->scanner()->location().beg_pos, | 144 factory(), name, parser_->scanner()->location().beg_pos, |
| 152 parser_->scanner()->location().end_pos); | 145 parser_->scanner()->location().end_pos); |
| 153 Declaration* declaration = factory()->NewVariableDeclaration( | 146 Declaration* declaration = factory()->NewVariableDeclaration( |
| 154 proxy, descriptor_->scope, descriptor_->declaration_pos); | 147 proxy, descriptor_->scope, descriptor_->declaration_pos); |
| 155 Variable* var = parser_->Declare(declaration, descriptor_->declaration_kind, | 148 Variable* var = parser_->Declare(declaration, descriptor_->declaration_kind, |
| 156 descriptor_->mode, | 149 descriptor_->mode, |
| 157 DefaultInitializationFlag(descriptor_->mode), | 150 DefaultInitializationFlag(descriptor_->mode), |
| 158 ok_, descriptor_->hoist_scope); | 151 ok_, descriptor_->hoist_scope); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 NOT_A_PATTERN(TryFinallyStatement) | 695 NOT_A_PATTERN(TryFinallyStatement) |
| 703 NOT_A_PATTERN(UnaryOperation) | 696 NOT_A_PATTERN(UnaryOperation) |
| 704 NOT_A_PATTERN(VariableDeclaration) | 697 NOT_A_PATTERN(VariableDeclaration) |
| 705 NOT_A_PATTERN(WhileStatement) | 698 NOT_A_PATTERN(WhileStatement) |
| 706 NOT_A_PATTERN(WithStatement) | 699 NOT_A_PATTERN(WithStatement) |
| 707 NOT_A_PATTERN(Yield) | 700 NOT_A_PATTERN(Yield) |
| 708 | 701 |
| 709 #undef NOT_A_PATTERN | 702 #undef NOT_A_PATTERN |
| 710 } // namespace internal | 703 } // namespace internal |
| 711 } // namespace v8 | 704 } // namespace v8 |
| OLD | NEW |