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 "src/scopeinfo.h" | 5 #include "src/scopeinfo.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 Factory* factory = isolate->factory(); | 81 Factory* factory = isolate->factory(); |
82 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 82 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
83 | 83 |
84 bool has_simple_parameters = | 84 bool has_simple_parameters = |
85 scope->is_function_scope() && scope->has_simple_parameters(); | 85 scope->is_function_scope() && scope->has_simple_parameters(); |
86 | 86 |
87 // Encode the flags. | 87 // Encode the flags. |
88 int flags = ScopeTypeField::encode(scope->scope_type()) | | 88 int flags = ScopeTypeField::encode(scope->scope_type()) | |
89 CallsEvalField::encode(scope->calls_eval()) | | 89 CallsEvalField::encode(scope->calls_eval()) | |
90 LanguageModeField::encode(scope->language_mode()) | | 90 LanguageModeField::encode(scope->language_mode()) | |
| 91 DeclarationScopeField::encode(scope->is_declaration_scope()) | |
91 ReceiverVariableField::encode(receiver_info) | | 92 ReceiverVariableField::encode(receiver_info) | |
92 FunctionVariableField::encode(function_name_info) | | 93 FunctionVariableField::encode(function_name_info) | |
93 FunctionVariableMode::encode(function_variable_mode) | | 94 FunctionVariableMode::encode(function_variable_mode) | |
94 AsmModuleField::encode(scope->asm_module()) | | 95 AsmModuleField::encode(scope->asm_module()) | |
95 AsmFunctionField::encode(scope->asm_function()) | | 96 AsmFunctionField::encode(scope->asm_function()) | |
96 HasSimpleParametersField::encode(has_simple_parameters) | | 97 HasSimpleParametersField::encode(has_simple_parameters) | |
97 FunctionKindField::encode(scope->function_kind()); | 98 FunctionKindField::encode(scope->function_kind()); |
98 scope_info->SetFlags(flags); | 99 scope_info->SetFlags(flags); |
99 scope_info->SetParameterCount(parameter_count); | 100 scope_info->SetParameterCount(parameter_count); |
100 scope_info->SetStackLocalCount(stack_local_count); | 101 scope_info->SetStackLocalCount(stack_local_count); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 3 * strong_mode_free_variable_count + | 237 3 * strong_mode_free_variable_count + |
237 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 238 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
238 | 239 |
239 Factory* factory = isolate->factory(); | 240 Factory* factory = isolate->factory(); |
240 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 241 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
241 | 242 |
242 // Encode the flags. | 243 // Encode the flags. |
243 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | 244 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | |
244 CallsEvalField::encode(false) | | 245 CallsEvalField::encode(false) | |
245 LanguageModeField::encode(SLOPPY) | | 246 LanguageModeField::encode(SLOPPY) | |
| 247 DeclarationScopeField::encode(true) | |
246 ReceiverVariableField::encode(receiver_info) | | 248 ReceiverVariableField::encode(receiver_info) | |
247 FunctionVariableField::encode(function_name_info) | | 249 FunctionVariableField::encode(function_name_info) | |
248 FunctionVariableMode::encode(function_variable_mode) | | 250 FunctionVariableMode::encode(function_variable_mode) | |
249 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 251 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
250 HasSimpleParametersField::encode(has_simple_parameters) | | 252 HasSimpleParametersField::encode(has_simple_parameters) | |
251 FunctionKindField::encode(FunctionKind::kNormalFunction); | 253 FunctionKindField::encode(FunctionKind::kNormalFunction); |
252 scope_info->SetFlags(flags); | 254 scope_info->SetFlags(flags); |
253 scope_info->SetParameterCount(parameter_count); | 255 scope_info->SetParameterCount(parameter_count); |
254 scope_info->SetStackLocalCount(stack_local_count); | 256 scope_info->SetStackLocalCount(stack_local_count); |
255 scope_info->SetContextLocalCount(context_local_count); | 257 scope_info->SetContextLocalCount(context_local_count); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 bool ScopeInfo::CallsEval() { | 305 bool ScopeInfo::CallsEval() { |
304 return length() > 0 && CallsEvalField::decode(Flags()); | 306 return length() > 0 && CallsEvalField::decode(Flags()); |
305 } | 307 } |
306 | 308 |
307 | 309 |
308 LanguageMode ScopeInfo::language_mode() { | 310 LanguageMode ScopeInfo::language_mode() { |
309 return length() > 0 ? LanguageModeField::decode(Flags()) : SLOPPY; | 311 return length() > 0 ? LanguageModeField::decode(Flags()) : SLOPPY; |
310 } | 312 } |
311 | 313 |
312 | 314 |
| 315 bool ScopeInfo::is_declaration_scope() { |
| 316 return DeclarationScopeField::decode(Flags()); |
| 317 } |
| 318 |
| 319 |
313 int ScopeInfo::LocalCount() { | 320 int ScopeInfo::LocalCount() { |
314 return StackLocalCount() + ContextLocalCount(); | 321 return StackLocalCount() + ContextLocalCount(); |
315 } | 322 } |
316 | 323 |
317 | 324 |
318 int ScopeInfo::StackSlotCount() { | 325 int ScopeInfo::StackSlotCount() { |
319 if (length() > 0) { | 326 if (length() > 0) { |
320 bool function_name_stack_slot = | 327 bool function_name_stack_slot = |
321 FunctionVariableField::decode(Flags()) == STACK; | 328 FunctionVariableField::decode(Flags()) == STACK; |
322 return StackLocalCount() + (function_name_stack_slot ? 1 : 0); | 329 return StackLocalCount() + (function_name_stack_slot ? 1 : 0); |
323 } | 330 } |
324 return 0; | 331 return 0; |
325 } | 332 } |
326 | 333 |
327 | 334 |
328 int ScopeInfo::ContextLength() { | 335 int ScopeInfo::ContextLength() { |
329 if (length() > 0) { | 336 if (length() > 0) { |
330 int context_locals = ContextLocalCount(); | 337 int context_locals = ContextLocalCount(); |
331 int context_globals = ContextGlobalCount(); | 338 int context_globals = ContextGlobalCount(); |
332 bool function_name_context_slot = | 339 bool function_name_context_slot = |
333 FunctionVariableField::decode(Flags()) == CONTEXT; | 340 FunctionVariableField::decode(Flags()) == CONTEXT; |
334 bool has_context = context_locals > 0 || context_globals > 0 || | 341 bool has_context = context_locals > 0 || context_globals > 0 || |
335 function_name_context_slot || | 342 function_name_context_slot || |
336 scope_type() == WITH_SCOPE || | 343 scope_type() == WITH_SCOPE || |
| 344 (scope_type() == BLOCK_SCOPE && CallsSloppyEval() && |
| 345 is_declaration_scope()) || |
337 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || | 346 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || |
338 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || | 347 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || |
339 scope_type() == MODULE_SCOPE; | 348 scope_type() == MODULE_SCOPE; |
340 | 349 |
341 if (has_context) { | 350 if (has_context) { |
342 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals + | 351 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals + |
343 (function_name_context_slot ? 1 : 0); | 352 (function_name_context_slot ? 1 : 0); |
344 } | 353 } |
345 } | 354 } |
346 return 0; | 355 return 0; |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 info->set_mode(i, var->mode()); | 838 info->set_mode(i, var->mode()); |
830 DCHECK(var->index() >= 0); | 839 DCHECK(var->index() >= 0); |
831 info->set_index(i, var->index()); | 840 info->set_index(i, var->index()); |
832 } | 841 } |
833 DCHECK(i == info->length()); | 842 DCHECK(i == info->length()); |
834 return info; | 843 return info; |
835 } | 844 } |
836 | 845 |
837 } // namespace internal | 846 } // namespace internal |
838 } // namespace v8 | 847 } // namespace v8 |
OLD | NEW |