OLD | NEW |
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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // 1) Propagate scope information. | 649 // 1) Propagate scope information. |
650 bool outer_scope_calls_sloppy_eval = false; | 650 bool outer_scope_calls_sloppy_eval = false; |
651 if (outer_scope_ != NULL) { | 651 if (outer_scope_ != NULL) { |
652 outer_scope_calls_sloppy_eval = | 652 outer_scope_calls_sloppy_eval = |
653 outer_scope_->outer_scope_calls_sloppy_eval() | | 653 outer_scope_->outer_scope_calls_sloppy_eval() | |
654 outer_scope_->calls_sloppy_eval(); | 654 outer_scope_->calls_sloppy_eval(); |
655 } | 655 } |
656 PropagateScopeInfo(outer_scope_calls_sloppy_eval); | 656 PropagateScopeInfo(outer_scope_calls_sloppy_eval); |
657 | 657 |
658 // 2) Allocate module instances. | 658 // 2) Allocate module instances. |
659 if (FLAG_harmony_modules && (is_script_scope() || is_module_scope())) { | 659 if (FLAG_harmony_modules && is_script_scope()) { |
660 DCHECK(num_modules_ == 0); | 660 DCHECK(num_modules_ == 0); |
661 AllocateModulesRecursively(this); | 661 AllocateModules(); |
662 } | 662 } |
663 | 663 |
664 // 3) Resolve variables. | 664 // 3) Resolve variables. |
665 if (!ResolveVariablesRecursively(info, factory)) return false; | 665 if (!ResolveVariablesRecursively(info, factory)) return false; |
666 | 666 |
667 // 4) Allocate variables. | 667 // 4) Allocate variables. |
668 AllocateVariablesRecursively(info->isolate()); | 668 AllocateVariablesRecursively(info->isolate()); |
669 | 669 |
670 return true; | 670 return true; |
671 } | 671 } |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 // need the minimal number of slots if we must have a context. | 1430 // need the minimal number of slots if we must have a context. |
1431 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { | 1431 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { |
1432 num_heap_slots_ = 0; | 1432 num_heap_slots_ = 0; |
1433 } | 1433 } |
1434 | 1434 |
1435 // Allocation done. | 1435 // Allocation done. |
1436 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1436 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1437 } | 1437 } |
1438 | 1438 |
1439 | 1439 |
1440 void Scope::AllocateModulesRecursively(Scope* host_scope) { | 1440 void Scope::AllocateModules() { |
1441 if (already_resolved()) return; | 1441 DCHECK(is_script_scope()); |
1442 if (is_module_scope()) { | 1442 DCHECK(!already_resolved()); |
1443 DCHECK(module_descriptor_->IsFrozen()); | |
1444 DCHECK(module_var_ == NULL); | |
1445 module_var_ = | |
1446 host_scope->NewInternal(ast_value_factory_->dot_module_string()); | |
1447 ++host_scope->num_modules_; | |
1448 } | |
1449 | |
1450 for (int i = 0; i < inner_scopes_.length(); i++) { | 1443 for (int i = 0; i < inner_scopes_.length(); i++) { |
1451 Scope* inner_scope = inner_scopes_.at(i); | 1444 Scope* scope = inner_scopes_.at(i); |
1452 inner_scope->AllocateModulesRecursively(host_scope); | 1445 if (scope->is_module_scope()) { |
| 1446 DCHECK(!scope->already_resolved()); |
| 1447 DCHECK(scope->module_descriptor_->IsFrozen()); |
| 1448 DCHECK_NULL(scope->module_var_); |
| 1449 scope->module_var_ = NewInternal(ast_value_factory_->dot_module_string()); |
| 1450 ++num_modules_; |
| 1451 } |
1453 } | 1452 } |
1454 } | 1453 } |
1455 | 1454 |
1456 | 1455 |
1457 int Scope::StackLocalCount() const { | 1456 int Scope::StackLocalCount() const { |
1458 return num_stack_slots() - | 1457 return num_stack_slots() - |
1459 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1458 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1460 } | 1459 } |
1461 | 1460 |
1462 | 1461 |
1463 int Scope::ContextLocalCount() const { | 1462 int Scope::ContextLocalCount() const { |
1464 if (num_heap_slots() == 0) return 0; | 1463 if (num_heap_slots() == 0) return 0; |
1465 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1464 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1466 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1465 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1467 } | 1466 } |
1468 } } // namespace v8::internal | 1467 } } // namespace v8::internal |
OLD | NEW |