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

Side by Side Diff: src/scopes.cc

Issue 1225413005: [es6] Check declaration conflicts between non-simple parameters and the function body (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 5 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 | « src/parser.cc ('k') | test/mjsunit/harmony/destructuring.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) { 568 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) {
569 DCHECK(HasIllegalRedeclaration()); 569 DCHECK(HasIllegalRedeclaration());
570 illegal_redecl_->Accept(visitor); 570 illegal_redecl_->Accept(visitor);
571 } 571 }
572 572
573 573
574 Declaration* Scope::CheckConflictingVarDeclarations() { 574 Declaration* Scope::CheckConflictingVarDeclarations() {
575 int length = decls_.length(); 575 int length = decls_.length();
576 for (int i = 0; i < length; i++) { 576 for (int i = 0; i < length; i++) {
577 Declaration* decl = decls_[i]; 577 Declaration* decl = decls_[i];
578 if (decl->mode() != VAR) continue; 578 if (decl->mode() != VAR && !is_block_scope()) continue;
579 const AstRawString* name = decl->proxy()->raw_name(); 579 const AstRawString* name = decl->proxy()->raw_name();
580 580
581 // Iterate through all scopes until and including the declaration scope. 581 // Iterate through all scopes until and including the declaration scope.
582 // If the declaration scope is a (declaration) block scope, also continue
583 // (that is to handle the special inner scope of functions with
584 // destructuring parameters, which may not shadow any variables from
585 // the surrounding function scope).
582 Scope* previous = NULL; 586 Scope* previous = NULL;
583 Scope* current = decl->scope(); 587 Scope* current = decl->scope();
588 // Lexical vs lexical conflicts within the same scope have already been
589 // captured in Parser::Declare. The only conflicts we still need to check
590 // are lexical vs VAR, or any declarations within a declaration block scope
591 // vs lexical declarations in its surrounding (function) scope.
592 if (decl->mode() != VAR) current = current->outer_scope_;
584 do { 593 do {
585 // There is a conflict if there exists a non-VAR binding. 594 // There is a conflict if there exists a non-VAR binding.
586 Variable* other_var = current->variables_.Lookup(name); 595 Variable* other_var = current->variables_.Lookup(name);
587 if (other_var != NULL && other_var->mode() != VAR) { 596 if (other_var != NULL && other_var->mode() != VAR) {
588 return decl; 597 return decl;
589 } 598 }
590 previous = current; 599 previous = current;
591 current = current->outer_scope_; 600 current = current->outer_scope_;
592 } while (!previous->is_declaration_scope()); 601 } while (!previous->is_declaration_scope() || previous->is_block_scope());
593 } 602 }
594 return NULL; 603 return NULL;
595 } 604 }
596 605
597 606
598 class VarAndOrder { 607 class VarAndOrder {
599 public: 608 public:
600 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } 609 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { }
601 Variable* var() const { return var_; } 610 Variable* var() const { return var_; }
602 int order() const { return order_; } 611 int order() const { return order_; }
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 bool is_function_var_in_context = 1625 bool is_function_var_in_context =
1617 function_ != NULL && function_->proxy()->var()->IsContextSlot(); 1626 function_ != NULL && function_->proxy()->var()->IsContextSlot();
1618 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1627 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1619 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); 1628 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0);
1620 } 1629 }
1621 1630
1622 1631
1623 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1632 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1624 } // namespace internal 1633 } // namespace internal
1625 } // namespace v8 1634 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/destructuring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698