Chromium Code Reviews| 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 DCHECK(has_this_declaration()); | 429 DCHECK(has_this_declaration()); |
| 430 | 430 |
| 431 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 431 bool subclass_constructor = IsSubclassConstructor(function_kind_); |
| 432 Variable* var = Declare( | 432 Variable* var = Declare( |
| 433 zone(), this, ast_value_factory->this_string(), | 433 zone(), this, ast_value_factory->this_string(), |
| 434 subclass_constructor ? CONST : VAR, Variable::THIS, | 434 subclass_constructor ? CONST : VAR, Variable::THIS, |
| 435 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 435 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
| 436 receiver_ = var; | 436 receiver_ = var; |
| 437 } | 437 } |
| 438 | 438 |
| 439 void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) { | |
| 440 DCHECK(is_function_scope()); | |
| 441 DCHECK(!is_arrow_scope()); | |
| 442 | |
| 443 Variable* arg_variable = LookupLocal(ast_value_factory->arguments_string()); | |
| 444 if (arg_variable != NULL && IsLexicalVariableMode(arg_variable->mode())) { | |
|
adamk
2016/08/30 20:45:56
Please add a comment here explaining what you're d
lpy
2016/09/01 01:17:30
Done.
| |
| 445 return; | |
| 446 } | |
| 447 | |
| 448 // Declare 'arguments' variable which exists in all non arrow functions. | |
| 449 // Note that it might never be accessed, in which case it won't be | |
| 450 // allocated during variable allocation. | |
| 451 arguments_ = Declare(zone(), this, ast_value_factory->arguments_string(), VAR, | |
|
adamk
2016/08/30 20:45:56
I think you only need to do this if arg_variable =
lpy
2016/09/01 01:17:30
Done.
| |
| 452 Variable::ARGUMENTS, kCreatedInitialized); | |
| 453 } | |
| 454 | |
| 439 void DeclarationScope::DeclareDefaultFunctionVariables( | 455 void DeclarationScope::DeclareDefaultFunctionVariables( |
| 440 AstValueFactory* ast_value_factory) { | 456 AstValueFactory* ast_value_factory) { |
| 441 DCHECK(is_function_scope()); | 457 DCHECK(is_function_scope()); |
| 442 DCHECK(!is_arrow_scope()); | 458 DCHECK(!is_arrow_scope()); |
| 443 // Declare 'arguments' variable which exists in all non arrow functions. | |
| 444 // Note that it might never be accessed, in which case it won't be | |
| 445 // allocated during variable allocation. | |
| 446 arguments_ = Declare(zone(), this, ast_value_factory->arguments_string(), VAR, | |
| 447 Variable::ARGUMENTS, kCreatedInitialized); | |
| 448 | 459 |
| 449 new_target_ = Declare(zone(), this, ast_value_factory->new_target_string(), | 460 new_target_ = Declare(zone(), this, ast_value_factory->new_target_string(), |
| 450 CONST, Variable::NORMAL, kCreatedInitialized); | 461 CONST, Variable::NORMAL, kCreatedInitialized); |
| 451 | 462 |
| 452 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || | 463 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || |
| 453 IsAccessorFunction(function_kind_)) { | 464 IsAccessorFunction(function_kind_)) { |
| 454 this_function_ = | 465 this_function_ = |
| 455 Declare(zone(), this, ast_value_factory->this_function_string(), CONST, | 466 Declare(zone(), this, ast_value_factory->this_function_string(), CONST, |
| 456 Variable::NORMAL, kCreatedInitialized); | 467 Variable::NORMAL, kCreatedInitialized); |
| 457 } | 468 } |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1494 // Therefore in strict mode we allocate parameters as if 'arguments' | 1505 // Therefore in strict mode we allocate parameters as if 'arguments' |
| 1495 // were not used. | 1506 // were not used. |
| 1496 // If the parameter list is not simple, arguments isn't sloppy either. | 1507 // If the parameter list is not simple, arguments isn't sloppy either. |
| 1497 uses_sloppy_arguments = | 1508 uses_sloppy_arguments = |
| 1498 is_sloppy(language_mode()) && has_simple_parameters(); | 1509 is_sloppy(language_mode()) && has_simple_parameters(); |
| 1499 } else { | 1510 } else { |
| 1500 // 'arguments' is unused. Tell the code generator that it does not need to | 1511 // 'arguments' is unused. Tell the code generator that it does not need to |
| 1501 // allocate the arguments object by nulling out arguments_. | 1512 // allocate the arguments object by nulling out arguments_. |
| 1502 arguments_ = nullptr; | 1513 arguments_ = nullptr; |
| 1503 } | 1514 } |
| 1504 | |
| 1505 } else { | |
| 1506 DCHECK(is_arrow_scope()); | |
| 1507 } | 1515 } |
| 1508 | 1516 |
| 1509 // The same parameter may occur multiple times in the parameters_ list. | 1517 // The same parameter may occur multiple times in the parameters_ list. |
| 1510 // If it does, and if it is not copied into the context object, it must | 1518 // If it does, and if it is not copied into the context object, it must |
| 1511 // receive the highest parameter index for that parameter; thus iteration | 1519 // receive the highest parameter index for that parameter; thus iteration |
| 1512 // order is relevant! | 1520 // order is relevant! |
| 1513 for (int i = num_parameters() - 1; i >= 0; --i) { | 1521 for (int i = num_parameters() - 1; i >= 0; --i) { |
| 1514 Variable* var = params_[i]; | 1522 Variable* var = params_[i]; |
| 1515 DCHECK(!has_rest_ || var != rest_parameter()); | 1523 DCHECK(!has_rest_ || var != rest_parameter()); |
| 1516 DCHECK_EQ(this, var->scope()); | 1524 DCHECK_EQ(this, var->scope()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 Variable* function = | 1664 Variable* function = |
| 1657 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1665 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 1658 bool is_function_var_in_context = | 1666 bool is_function_var_in_context = |
| 1659 function != nullptr && function->IsContextSlot(); | 1667 function != nullptr && function->IsContextSlot(); |
| 1660 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1668 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1661 (is_function_var_in_context ? 1 : 0); | 1669 (is_function_var_in_context ? 1 : 0); |
| 1662 } | 1670 } |
| 1663 | 1671 |
| 1664 } // namespace internal | 1672 } // namespace internal |
| 1665 } // namespace v8 | 1673 } // namespace v8 |
| OLD | NEW |