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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/scopes.h" | 8 #include "src/scopes.h" |
9 #include "src/variables.h" | 9 #include "src/variables.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; | 26 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; |
27 case INTERNAL: return "INTERNAL"; | 27 case INTERNAL: return "INTERNAL"; |
28 case TEMPORARY: return "TEMPORARY"; | 28 case TEMPORARY: return "TEMPORARY"; |
29 } | 29 } |
30 UNREACHABLE(); | 30 UNREACHABLE(); |
31 return NULL; | 31 return NULL; |
32 } | 32 } |
33 | 33 |
34 | 34 |
35 Variable::Variable(Scope* scope, | 35 Variable::Variable(Scope* scope, |
36 const AstString* name, | 36 Handle<String> name, |
37 VariableMode mode, | 37 VariableMode mode, |
38 bool is_valid_ref, | 38 bool is_valid_ref, |
39 Kind kind, | 39 Kind kind, |
40 InitializationFlag initialization_flag, | 40 InitializationFlag initialization_flag, |
41 Interface* interface) | 41 Interface* interface) |
42 : scope_(scope), | 42 : scope_(scope), |
43 name_(name), | 43 name_(name), |
44 mode_(mode), | 44 mode_(mode), |
45 kind_(kind), | 45 kind_(kind), |
46 location_(UNALLOCATED), | 46 location_(UNALLOCATED), |
47 index_(-1), | 47 index_(-1), |
48 initializer_position_(RelocInfo::kNoPosition), | 48 initializer_position_(RelocInfo::kNoPosition), |
49 local_if_not_shadowed_(NULL), | 49 local_if_not_shadowed_(NULL), |
50 is_valid_ref_(is_valid_ref), | 50 is_valid_ref_(is_valid_ref), |
51 force_context_allocation_(false), | 51 force_context_allocation_(false), |
52 is_used_(false), | 52 is_used_(false), |
53 initialization_flag_(initialization_flag), | 53 initialization_flag_(initialization_flag), |
54 interface_(interface) { | 54 interface_(interface) { |
| 55 // Names must be canonicalized for fast equality checks. |
| 56 ASSERT(name->IsInternalizedString()); |
55 // Var declared variables never need initialization. | 57 // Var declared variables never need initialization. |
56 ASSERT(!(mode == VAR && initialization_flag == kNeedsInitialization)); | 58 ASSERT(!(mode == VAR && initialization_flag == kNeedsInitialization)); |
57 } | 59 } |
58 | 60 |
59 | 61 |
60 bool Variable::IsGlobalObjectProperty() const { | 62 bool Variable::IsGlobalObjectProperty() const { |
61 // Temporaries are never global, they must always be allocated in the | 63 // Temporaries are never global, they must always be allocated in the |
62 // activation frame. | 64 // activation frame. |
63 return (IsDynamicVariableMode(mode_) || | 65 return (IsDynamicVariableMode(mode_) || |
64 (IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_))) | 66 (IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_))) |
65 && scope_ != NULL && scope_->is_global_scope(); | 67 && scope_ != NULL && scope_->is_global_scope(); |
66 } | 68 } |
67 | 69 |
68 | 70 |
69 int Variable::CompareIndex(Variable* const* v, Variable* const* w) { | 71 int Variable::CompareIndex(Variable* const* v, Variable* const* w) { |
70 int x = (*v)->index(); | 72 int x = (*v)->index(); |
71 int y = (*w)->index(); | 73 int y = (*w)->index(); |
72 // Consider sorting them according to type as well? | 74 // Consider sorting them according to type as well? |
73 return x - y; | 75 return x - y; |
74 } | 76 } |
75 | 77 |
76 } } // namespace v8::internal | 78 } } // namespace v8::internal |
OLD | NEW |