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 |
374 // Analyze() must have been called once to create the ScopeInfo. | 377 // Analyze() must have been called once to create the ScopeInfo. |
375 Handle<ScopeInfo> scope_info() { | 378 Handle<ScopeInfo> scope_info() { |
376 DCHECK(!scope_info_.is_null()); | 379 DCHECK(!scope_info_.is_null()); |
377 return scope_info_; | 380 return scope_info_; |
378 } | 381 } |
379 | 382 |
380 // --------------------------------------------------------------------------- | 383 // --------------------------------------------------------------------------- |
381 // Strict mode support. | 384 // Strict mode support. |
382 bool IsDeclared(const AstRawString* name) { | 385 bool IsDeclared(const AstRawString* name) { |
383 // During formal parameter list parsing the scope only contains | 386 // During formal parameter list parsing the scope only contains |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 Variable* new_target_var() { return new_target_; } | 673 Variable* new_target_var() { return new_target_; } |
671 | 674 |
672 // The variable holding the function literal for named function | 675 // The variable holding the function literal for named function |
673 // literals, or NULL. Only valid for function scopes. | 676 // literals, or NULL. Only valid for function scopes. |
674 Variable* function_var() const { | 677 Variable* function_var() const { |
675 DCHECK(is_function_scope()); | 678 DCHECK(is_function_scope()); |
676 return function_; | 679 return function_; |
677 } | 680 } |
678 | 681 |
679 // Parameters. The left-most parameter has index 0. | 682 // Parameters. The left-most parameter has index 0. |
680 // Only valid for function scopes. | 683 // Only valid for function and module scopes. |
681 Variable* parameter(int index) const { | 684 Variable* parameter(int index) const { |
682 DCHECK(is_function_scope()); | 685 DCHECK(is_function_scope() || is_module_scope()); |
683 return params_[index]; | 686 return params_[index]; |
684 } | 687 } |
685 | 688 |
686 // Returns the default function arity excluding default or rest parameters. | 689 // Returns the default function arity excluding default or rest parameters. |
687 int default_function_length() const { return arity_; } | 690 int default_function_length() const { return arity_; } |
688 | 691 |
689 // Returns the number of formal parameters, excluding a possible rest | 692 // Returns the number of formal parameters, excluding a possible rest |
690 // parameter. Examples: | 693 // parameter. Examples: |
691 // function foo(a, b) {} ==> 2 | 694 // function foo(a, b) {} ==> 2 |
692 // function foo(a, b, ...c) {} ==> 2 | 695 // function foo(a, b, ...c) {} ==> 2 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 void AllocateModuleVariables(); | 858 void AllocateModuleVariables(); |
856 | 859 |
857 private: | 860 private: |
858 ModuleDescriptor* module_descriptor_; | 861 ModuleDescriptor* module_descriptor_; |
859 }; | 862 }; |
860 | 863 |
861 } // namespace internal | 864 } // namespace internal |
862 } // namespace v8 | 865 } // namespace v8 |
863 | 866 |
864 #endif // V8_AST_SCOPES_H_ | 867 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |