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.h" | 5 #include "src/ast.h" |
6 #include "src/messages.h" | 6 #include "src/messages.h" |
| 7 #include "src/parameter-initializer-rewriter.h" |
7 #include "src/parser.h" | 8 #include "src/parser.h" |
8 | 9 |
9 namespace v8 { | 10 namespace v8 { |
10 | 11 |
11 namespace internal { | 12 namespace internal { |
12 | 13 |
13 | 14 |
14 void Parser::PatternRewriter::DeclareAndInitializeVariables( | 15 void Parser::PatternRewriter::DeclareAndInitializeVariables( |
15 Block* block, const DeclarationDescriptor* declaration_descriptor, | 16 Block* block, const DeclarationDescriptor* declaration_descriptor, |
16 const DeclarationParsingResult::Declaration* declaration, | 17 const DeclarationParsingResult::Declaration* declaration, |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // let {<pattern> = <init>} = <value> | 353 // let {<pattern> = <init>} = <value> |
353 // becomes | 354 // becomes |
354 // temp = <value>; | 355 // temp = <value>; |
355 // <pattern> = temp === undefined ? <init> : temp; | 356 // <pattern> = temp === undefined ? <init> : temp; |
356 DCHECK(node->op() == Token::ASSIGN); | 357 DCHECK(node->op() == Token::ASSIGN); |
357 auto temp = CreateTempVar(current_value_); | 358 auto temp = CreateTempVar(current_value_); |
358 Expression* is_undefined = factory()->NewCompareOperation( | 359 Expression* is_undefined = factory()->NewCompareOperation( |
359 Token::EQ_STRICT, factory()->NewVariableProxy(temp), | 360 Token::EQ_STRICT, factory()->NewVariableProxy(temp), |
360 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 361 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
361 RelocInfo::kNoPosition); | 362 RelocInfo::kNoPosition); |
| 363 Expression* initializer = node->value(); |
| 364 if (descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER && |
| 365 descriptor_->scope->is_arrow_scope()) { |
| 366 // TODO(adamk): Only call this if necessary. |
| 367 RewriteParameterInitializerScope( |
| 368 descriptor_->parser->stack_limit(), initializer, |
| 369 descriptor_->scope->outer_scope(), descriptor_->scope); |
| 370 } |
362 Expression* value = factory()->NewConditional( | 371 Expression* value = factory()->NewConditional( |
363 is_undefined, node->value(), factory()->NewVariableProxy(temp), | 372 is_undefined, initializer, factory()->NewVariableProxy(temp), |
364 RelocInfo::kNoPosition); | 373 RelocInfo::kNoPosition); |
365 RecurseIntoSubpattern(node->target(), value); | 374 RecurseIntoSubpattern(node->target(), value); |
366 } | 375 } |
367 | 376 |
368 | 377 |
369 // =============== UNREACHABLE ============================= | 378 // =============== UNREACHABLE ============================= |
370 | 379 |
371 void Parser::PatternRewriter::Visit(AstNode* node) { UNREACHABLE(); } | 380 void Parser::PatternRewriter::Visit(AstNode* node) { UNREACHABLE(); } |
372 | 381 |
373 #define NOT_A_PATTERN(Node) \ | 382 #define NOT_A_PATTERN(Node) \ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 NOT_A_PATTERN(TryFinallyStatement) | 426 NOT_A_PATTERN(TryFinallyStatement) |
418 NOT_A_PATTERN(UnaryOperation) | 427 NOT_A_PATTERN(UnaryOperation) |
419 NOT_A_PATTERN(VariableDeclaration) | 428 NOT_A_PATTERN(VariableDeclaration) |
420 NOT_A_PATTERN(WhileStatement) | 429 NOT_A_PATTERN(WhileStatement) |
421 NOT_A_PATTERN(WithStatement) | 430 NOT_A_PATTERN(WithStatement) |
422 NOT_A_PATTERN(Yield) | 431 NOT_A_PATTERN(Yield) |
423 | 432 |
424 #undef NOT_A_PATTERN | 433 #undef NOT_A_PATTERN |
425 } // namespace internal | 434 } // namespace internal |
426 } // namespace v8 | 435 } // namespace v8 |
OLD | NEW |