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

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

Issue 1542813003: [debugger] step on every assignment in destructuring bind. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix: only emit statement positions for subpatterns 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.h ('k') | test/mjsunit/harmony/debug-step-destructuring-bind.js » ('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 {
11 11
12 namespace internal { 12 namespace internal {
13 13
14 void Parser::PatternRewriter::DeclareAndInitializeVariables( 14 void Parser::PatternRewriter::DeclareAndInitializeVariables(
15 Block* block, const DeclarationDescriptor* declaration_descriptor, 15 Block* block, const DeclarationDescriptor* declaration_descriptor,
16 const DeclarationParsingResult::Declaration* declaration, 16 const DeclarationParsingResult::Declaration* declaration,
17 ZoneList<const AstRawString*>* names, bool* ok) { 17 ZoneList<const AstRawString*>* names, bool* ok) {
18 PatternRewriter rewriter; 18 PatternRewriter rewriter;
19 19
20 rewriter.scope_ = declaration_descriptor->scope; 20 rewriter.scope_ = declaration_descriptor->scope;
21 rewriter.parser_ = declaration_descriptor->parser; 21 rewriter.parser_ = declaration_descriptor->parser;
22 rewriter.context_ = BINDING; 22 rewriter.context_ = BINDING;
23 rewriter.pattern_ = declaration->pattern; 23 rewriter.pattern_ = declaration->pattern;
24 rewriter.initializer_position_ = declaration->initializer_position; 24 rewriter.initializer_position_ = declaration->initializer_position;
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 rewriter.recursion_level_ = 0;
29 30
30 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer); 31 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer);
31 } 32 }
32 33
33 34
34 void Parser::PatternRewriter::RewriteDestructuringAssignment( 35 void Parser::PatternRewriter::RewriteDestructuringAssignment(
35 Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) { 36 Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) {
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 bool ok = true;
41 rewriter.scope_ = scope; 42 rewriter.scope_ = scope;
42 rewriter.parser_ = parser; 43 rewriter.parser_ = parser;
43 rewriter.context_ = ASSIGNMENT; 44 rewriter.context_ = ASSIGNMENT;
44 rewriter.pattern_ = to_rewrite; 45 rewriter.pattern_ = to_rewrite;
45 rewriter.block_ = nullptr; 46 rewriter.block_ = nullptr;
46 rewriter.descriptor_ = nullptr; 47 rewriter.descriptor_ = nullptr;
47 rewriter.names_ = nullptr; 48 rewriter.names_ = nullptr;
48 rewriter.ok_ = &ok; 49 rewriter.ok_ = &ok;
50 rewriter.recursion_level_ = 0;
49 51
50 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr); 52 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr);
51 DCHECK(ok); 53 DCHECK(ok);
52 } 54 }
53 55
54 56
55 Expression* Parser::PatternRewriter::RewriteDestructuringAssignment( 57 Expression* Parser::PatternRewriter::RewriteDestructuringAssignment(
56 Parser* parser, Assignment* assignment, Scope* scope) { 58 Parser* parser, Assignment* assignment, Scope* scope) {
57 DCHECK_NOT_NULL(assignment); 59 DCHECK_NOT_NULL(assignment);
58 DCHECK_EQ(Token::ASSIGN, assignment->op()); 60 DCHECK_EQ(Token::ASSIGN, assignment->op());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Constant initializations always assign to the declared constant which 275 // Constant initializations always assign to the declared constant which
274 // is always at the function scope level. This is only relevant for 276 // is always at the function scope level. This is only relevant for
275 // dynamically looked-up variables and constants (the 277 // dynamically looked-up variables and constants (the
276 // start context for constant lookups is always the function context, 278 // start context for constant lookups is always the function context,
277 // while it is the top context for var declared variables). Sigh... 279 // while it is the top context for var declared variables). Sigh...
278 // For 'let' and 'const' declared variables in harmony mode the 280 // For 'let' and 'const' declared variables in harmony mode the
279 // initialization also always assigns to the declared variable. 281 // initialization also always assigns to the declared variable.
280 DCHECK_NOT_NULL(proxy); 282 DCHECK_NOT_NULL(proxy);
281 DCHECK_NOT_NULL(proxy->var()); 283 DCHECK_NOT_NULL(proxy->var());
282 DCHECK_NOT_NULL(value); 284 DCHECK_NOT_NULL(value);
283 Assignment* assignment = factory()->NewAssignment( 285 // Add break location for destructured sub-pattern.
284 Token::INIT, proxy, value, descriptor_->initialization_pos); 286 int pos = IsSubPattern() ? pattern->position() : RelocInfo::kNoPosition;
287 Assignment* assignment =
288 factory()->NewAssignment(Token::INIT, proxy, value, pos);
285 block_->statements()->Add( 289 block_->statements()->Add(
286 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 290 factory()->NewExpressionStatement(assignment, pos), zone());
287 zone());
288 value = NULL; 291 value = NULL;
289 } 292 }
290 293
291 // 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
292 // have a pending initialization value. 295 // have a pending initialization value.
293 if (value != NULL) { 296 if (value != NULL) {
294 DCHECK(descriptor_->mode == VAR); 297 DCHECK(descriptor_->mode == VAR);
295 // 'var' initializations are simply assignments (with all the consequences 298 // 'var' initializations are simply assignments (with all the consequences
296 // 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
297 // property). 300 // property).
298 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); 301 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name);
299 Assignment* assignment = factory()->NewAssignment( 302 // Add break location for destructured sub-pattern.
300 Token::INIT, proxy, value, descriptor_->initialization_pos); 303 int pos = IsSubPattern() ? pattern->position() : RelocInfo::kNoPosition;
304 Assignment* assignment =
305 factory()->NewAssignment(Token::INIT, proxy, value, pos);
301 block_->statements()->Add( 306 block_->statements()->Add(
302 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 307 factory()->NewExpressionStatement(assignment, pos), zone());
303 zone());
304 } 308 }
305 } 309 }
306 310
307 311
308 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { 312 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) {
309 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); 313 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string());
310 if (value != nullptr) { 314 if (value != nullptr) {
311 auto assignment = factory()->NewAssignment( 315 auto assignment = factory()->NewAssignment(
312 Token::ASSIGN, factory()->NewVariableProxy(temp), value, 316 Token::ASSIGN, factory()->NewVariableProxy(temp), value,
313 RelocInfo::kNoPosition); 317 RelocInfo::kNoPosition);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 NOT_A_PATTERN(TryFinallyStatement) 619 NOT_A_PATTERN(TryFinallyStatement)
616 NOT_A_PATTERN(UnaryOperation) 620 NOT_A_PATTERN(UnaryOperation)
617 NOT_A_PATTERN(VariableDeclaration) 621 NOT_A_PATTERN(VariableDeclaration)
618 NOT_A_PATTERN(WhileStatement) 622 NOT_A_PATTERN(WhileStatement)
619 NOT_A_PATTERN(WithStatement) 623 NOT_A_PATTERN(WithStatement)
620 NOT_A_PATTERN(Yield) 624 NOT_A_PATTERN(Yield)
621 625
622 #undef NOT_A_PATTERN 626 #undef NOT_A_PATTERN
623 } // namespace internal 627 } // namespace internal
624 } // namespace v8 628 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | test/mjsunit/harmony/debug-step-destructuring-bind.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698