| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/scopeinfo.h" | 10 #include "src/scopeinfo.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 bool function_name_context_slot = | 333 bool function_name_context_slot = |
| 334 FunctionVariableField::decode(Flags()) == CONTEXT; | 334 FunctionVariableField::decode(Flags()) == CONTEXT; |
| 335 bool has_context = context_locals > 0 || context_globals > 0 || | 335 bool has_context = context_locals > 0 || context_globals > 0 || |
| 336 function_name_context_slot || | 336 function_name_context_slot || |
| 337 scope_type() == WITH_SCOPE || | 337 scope_type() == WITH_SCOPE || |
| 338 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || | 338 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || |
| 339 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || | 339 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || |
| 340 scope_type() == MODULE_SCOPE; | 340 scope_type() == MODULE_SCOPE; |
| 341 | 341 |
| 342 if (has_context) { | 342 if (has_context) { |
| 343 return Context::MIN_CONTEXT_SLOTS + context_locals + 2 * context_globals + | 343 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals + |
| 344 (function_name_context_slot ? 1 : 0); | 344 (function_name_context_slot ? 1 : 0); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 return 0; | 347 return 0; |
| 348 } | 348 } |
| 349 | 349 |
| 350 | 350 |
| 351 bool ScopeInfo::HasReceiver() { | 351 bool ScopeInfo::HasReceiver() { |
| 352 if (length() > 0) { | 352 if (length() > 0) { |
| 353 return NONE != ReceiverVariableField::decode(Flags()); | 353 return NONE != ReceiverVariableField::decode(Flags()); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 *init_flag = scope_info->ContextLocalInitFlag(var); | 546 *init_flag = scope_info->ContextLocalInitFlag(var); |
| 547 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); | 547 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); |
| 548 | 548 |
| 549 if (var < scope_info->ContextLocalCount()) { | 549 if (var < scope_info->ContextLocalCount()) { |
| 550 *location = VariableLocation::CONTEXT; | 550 *location = VariableLocation::CONTEXT; |
| 551 result = Context::MIN_CONTEXT_SLOTS + var; | 551 result = Context::MIN_CONTEXT_SLOTS + var; |
| 552 } else { | 552 } else { |
| 553 var -= scope_info->ContextLocalCount(); | 553 var -= scope_info->ContextLocalCount(); |
| 554 *location = VariableLocation::GLOBAL; | 554 *location = VariableLocation::GLOBAL; |
| 555 result = Context::MIN_CONTEXT_SLOTS + | 555 result = Context::MIN_CONTEXT_SLOTS + |
| 556 scope_info->ContextLocalCount() + 2 * var; | 556 scope_info->ContextLocalCount() + var; |
| 557 } | 557 } |
| 558 | 558 |
| 559 context_slot_cache->Update(scope_info, name, *mode, *location, | 559 context_slot_cache->Update(scope_info, name, *mode, *location, |
| 560 *init_flag, *maybe_assigned_flag, result); | 560 *init_flag, *maybe_assigned_flag, result); |
| 561 DCHECK(result < scope_info->ContextLength()); | 561 DCHECK(result < scope_info->ContextLength()); |
| 562 return result; | 562 return result; |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 // Cache as not found. Mode, location, init flag and maybe assigned flag | 565 // Cache as not found. Mode, location, init flag and maybe assigned flag |
| 566 // don't matter. | 566 // don't matter. |
| 567 context_slot_cache->Update(scope_info, name, TEMPORARY, | 567 context_slot_cache->Update(scope_info, name, TEMPORARY, |
| 568 VariableLocation::CONTEXT, kNeedsInitialization, | 568 VariableLocation::CONTEXT, kNeedsInitialization, |
| 569 kNotAssigned, -1); | 569 kNotAssigned, -1); |
| 570 } | 570 } |
| 571 return -1; | 571 return -1; |
| 572 } | 572 } |
| 573 | 573 |
| 574 | 574 |
| 575 String* ScopeInfo::ContextSlotName(int slot_index) { |
| 576 int const var = slot_index - Context::MIN_CONTEXT_SLOTS; |
| 577 DCHECK_LE(0, var); |
| 578 DCHECK_LT(var, ContextLocalCount() + ContextGlobalCount()); |
| 579 return ContextLocalName(var); |
| 580 } |
| 581 |
| 582 |
| 575 int ScopeInfo::ParameterIndex(String* name) { | 583 int ScopeInfo::ParameterIndex(String* name) { |
| 576 DCHECK(name->IsInternalizedString()); | 584 DCHECK(name->IsInternalizedString()); |
| 577 if (length() > 0) { | 585 if (length() > 0) { |
| 578 // We must read parameters from the end since for | 586 // We must read parameters from the end since for |
| 579 // multiply declared parameters the value of the | 587 // multiply declared parameters the value of the |
| 580 // last declaration of that parameter is used | 588 // last declaration of that parameter is used |
| 581 // inside a function (and thus we need to look | 589 // inside a function (and thus we need to look |
| 582 // at the last index). Was bug# 1110337. | 590 // at the last index). Was bug# 1110337. |
| 583 int start = ParameterEntriesIndex(); | 591 int start = ParameterEntriesIndex(); |
| 584 int end = ParameterEntriesIndex() + ParameterCount(); | 592 int end = ParameterEntriesIndex() + ParameterCount(); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 info->set_mode(i, var->mode()); | 854 info->set_mode(i, var->mode()); |
| 847 DCHECK(var->index() >= 0); | 855 DCHECK(var->index() >= 0); |
| 848 info->set_index(i, var->index()); | 856 info->set_index(i, var->index()); |
| 849 } | 857 } |
| 850 DCHECK(i == info->length()); | 858 DCHECK(i == info->length()); |
| 851 return info; | 859 return info; |
| 852 } | 860 } |
| 853 | 861 |
| 854 } // namespace internal | 862 } // namespace internal |
| 855 } // namespace v8 | 863 } // namespace v8 |
| OLD | NEW |