Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 1517973002: [es6] support AssignmentPattern as LHS in for-in/of loops (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Centralize the error validation to a single place, to ease confusion Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
37 PatternRewriter rewriter; 36 PatternRewriter rewriter;
38 37
39 DCHECK(!to_rewrite->is_rewritten()); 38 DCHECK(!to_rewrite->is_rewritten());
40 39
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);
51 } 52 }
52 53
53 54
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
54 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const { 66 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const {
55 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER; 67 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER;
56 } 68 }
57 69
58 70
59 bool Parser::PatternRewriter::IsBindingContext(PatternContext c) const { 71 bool Parser::PatternRewriter::IsBindingContext(PatternContext c) const {
60 return c == BINDING || c == INITIALIZER; 72 return c == BINDING || c == INITIALIZER;
61 } 73 }
62 74
63 75
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 NOT_A_PATTERN(TryFinallyStatement) 615 NOT_A_PATTERN(TryFinallyStatement)
604 NOT_A_PATTERN(UnaryOperation) 616 NOT_A_PATTERN(UnaryOperation)
605 NOT_A_PATTERN(VariableDeclaration) 617 NOT_A_PATTERN(VariableDeclaration)
606 NOT_A_PATTERN(WhileStatement) 618 NOT_A_PATTERN(WhileStatement)
607 NOT_A_PATTERN(WithStatement) 619 NOT_A_PATTERN(WithStatement)
608 NOT_A_PATTERN(Yield) 620 NOT_A_PATTERN(Yield)
609 621
610 #undef NOT_A_PATTERN 622 #undef NOT_A_PATTERN
611 } // namespace internal 623 } // namespace internal
612 } // namespace v8 624 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698