OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_VARIABLES_H_ | 5 #ifndef V8_VARIABLES_H_ |
6 #define V8_VARIABLES_H_ | 6 #define V8_VARIABLES_H_ |
7 | 7 |
8 #include "src/ast-value-factory.h" | 8 #include "src/ast-value-factory.h" |
9 #include "src/zone.h" | 9 #include "src/zone.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // The AST refers to variables via VariableProxies - placeholders for the actual | 14 // The AST refers to variables via VariableProxies - placeholders for the actual |
15 // variables. Variables themselves are never directly referred to from the AST, | 15 // variables. Variables themselves are never directly referred to from the AST, |
16 // they are maintained by scopes, and referred to from VariableProxies and Slots | 16 // they are maintained by scopes, and referred to from VariableProxies and Slots |
17 // after binding and variable allocation. | 17 // after binding and variable allocation. |
18 | 18 |
19 class ClassVariable; | 19 class ClassVariable; |
20 | 20 |
21 class Variable: public ZoneObject { | 21 class Variable: public ZoneObject { |
22 public: | 22 public: |
23 enum Kind { NORMAL, FUNCTION, CLASS, THIS, ARGUMENTS }; | 23 enum Kind { NORMAL, FUNCTION, CLASS, THIS, NEW_TARGET, ARGUMENTS }; |
24 | 24 |
25 enum Location { | 25 enum Location { |
26 // Before and during variable allocation, a variable whose location is | 26 // Before and during variable allocation, a variable whose location is |
27 // not yet determined. After allocation, a variable looked up as a | 27 // not yet determined. After allocation, a variable looked up as a |
28 // property on the global object (and possibly absent). name() is the | 28 // property on the global object (and possibly absent). name() is the |
29 // variable name, index() is invalid. | 29 // variable name, index() is invalid. |
30 UNALLOCATED, | 30 UNALLOCATED, |
31 | 31 |
32 // A slot in the parameter section on the stack. index() is the | 32 // A slot in the parameter section on the stack. index() is the |
33 // parameter index, counting left-to-right. The receiver is index -1; | 33 // parameter index, counting left-to-right. The receiver is index -1; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } | 97 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } |
98 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } | 98 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } |
99 bool binding_needs_init() const { | 99 bool binding_needs_init() const { |
100 return initialization_flag_ == kNeedsInitialization; | 100 return initialization_flag_ == kNeedsInitialization; |
101 } | 101 } |
102 | 102 |
103 bool is_function() const { return kind_ == FUNCTION; } | 103 bool is_function() const { return kind_ == FUNCTION; } |
104 bool is_class() const { return kind_ == CLASS; } | 104 bool is_class() const { return kind_ == CLASS; } |
105 bool is_this() const { return kind_ == THIS; } | 105 bool is_this() const { return kind_ == THIS; } |
| 106 bool is_new_target() const { return kind_ == NEW_TARGET; } |
106 bool is_arguments() const { return kind_ == ARGUMENTS; } | 107 bool is_arguments() const { return kind_ == ARGUMENTS; } |
107 | 108 |
108 ClassVariable* AsClassVariable() { | 109 ClassVariable* AsClassVariable() { |
109 DCHECK(is_class()); | 110 DCHECK(is_class()); |
110 return reinterpret_cast<ClassVariable*>(this); | 111 return reinterpret_cast<ClassVariable*>(this); |
111 } | 112 } |
112 | 113 |
113 // True if the variable is named eval and not known to be shadowed. | 114 // True if the variable is named eval and not known to be shadowed. |
114 bool is_possibly_eval(Isolate* isolate) const { | 115 bool is_possibly_eval(Isolate* isolate) const { |
115 return IsVariable(isolate->factory()->eval_string()); | 116 return IsVariable(isolate->factory()->eval_string()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 201 |
201 private: | 202 private: |
202 // For classes we keep track of consecutive groups of delcarations. They are | 203 // For classes we keep track of consecutive groups of delcarations. They are |
203 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement | 204 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement |
204 // checks for functions too. | 205 // checks for functions too. |
205 int declaration_group_start_; | 206 int declaration_group_start_; |
206 }; | 207 }; |
207 } } // namespace v8::internal | 208 } } // namespace v8::internal |
208 | 209 |
209 #endif // V8_VARIABLES_H_ | 210 #endif // V8_VARIABLES_H_ |
OLD | NEW |