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/scopeinfo.h" | 10 #include "src/scopeinfo.h" |
10 #include "src/scopes.h" | 11 #include "src/scopes.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 | 16 |
16 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 17 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
17 Scope* scope) { | 18 Scope* scope) { |
18 // Collect stack and context locals. | 19 // Collect stack and context locals. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 186 |
186 DCHECK(index == scope_info->length()); | 187 DCHECK(index == scope_info->length()); |
187 DCHECK(scope->num_parameters() == scope_info->ParameterCount()); | 188 DCHECK(scope->num_parameters() == scope_info->ParameterCount()); |
188 DCHECK(scope->num_heap_slots() == scope_info->ContextLength() || | 189 DCHECK(scope->num_heap_slots() == scope_info->ContextLength() || |
189 (scope->num_heap_slots() == kVariablePartIndex && | 190 (scope->num_heap_slots() == kVariablePartIndex && |
190 scope_info->ContextLength() == 0)); | 191 scope_info->ContextLength() == 0)); |
191 return scope_info; | 192 return scope_info; |
192 } | 193 } |
193 | 194 |
194 | 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 |
195 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { | 267 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { |
196 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); | 268 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); |
197 } | 269 } |
198 | 270 |
199 | 271 |
200 ScopeType ScopeInfo::scope_type() { | 272 ScopeType ScopeInfo::scope_type() { |
201 DCHECK(length() > 0); | 273 DCHECK(length() > 0); |
202 return ScopeTypeField::decode(Flags()); | 274 return ScopeTypeField::decode(Flags()); |
203 } | 275 } |
204 | 276 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 info->set_mode(i, var->mode()); | 791 info->set_mode(i, var->mode()); |
720 DCHECK(var->index() >= 0); | 792 DCHECK(var->index() >= 0); |
721 info->set_index(i, var->index()); | 793 info->set_index(i, var->index()); |
722 } | 794 } |
723 DCHECK(i == info->length()); | 795 DCHECK(i == info->length()); |
724 return info; | 796 return info; |
725 } | 797 } |
726 | 798 |
727 } // namespace internal | 799 } // namespace internal |
728 } // namespace v8 | 800 } // namespace v8 |
OLD | NEW |