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

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

Issue 2634123002: [parser] Pessimistically assume top-level variables will be assigned. (Closed)
Patch Set: Feedback. Created 3 years, 11 months 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 | « no previous file | test/cctest/test-parsing.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/objects-inl.h" 7 #include "src/objects-inl.h"
8 #include "src/parsing/parameter-initializer-rewriter.h" 8 #include "src/parsing/parameter-initializer-rewriter.h"
9 #include "src/parsing/parser.h" 9 #include "src/parsing/parser.h"
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } else { 217 } else {
218 // For 'let' and 'const' declared variables the initialization always 218 // For 'let' and 'const' declared variables the initialization always
219 // assigns to the declared variable. 219 // assigns to the declared variable.
220 // But for var declarations we need to do a new lookup. 220 // But for var declarations we need to do a new lookup.
221 if (descriptor_->mode == VAR) { 221 if (descriptor_->mode == VAR) {
222 proxy = var_init_scope->NewUnresolved(factory(), name); 222 proxy = var_init_scope->NewUnresolved(factory(), name);
223 // TODO(neis): Set is_assigned on proxy. 223 // TODO(neis): Set is_assigned on proxy.
224 } else { 224 } else {
225 DCHECK_NOT_NULL(proxy); 225 DCHECK_NOT_NULL(proxy);
226 DCHECK_NOT_NULL(proxy->var()); 226 DCHECK_NOT_NULL(proxy->var());
227 if (var_init_scope->is_script_scope() ||
228 var_init_scope->is_module_scope()) {
229 // We have to pessimistically assume that top-level variables will be
230 // assigned. This is because there may be lazily parsed top-level
adamk 2017/01/17 18:09:04 As discussed offline, this comment is slightly mis
231 // functions, which, for efficiency, we preparse without variable
232 // tracking.
233 proxy->set_is_assigned();
234 }
227 } 235 }
228 // Add break location for destructured sub-pattern. 236 // Add break location for destructured sub-pattern.
229 int pos = IsSubPattern() ? pattern->position() : value->position(); 237 int pos = IsSubPattern() ? pattern->position() : value->position();
230 Assignment* assignment = 238 Assignment* assignment =
231 factory()->NewAssignment(Token::INIT, proxy, value, pos); 239 factory()->NewAssignment(Token::INIT, proxy, value, pos);
232 block_->statements()->Add( 240 block_->statements()->Add(
233 factory()->NewExpressionStatement(assignment, pos), zone()); 241 factory()->NewExpressionStatement(assignment, pos), zone());
234 } 242 }
235 } 243 }
236 244
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 NOT_A_PATTERN(TryFinallyStatement) 700 NOT_A_PATTERN(TryFinallyStatement)
693 NOT_A_PATTERN(UnaryOperation) 701 NOT_A_PATTERN(UnaryOperation)
694 NOT_A_PATTERN(VariableDeclaration) 702 NOT_A_PATTERN(VariableDeclaration)
695 NOT_A_PATTERN(WhileStatement) 703 NOT_A_PATTERN(WhileStatement)
696 NOT_A_PATTERN(WithStatement) 704 NOT_A_PATTERN(WithStatement)
697 NOT_A_PATTERN(Yield) 705 NOT_A_PATTERN(Yield)
698 706
699 #undef NOT_A_PATTERN 707 #undef NOT_A_PATTERN
700 } // namespace internal 708 } // namespace internal
701 } // namespace v8 709 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698