| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/parser.h" | 10 #include "src/parser.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 inner_scope_calls_eval_ = false; | 173 inner_scope_calls_eval_ = false; |
| 174 inner_scope_uses_arguments_ = false; | 174 inner_scope_uses_arguments_ = false; |
| 175 force_eager_compilation_ = false; | 175 force_eager_compilation_ = false; |
| 176 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 176 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
| 177 ? outer_scope->has_forced_context_allocation() : false; | 177 ? outer_scope->has_forced_context_allocation() : false; |
| 178 num_var_or_const_ = 0; | 178 num_var_or_const_ = 0; |
| 179 num_stack_slots_ = 0; | 179 num_stack_slots_ = 0; |
| 180 num_heap_slots_ = 0; | 180 num_heap_slots_ = 0; |
| 181 num_global_slots_ = 0; | 181 num_global_slots_ = 0; |
| 182 num_modules_ = 0; | 182 num_modules_ = 0; |
| 183 module_var_ = NULL, | 183 module_var_ = NULL; |
| 184 has_simple_parameters_ = true; |
| 184 rest_parameter_ = NULL; | 185 rest_parameter_ = NULL; |
| 185 rest_index_ = -1; | 186 rest_index_ = -1; |
| 186 scope_info_ = scope_info; | 187 scope_info_ = scope_info; |
| 187 start_position_ = RelocInfo::kNoPosition; | 188 start_position_ = RelocInfo::kNoPosition; |
| 188 end_position_ = RelocInfo::kNoPosition; | 189 end_position_ = RelocInfo::kNoPosition; |
| 189 if (!scope_info.is_null()) { | 190 if (!scope_info.is_null()) { |
| 190 scope_calls_eval_ = scope_info->CallsEval(); | 191 scope_calls_eval_ = scope_info->CallsEval(); |
| 191 language_mode_ = scope_info->language_mode(); | 192 language_mode_ = scope_info->language_mode(); |
| 192 function_kind_ = scope_info->function_kind(); | 193 function_kind_ = scope_info->function_kind(); |
| 193 } | 194 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 462 } |
| 462 | 463 |
| 463 | 464 |
| 464 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 465 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
| 465 bool is_rest, bool* is_duplicate) { | 466 bool is_rest, bool* is_duplicate) { |
| 466 DCHECK(!already_resolved()); | 467 DCHECK(!already_resolved()); |
| 467 DCHECK(is_function_scope()); | 468 DCHECK(is_function_scope()); |
| 468 Variable* var; | 469 Variable* var; |
| 469 if (mode == TEMPORARY) { | 470 if (mode == TEMPORARY) { |
| 470 var = NewTemporary(name); | 471 var = NewTemporary(name); |
| 472 has_simple_parameters_ = false; |
| 471 } else { | 473 } else { |
| 472 var = variables_.Declare(this, name, mode, Variable::NORMAL, | 474 var = variables_.Declare(this, name, mode, Variable::NORMAL, |
| 473 kCreatedInitialized); | 475 kCreatedInitialized); |
| 474 // TODO(wingo): Avoid O(n^2) check. | 476 // TODO(wingo): Avoid O(n^2) check. |
| 475 *is_duplicate = IsDeclaredParameter(name); | 477 *is_duplicate = IsDeclaredParameter(name); |
| 476 } | 478 } |
| 477 if (is_rest) { | 479 if (is_rest) { |
| 478 DCHECK_NULL(rest_parameter_); | 480 DCHECK_NULL(rest_parameter_); |
| 479 rest_parameter_ = var; | 481 rest_parameter_ = var; |
| 480 rest_index_ = num_parameters(); | 482 rest_index_ = num_parameters(); |
| 483 has_simple_parameters_ = false; |
| 481 } | 484 } |
| 482 params_.Add(var, zone()); | 485 params_.Add(var, zone()); |
| 483 return var; | 486 return var; |
| 484 } | 487 } |
| 485 | 488 |
| 486 | 489 |
| 487 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 490 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
| 488 InitializationFlag init_flag, Variable::Kind kind, | 491 InitializationFlag init_flag, Variable::Kind kind, |
| 489 MaybeAssignedFlag maybe_assigned_flag, | 492 MaybeAssignedFlag maybe_assigned_flag, |
| 490 int declaration_group_start) { | 493 int declaration_group_start) { |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 // parameters, which is why we don't need to allocate an arguments | 1395 // parameters, which is why we don't need to allocate an arguments |
| 1393 // object in that case. | 1396 // object in that case. |
| 1394 | 1397 |
| 1395 // We are using 'arguments'. Tell the code generator that is needs to | 1398 // We are using 'arguments'. Tell the code generator that is needs to |
| 1396 // allocate the arguments object by setting 'arguments_'. | 1399 // allocate the arguments object by setting 'arguments_'. |
| 1397 arguments_ = arguments; | 1400 arguments_ = arguments; |
| 1398 | 1401 |
| 1399 // In strict mode 'arguments' does not alias formal parameters. | 1402 // In strict mode 'arguments' does not alias formal parameters. |
| 1400 // Therefore in strict mode we allocate parameters as if 'arguments' | 1403 // Therefore in strict mode we allocate parameters as if 'arguments' |
| 1401 // were not used. | 1404 // were not used. |
| 1402 uses_sloppy_arguments = is_sloppy(language_mode()); | 1405 // If the parameter list is not simple, arguments isn't sloppy either. |
| 1406 uses_sloppy_arguments = |
| 1407 is_sloppy(language_mode()) && has_simple_parameters(); |
| 1403 } | 1408 } |
| 1404 | 1409 |
| 1405 if (rest_parameter_ && !MustAllocate(rest_parameter_)) { | 1410 if (rest_parameter_ && !MustAllocate(rest_parameter_)) { |
| 1406 rest_parameter_ = NULL; | 1411 rest_parameter_ = NULL; |
| 1407 } | 1412 } |
| 1408 | 1413 |
| 1409 // The same parameter may occur multiple times in the parameters_ list. | 1414 // The same parameter may occur multiple times in the parameters_ list. |
| 1410 // If it does, and if it is not copied into the context object, it must | 1415 // If it does, and if it is not copied into the context object, it must |
| 1411 // receive the highest parameter index for that parameter; thus iteration | 1416 // receive the highest parameter index for that parameter; thus iteration |
| 1412 // order is relevant! | 1417 // order is relevant! |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1611 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1607 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1612 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1608 (is_function_var_in_context ? 1 : 0); | 1613 (is_function_var_in_context ? 1 : 0); |
| 1609 } | 1614 } |
| 1610 | 1615 |
| 1611 | 1616 |
| 1612 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1617 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1613 | 1618 |
| 1614 } // namespace internal | 1619 } // namespace internal |
| 1615 } // namespace v8 | 1620 } // namespace v8 |
| OLD | NEW |