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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 // Add context globals' names. | 144 // Add context globals' names. |
145 DCHECK(index == scope_info->ContextGlobalNameEntriesIndex()); | 145 DCHECK(index == scope_info->ContextGlobalNameEntriesIndex()); |
146 for (int i = 0; i < context_global_count; ++i) { | 146 for (int i = 0; i < context_global_count; ++i) { |
147 scope_info->set(index++, *context_globals[i]->name()); | 147 scope_info->set(index++, *context_globals[i]->name()); |
148 } | 148 } |
149 | 149 |
150 // Add context locals' info. | 150 // Add context locals' info. |
151 DCHECK(index == scope_info->ContextLocalInfoEntriesIndex()); | 151 DCHECK(index == scope_info->ContextLocalInfoEntriesIndex()); |
152 bool encountered_lexical = false; | |
153 int lexical_context_local_count = 0; | |
154 for (int i = 0; i < context_local_count; ++i) { | 152 for (int i = 0; i < context_local_count; ++i) { |
155 Variable* var = context_locals[i]; | 153 Variable* var = context_locals[i]; |
156 uint32_t value = | 154 uint32_t value = |
157 ContextLocalMode::encode(var->mode()) | | 155 ContextLocalMode::encode(var->mode()) | |
158 ContextLocalInitFlag::encode(var->initialization_flag()) | | 156 ContextLocalInitFlag::encode(var->initialization_flag()) | |
159 ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned()); | 157 ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned()); |
160 scope_info->set(index++, Smi::FromInt(value)); | 158 scope_info->set(index++, Smi::FromInt(value)); |
161 if (encountered_lexical) { | |
162 // Check that context locals are sorted so that lexicals are at the end. | |
163 DCHECK(IsLexicalVariableMode(var->mode())); | |
164 } else if (IsLexicalVariableMode(var->mode())) { | |
165 lexical_context_local_count = context_local_count - i; | |
166 } | |
167 } | 159 } |
168 | 160 |
169 scope_info->SetLexicalContextLocalCount(lexical_context_local_count); | |
170 | |
171 // Add context globals' info. | 161 // Add context globals' info. |
172 DCHECK(index == scope_info->ContextGlobalInfoEntriesIndex()); | 162 DCHECK(index == scope_info->ContextGlobalInfoEntriesIndex()); |
173 for (int i = 0; i < context_global_count; ++i) { | 163 for (int i = 0; i < context_global_count; ++i) { |
174 Variable* var = context_globals[i]; | 164 Variable* var = context_globals[i]; |
175 // TODO(ishell): do we need this kind of info for globals here? | 165 // TODO(ishell): do we need this kind of info for globals here? |
176 uint32_t value = | 166 uint32_t value = |
177 ContextLocalMode::encode(var->mode()) | | 167 ContextLocalMode::encode(var->mode()) | |
178 ContextLocalInitFlag::encode(var->initialization_flag()) | | 168 ContextLocalInitFlag::encode(var->initialization_flag()) | |
179 ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned()); | 169 ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned()); |
180 scope_info->set(index++, Smi::FromInt(value)); | 170 scope_info->set(index++, Smi::FromInt(value)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 scope_info->ContextLength() == 0)); | 215 scope_info->ContextLength() == 0)); |
226 return scope_info; | 216 return scope_info; |
227 } | 217 } |
228 | 218 |
229 | 219 |
230 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 220 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
231 DCHECK(isolate->bootstrapper()->IsActive()); | 221 DCHECK(isolate->bootstrapper()->IsActive()); |
232 | 222 |
233 const int stack_local_count = 0; | 223 const int stack_local_count = 0; |
234 const int context_local_count = 1; | 224 const int context_local_count = 1; |
235 const int lexical_context_local_count = 1; | |
236 const int context_global_count = 0; | 225 const int context_global_count = 0; |
237 const int strong_mode_free_variable_count = 0; | 226 const int strong_mode_free_variable_count = 0; |
238 const bool simple_parameter_list = true; | 227 const bool simple_parameter_list = true; |
239 const VariableAllocationInfo receiver_info = CONTEXT; | 228 const VariableAllocationInfo receiver_info = CONTEXT; |
240 const VariableAllocationInfo function_name_info = NONE; | 229 const VariableAllocationInfo function_name_info = NONE; |
241 const VariableMode function_variable_mode = VAR; | 230 const VariableMode function_variable_mode = VAR; |
242 const bool has_function_name = false; | 231 const bool has_function_name = false; |
243 const bool has_receiver = true; | 232 const bool has_receiver = true; |
244 const int parameter_count = 0; | 233 const int parameter_count = 0; |
245 const int length = kVariablePartIndex + parameter_count + | 234 const int length = kVariablePartIndex + parameter_count + |
(...skipping 12 matching lines...) Expand all Loading... |
258 ReceiverVariableField::encode(receiver_info) | | 247 ReceiverVariableField::encode(receiver_info) | |
259 FunctionVariableField::encode(function_name_info) | | 248 FunctionVariableField::encode(function_name_info) | |
260 FunctionVariableMode::encode(function_variable_mode) | | 249 FunctionVariableMode::encode(function_variable_mode) | |
261 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 250 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
262 IsSimpleParameterListField::encode(simple_parameter_list) | | 251 IsSimpleParameterListField::encode(simple_parameter_list) | |
263 FunctionKindField::encode(FunctionKind::kNormalFunction); | 252 FunctionKindField::encode(FunctionKind::kNormalFunction); |
264 scope_info->SetFlags(flags); | 253 scope_info->SetFlags(flags); |
265 scope_info->SetParameterCount(parameter_count); | 254 scope_info->SetParameterCount(parameter_count); |
266 scope_info->SetStackLocalCount(stack_local_count); | 255 scope_info->SetStackLocalCount(stack_local_count); |
267 scope_info->SetContextLocalCount(context_local_count); | 256 scope_info->SetContextLocalCount(context_local_count); |
268 scope_info->SetLexicalContextLocalCount(lexical_context_local_count); | |
269 scope_info->SetContextGlobalCount(context_global_count); | 257 scope_info->SetContextGlobalCount(context_global_count); |
270 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); | 258 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); |
271 | 259 |
272 int index = kVariablePartIndex; | 260 int index = kVariablePartIndex; |
273 const int first_slot_index = 0; | 261 const int first_slot_index = 0; |
274 DCHECK(index == scope_info->StackLocalFirstSlotIndex()); | 262 DCHECK(index == scope_info->StackLocalFirstSlotIndex()); |
275 scope_info->set(index++, Smi::FromInt(first_slot_index)); | 263 scope_info->set(index++, Smi::FromInt(first_slot_index)); |
276 DCHECK(index == scope_info->StackLocalEntriesIndex()); | 264 DCHECK(index == scope_info->StackLocalEntriesIndex()); |
277 | 265 |
278 // Here we add info for context-allocated "this". | 266 // Here we add info for context-allocated "this". |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } | 563 } |
576 } | 564 } |
577 // 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 |
578 // don't matter. | 566 // don't matter. |
579 context_slot_cache->Update(scope_info, name, TEMPORARY, | 567 context_slot_cache->Update(scope_info, name, TEMPORARY, |
580 VariableLocation::CONTEXT, kNeedsInitialization, | 568 VariableLocation::CONTEXT, kNeedsInitialization, |
581 kNotAssigned, -1); | 569 kNotAssigned, -1); |
582 } | 570 } |
583 return -1; | 571 return -1; |
584 } | 572 } |
585 | |
586 | |
587 int ScopeInfo::LexicalContextSlotIndex(Handle<ScopeInfo> scope_info, | |
588 Handle<String> name) { | |
589 DCHECK(name->IsInternalizedString()); | |
590 if (scope_info->length() > 0) { | |
591 // TODO(yangguo): consider using the context slot cache here. | |
592 int total_count = scope_info->ContextLocalCount(); | |
593 int lexical_count = scope_info->LexicalContextLocalCount(); | |
594 int non_lexical_count = total_count - lexical_count; | |
595 | |
596 int start = scope_info->ContextLocalNameEntriesIndex(); | |
597 int end = start + total_count; | |
598 int lexical_start = start + non_lexical_count; | |
599 | |
600 for (int i = lexical_start; i < end; ++i) { | |
601 if (*name == scope_info->get(i)) { | |
602 int var = i - start; | |
603 DCHECK(IsLexicalVariableMode(scope_info->ContextLocalMode(var))); | |
604 return Context::MIN_CONTEXT_SLOTS + var; | |
605 } | |
606 } | |
607 } | |
608 return -1; | |
609 } | |
610 | 573 |
611 | 574 |
612 String* ScopeInfo::ContextSlotName(int slot_index) { | 575 String* ScopeInfo::ContextSlotName(int slot_index) { |
613 int const var = slot_index - Context::MIN_CONTEXT_SLOTS; | 576 int const var = slot_index - Context::MIN_CONTEXT_SLOTS; |
614 DCHECK_LE(0, var); | 577 DCHECK_LE(0, var); |
615 DCHECK_LT(var, ContextLocalCount() + ContextGlobalCount()); | 578 DCHECK_LT(var, ContextLocalCount() + ContextGlobalCount()); |
616 return ContextLocalName(var); | 579 return ContextLocalName(var); |
617 } | 580 } |
618 | 581 |
619 | 582 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 info->set_mode(i, var->mode()); | 830 info->set_mode(i, var->mode()); |
868 DCHECK(var->index() >= 0); | 831 DCHECK(var->index() >= 0); |
869 info->set_index(i, var->index()); | 832 info->set_index(i, var->index()); |
870 } | 833 } |
871 DCHECK(i == info->length()); | 834 DCHECK(i == info->length()); |
872 return info; | 835 return info; |
873 } | 836 } |
874 | 837 |
875 } // namespace internal | 838 } // namespace internal |
876 } // namespace v8 | 839 } // namespace v8 |
OLD | NEW |