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 14 matching lines...) Expand all Loading... |
25 rewriter.block_ = block; | 25 rewriter.block_ = block; |
26 rewriter.descriptor_ = declaration_descriptor; | 26 rewriter.descriptor_ = declaration_descriptor; |
27 rewriter.names_ = names; | 27 rewriter.names_ = names; |
28 rewriter.ok_ = ok; | 28 rewriter.ok_ = ok; |
29 | 29 |
30 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer); | 30 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer); |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 void Parser::PatternRewriter::RewriteDestructuringAssignment( | 34 void Parser::PatternRewriter::RewriteDestructuringAssignment( |
35 Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) { | 35 Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope, |
| 36 bool* ok) { |
36 PatternRewriter rewriter; | 37 PatternRewriter rewriter; |
37 | 38 |
38 DCHECK(!to_rewrite->is_rewritten()); | 39 DCHECK(!to_rewrite->is_rewritten()); |
39 | 40 |
40 bool ok = true; | |
41 rewriter.scope_ = scope; | 41 rewriter.scope_ = scope; |
42 rewriter.parser_ = parser; | 42 rewriter.parser_ = parser; |
43 rewriter.context_ = ASSIGNMENT; | 43 rewriter.context_ = ASSIGNMENT; |
44 rewriter.pattern_ = to_rewrite; | 44 rewriter.pattern_ = to_rewrite; |
45 rewriter.block_ = nullptr; | 45 rewriter.block_ = nullptr; |
46 rewriter.descriptor_ = nullptr; | 46 rewriter.descriptor_ = nullptr; |
47 rewriter.names_ = nullptr; | 47 rewriter.names_ = nullptr; |
48 rewriter.ok_ = &ok; | 48 rewriter.ok_ = ok; |
49 | 49 |
50 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr); | 50 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr); |
51 DCHECK(ok); | |
52 } | 51 } |
53 | 52 |
54 | 53 |
55 Expression* Parser::PatternRewriter::RewriteDestructuringAssignment( | |
56 Parser* parser, Assignment* assignment, Scope* scope) { | |
57 DCHECK_NOT_NULL(assignment); | |
58 DCHECK_EQ(Token::ASSIGN, assignment->op()); | |
59 auto to_rewrite = | |
60 parser->factory()->NewRewritableAssignmentExpression(assignment); | |
61 RewriteDestructuringAssignment(parser, to_rewrite, scope); | |
62 return to_rewrite->expression(); | |
63 } | |
64 | |
65 | |
66 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const { | 54 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const { |
67 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER; | 55 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER; |
68 } | 56 } |
69 | 57 |
70 | 58 |
71 bool Parser::PatternRewriter::IsBindingContext(PatternContext c) const { | 59 bool Parser::PatternRewriter::IsBindingContext(PatternContext c) const { |
72 return c == BINDING || c == INITIALIZER; | 60 return c == BINDING || c == INITIALIZER; |
73 } | 61 } |
74 | 62 |
75 | 63 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 NOT_A_PATTERN(TryFinallyStatement) | 603 NOT_A_PATTERN(TryFinallyStatement) |
616 NOT_A_PATTERN(UnaryOperation) | 604 NOT_A_PATTERN(UnaryOperation) |
617 NOT_A_PATTERN(VariableDeclaration) | 605 NOT_A_PATTERN(VariableDeclaration) |
618 NOT_A_PATTERN(WhileStatement) | 606 NOT_A_PATTERN(WhileStatement) |
619 NOT_A_PATTERN(WithStatement) | 607 NOT_A_PATTERN(WithStatement) |
620 NOT_A_PATTERN(Yield) | 608 NOT_A_PATTERN(Yield) |
621 | 609 |
622 #undef NOT_A_PATTERN | 610 #undef NOT_A_PATTERN |
623 } // namespace internal | 611 } // namespace internal |
624 } // namespace v8 | 612 } // namespace v8 |
OLD | NEW |