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" | |
10 #include "src/scopeinfo.h" | 9 #include "src/scopeinfo.h" |
11 #include "src/scopes.h" | 10 #include "src/scopes.h" |
12 | 11 |
13 namespace v8 { | 12 namespace v8 { |
14 namespace internal { | 13 namespace internal { |
15 | 14 |
16 | 15 |
17 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 16 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
18 Scope* scope) { | 17 Scope* scope) { |
19 // Collect stack and context locals. | 18 // Collect stack and context locals. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 184 } |
186 | 185 |
187 DCHECK(index == scope_info->length()); | 186 DCHECK(index == scope_info->length()); |
188 DCHECK(scope->num_parameters() == scope_info->ParameterCount()); | 187 DCHECK(scope->num_parameters() == scope_info->ParameterCount()); |
189 DCHECK(scope->num_heap_slots() == scope_info->ContextLength() || | 188 DCHECK(scope->num_heap_slots() == scope_info->ContextLength() || |
190 (scope->num_heap_slots() == kVariablePartIndex && | 189 (scope->num_heap_slots() == kVariablePartIndex && |
191 scope_info->ContextLength() == 0)); | 190 scope_info->ContextLength() == 0)); |
192 return scope_info; | 191 return scope_info; |
193 } | 192 } |
194 | 193 |
195 | |
196 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | |
197 DCHECK(isolate->bootstrapper()->IsActive()); | |
198 | |
199 const int stack_local_count = 0; | |
200 const int context_local_count = 1; | |
201 const int strong_mode_free_variable_count = 0; | |
202 const bool simple_parameter_list = true; | |
203 const VariableAllocationInfo receiver_info = CONTEXT; | |
204 const VariableAllocationInfo function_name_info = NONE; | |
205 const VariableMode function_variable_mode = VAR; | |
206 const bool has_function_name = false; | |
207 const bool has_receiver = true; | |
208 const int parameter_count = 0; | |
209 const int length = kVariablePartIndex + parameter_count + | |
210 (1 + stack_local_count) + 2 * context_local_count + | |
211 3 * strong_mode_free_variable_count + | |
212 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | |
213 | |
214 Factory* factory = isolate->factory(); | |
215 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | |
216 | |
217 // Encode the flags. | |
218 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | |
219 CallsEvalField::encode(false) | | |
220 LanguageModeField::encode(SLOPPY) | | |
221 ReceiverVariableField::encode(receiver_info) | | |
222 FunctionVariableField::encode(function_name_info) | | |
223 FunctionVariableMode::encode(function_variable_mode) | | |
224 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | |
225 IsSimpleParameterListField::encode(simple_parameter_list) | | |
226 BlockScopeIsClassScopeField::encode(false) | | |
227 FunctionKindField::encode(FunctionKind::kNormalFunction); | |
228 scope_info->SetFlags(flags); | |
229 scope_info->SetParameterCount(parameter_count); | |
230 scope_info->SetStackLocalCount(stack_local_count); | |
231 scope_info->SetContextLocalCount(context_local_count); | |
232 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); | |
233 | |
234 int index = kVariablePartIndex; | |
235 const int first_slot_index = 0; | |
236 DCHECK(index == scope_info->StackLocalFirstSlotIndex()); | |
237 scope_info->set(index++, Smi::FromInt(first_slot_index)); | |
238 DCHECK(index == scope_info->StackLocalEntriesIndex()); | |
239 | |
240 // Here we add info for context-allocated "this". | |
241 DCHECK(index == scope_info->ContextLocalNameEntriesIndex()); | |
242 scope_info->set(index++, *isolate->factory()->this_string()); | |
243 DCHECK(index == scope_info->ContextLocalInfoEntriesIndex()); | |
244 const uint32_t value = ContextLocalMode::encode(CONST) | | |
245 ContextLocalInitFlag::encode(kCreatedInitialized) | | |
246 ContextLocalMaybeAssignedFlag::encode(kNotAssigned); | |
247 scope_info->set(index++, Smi::FromInt(value)); | |
248 | |
249 DCHECK(index == scope_info->StrongModeFreeVariableNameEntriesIndex()); | |
250 DCHECK(index == scope_info->StrongModeFreeVariablePositionEntriesIndex()); | |
251 | |
252 // And here we record that this scopeinfo binds a receiver. | |
253 DCHECK(index == scope_info->ReceiverEntryIndex()); | |
254 const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0; | |
255 scope_info->set(index++, Smi::FromInt(receiver_index)); | |
256 | |
257 DCHECK(index == scope_info->FunctionNameEntryIndex()); | |
258 | |
259 DCHECK_EQ(index, scope_info->length()); | |
260 DCHECK_EQ(scope_info->ParameterCount(), 0); | |
261 DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1); | |
262 | |
263 return scope_info; | |
264 } | |
265 | |
266 | 194 |
267 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { | 195 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { |
268 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); | 196 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); |
269 } | 197 } |
270 | 198 |
271 | 199 |
272 ScopeType ScopeInfo::scope_type() { | 200 ScopeType ScopeInfo::scope_type() { |
273 DCHECK(length() > 0); | 201 DCHECK(length() > 0); |
274 return ScopeTypeField::decode(Flags()); | 202 return ScopeTypeField::decode(Flags()); |
275 } | 203 } |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 info->set_mode(i, var->mode()); | 719 info->set_mode(i, var->mode()); |
792 DCHECK(var->index() >= 0); | 720 DCHECK(var->index() >= 0); |
793 info->set_index(i, var->index()); | 721 info->set_index(i, var->index()); |
794 } | 722 } |
795 DCHECK(i == info->length()); | 723 DCHECK(i == info->length()); |
796 return info; | 724 return info; |
797 } | 725 } |
798 | 726 |
799 } // namespace internal | 727 } // namespace internal |
800 } // namespace v8 | 728 } // namespace v8 |
OLD | NEW |