Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ast/scopes.h

Issue 2685683002: [async-await] (simpler) fix for Return in try/finally in async functions (Closed)
Patch Set: also shrink the bitfield for ReturnStatement::Type Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 GetRareVariable(RareVariable::kGeneratorObject);
729 }
730
731 Variable* promise_var() const {
732 DCHECK(is_function_scope());
733 DCHECK(IsAsyncFunction(function_kind_));
734 return GetRareVariable(RareVariable::kPromise);
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 20 matching lines...) Expand all
751 has_simple_parameters_ = false; 767 has_simple_parameters_ = false;
752 } 768 }
753 769
754 // The local variable 'arguments' if we need to allocate it; NULL otherwise. 770 // The local variable 'arguments' if we need to allocate it; NULL otherwise.
755 Variable* arguments() const { 771 Variable* arguments() const {
756 DCHECK(!is_arrow_scope() || arguments_ == nullptr); 772 DCHECK(!is_arrow_scope() || arguments_ == nullptr);
757 return arguments_; 773 return arguments_;
758 } 774 }
759 775
760 Variable* this_function_var() const { 776 Variable* this_function_var() const {
777 Variable* this_function = GetRareVariable(RareVariable::kThisFunction);
778
761 // This is only used in derived constructors atm. 779 // This is only used in derived constructors atm.
762 DCHECK(this_function_ == nullptr || 780 DCHECK(this_function == nullptr ||
763 (is_function_scope() && (IsClassConstructor(function_kind()) || 781 (is_function_scope() && (IsClassConstructor(function_kind()) ||
764 IsConciseMethod(function_kind()) || 782 IsConciseMethod(function_kind()) ||
765 IsAccessorFunction(function_kind())))); 783 IsAccessorFunction(function_kind()))));
766 return this_function_; 784 return this_function;
767 } 785 }
768 786
769 // Adds a local variable in this scope's locals list. This is for adjusting 787 // Adds a local variable in this scope's locals list. This is for adjusting
770 // the scope of temporaries and do-expression vars when desugaring parameter 788 // the scope of temporaries and do-expression vars when desugaring parameter
771 // initializers. 789 // initializers.
772 void AddLocal(Variable* var); 790 void AddLocal(Variable* var);
773 791
774 void DeclareSloppyBlockFunction( 792 void DeclareSloppyBlockFunction(
775 const AstRawString* name, Scope* scope, 793 const AstRawString* name, Scope* scope,
776 SloppyBlockFunctionStatement* statement = nullptr); 794 SloppyBlockFunctionStatement* statement = nullptr);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 // Map of function names to lists of functions defined in sloppy blocks 883 // Map of function names to lists of functions defined in sloppy blocks
866 SloppyBlockFunctionMap sloppy_block_function_map_; 884 SloppyBlockFunctionMap sloppy_block_function_map_;
867 // Convenience variable. 885 // Convenience variable.
868 Variable* receiver_; 886 Variable* receiver_;
869 // Function variable, if any; function scopes only. 887 // Function variable, if any; function scopes only.
870 Variable* function_; 888 Variable* function_;
871 // new.target variable, function scopes only. 889 // new.target variable, function scopes only.
872 Variable* new_target_; 890 Variable* new_target_;
873 // Convenience variable; function scopes only. 891 // Convenience variable; function scopes only.
874 Variable* arguments_; 892 Variable* arguments_;
875 // Convenience variable; Subclass constructor only 893
876 Variable* this_function_; 894 struct RareData : public ZoneObject {
895 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
896
897 // Convenience variable; Subclass constructor only
898 Variable* this_function = nullptr;
899
900 // Generator object, if any; generator function scopes and module scopes
901 // only.
902 Variable* generator_object = nullptr;
903 // Promise, if any; async function scopes only.
904 Variable* promise = nullptr;
905 };
906
907 enum class RareVariable {
908 kThisFunction = offsetof(RareData, this_function),
909 kGeneratorObject = offsetof(RareData, generator_object),
910 kPromise = offsetof(RareData, promise)
911 };
912
913 V8_INLINE RareData* EnsureRareData() {
914 if (rare_data_ == nullptr) {
915 rare_data_ = new (zone_) RareData;
916 }
917 return rare_data_;
918 }
919
920 V8_INLINE Variable* GetRareVariable(RareVariable id) const {
921 if (rare_data_ == nullptr) return nullptr;
922 return *reinterpret_cast<Variable**>(
923 reinterpret_cast<uint8_t*>(rare_data_) + static_cast<ptrdiff_t>(id));
924 }
925
926 // Set `var` to null if it's non-null and Predicate (Variable*) -> bool
927 // returns true.
928 template <typename Predicate>
929 V8_INLINE void NullifyRareVariableIf(RareVariable id, Predicate predicate) {
930 if (V8_LIKELY(rare_data_ == nullptr)) return;
931 Variable** var = reinterpret_cast<Variable**>(
932 reinterpret_cast<uint8_t*>(rare_data_) + static_cast<ptrdiff_t>(id));
933 if (*var && predicate(*var)) *var = nullptr;
934 }
935
936 RareData* rare_data_ = nullptr;
877 }; 937 };
878 938
879 class ModuleScope final : public DeclarationScope { 939 class ModuleScope final : public DeclarationScope {
880 public: 940 public:
881 ModuleScope(DeclarationScope* script_scope, 941 ModuleScope(DeclarationScope* script_scope,
882 AstValueFactory* ast_value_factory); 942 AstValueFactory* ast_value_factory);
883 943
884 // Deserialization. 944 // Deserialization.
885 // The generated ModuleDescriptor does not preserve all information. In 945 // The generated ModuleDescriptor does not preserve all information. In
886 // particular, its module_requests map will be empty because we no longer need 946 // particular, its module_requests map will be empty because we no longer need
(...skipping 11 matching lines...) Expand all
898 void AllocateModuleVariables(); 958 void AllocateModuleVariables();
899 959
900 private: 960 private:
901 ModuleDescriptor* module_descriptor_; 961 ModuleDescriptor* module_descriptor_;
902 }; 962 };
903 963
904 } // namespace internal 964 } // namespace internal
905 } // namespace v8 965 } // namespace v8
906 966
907 #endif // V8_AST_SCOPES_H_ 967 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698