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

Side by Side Diff: src/scopes.cc

Issue 1250513004: [es6] Make sure temporaries are not allocated in block scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/scopes.h ('k') | src/variables.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 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // was just added before, so we search backwards. 520 // was just added before, so we search backwards.
521 for (int i = unresolved_.length(); i-- > 0;) { 521 for (int i = unresolved_.length(); i-- > 0;) {
522 if (unresolved_[i] == var) { 522 if (unresolved_[i] == var) {
523 unresolved_.Remove(i); 523 unresolved_.Remove(i);
524 return; 524 return;
525 } 525 }
526 } 526 }
527 } 527 }
528 528
529 529
530 Variable* Scope::NewInternal(const AstRawString* name) {
531 DCHECK(!already_resolved());
532 Variable* var = new(zone()) Variable(this,
533 name,
534 INTERNAL,
535 Variable::NORMAL,
536 kCreatedInitialized);
537 internals_.Add(var, zone());
538 return var;
539 }
540
541
542 Variable* Scope::NewTemporary(const AstRawString* name) { 530 Variable* Scope::NewTemporary(const AstRawString* name) {
543 DCHECK(!already_resolved()); 531 DCHECK(!already_resolved());
544 Variable* var = new(zone()) Variable(this, 532 Scope* scope = this->TemporaryScope();
533 Variable* var = new(zone()) Variable(scope,
545 name, 534 name,
546 TEMPORARY, 535 TEMPORARY,
547 Variable::NORMAL, 536 Variable::NORMAL,
548 kCreatedInitialized); 537 kCreatedInitialized);
549 temps_.Add(var, zone()); 538 scope->temps_.Add(var, zone());
550 return var; 539 return var;
551 } 540 }
552 541
553 542
554 void Scope::AddDeclaration(Declaration* declaration) { 543 void Scope::AddDeclaration(Declaration* declaration) {
555 decls_.Add(declaration, zone()); 544 decls_.Add(declaration, zone());
556 } 545 }
557 546
558 547
559 void Scope::SetIllegalRedeclaration(Expression* expression) { 548 void Scope::SetIllegalRedeclaration(Expression* expression) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 754
766 Scope* Scope::DeclarationScope() { 755 Scope* Scope::DeclarationScope() {
767 Scope* scope = this; 756 Scope* scope = this;
768 while (!scope->is_declaration_scope()) { 757 while (!scope->is_declaration_scope()) {
769 scope = scope->outer_scope(); 758 scope = scope->outer_scope();
770 } 759 }
771 return scope; 760 return scope;
772 } 761 }
773 762
774 763
764 Scope* Scope::TemporaryScope() {
765 Scope* scope = this;
766 while (!scope->is_declaration_scope() || scope->is_block_scope()) {
767 scope = scope->outer_scope();
768 }
769 return scope;
770 }
771
772
775 Scope* Scope::ReceiverScope() { 773 Scope* Scope::ReceiverScope() {
776 Scope* scope = this; 774 Scope* scope = this;
777 while (!scope->is_script_scope() && 775 while (!scope->is_script_scope() &&
778 (!scope->is_function_scope() || scope->is_arrow_scope())) { 776 (!scope->is_function_scope() || scope->is_arrow_scope())) {
779 scope = scope->outer_scope(); 777 scope = scope->outer_scope();
780 } 778 }
781 return scope; 779 return scope;
782 } 780 }
783 781
784 782
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 // that it might be accessed from the current or an inner scope (through 1345 // that it might be accessed from the current or an inner scope (through
1348 // an eval() call or a runtime with lookup), it must be allocated in the 1346 // an eval() call or a runtime with lookup), it must be allocated in the
1349 // context. 1347 // context.
1350 // 1348 //
1351 // Exceptions: If the scope as a whole has forced context allocation, all 1349 // Exceptions: If the scope as a whole has forced context allocation, all
1352 // variables will have context allocation, even temporaries. Otherwise 1350 // variables will have context allocation, even temporaries. Otherwise
1353 // temporary variables are always stack-allocated. Catch-bound variables are 1351 // temporary variables are always stack-allocated. Catch-bound variables are
1354 // always context-allocated. 1352 // always context-allocated.
1355 if (has_forced_context_allocation()) return true; 1353 if (has_forced_context_allocation()) return true;
1356 if (var->mode() == TEMPORARY) return false; 1354 if (var->mode() == TEMPORARY) return false;
1357 if (var->mode() == INTERNAL) return true;
1358 if (is_catch_scope() || is_module_scope()) return true; 1355 if (is_catch_scope() || is_module_scope()) return true;
1359 if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true; 1356 if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true;
1360 return var->has_forced_context_allocation() || 1357 return var->has_forced_context_allocation() ||
1361 scope_calls_eval_ || 1358 scope_calls_eval_ ||
1362 inner_scope_calls_eval_ || 1359 inner_scope_calls_eval_ ||
1363 scope_contains_with_; 1360 scope_contains_with_;
1364 } 1361 }
1365 1362
1366 1363
1367 bool Scope::HasArgumentsParameter(Isolate* isolate) { 1364 bool Scope::HasArgumentsParameter(Isolate* isolate) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 1599
1603 void Scope::AllocateModules() { 1600 void Scope::AllocateModules() {
1604 DCHECK(is_script_scope()); 1601 DCHECK(is_script_scope());
1605 DCHECK(!already_resolved()); 1602 DCHECK(!already_resolved());
1606 for (int i = 0; i < inner_scopes_.length(); i++) { 1603 for (int i = 0; i < inner_scopes_.length(); i++) {
1607 Scope* scope = inner_scopes_.at(i); 1604 Scope* scope = inner_scopes_.at(i);
1608 if (scope->is_module_scope()) { 1605 if (scope->is_module_scope()) {
1609 DCHECK(!scope->already_resolved()); 1606 DCHECK(!scope->already_resolved());
1610 DCHECK(scope->module_descriptor_->IsFrozen()); 1607 DCHECK(scope->module_descriptor_->IsFrozen());
1611 DCHECK_NULL(scope->module_var_); 1608 DCHECK_NULL(scope->module_var_);
1612 scope->module_var_ = NewInternal(ast_value_factory_->dot_module_string()); 1609 scope->module_var_ =
1610 NewTemporary(ast_value_factory_->dot_module_string());
1613 ++num_modules_; 1611 ++num_modules_;
1614 } 1612 }
1615 } 1613 }
1616 } 1614 }
1617 1615
1618 1616
1619 int Scope::StackLocalCount() const { 1617 int Scope::StackLocalCount() const {
1620 return num_stack_slots() - 1618 return num_stack_slots() -
1621 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1619 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1622 } 1620 }
1623 1621
1624 1622
1625 int Scope::ContextLocalCount() const { 1623 int Scope::ContextLocalCount() const {
1626 if (num_heap_slots() == 0) return 0; 1624 if (num_heap_slots() == 0) return 0;
1627 bool is_function_var_in_context = 1625 bool is_function_var_in_context =
1628 function_ != NULL && function_->proxy()->var()->IsContextSlot(); 1626 function_ != NULL && function_->proxy()->var()->IsContextSlot();
1629 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1627 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1630 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); 1628 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0);
1631 } 1629 }
1632 1630
1633 1631
1634 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1632 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1635 } // namespace internal 1633 } // namespace internal
1636 } // namespace v8 1634 } // namespace v8
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698