| 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/ast/context-slot-cache.h" | 7 #include "src/ast/context-slot-cache.h" |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 // An entry in ModuleVariableEntries consists of several slots: | 14 // An entry in ModuleVariableEntries consists of several slots: |
| 15 enum ModuleVariableEntryOffset { | 15 enum ModuleVariableEntryOffset { |
| 16 kModuleVariableNameOffset, | 16 kModuleVariableNameOffset, |
| 17 kModuleVariableIndexOffset, | 17 kModuleVariableIndexOffset, |
| 18 kModuleVariablePropertiesOffset, | 18 kModuleVariablePropertiesOffset, |
| 19 kModuleVariableEntryLength // Sentinel value. | 19 kModuleVariableEntryLength // Sentinel value. |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 22 #ifdef DEBUG |
| 23 Scope* scope) { | 23 bool ScopeInfo::Equals(ScopeInfo* other) const { |
| 24 if (length() != other->length()) return false; |
| 25 for (int index = 0; index < length(); ++index) { |
| 26 Object* entry = get(index); |
| 27 Object* other_entry = other->get(index); |
| 28 if (entry->IsSmi()) { |
| 29 if (entry != other_entry) return false; |
| 30 } else { |
| 31 if (HeapObject::cast(entry)->map()->instance_type() != |
| 32 HeapObject::cast(other_entry)->map()->instance_type()) { |
| 33 return false; |
| 34 } |
| 35 if (entry->IsString()) { |
| 36 if (!String::cast(entry)->Equals(String::cast(other_entry))) { |
| 37 return false; |
| 38 } |
| 39 } else if (entry->IsScopeInfo()) { |
| 40 if (!ScopeInfo::cast(entry)->Equals(ScopeInfo::cast(other_entry))) { |
| 41 return false; |
| 42 } |
| 43 } else if (entry->IsModuleInfo()) { |
| 44 if (!ModuleInfo::cast(entry)->Equals(ModuleInfo::cast(other_entry))) { |
| 45 return false; |
| 46 } |
| 47 } else { |
| 48 UNREACHABLE(); |
| 49 return false; |
| 50 } |
| 51 } |
| 52 } |
| 53 return true; |
| 54 } |
| 55 #endif |
| 56 |
| 57 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope, |
| 58 MaybeHandle<ScopeInfo> outer_scope) { |
| 24 // Collect variables. | 59 // Collect variables. |
| 25 ZoneList<Variable*>* locals = scope->locals(); | 60 ZoneList<Variable*>* locals = scope->locals(); |
| 26 int stack_local_count = 0; | 61 int stack_local_count = 0; |
| 27 int context_local_count = 0; | 62 int context_local_count = 0; |
| 28 int module_vars_count = 0; | 63 int module_vars_count = 0; |
| 29 // Stack allocated block scope variables are allocated in the parent | 64 // Stack allocated block scope variables are allocated in the parent |
| 30 // declaration scope, but are recorded in the block scope's scope info. First | 65 // declaration scope, but are recorded in the block scope's scope info. First |
| 31 // slot index indicates at which offset a particular scope starts in the | 66 // slot index indicates at which offset a particular scope starts in the |
| 32 // parent declaration scope. | 67 // parent declaration scope. |
| 33 int first_slot_index = 0; | 68 int first_slot_index = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DCHECK(var->IsStackLocal()); | 122 DCHECK(var->IsStackLocal()); |
| 88 function_name_info = STACK; | 123 function_name_info = STACK; |
| 89 } | 124 } |
| 90 } else { | 125 } else { |
| 91 function_name_info = NONE; | 126 function_name_info = NONE; |
| 92 } | 127 } |
| 93 | 128 |
| 94 const bool has_function_name = function_name_info != NONE; | 129 const bool has_function_name = function_name_info != NONE; |
| 95 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; | 130 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; |
| 96 const int parameter_count = scope->num_parameters(); | 131 const int parameter_count = scope->num_parameters(); |
| 132 const bool has_outer_scope_info = !outer_scope.is_null(); |
| 97 const int length = kVariablePartIndex + parameter_count + | 133 const int length = kVariablePartIndex + parameter_count + |
| 98 (1 + stack_local_count) + 2 * context_local_count + | 134 (1 + stack_local_count) + 2 * context_local_count + |
| 99 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0) + | 135 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0) + |
| 136 (has_outer_scope_info ? 1 : 0) + |
| 100 (scope->is_module_scope() | 137 (scope->is_module_scope() |
| 101 ? 2 + kModuleVariableEntryLength * module_vars_count | 138 ? 2 + kModuleVariableEntryLength * module_vars_count |
| 102 : 0); | 139 : 0); |
| 103 | 140 |
| 104 Factory* factory = isolate->factory(); | 141 Factory* factory = isolate->factory(); |
| 105 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 142 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 106 | 143 |
| 107 bool has_simple_parameters = false; | 144 bool has_simple_parameters = false; |
| 108 bool asm_module = false; | 145 bool asm_module = false; |
| 109 bool asm_function = false; | 146 bool asm_function = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 int flags = ScopeTypeField::encode(scope->scope_type()) | | 157 int flags = ScopeTypeField::encode(scope->scope_type()) | |
| 121 CallsEvalField::encode(scope->calls_eval()) | | 158 CallsEvalField::encode(scope->calls_eval()) | |
| 122 LanguageModeField::encode(scope->language_mode()) | | 159 LanguageModeField::encode(scope->language_mode()) | |
| 123 DeclarationScopeField::encode(scope->is_declaration_scope()) | | 160 DeclarationScopeField::encode(scope->is_declaration_scope()) | |
| 124 ReceiverVariableField::encode(receiver_info) | | 161 ReceiverVariableField::encode(receiver_info) | |
| 125 HasNewTargetField::encode(has_new_target) | | 162 HasNewTargetField::encode(has_new_target) | |
| 126 FunctionVariableField::encode(function_name_info) | | 163 FunctionVariableField::encode(function_name_info) | |
| 127 AsmModuleField::encode(asm_module) | | 164 AsmModuleField::encode(asm_module) | |
| 128 AsmFunctionField::encode(asm_function) | | 165 AsmFunctionField::encode(asm_function) | |
| 129 HasSimpleParametersField::encode(has_simple_parameters) | | 166 HasSimpleParametersField::encode(has_simple_parameters) | |
| 130 FunctionKindField::encode(function_kind); | 167 FunctionKindField::encode(function_kind) | |
| 168 HasOuterScopeInfoField::encode(has_outer_scope_info); |
| 131 scope_info->SetFlags(flags); | 169 scope_info->SetFlags(flags); |
| 132 | 170 |
| 133 scope_info->SetParameterCount(parameter_count); | 171 scope_info->SetParameterCount(parameter_count); |
| 134 scope_info->SetStackLocalCount(stack_local_count); | 172 scope_info->SetStackLocalCount(stack_local_count); |
| 135 scope_info->SetContextLocalCount(context_local_count); | 173 scope_info->SetContextLocalCount(context_local_count); |
| 136 | 174 |
| 137 int index = kVariablePartIndex; | 175 int index = kVariablePartIndex; |
| 138 // Add parameters. | 176 // Add parameters. |
| 139 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); | 177 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); |
| 140 if (scope->is_declaration_scope()) { | 178 if (scope->is_declaration_scope()) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 253 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); |
| 216 if (has_function_name) { | 254 if (has_function_name) { |
| 217 int var_index = scope->AsDeclarationScope()->function_var()->index(); | 255 int var_index = scope->AsDeclarationScope()->function_var()->index(); |
| 218 scope_info->set(index++, | 256 scope_info->set(index++, |
| 219 *scope->AsDeclarationScope()->function_var()->name()); | 257 *scope->AsDeclarationScope()->function_var()->name()); |
| 220 scope_info->set(index++, Smi::FromInt(var_index)); | 258 scope_info->set(index++, Smi::FromInt(var_index)); |
| 221 DCHECK(function_name_info != CONTEXT || | 259 DCHECK(function_name_info != CONTEXT || |
| 222 var_index == scope_info->ContextLength() - 1); | 260 var_index == scope_info->ContextLength() - 1); |
| 223 } | 261 } |
| 224 | 262 |
| 263 // If present, add the outer scope info. |
| 264 DCHECK(index == scope_info->OuterScopeInfoEntryIndex()); |
| 265 if (has_outer_scope_info) { |
| 266 scope_info->set(index++, *outer_scope.ToHandleChecked()); |
| 267 } |
| 268 |
| 225 // Module-specific information (only for module scopes). | 269 // Module-specific information (only for module scopes). |
| 226 if (scope->is_module_scope()) { | 270 if (scope->is_module_scope()) { |
| 227 Handle<ModuleInfo> module_info = | 271 Handle<ModuleInfo> module_info = |
| 228 ModuleInfo::New(isolate, scope->AsModuleScope()->module()); | 272 ModuleInfo::New(isolate, scope->AsModuleScope()->module()); |
| 229 DCHECK_EQ(index, scope_info->ModuleInfoEntryIndex()); | 273 DCHECK_EQ(index, scope_info->ModuleInfoEntryIndex()); |
| 230 scope_info->set(index++, *module_info); | 274 scope_info->set(index++, *module_info); |
| 231 DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); | 275 DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); |
| 232 scope_info->set(index++, Smi::FromInt(module_vars_count)); | 276 scope_info->set(index++, Smi::FromInt(module_vars_count)); |
| 233 DCHECK_EQ(index, scope_info->ModuleVariableEntriesIndex()); | 277 DCHECK_EQ(index, scope_info->ModuleVariableEntriesIndex()); |
| 234 // The variable entries themselves have already been written above. | 278 // The variable entries themselves have already been written above. |
| 235 index += kModuleVariableEntryLength * module_vars_count; | 279 index += kModuleVariableEntryLength * module_vars_count; |
| 236 } | 280 } |
| 237 | 281 |
| 238 DCHECK_EQ(index, scope_info->length()); | 282 DCHECK_EQ(index, scope_info->length()); |
| 239 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); | 283 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); |
| 240 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); | 284 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); |
| 241 return scope_info; | 285 return scope_info; |
| 242 } | 286 } |
| 243 | 287 |
| 244 Handle<ScopeInfo> ScopeInfo::CreateForWithScope(Isolate* isolate) { | 288 Handle<ScopeInfo> ScopeInfo::CreateForWithScope( |
| 245 const int length = kVariablePartIndex + 1; | 289 Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope) { |
| 290 const bool has_outer_scope_info = !outer_scope.is_null(); |
| 291 const int length = kVariablePartIndex + 1 + (has_outer_scope_info ? 1 : 0); |
| 246 | 292 |
| 247 Factory* factory = isolate->factory(); | 293 Factory* factory = isolate->factory(); |
| 248 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 294 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 249 | 295 |
| 250 // Encode the flags. | 296 // Encode the flags. |
| 251 int flags = | 297 int flags = |
| 252 ScopeTypeField::encode(WITH_SCOPE) | CallsEvalField::encode(false) | | 298 ScopeTypeField::encode(WITH_SCOPE) | CallsEvalField::encode(false) | |
| 253 LanguageModeField::encode(SLOPPY) | DeclarationScopeField::encode(false) | | 299 LanguageModeField::encode(SLOPPY) | DeclarationScopeField::encode(false) | |
| 254 ReceiverVariableField::encode(NONE) | HasNewTargetField::encode(false) | | 300 ReceiverVariableField::encode(NONE) | HasNewTargetField::encode(false) | |
| 255 FunctionVariableField::encode(NONE) | AsmModuleField::encode(false) | | 301 FunctionVariableField::encode(NONE) | AsmModuleField::encode(false) | |
| 256 AsmFunctionField::encode(false) | HasSimpleParametersField::encode(true) | | 302 AsmFunctionField::encode(false) | HasSimpleParametersField::encode(true) | |
| 257 FunctionKindField::encode(kNormalFunction); | 303 FunctionKindField::encode(kNormalFunction) | |
| 304 HasOuterScopeInfoField::encode(has_outer_scope_info); |
| 258 scope_info->SetFlags(flags); | 305 scope_info->SetFlags(flags); |
| 259 | 306 |
| 260 scope_info->SetParameterCount(0); | 307 scope_info->SetParameterCount(0); |
| 261 scope_info->SetStackLocalCount(0); | 308 scope_info->SetStackLocalCount(0); |
| 262 scope_info->SetContextLocalCount(0); | 309 scope_info->SetContextLocalCount(0); |
| 263 | 310 |
| 264 int index = kVariablePartIndex; | 311 int index = kVariablePartIndex; |
| 265 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); | 312 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); |
| 266 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 313 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
| 267 scope_info->set(index++, Smi::FromInt(0)); | 314 scope_info->set(index++, Smi::FromInt(0)); |
| 268 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 315 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); |
| 269 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 316 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); |
| 270 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 317 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); |
| 318 DCHECK(index == scope_info->OuterScopeInfoEntryIndex()); |
| 319 if (has_outer_scope_info) { |
| 320 scope_info->set(index++, *outer_scope.ToHandleChecked()); |
| 321 } |
| 271 DCHECK_EQ(index, scope_info->length()); | 322 DCHECK_EQ(index, scope_info->length()); |
| 272 DCHECK_EQ(0, scope_info->ParameterCount()); | 323 DCHECK_EQ(0, scope_info->ParameterCount()); |
| 273 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, scope_info->ContextLength()); | 324 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, scope_info->ContextLength()); |
| 274 return scope_info; | 325 return scope_info; |
| 275 } | 326 } |
| 276 | 327 |
| 277 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 328 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
| 278 DCHECK(isolate->bootstrapper()->IsActive()); | 329 DCHECK(isolate->bootstrapper()->IsActive()); |
| 279 | 330 |
| 280 const int stack_local_count = 0; | 331 const int stack_local_count = 0; |
| 281 const int context_local_count = 1; | 332 const int context_local_count = 1; |
| 282 const bool has_simple_parameters = true; | 333 const bool has_simple_parameters = true; |
| 283 const VariableAllocationInfo receiver_info = CONTEXT; | 334 const VariableAllocationInfo receiver_info = CONTEXT; |
| 284 const VariableAllocationInfo function_name_info = NONE; | 335 const VariableAllocationInfo function_name_info = NONE; |
| 285 const bool has_function_name = false; | 336 const bool has_function_name = false; |
| 286 const bool has_receiver = true; | 337 const bool has_receiver = true; |
| 338 const bool has_outer_scope_info = false; |
| 287 const int parameter_count = 0; | 339 const int parameter_count = 0; |
| 288 const int length = kVariablePartIndex + parameter_count + | 340 const int length = kVariablePartIndex + parameter_count + |
| 289 (1 + stack_local_count) + 2 * context_local_count + | 341 (1 + stack_local_count) + 2 * context_local_count + |
| 290 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 342 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0) + |
| 343 (has_outer_scope_info ? 1 : 0); |
| 291 | 344 |
| 292 Factory* factory = isolate->factory(); | 345 Factory* factory = isolate->factory(); |
| 293 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 346 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 294 | 347 |
| 295 // Encode the flags. | 348 // Encode the flags. |
| 296 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | 349 int flags = |
| 297 CallsEvalField::encode(false) | | 350 ScopeTypeField::encode(SCRIPT_SCOPE) | CallsEvalField::encode(false) | |
| 298 LanguageModeField::encode(SLOPPY) | | 351 LanguageModeField::encode(SLOPPY) | DeclarationScopeField::encode(true) | |
| 299 DeclarationScopeField::encode(true) | | 352 ReceiverVariableField::encode(receiver_info) | |
| 300 ReceiverVariableField::encode(receiver_info) | | 353 FunctionVariableField::encode(function_name_info) | |
| 301 FunctionVariableField::encode(function_name_info) | | 354 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
| 302 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 355 HasSimpleParametersField::encode(has_simple_parameters) | |
| 303 HasSimpleParametersField::encode(has_simple_parameters) | | 356 FunctionKindField::encode(FunctionKind::kNormalFunction) | |
| 304 FunctionKindField::encode(FunctionKind::kNormalFunction); | 357 HasOuterScopeInfoField::encode(has_outer_scope_info); |
| 305 scope_info->SetFlags(flags); | 358 scope_info->SetFlags(flags); |
| 306 scope_info->SetParameterCount(parameter_count); | 359 scope_info->SetParameterCount(parameter_count); |
| 307 scope_info->SetStackLocalCount(stack_local_count); | 360 scope_info->SetStackLocalCount(stack_local_count); |
| 308 scope_info->SetContextLocalCount(context_local_count); | 361 scope_info->SetContextLocalCount(context_local_count); |
| 309 | 362 |
| 310 int index = kVariablePartIndex; | 363 int index = kVariablePartIndex; |
| 311 const int first_slot_index = 0; | 364 const int first_slot_index = 0; |
| 312 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 365 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
| 313 scope_info->set(index++, Smi::FromInt(first_slot_index)); | 366 scope_info->set(index++, Smi::FromInt(first_slot_index)); |
| 314 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 367 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); |
| 315 | 368 |
| 316 // Here we add info for context-allocated "this". | 369 // Here we add info for context-allocated "this". |
| 317 DCHECK_EQ(index, scope_info->ContextLocalNameEntriesIndex()); | 370 DCHECK_EQ(index, scope_info->ContextLocalNameEntriesIndex()); |
| 318 scope_info->set(index++, *isolate->factory()->this_string()); | 371 scope_info->set(index++, *isolate->factory()->this_string()); |
| 319 DCHECK_EQ(index, scope_info->ContextLocalInfoEntriesIndex()); | 372 DCHECK_EQ(index, scope_info->ContextLocalInfoEntriesIndex()); |
| 320 const uint32_t value = VariableModeField::encode(CONST) | | 373 const uint32_t value = VariableModeField::encode(CONST) | |
| 321 InitFlagField::encode(kCreatedInitialized) | | 374 InitFlagField::encode(kCreatedInitialized) | |
| 322 MaybeAssignedFlagField::encode(kNotAssigned); | 375 MaybeAssignedFlagField::encode(kNotAssigned); |
| 323 scope_info->set(index++, Smi::FromInt(value)); | 376 scope_info->set(index++, Smi::FromInt(value)); |
| 324 | 377 |
| 325 // And here we record that this scopeinfo binds a receiver. | 378 // And here we record that this scopeinfo binds a receiver. |
| 326 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 379 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); |
| 327 const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0; | 380 const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0; |
| 328 scope_info->set(index++, Smi::FromInt(receiver_index)); | 381 scope_info->set(index++, Smi::FromInt(receiver_index)); |
| 329 | 382 |
| 330 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 383 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); |
| 384 DCHECK_EQ(index, scope_info->OuterScopeInfoEntryIndex()); |
| 331 | 385 |
| 332 DCHECK_EQ(index, scope_info->length()); | 386 DCHECK_EQ(index, scope_info->length()); |
| 333 DCHECK_EQ(scope_info->ParameterCount(), 0); | 387 DCHECK_EQ(scope_info->ParameterCount(), 0); |
| 334 DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1); | 388 DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1); |
| 335 | 389 |
| 336 return scope_info; | 390 return scope_info; |
| 337 } | 391 } |
| 338 | 392 |
| 339 | 393 |
| 340 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { | 394 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 476 |
| 423 | 477 |
| 424 bool ScopeInfo::HasFunctionName() { | 478 bool ScopeInfo::HasFunctionName() { |
| 425 if (length() > 0) { | 479 if (length() > 0) { |
| 426 return NONE != FunctionVariableField::decode(Flags()); | 480 return NONE != FunctionVariableField::decode(Flags()); |
| 427 } else { | 481 } else { |
| 428 return false; | 482 return false; |
| 429 } | 483 } |
| 430 } | 484 } |
| 431 | 485 |
| 486 bool ScopeInfo::HasOuterScopeInfo() { |
| 487 if (length() > 0) { |
| 488 return HasOuterScopeInfoField::decode(Flags()); |
| 489 } else { |
| 490 return false; |
| 491 } |
| 492 } |
| 432 | 493 |
| 433 bool ScopeInfo::HasHeapAllocatedLocals() { | 494 bool ScopeInfo::HasHeapAllocatedLocals() { |
| 434 if (length() > 0) { | 495 if (length() > 0) { |
| 435 return ContextLocalCount() > 0; | 496 return ContextLocalCount() > 0; |
| 436 } else { | 497 } else { |
| 437 return false; | 498 return false; |
| 438 } | 499 } |
| 439 } | 500 } |
| 440 | 501 |
| 441 | 502 |
| 442 bool ScopeInfo::HasContext() { | 503 bool ScopeInfo::HasContext() { |
| 443 return ContextLength() > 0; | 504 return ContextLength() > 0; |
| 444 } | 505 } |
| 445 | 506 |
| 446 | 507 |
| 447 String* ScopeInfo::FunctionName() { | 508 String* ScopeInfo::FunctionName() { |
| 448 DCHECK(HasFunctionName()); | 509 DCHECK(HasFunctionName()); |
| 449 return String::cast(get(FunctionNameEntryIndex())); | 510 return String::cast(get(FunctionNameEntryIndex())); |
| 450 } | 511 } |
| 451 | 512 |
| 513 ScopeInfo* ScopeInfo::OuterScopeInfo() { |
| 514 DCHECK(HasOuterScopeInfo()); |
| 515 return ScopeInfo::cast(get(OuterScopeInfoEntryIndex())); |
| 516 } |
| 517 |
| 452 ModuleInfo* ScopeInfo::ModuleDescriptorInfo() { | 518 ModuleInfo* ScopeInfo::ModuleDescriptorInfo() { |
| 453 DCHECK(scope_type() == MODULE_SCOPE); | 519 DCHECK(scope_type() == MODULE_SCOPE); |
| 454 return static_cast<ModuleInfo*>(get(ModuleInfoEntryIndex())); | 520 return static_cast<ModuleInfo*>(get(ModuleInfoEntryIndex())); |
| 455 } | 521 } |
| 456 | 522 |
| 457 String* ScopeInfo::ParameterName(int var) { | 523 String* ScopeInfo::ParameterName(int var) { |
| 458 DCHECK_LE(0, var); | 524 DCHECK_LE(0, var); |
| 459 DCHECK_LT(var, ParameterCount()); | 525 DCHECK_LT(var, ParameterCount()); |
| 460 int info_index = ParameterEntriesIndex() + var; | 526 int info_index = ParameterEntriesIndex() + var; |
| 461 return String::cast(get(info_index)); | 527 return String::cast(get(info_index)); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 759 } |
| 694 | 760 |
| 695 int ScopeInfo::ReceiverEntryIndex() { | 761 int ScopeInfo::ReceiverEntryIndex() { |
| 696 return ContextLocalInfoEntriesIndex() + ContextLocalCount(); | 762 return ContextLocalInfoEntriesIndex() + ContextLocalCount(); |
| 697 } | 763 } |
| 698 | 764 |
| 699 int ScopeInfo::FunctionNameEntryIndex() { | 765 int ScopeInfo::FunctionNameEntryIndex() { |
| 700 return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0); | 766 return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0); |
| 701 } | 767 } |
| 702 | 768 |
| 769 int ScopeInfo::OuterScopeInfoEntryIndex() { |
| 770 return FunctionNameEntryIndex() + (HasFunctionName() ? 2 : 0); |
| 771 } |
| 772 |
| 703 int ScopeInfo::ModuleInfoEntryIndex() { | 773 int ScopeInfo::ModuleInfoEntryIndex() { |
| 704 return FunctionNameEntryIndex() + (HasFunctionName() ? 2 : 0); | 774 return OuterScopeInfoEntryIndex() + (HasOuterScopeInfo() ? 1 : 0); |
| 705 } | 775 } |
| 706 | 776 |
| 707 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoEntryIndex() + 1; } | 777 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoEntryIndex() + 1; } |
| 708 | 778 |
| 709 int ScopeInfo::ModuleVariableEntriesIndex() { | 779 int ScopeInfo::ModuleVariableEntriesIndex() { |
| 710 return ModuleVariableCountIndex() + 1; | 780 return ModuleVariableCountIndex() + 1; |
| 711 } | 781 } |
| 712 | 782 |
| 713 #ifdef DEBUG | 783 #ifdef DEBUG |
| 714 | 784 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 } | 846 } |
| 777 | 847 |
| 778 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); | 848 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); |
| 779 result->set(kSpecialExportsIndex, *special_exports); | 849 result->set(kSpecialExportsIndex, *special_exports); |
| 780 result->set(kRegularExportsIndex, *regular_exports); | 850 result->set(kRegularExportsIndex, *regular_exports); |
| 781 return result; | 851 return result; |
| 782 } | 852 } |
| 783 | 853 |
| 784 } // namespace internal | 854 } // namespace internal |
| 785 } // namespace v8 | 855 } // namespace v8 |
| OLD | NEW |