| 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(Type type) | 117 Scope::Scope(ScopeType 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, Type type) | 130 Scope::Scope(Scope* outer_scope, ScopeType 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 Type type, | 149 ScopeType 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(Type type, | 188 void Scope::SetDefaults(ScopeType 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; |
| 211 } | 213 } |
| 212 | 214 |
| 213 | 215 |
| 214 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, | 216 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, |
| 215 Scope* global_scope) { | 217 Scope* global_scope) { |
| 216 // Reconstruct the outer scope chain from a closure's context chain. | 218 // Reconstruct the outer scope chain from a closure's context chain. |
| 217 ASSERT(!info->closure().is_null()); | 219 ASSERT(!info->closure().is_null()); |
| 218 Context* context = info->closure()->context(); | 220 Context* context = info->closure()->context(); |
| 219 Scope* current_scope = NULL; | 221 Scope* current_scope = NULL; |
| 220 Scope* innermost_scope = NULL; | 222 Scope* innermost_scope = NULL; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 625 |
| 624 | 626 |
| 625 Handle<SerializedScopeInfo> Scope::GetSerializedScopeInfo() { | 627 Handle<SerializedScopeInfo> Scope::GetSerializedScopeInfo() { |
| 626 if (scope_info_.is_null()) { | 628 if (scope_info_.is_null()) { |
| 627 scope_info_ = SerializedScopeInfo::Create(this); | 629 scope_info_ = SerializedScopeInfo::Create(this); |
| 628 } | 630 } |
| 629 return scope_info_; | 631 return scope_info_; |
| 630 } | 632 } |
| 631 | 633 |
| 632 | 634 |
| 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 |
| 633 #ifdef DEBUG | 653 #ifdef DEBUG |
| 634 static const char* Header(Scope::Type type) { | 654 static const char* Header(ScopeType type) { |
| 635 switch (type) { | 655 switch (type) { |
| 636 case Scope::EVAL_SCOPE: return "eval"; | 656 case EVAL_SCOPE: return "eval"; |
| 637 case Scope::FUNCTION_SCOPE: return "function"; | 657 case FUNCTION_SCOPE: return "function"; |
| 638 case Scope::GLOBAL_SCOPE: return "global"; | 658 case GLOBAL_SCOPE: return "global"; |
| 639 case Scope::CATCH_SCOPE: return "catch"; | 659 case CATCH_SCOPE: return "catch"; |
| 640 case Scope::BLOCK_SCOPE: return "block"; | 660 case BLOCK_SCOPE: return "block"; |
| 641 case Scope::WITH_SCOPE: return "with"; | 661 case WITH_SCOPE: return "with"; |
| 642 } | 662 } |
| 643 UNREACHABLE(); | 663 UNREACHABLE(); |
| 644 return NULL; | 664 return NULL; |
| 645 } | 665 } |
| 646 | 666 |
| 647 | 667 |
| 648 static void Indent(int n, const char* str) { | 668 static void Indent(int n, const char* str) { |
| 649 PrintF("%*s%s", n, "", str); | 669 PrintF("%*s%s", n, "", str); |
| 650 } | 670 } |
| 651 | 671 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1156 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
| 1137 !must_have_local_context) { | 1157 !must_have_local_context) { |
| 1138 num_heap_slots_ = 0; | 1158 num_heap_slots_ = 0; |
| 1139 } | 1159 } |
| 1140 | 1160 |
| 1141 // Allocation done. | 1161 // Allocation done. |
| 1142 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1162 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1143 } | 1163 } |
| 1144 | 1164 |
| 1145 } } // namespace v8::internal | 1165 } } // namespace v8::internal |
| OLD | NEW |