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/hashmap.h" | 8 #include "src/base/hashmap.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // function, or eval scope. Same as DeclarationScope(), but skips declaration | 364 // function, or eval scope. Same as DeclarationScope(), but skips declaration |
365 // "block" scopes. Used for differentiating associated function objects (i.e., | 365 // "block" scopes. Used for differentiating associated function objects (i.e., |
366 // the scope for which a function prologue allocates a context) or declaring | 366 // the scope for which a function prologue allocates a context) or declaring |
367 // temporaries. | 367 // temporaries. |
368 DeclarationScope* GetClosureScope(); | 368 DeclarationScope* GetClosureScope(); |
369 | 369 |
370 // Find the first (non-arrow) function or script scope. This is where | 370 // Find the first (non-arrow) function or script scope. This is where |
371 // 'this' is bound, and what determines the function kind. | 371 // 'this' is bound, and what determines the function kind. |
372 DeclarationScope* GetReceiverScope(); | 372 DeclarationScope* GetReceiverScope(); |
373 | 373 |
374 // Find the module scope, assuming there is one. | |
375 ModuleScope* GetModuleScope(); | |
376 | |
377 // Analyze() must have been called once to create the ScopeInfo. | 374 // Analyze() must have been called once to create the ScopeInfo. |
378 Handle<ScopeInfo> scope_info() { | 375 Handle<ScopeInfo> scope_info() { |
379 DCHECK(!scope_info_.is_null()); | 376 DCHECK(!scope_info_.is_null()); |
380 return scope_info_; | 377 return scope_info_; |
381 } | 378 } |
382 | 379 |
383 // --------------------------------------------------------------------------- | 380 // --------------------------------------------------------------------------- |
384 // Strict mode support. | 381 // Strict mode support. |
385 bool IsDeclared(const AstRawString* name) { | 382 bool IsDeclared(const AstRawString* name) { |
386 // During formal parameter list parsing the scope only contains | 383 // During formal parameter list parsing the scope only contains |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 Variable* new_target_var() { return new_target_; } | 670 Variable* new_target_var() { return new_target_; } |
674 | 671 |
675 // The variable holding the function literal for named function | 672 // The variable holding the function literal for named function |
676 // literals, or NULL. Only valid for function scopes. | 673 // literals, or NULL. Only valid for function scopes. |
677 Variable* function_var() const { | 674 Variable* function_var() const { |
678 DCHECK(is_function_scope()); | 675 DCHECK(is_function_scope()); |
679 return function_; | 676 return function_; |
680 } | 677 } |
681 | 678 |
682 // Parameters. The left-most parameter has index 0. | 679 // Parameters. The left-most parameter has index 0. |
683 // Only valid for function and module scopes. | 680 // Only valid for function scopes. |
684 Variable* parameter(int index) const { | 681 Variable* parameter(int index) const { |
685 DCHECK(is_function_scope() || is_module_scope()); | 682 DCHECK(is_function_scope()); |
686 return params_[index]; | 683 return params_[index]; |
687 } | 684 } |
688 | 685 |
689 // Returns the default function arity excluding default or rest parameters. | 686 // Returns the default function arity excluding default or rest parameters. |
690 int default_function_length() const { return arity_; } | 687 int default_function_length() const { return arity_; } |
691 | 688 |
692 // Returns the number of formal parameters, excluding a possible rest | 689 // Returns the number of formal parameters, excluding a possible rest |
693 // parameter. Examples: | 690 // parameter. Examples: |
694 // function foo(a, b) {} ==> 2 | 691 // function foo(a, b) {} ==> 2 |
695 // function foo(a, b, ...c) {} ==> 2 | 692 // function foo(a, b, ...c) {} ==> 2 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 void AllocateModuleVariables(); | 855 void AllocateModuleVariables(); |
859 | 856 |
860 private: | 857 private: |
861 ModuleDescriptor* module_descriptor_; | 858 ModuleDescriptor* module_descriptor_; |
862 }; | 859 }; |
863 | 860 |
864 } // namespace internal | 861 } // namespace internal |
865 } // namespace v8 | 862 } // namespace v8 |
866 | 863 |
867 #endif // V8_AST_SCOPES_H_ | 864 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |