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 248 matching lines...) Loading... |
259 initialize = | 259 initialize = |
260 factory()->NewCallRuntime(Runtime::kInitializeVarGlobal, arguments, | 260 factory()->NewCallRuntime(Runtime::kInitializeVarGlobal, arguments, |
261 descriptor_->declaration_pos); | 261 descriptor_->declaration_pos); |
262 } else { | 262 } else { |
263 initialize = NULL; | 263 initialize = NULL; |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 if (initialize != NULL) { | 267 if (initialize != NULL) { |
268 block_->statements()->Add( | 268 block_->statements()->Add( |
269 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), | 269 factory()->NewExpressionStatement(initialize, initialize->position()), |
270 zone()); | 270 zone()); |
271 } | 271 } |
272 } else if (value != nullptr && (descriptor_->mode == CONST_LEGACY || | 272 } else if (value != nullptr && (descriptor_->mode == CONST_LEGACY || |
273 IsLexicalVariableMode(descriptor_->mode))) { | 273 IsLexicalVariableMode(descriptor_->mode))) { |
274 // Constant initializations always assign to the declared constant which | 274 // Constant initializations always assign to the declared constant which |
275 // is always at the function scope level. This is only relevant for | 275 // is always at the function scope level. This is only relevant for |
276 // dynamically looked-up variables and constants (the | 276 // dynamically looked-up variables and constants (the |
277 // start context for constant lookups is always the function context, | 277 // start context for constant lookups is always the function context, |
278 // while it is the top context for var declared variables). Sigh... | 278 // while it is the top context for var declared variables). Sigh... |
279 // For 'let' and 'const' declared variables in harmony mode the | 279 // For 'let' and 'const' declared variables in harmony mode the |
280 // initialization also always assigns to the declared variable. | 280 // initialization also always assigns to the declared variable. |
281 DCHECK_NOT_NULL(proxy); | 281 DCHECK_NOT_NULL(proxy); |
282 DCHECK_NOT_NULL(proxy->var()); | 282 DCHECK_NOT_NULL(proxy->var()); |
283 DCHECK_NOT_NULL(value); | 283 DCHECK_NOT_NULL(value); |
284 // Add break location for destructured sub-pattern. | 284 // Add break location for destructured sub-pattern. |
285 int pos = IsSubPattern() ? pattern->position() : RelocInfo::kNoPosition; | 285 int pos = |
| 286 IsSubPattern() ? pattern->position() : descriptor_->initialization_pos; |
286 Assignment* assignment = | 287 Assignment* assignment = |
287 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 288 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
288 block_->statements()->Add( | 289 block_->statements()->Add( |
289 factory()->NewExpressionStatement(assignment, pos), zone()); | 290 factory()->NewExpressionStatement(assignment, pos), zone()); |
290 value = NULL; | 291 value = NULL; |
291 } | 292 } |
292 | 293 |
293 // Add an assignment node to the initialization statement block if we still | 294 // Add an assignment node to the initialization statement block if we still |
294 // have a pending initialization value. | 295 // have a pending initialization value. |
295 if (value != NULL) { | 296 if (value != NULL) { |
296 DCHECK(descriptor_->mode == VAR); | 297 DCHECK(descriptor_->mode == VAR); |
297 // 'var' initializations are simply assignments (with all the consequences | 298 // 'var' initializations are simply assignments (with all the consequences |
298 // if they are inside a 'with' statement - they may change a 'with' object | 299 // if they are inside a 'with' statement - they may change a 'with' object |
299 // property). | 300 // property). |
300 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); | 301 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); |
301 // Add break location for destructured sub-pattern. | 302 // Add break location for destructured sub-pattern. |
302 int pos = IsSubPattern() ? pattern->position() : RelocInfo::kNoPosition; | 303 int pos = |
| 304 IsSubPattern() ? pattern->position() : descriptor_->initialization_pos; |
303 Assignment* assignment = | 305 Assignment* assignment = |
304 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 306 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
305 block_->statements()->Add( | 307 block_->statements()->Add( |
306 factory()->NewExpressionStatement(assignment, pos), zone()); | 308 factory()->NewExpressionStatement(assignment, pos), zone()); |
307 } | 309 } |
308 } | 310 } |
309 | 311 |
310 | 312 |
311 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { | 313 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { |
312 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); | 314 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); |
(...skipping 305 matching lines...) Loading... |
618 NOT_A_PATTERN(TryFinallyStatement) | 620 NOT_A_PATTERN(TryFinallyStatement) |
619 NOT_A_PATTERN(UnaryOperation) | 621 NOT_A_PATTERN(UnaryOperation) |
620 NOT_A_PATTERN(VariableDeclaration) | 622 NOT_A_PATTERN(VariableDeclaration) |
621 NOT_A_PATTERN(WhileStatement) | 623 NOT_A_PATTERN(WhileStatement) |
622 NOT_A_PATTERN(WithStatement) | 624 NOT_A_PATTERN(WithStatement) |
623 NOT_A_PATTERN(Yield) | 625 NOT_A_PATTERN(Yield) |
624 | 626 |
625 #undef NOT_A_PATTERN | 627 #undef NOT_A_PATTERN |
626 } // namespace internal | 628 } // namespace internal |
627 } // namespace v8 | 629 } // namespace v8 |
OLD | NEW |