| 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" |
| 11 #include "src/scopeinfo.h" | 11 #include "src/scopeinfo.h" |
| 12 #include "src/scopes.h" | 12 #include "src/scopes.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 // TODO(ishell): remove this once compiler support is landed. | |
| 18 bool enable_context_globals = false; | |
| 19 | |
| 20 // ---------------------------------------------------------------------------- | 17 // ---------------------------------------------------------------------------- |
| 21 // Implementation of LocalsMap | 18 // Implementation of LocalsMap |
| 22 // | 19 // |
| 23 // Note: We are storing the handle locations as key values in the hash map. | 20 // Note: We are storing the handle locations as key values in the hash map. |
| 24 // When inserting a new variable via Declare(), we rely on the fact that | 21 // When inserting a new variable via Declare(), we rely on the fact that |
| 25 // the handle location remains alive for the duration of that variable | 22 // the handle location remains alive for the duration of that variable |
| 26 // use. Because a Variable holding a handle with the same location exists | 23 // use. Because a Variable holding a handle with the same location exists |
| 27 // this is ensured. | 24 // this is ensured. |
| 28 | 25 |
| 29 VariableMap::VariableMap(Zone* zone) | 26 VariableMap::VariableMap(Zone* zone) |
| (...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 AllocateStackSlot(var); | 1468 AllocateStackSlot(var); |
| 1472 } | 1469 } |
| 1473 } | 1470 } |
| 1474 } | 1471 } |
| 1475 | 1472 |
| 1476 | 1473 |
| 1477 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { | 1474 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { |
| 1478 DCHECK(var->scope() == this); | 1475 DCHECK(var->scope() == this); |
| 1479 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || | 1476 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || |
| 1480 !var->IsStackLocal()); | 1477 !var->IsStackLocal()); |
| 1481 if (var->IsUnallocated() && var->IsStaticGlobalObjectProperty()) { | 1478 if (var->IsUnallocated()) { |
| 1482 DCHECK_EQ(-1, var->index()); | 1479 if (var->IsStaticGlobalObjectProperty()) { |
| 1483 DCHECK(var->name()->IsString()); | 1480 DCHECK_EQ(-1, var->index()); |
| 1484 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_); | 1481 DCHECK(var->name()->IsString()); |
| 1485 num_global_slots_++; | 1482 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_); |
| 1486 // Each global variable occupies two slots in the context: for reads | 1483 num_global_slots_++; |
| 1487 // and writes. | 1484 // Each global variable occupies two slots in the context: for reads |
| 1488 num_heap_slots_ += 2; | 1485 // and writes. |
| 1486 num_heap_slots_ += 2; |
| 1487 } else { |
| 1488 // There must be only DYNAMIC_GLOBAL in the script scope. |
| 1489 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
| 1490 } |
| 1489 } | 1491 } |
| 1490 } | 1492 } |
| 1491 | 1493 |
| 1492 | 1494 |
| 1493 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { | 1495 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
| 1494 // All variables that have no rewrite yet are non-parameter locals. | 1496 // All variables that have no rewrite yet are non-parameter locals. |
| 1495 for (int i = 0; i < temps_.length(); i++) { | 1497 for (int i = 0; i < temps_.length(); i++) { |
| 1496 AllocateNonParameterLocal(isolate, temps_[i]); | 1498 AllocateNonParameterLocal(isolate, temps_[i]); |
| 1497 } | 1499 } |
| 1498 | 1500 |
| 1499 for (int i = 0; i < internals_.length(); i++) { | 1501 for (int i = 0; i < internals_.length(); i++) { |
| 1500 AllocateNonParameterLocal(isolate, internals_[i]); | 1502 AllocateNonParameterLocal(isolate, internals_[i]); |
| 1501 } | 1503 } |
| 1502 | 1504 |
| 1503 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 1505 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 1504 for (VariableMap::Entry* p = variables_.Start(); | 1506 for (VariableMap::Entry* p = variables_.Start(); |
| 1505 p != NULL; | 1507 p != NULL; |
| 1506 p = variables_.Next(p)) { | 1508 p = variables_.Next(p)) { |
| 1507 Variable* var = reinterpret_cast<Variable*>(p->value); | 1509 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 1508 vars.Add(VarAndOrder(var, p->order), zone()); | 1510 vars.Add(VarAndOrder(var, p->order), zone()); |
| 1509 } | 1511 } |
| 1510 vars.Sort(VarAndOrder::Compare); | 1512 vars.Sort(VarAndOrder::Compare); |
| 1511 int var_count = vars.length(); | 1513 int var_count = vars.length(); |
| 1512 for (int i = 0; i < var_count; i++) { | 1514 for (int i = 0; i < var_count; i++) { |
| 1513 AllocateNonParameterLocal(isolate, vars[i].var()); | 1515 AllocateNonParameterLocal(isolate, vars[i].var()); |
| 1514 } | 1516 } |
| 1515 | 1517 |
| 1516 if (enable_context_globals) { | 1518 for (int i = 0; i < var_count; i++) { |
| 1517 for (int i = 0; i < var_count; i++) { | 1519 AllocateDeclaredGlobal(isolate, vars[i].var()); |
| 1518 AllocateDeclaredGlobal(isolate, vars[i].var()); | |
| 1519 } | |
| 1520 } | 1520 } |
| 1521 | 1521 |
| 1522 // For now, function_ must be allocated at the very end. If it gets | 1522 // For now, function_ must be allocated at the very end. If it gets |
| 1523 // allocated in the context, it must be the last slot in the context, | 1523 // allocated in the context, it must be the last slot in the context, |
| 1524 // because of the current ScopeInfo implementation (see | 1524 // because of the current ScopeInfo implementation (see |
| 1525 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1525 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
| 1526 if (function_ != nullptr) { | 1526 if (function_ != nullptr) { |
| 1527 AllocateNonParameterLocal(isolate, function_->proxy()->var()); | 1527 AllocateNonParameterLocal(isolate, function_->proxy()->var()); |
| 1528 } | 1528 } |
| 1529 | 1529 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 bool is_function_var_in_context = | 1611 bool is_function_var_in_context = |
| 1612 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1612 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1613 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1613 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1614 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); | 1614 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 | 1617 |
| 1618 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1618 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1619 } // namespace internal | 1619 } // namespace internal |
| 1620 } // namespace v8 | 1620 } // namespace v8 |
| OLD | NEW |