| 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 16 matching lines...) Expand all Loading... |
| 27 &strong_mode_free_variables); | 27 &strong_mode_free_variables); |
| 28 const int stack_local_count = stack_locals.length(); | 28 const int stack_local_count = stack_locals.length(); |
| 29 const int context_local_count = context_locals.length(); | 29 const int context_local_count = context_locals.length(); |
| 30 const int context_global_count = context_globals.length(); | 30 const int context_global_count = context_globals.length(); |
| 31 const int strong_mode_free_variable_count = | 31 const int strong_mode_free_variable_count = |
| 32 strong_mode_free_variables.length(); | 32 strong_mode_free_variables.length(); |
| 33 // Make sure we allocate the correct amount. | 33 // Make sure we allocate the correct amount. |
| 34 DCHECK_EQ(scope->ContextLocalCount(), context_local_count); | 34 DCHECK_EQ(scope->ContextLocalCount(), context_local_count); |
| 35 DCHECK_EQ(scope->ContextGlobalCount(), context_global_count); | 35 DCHECK_EQ(scope->ContextGlobalCount(), context_global_count); |
| 36 | 36 |
| 37 bool simple_parameter_list = | |
| 38 scope->is_function_scope() ? scope->is_simple_parameter_list() : true; | |
| 39 | |
| 40 // Determine use and location of the "this" binding if it is present. | 37 // Determine use and location of the "this" binding if it is present. |
| 41 VariableAllocationInfo receiver_info; | 38 VariableAllocationInfo receiver_info; |
| 42 if (scope->has_this_declaration()) { | 39 if (scope->has_this_declaration()) { |
| 43 Variable* var = scope->receiver(); | 40 Variable* var = scope->receiver(); |
| 44 if (!var->is_used()) { | 41 if (!var->is_used()) { |
| 45 receiver_info = UNUSED; | 42 receiver_info = UNUSED; |
| 46 } else if (var->IsContextSlot()) { | 43 } else if (var->IsContextSlot()) { |
| 47 receiver_info = CONTEXT; | 44 receiver_info = CONTEXT; |
| 48 } else { | 45 } else { |
| 49 DCHECK(var->IsParameter()); | 46 DCHECK(var->IsParameter()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 const int parameter_count = scope->num_parameters(); | 75 const int parameter_count = scope->num_parameters(); |
| 79 const int length = kVariablePartIndex + parameter_count + | 76 const int length = kVariablePartIndex + parameter_count + |
| 80 (1 + stack_local_count) + 2 * context_local_count + | 77 (1 + stack_local_count) + 2 * context_local_count + |
| 81 2 * context_global_count + | 78 2 * context_global_count + |
| 82 3 * strong_mode_free_variable_count + | 79 3 * strong_mode_free_variable_count + |
| 83 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 80 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| 84 | 81 |
| 85 Factory* factory = isolate->factory(); | 82 Factory* factory = isolate->factory(); |
| 86 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 83 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 87 | 84 |
| 85 bool has_simple_parameters = |
| 86 scope->is_function_scope() && scope->has_simple_parameters(); |
| 87 |
| 88 // Encode the flags. | 88 // Encode the flags. |
| 89 int flags = ScopeTypeField::encode(scope->scope_type()) | | 89 int flags = ScopeTypeField::encode(scope->scope_type()) | |
| 90 CallsEvalField::encode(scope->calls_eval()) | | 90 CallsEvalField::encode(scope->calls_eval()) | |
| 91 LanguageModeField::encode(scope->language_mode()) | | 91 LanguageModeField::encode(scope->language_mode()) | |
| 92 ReceiverVariableField::encode(receiver_info) | | 92 ReceiverVariableField::encode(receiver_info) | |
| 93 FunctionVariableField::encode(function_name_info) | | 93 FunctionVariableField::encode(function_name_info) | |
| 94 FunctionVariableMode::encode(function_variable_mode) | | 94 FunctionVariableMode::encode(function_variable_mode) | |
| 95 AsmModuleField::encode(scope->asm_module()) | | 95 AsmModuleField::encode(scope->asm_module()) | |
| 96 AsmFunctionField::encode(scope->asm_function()) | | 96 AsmFunctionField::encode(scope->asm_function()) | |
| 97 IsSimpleParameterListField::encode(simple_parameter_list) | | 97 HasSimpleParametersField::encode(has_simple_parameters) | |
| 98 FunctionKindField::encode(scope->function_kind()); | 98 FunctionKindField::encode(scope->function_kind()); |
| 99 scope_info->SetFlags(flags); | 99 scope_info->SetFlags(flags); |
| 100 scope_info->SetParameterCount(parameter_count); | 100 scope_info->SetParameterCount(parameter_count); |
| 101 scope_info->SetStackLocalCount(stack_local_count); | 101 scope_info->SetStackLocalCount(stack_local_count); |
| 102 scope_info->SetContextLocalCount(context_local_count); | 102 scope_info->SetContextLocalCount(context_local_count); |
| 103 scope_info->SetContextGlobalCount(context_global_count); | 103 scope_info->SetContextGlobalCount(context_global_count); |
| 104 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); | 104 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); |
| 105 | 105 |
| 106 int index = kVariablePartIndex; | 106 int index = kVariablePartIndex; |
| 107 // Add parameters. | 107 // Add parameters. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 | 219 |
| 220 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 220 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
| 221 DCHECK(isolate->bootstrapper()->IsActive()); | 221 DCHECK(isolate->bootstrapper()->IsActive()); |
| 222 | 222 |
| 223 const int stack_local_count = 0; | 223 const int stack_local_count = 0; |
| 224 const int context_local_count = 1; | 224 const int context_local_count = 1; |
| 225 const int context_global_count = 0; | 225 const int context_global_count = 0; |
| 226 const int strong_mode_free_variable_count = 0; | 226 const int strong_mode_free_variable_count = 0; |
| 227 const bool simple_parameter_list = true; | 227 const bool has_simple_parameters = true; |
| 228 const VariableAllocationInfo receiver_info = CONTEXT; | 228 const VariableAllocationInfo receiver_info = CONTEXT; |
| 229 const VariableAllocationInfo function_name_info = NONE; | 229 const VariableAllocationInfo function_name_info = NONE; |
| 230 const VariableMode function_variable_mode = VAR; | 230 const VariableMode function_variable_mode = VAR; |
| 231 const bool has_function_name = false; | 231 const bool has_function_name = false; |
| 232 const bool has_receiver = true; | 232 const bool has_receiver = true; |
| 233 const int parameter_count = 0; | 233 const int parameter_count = 0; |
| 234 const int length = kVariablePartIndex + parameter_count + | 234 const int length = kVariablePartIndex + parameter_count + |
| 235 (1 + stack_local_count) + 2 * context_local_count + | 235 (1 + stack_local_count) + 2 * context_local_count + |
| 236 2 * context_global_count + | 236 2 * context_global_count + |
| 237 3 * strong_mode_free_variable_count + | 237 3 * strong_mode_free_variable_count + |
| 238 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 238 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| 239 | 239 |
| 240 Factory* factory = isolate->factory(); | 240 Factory* factory = isolate->factory(); |
| 241 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 241 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 242 | 242 |
| 243 // Encode the flags. | 243 // Encode the flags. |
| 244 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | 244 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | |
| 245 CallsEvalField::encode(false) | | 245 CallsEvalField::encode(false) | |
| 246 LanguageModeField::encode(SLOPPY) | | 246 LanguageModeField::encode(SLOPPY) | |
| 247 ReceiverVariableField::encode(receiver_info) | | 247 ReceiverVariableField::encode(receiver_info) | |
| 248 FunctionVariableField::encode(function_name_info) | | 248 FunctionVariableField::encode(function_name_info) | |
| 249 FunctionVariableMode::encode(function_variable_mode) | | 249 FunctionVariableMode::encode(function_variable_mode) | |
| 250 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 250 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
| 251 IsSimpleParameterListField::encode(simple_parameter_list) | | 251 HasSimpleParametersField::encode(has_simple_parameters) | |
| 252 FunctionKindField::encode(FunctionKind::kNormalFunction); | 252 FunctionKindField::encode(FunctionKind::kNormalFunction); |
| 253 scope_info->SetFlags(flags); | 253 scope_info->SetFlags(flags); |
| 254 scope_info->SetParameterCount(parameter_count); | 254 scope_info->SetParameterCount(parameter_count); |
| 255 scope_info->SetStackLocalCount(stack_local_count); | 255 scope_info->SetStackLocalCount(stack_local_count); |
| 256 scope_info->SetContextLocalCount(context_local_count); | 256 scope_info->SetContextLocalCount(context_local_count); |
| 257 scope_info->SetContextGlobalCount(context_global_count); | 257 scope_info->SetContextGlobalCount(context_global_count); |
| 258 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); | 258 scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count); |
| 259 | 259 |
| 260 int index = kVariablePartIndex; | 260 int index = kVariablePartIndex; |
| 261 const int first_slot_index = 0; | 261 const int first_slot_index = 0; |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 info->set_mode(i, var->mode()); | 830 info->set_mode(i, var->mode()); |
| 831 DCHECK(var->index() >= 0); | 831 DCHECK(var->index() >= 0); |
| 832 info->set_index(i, var->index()); | 832 info->set_index(i, var->index()); |
| 833 } | 833 } |
| 834 DCHECK(i == info->length()); | 834 DCHECK(i == info->length()); |
| 835 return info; | 835 return info; |
| 836 } | 836 } |
| 837 | 837 |
| 838 } // namespace internal | 838 } // namespace internal |
| 839 } // namespace v8 | 839 } // namespace v8 |
| OLD | NEW |