OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 return NULL; | 108 return NULL; |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 // ---------------------------------------------------------------------------- | 112 // ---------------------------------------------------------------------------- |
113 // Implementation of Scope | 113 // Implementation of Scope |
114 | 114 |
115 | 115 |
116 // Dummy constructor | 116 // Dummy constructor |
117 Scope::Scope(ScopeType type) | 117 Scope::Scope(Type type) |
118 : isolate_(Isolate::Current()), | 118 : isolate_(Isolate::Current()), |
119 inner_scopes_(0), | 119 inner_scopes_(0), |
120 variables_(false), | 120 variables_(false), |
121 temps_(0), | 121 temps_(0), |
122 params_(0), | 122 params_(0), |
123 unresolved_(0), | 123 unresolved_(0), |
124 decls_(0), | 124 decls_(0), |
125 already_resolved_(false) { | 125 already_resolved_(false) { |
126 SetDefaults(type, NULL, Handle<SerializedScopeInfo>::null()); | 126 SetDefaults(type, NULL, Handle<SerializedScopeInfo>::null()); |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 Scope::Scope(Scope* outer_scope, ScopeType type) | 130 Scope::Scope(Scope* outer_scope, Type type) |
131 : isolate_(Isolate::Current()), | 131 : isolate_(Isolate::Current()), |
132 inner_scopes_(4), | 132 inner_scopes_(4), |
133 variables_(), | 133 variables_(), |
134 temps_(4), | 134 temps_(4), |
135 params_(4), | 135 params_(4), |
136 unresolved_(16), | 136 unresolved_(16), |
137 decls_(4), | 137 decls_(4), |
138 already_resolved_(false) { | 138 already_resolved_(false) { |
139 SetDefaults(type, outer_scope, Handle<SerializedScopeInfo>::null()); | 139 SetDefaults(type, outer_scope, Handle<SerializedScopeInfo>::null()); |
140 // At some point we might want to provide outer scopes to | 140 // At some point we might want to provide outer scopes to |
141 // eval scopes (by walking the stack and reading the scope info). | 141 // eval scopes (by walking the stack and reading the scope info). |
142 // In that case, the ASSERT below needs to be adjusted. | 142 // In that case, the ASSERT below needs to be adjusted. |
143 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); | 143 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); |
144 ASSERT(!HasIllegalRedeclaration()); | 144 ASSERT(!HasIllegalRedeclaration()); |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 Scope::Scope(Scope* inner_scope, | 148 Scope::Scope(Scope* inner_scope, |
149 ScopeType type, | 149 Type type, |
150 Handle<SerializedScopeInfo> scope_info) | 150 Handle<SerializedScopeInfo> scope_info) |
151 : isolate_(Isolate::Current()), | 151 : isolate_(Isolate::Current()), |
152 inner_scopes_(4), | 152 inner_scopes_(4), |
153 variables_(), | 153 variables_(), |
154 temps_(4), | 154 temps_(4), |
155 params_(4), | 155 params_(4), |
156 unresolved_(16), | 156 unresolved_(16), |
157 decls_(4), | 157 decls_(4), |
158 already_resolved_(true) { | 158 already_resolved_(true) { |
159 SetDefaults(type, NULL, scope_info); | 159 SetDefaults(type, NULL, scope_info); |
(...skipping 18 matching lines...) Expand all Loading... |
178 ++num_var_or_const_; | 178 ++num_var_or_const_; |
179 Variable* variable = variables_.Declare(this, | 179 Variable* variable = variables_.Declare(this, |
180 catch_variable_name, | 180 catch_variable_name, |
181 VAR, | 181 VAR, |
182 true, // Valid left-hand side. | 182 true, // Valid left-hand side. |
183 Variable::NORMAL); | 183 Variable::NORMAL); |
184 AllocateHeapSlot(variable); | 184 AllocateHeapSlot(variable); |
185 } | 185 } |
186 | 186 |
187 | 187 |
188 void Scope::SetDefaults(ScopeType type, | 188 void Scope::SetDefaults(Type type, |
189 Scope* outer_scope, | 189 Scope* outer_scope, |
190 Handle<SerializedScopeInfo> scope_info) { | 190 Handle<SerializedScopeInfo> scope_info) { |
191 outer_scope_ = outer_scope; | 191 outer_scope_ = outer_scope; |
192 type_ = type; | 192 type_ = type; |
193 scope_name_ = isolate_->factory()->empty_symbol(); | 193 scope_name_ = isolate_->factory()->empty_symbol(); |
194 dynamics_ = NULL; | 194 dynamics_ = NULL; |
195 receiver_ = NULL; | 195 receiver_ = NULL; |
196 function_ = NULL; | 196 function_ = NULL; |
197 arguments_ = NULL; | 197 arguments_ = NULL; |
198 illegal_redecl_ = NULL; | 198 illegal_redecl_ = NULL; |
199 scope_inside_with_ = false; | 199 scope_inside_with_ = false; |
200 scope_contains_with_ = false; | 200 scope_contains_with_ = false; |
201 scope_calls_eval_ = false; | 201 scope_calls_eval_ = false; |
202 // Inherit the strict mode from the parent scope. | 202 // Inherit the strict mode from the parent scope. |
203 strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_; | 203 strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_; |
204 outer_scope_calls_non_strict_eval_ = false; | 204 outer_scope_calls_non_strict_eval_ = false; |
205 inner_scope_calls_eval_ = false; | 205 inner_scope_calls_eval_ = false; |
206 force_eager_compilation_ = false; | 206 force_eager_compilation_ = false; |
207 num_var_or_const_ = 0; | 207 num_var_or_const_ = 0; |
208 num_stack_slots_ = 0; | 208 num_stack_slots_ = 0; |
209 num_heap_slots_ = 0; | 209 num_heap_slots_ = 0; |
210 scope_info_ = scope_info; | 210 scope_info_ = scope_info; |
211 start_position_ = RelocInfo::kNoPosition; | |
212 end_position_ = RelocInfo::kNoPosition; | |
213 } | 211 } |
214 | 212 |
215 | 213 |
216 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, | 214 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, |
217 Scope* global_scope) { | 215 Scope* global_scope) { |
218 // Reconstruct the outer scope chain from a closure's context chain. | 216 // Reconstruct the outer scope chain from a closure's context chain. |
219 ASSERT(!info->closure().is_null()); | 217 ASSERT(!info->closure().is_null()); |
220 Context* context = info->closure()->context(); | 218 Context* context = info->closure()->context(); |
221 Scope* current_scope = NULL; | 219 Scope* current_scope = NULL; |
222 Scope* innermost_scope = NULL; | 220 Scope* innermost_scope = NULL; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 623 |
626 | 624 |
627 Handle<SerializedScopeInfo> Scope::GetSerializedScopeInfo() { | 625 Handle<SerializedScopeInfo> Scope::GetSerializedScopeInfo() { |
628 if (scope_info_.is_null()) { | 626 if (scope_info_.is_null()) { |
629 scope_info_ = SerializedScopeInfo::Create(this); | 627 scope_info_ = SerializedScopeInfo::Create(this); |
630 } | 628 } |
631 return scope_info_; | 629 return scope_info_; |
632 } | 630 } |
633 | 631 |
634 | 632 |
635 void Scope::GetNestedScopeChain( | |
636 List<Handle<SerializedScopeInfo> >* chain, | |
637 int position) { | |
638 chain->Add(Handle<SerializedScopeInfo>(GetSerializedScopeInfo())); | |
639 | |
640 for (int i = 0; i < inner_scopes_.length(); i++) { | |
641 Scope* scope = inner_scopes_[i]; | |
642 int beg_pos = scope->start_position(); | |
643 int end_pos = scope->end_position(); | |
644 ASSERT(beg_pos >= 0 && end_pos >= 0); | |
645 if (beg_pos <= position && position <= end_pos) { | |
646 scope->GetNestedScopeChain(chain, position); | |
647 return; | |
648 } | |
649 } | |
650 } | |
651 | |
652 | |
653 #ifdef DEBUG | 633 #ifdef DEBUG |
654 static const char* Header(ScopeType type) { | 634 static const char* Header(Scope::Type type) { |
655 switch (type) { | 635 switch (type) { |
656 case EVAL_SCOPE: return "eval"; | 636 case Scope::EVAL_SCOPE: return "eval"; |
657 case FUNCTION_SCOPE: return "function"; | 637 case Scope::FUNCTION_SCOPE: return "function"; |
658 case GLOBAL_SCOPE: return "global"; | 638 case Scope::GLOBAL_SCOPE: return "global"; |
659 case CATCH_SCOPE: return "catch"; | 639 case Scope::CATCH_SCOPE: return "catch"; |
660 case BLOCK_SCOPE: return "block"; | 640 case Scope::BLOCK_SCOPE: return "block"; |
661 case WITH_SCOPE: return "with"; | 641 case Scope::WITH_SCOPE: return "with"; |
662 } | 642 } |
663 UNREACHABLE(); | 643 UNREACHABLE(); |
664 return NULL; | 644 return NULL; |
665 } | 645 } |
666 | 646 |
667 | 647 |
668 static void Indent(int n, const char* str) { | 648 static void Indent(int n, const char* str) { |
669 PrintF("%*s%s", n, "", str); | 649 PrintF("%*s%s", n, "", str); |
670 } | 650 } |
671 | 651 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1136 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
1157 !must_have_local_context) { | 1137 !must_have_local_context) { |
1158 num_heap_slots_ = 0; | 1138 num_heap_slots_ = 0; |
1159 } | 1139 } |
1160 | 1140 |
1161 // Allocation done. | 1141 // Allocation done. |
1162 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1142 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1163 } | 1143 } |
1164 | 1144 |
1165 } } // namespace v8::internal | 1145 } } // namespace v8::internal |
OLD | NEW |