Index: src/scopeinfo.cc |
diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc |
index e490fd9ce48f11eff84aa20f143f852dfea3d7ac..9fb88e4e232e1153e07939dba55d55c1a3e60ca2 100644 |
--- a/src/scopeinfo.cc |
+++ b/src/scopeinfo.cc |
@@ -149,6 +149,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
// Add context locals' info. |
DCHECK(index == scope_info->ContextLocalInfoEntriesIndex()); |
+ bool encountered_lexical = false; |
+ int lexical_context_local_count = 0; |
for (int i = 0; i < context_local_count; ++i) { |
Variable* var = context_locals[i]; |
uint32_t value = |
@@ -156,8 +158,16 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
ContextLocalInitFlag::encode(var->initialization_flag()) | |
ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned()); |
scope_info->set(index++, Smi::FromInt(value)); |
+ if (encountered_lexical) { |
+ // Check that context locals are sorted so that lexicals are at the end. |
+ DCHECK(IsLexicalVariableMode(var->mode())); |
+ } else if (IsLexicalVariableMode(var->mode())) { |
+ lexical_context_local_count = context_local_count - i; |
+ } |
} |
+ scope_info->SetLexicalContextLocalCount(lexical_context_local_count); |
+ |
// Add context globals' info. |
DCHECK(index == scope_info->ContextGlobalInfoEntriesIndex()); |
for (int i = 0; i < context_global_count; ++i) { |
@@ -222,6 +232,7 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
const int stack_local_count = 0; |
const int context_local_count = 1; |
+ const int lexical_context_local_count = 1; |
const int context_global_count = 0; |
const int strong_mode_free_variable_count = 0; |
const bool simple_parameter_list = true; |
@@ -254,6 +265,7 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
scope_info->SetParameterCount(parameter_count); |
scope_info->SetStackLocalCount(stack_local_count); |
scope_info->SetContextLocalCount(context_local_count); |
+ scope_info->SetLexicalContextLocalCount(lexical_context_local_count); |
scope_info->SetContextGlobalCount(context_global_count); |
scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); |
@@ -572,6 +584,31 @@ int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
} |
+int ScopeInfo::LexicalContextSlotIndex(Handle<ScopeInfo> scope_info, |
+ Handle<String> name) { |
+ DCHECK(name->IsInternalizedString()); |
+ if (scope_info->length() > 0) { |
+ // TODO(yangguo): consider using the context slot cache here. |
+ int total_count = scope_info->ContextLocalCount(); |
+ int lexical_count = scope_info->LexicalContextLocalCount(); |
+ int non_lexical_count = total_count - lexical_count; |
+ |
+ int start = scope_info->ContextLocalNameEntriesIndex(); |
+ int end = start + total_count; |
+ int lexical_start = start + non_lexical_count; |
+ |
+ for (int i = lexical_start; i < end; ++i) { |
+ if (*name == scope_info->get(i)) { |
+ int var = i - start; |
+ DCHECK(IsLexicalVariableMode(scope_info->ContextLocalMode(var))); |
+ return Context::MIN_CONTEXT_SLOTS + var; |
+ } |
+ } |
+ } |
+ return -1; |
+} |
+ |
+ |
String* ScopeInfo::ContextSlotName(int slot_index) { |
int const var = slot_index - Context::MIN_CONTEXT_SLOTS; |
DCHECK_LE(0, var); |