| 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 #ifndef V8_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
| 6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 // Declare the function variable for a function literal. This variable | 673 // Declare the function variable for a function literal. This variable |
| 674 // is in an intermediate scope between this function scope and the the | 674 // is in an intermediate scope between this function scope and the the |
| 675 // outer scope. Only possible for function scopes; at most one variable. | 675 // outer scope. Only possible for function scopes; at most one variable. |
| 676 // | 676 // |
| 677 // This function needs to be called after all other variables have been | 677 // This function needs to be called after all other variables have been |
| 678 // declared in the scope. It will add a variable for {name} to {variables_}; | 678 // declared in the scope. It will add a variable for {name} to {variables_}; |
| 679 // either the function variable itself, or a non-local in case the function | 679 // either the function variable itself, or a non-local in case the function |
| 680 // calls sloppy eval. | 680 // calls sloppy eval. |
| 681 Variable* DeclareFunctionVar(const AstRawString* name); | 681 Variable* DeclareFunctionVar(const AstRawString* name); |
| 682 | 682 |
| 683 // Declare some special internal variables which must be accessible to |
| 684 // Ignition without ScopeInfo. |
| 685 Variable* DeclareGeneratorObjectVar(const AstRawString* name); |
| 686 Variable* DeclarePromiseVar(const AstRawString* name); |
| 687 |
| 683 // Declare a parameter in this scope. When there are duplicated | 688 // Declare a parameter in this scope. When there are duplicated |
| 684 // parameters the rightmost one 'wins'. However, the implementation | 689 // parameters the rightmost one 'wins'. However, the implementation |
| 685 // expects all parameters to be declared and from left to right. | 690 // expects all parameters to be declared and from left to right. |
| 686 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 691 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
| 687 bool is_optional, bool is_rest, bool* is_duplicate, | 692 bool is_optional, bool is_rest, bool* is_duplicate, |
| 688 AstValueFactory* ast_value_factory); | 693 AstValueFactory* ast_value_factory); |
| 689 | 694 |
| 690 // Declare an implicit global variable in this scope which must be a | 695 // Declare an implicit global variable in this scope which must be a |
| 691 // script scope. The variable was introduced (possibly from an inner | 696 // script scope. The variable was introduced (possibly from an inner |
| 692 // scope) by a reference to an unresolved variable with no intervening | 697 // scope) by a reference to an unresolved variable with no intervening |
| (...skipping 18 matching lines...) Expand all Loading... |
| 711 // The variable corresponding to the 'new.target' value. | 716 // The variable corresponding to the 'new.target' value. |
| 712 Variable* new_target_var() { return new_target_; } | 717 Variable* new_target_var() { return new_target_; } |
| 713 | 718 |
| 714 // The variable holding the function literal for named function | 719 // The variable holding the function literal for named function |
| 715 // literals, or NULL. Only valid for function scopes. | 720 // literals, or NULL. Only valid for function scopes. |
| 716 Variable* function_var() const { | 721 Variable* function_var() const { |
| 717 DCHECK(is_function_scope()); | 722 DCHECK(is_function_scope()); |
| 718 return function_; | 723 return function_; |
| 719 } | 724 } |
| 720 | 725 |
| 726 Variable* generator_object_var() const { |
| 727 DCHECK(is_function_scope() || is_module_scope()); |
| 728 return generator_object_; |
| 729 } |
| 730 |
| 731 Variable* promise_var() const { |
| 732 DCHECK(is_function_scope()); |
| 733 DCHECK(IsAsyncFunction(function_kind_)); |
| 734 return promise_; |
| 735 } |
| 736 |
| 721 // Parameters. The left-most parameter has index 0. | 737 // Parameters. The left-most parameter has index 0. |
| 722 // Only valid for function and module scopes. | 738 // Only valid for function and module scopes. |
| 723 Variable* parameter(int index) const { | 739 Variable* parameter(int index) const { |
| 724 DCHECK(is_function_scope() || is_module_scope()); | 740 DCHECK(is_function_scope() || is_module_scope()); |
| 725 return params_[index]; | 741 return params_[index]; |
| 726 } | 742 } |
| 727 | 743 |
| 728 // Returns the number of formal parameters, excluding a possible rest | 744 // Returns the number of formal parameters, excluding a possible rest |
| 729 // parameter. Examples: | 745 // parameter. Examples: |
| 730 // function foo(a, b) {} ==> 2 | 746 // function foo(a, b) {} ==> 2 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 // Convenience variable. | 883 // Convenience variable. |
| 868 Variable* receiver_; | 884 Variable* receiver_; |
| 869 // Function variable, if any; function scopes only. | 885 // Function variable, if any; function scopes only. |
| 870 Variable* function_; | 886 Variable* function_; |
| 871 // new.target variable, function scopes only. | 887 // new.target variable, function scopes only. |
| 872 Variable* new_target_; | 888 Variable* new_target_; |
| 873 // Convenience variable; function scopes only. | 889 // Convenience variable; function scopes only. |
| 874 Variable* arguments_; | 890 Variable* arguments_; |
| 875 // Convenience variable; Subclass constructor only | 891 // Convenience variable; Subclass constructor only |
| 876 Variable* this_function_; | 892 Variable* this_function_; |
| 893 |
| 894 // Generator object, if any; generator function scopes and module scopes only. |
| 895 Variable* generator_object_; |
| 896 // Promise, if any; async function scopes only. |
| 897 Variable* promise_; |
| 877 }; | 898 }; |
| 878 | 899 |
| 879 class ModuleScope final : public DeclarationScope { | 900 class ModuleScope final : public DeclarationScope { |
| 880 public: | 901 public: |
| 881 ModuleScope(DeclarationScope* script_scope, | 902 ModuleScope(DeclarationScope* script_scope, |
| 882 AstValueFactory* ast_value_factory); | 903 AstValueFactory* ast_value_factory); |
| 883 | 904 |
| 884 // Deserialization. | 905 // Deserialization. |
| 885 // The generated ModuleDescriptor does not preserve all information. In | 906 // The generated ModuleDescriptor does not preserve all information. In |
| 886 // particular, its module_requests map will be empty because we no longer need | 907 // particular, its module_requests map will be empty because we no longer need |
| (...skipping 11 matching lines...) Expand all Loading... |
| 898 void AllocateModuleVariables(); | 919 void AllocateModuleVariables(); |
| 899 | 920 |
| 900 private: | 921 private: |
| 901 ModuleDescriptor* module_descriptor_; | 922 ModuleDescriptor* module_descriptor_; |
| 902 }; | 923 }; |
| 903 | 924 |
| 904 } // namespace internal | 925 } // namespace internal |
| 905 } // namespace v8 | 926 } // namespace v8 |
| 906 | 927 |
| 907 #endif // V8_AST_SCOPES_H_ | 928 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |