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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } else { | 265 } else { |
266 initialize = NULL; | 266 initialize = NULL; |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 if (initialize != NULL) { | 270 if (initialize != NULL) { |
271 block_->statements()->Add( | 271 block_->statements()->Add( |
272 factory()->NewExpressionStatement(initialize, initialize->position()), | 272 factory()->NewExpressionStatement(initialize, initialize->position()), |
273 zone()); | 273 zone()); |
274 } | 274 } |
275 } else if (value != nullptr && (descriptor_->mode == CONST_LEGACY || | 275 } else if (value != nullptr && IsLexicalVariableMode(descriptor_->mode)) { |
276 IsLexicalVariableMode(descriptor_->mode))) { | 276 // For 'let' and 'const' declared variables the initialization always |
277 // Constant initializations always assign to the declared constant which | 277 // assigns to the declared variable. |
278 // is always at the function scope level. This is only relevant for | |
279 // dynamically looked-up variables and constants (the | |
280 // start context for constant lookups is always the function context, | |
281 // while it is the top context for var declared variables). Sigh... | |
282 // For 'let' and 'const' declared variables in harmony mode the | |
283 // initialization also always assigns to the declared variable. | |
284 DCHECK_NOT_NULL(proxy); | 278 DCHECK_NOT_NULL(proxy); |
285 DCHECK_NOT_NULL(proxy->var()); | 279 DCHECK_NOT_NULL(proxy->var()); |
286 DCHECK_NOT_NULL(value); | 280 DCHECK_NOT_NULL(value); |
287 // Add break location for destructured sub-pattern. | 281 // Add break location for destructured sub-pattern. |
288 int pos = IsSubPattern() ? pattern->position() : value->position(); | 282 int pos = IsSubPattern() ? pattern->position() : value->position(); |
289 Assignment* assignment = | 283 Assignment* assignment = |
290 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 284 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
291 block_->statements()->Add( | 285 block_->statements()->Add( |
292 factory()->NewExpressionStatement(assignment, pos), zone()); | 286 factory()->NewExpressionStatement(assignment, pos), zone()); |
293 value = NULL; | 287 value = NULL; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 NOT_A_PATTERN(TryFinallyStatement) | 740 NOT_A_PATTERN(TryFinallyStatement) |
747 NOT_A_PATTERN(UnaryOperation) | 741 NOT_A_PATTERN(UnaryOperation) |
748 NOT_A_PATTERN(VariableDeclaration) | 742 NOT_A_PATTERN(VariableDeclaration) |
749 NOT_A_PATTERN(WhileStatement) | 743 NOT_A_PATTERN(WhileStatement) |
750 NOT_A_PATTERN(WithStatement) | 744 NOT_A_PATTERN(WithStatement) |
751 NOT_A_PATTERN(Yield) | 745 NOT_A_PATTERN(Yield) |
752 | 746 |
753 #undef NOT_A_PATTERN | 747 #undef NOT_A_PATTERN |
754 } // namespace internal | 748 } // namespace internal |
755 } // namespace v8 | 749 } // namespace v8 |
OLD | NEW |