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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/scopes.h" | 7 #include "src/scopes.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 function_ = NULL; | 163 function_ = NULL; |
164 arguments_ = NULL; | 164 arguments_ = NULL; |
165 illegal_redecl_ = NULL; | 165 illegal_redecl_ = NULL; |
166 scope_inside_with_ = false; | 166 scope_inside_with_ = false; |
167 scope_contains_with_ = false; | 167 scope_contains_with_ = false; |
168 scope_calls_eval_ = false; | 168 scope_calls_eval_ = false; |
169 // Inherit the strict mode from the parent scope. | 169 // Inherit the strict mode from the parent scope. |
170 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; | 170 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; |
171 outer_scope_calls_sloppy_eval_ = false; | 171 outer_scope_calls_sloppy_eval_ = false; |
172 inner_scope_calls_eval_ = false; | 172 inner_scope_calls_eval_ = false; |
173 inner_scope_contains_with_ = false; | |
174 force_eager_compilation_ = false; | 173 force_eager_compilation_ = false; |
175 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 174 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
176 ? outer_scope->has_forced_context_allocation() : false; | 175 ? outer_scope->has_forced_context_allocation() : false; |
177 num_var_or_const_ = 0; | 176 num_var_or_const_ = 0; |
178 num_stack_slots_ = 0; | 177 num_stack_slots_ = 0; |
179 num_heap_slots_ = 0; | 178 num_heap_slots_ = 0; |
180 num_modules_ = 0; | 179 num_modules_ = 0; |
181 module_var_ = NULL, | 180 module_var_ = NULL, |
182 scope_info_ = scope_info; | 181 scope_info_ = scope_info; |
183 start_position_ = RelocInfo::kNoPosition; | 182 start_position_ = RelocInfo::kNoPosition; |
184 end_position_ = RelocInfo::kNoPosition; | 183 end_position_ = RelocInfo::kNoPosition; |
185 if (!scope_info.is_null()) { | 184 if (!scope_info.is_null()) { |
186 scope_calls_eval_ = scope_info->CallsEval(); | 185 scope_calls_eval_ = scope_info->CallsEval(); |
187 strict_mode_ = scope_info->strict_mode(); | 186 strict_mode_ = scope_info->strict_mode(); |
188 } | 187 } |
189 } | 188 } |
190 | 189 |
191 | 190 |
192 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope, | 191 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope, |
193 Zone* zone) { | 192 Zone* zone) { |
194 // Reconstruct the outer scope chain from a closure's context chain. | 193 // Reconstruct the outer scope chain from a closure's context chain. |
195 Scope* current_scope = NULL; | 194 Scope* current_scope = NULL; |
196 Scope* innermost_scope = NULL; | 195 Scope* innermost_scope = NULL; |
197 bool contains_with = false; | 196 bool contains_with = false; |
198 bool inner_contains_with = false; | |
199 while (!context->IsNativeContext()) { | 197 while (!context->IsNativeContext()) { |
200 if (context->IsWithContext()) { | 198 if (context->IsWithContext()) { |
201 Scope* with_scope = new(zone) Scope(current_scope, | 199 Scope* with_scope = new(zone) Scope(current_scope, |
202 WITH_SCOPE, | 200 WITH_SCOPE, |
203 Handle<ScopeInfo>::null(), | 201 Handle<ScopeInfo>::null(), |
204 global_scope->ast_value_factory_, | 202 global_scope->ast_value_factory_, |
205 zone); | 203 zone); |
206 current_scope = with_scope; | 204 current_scope = with_scope; |
207 // All the inner scopes are inside a with. | 205 // All the inner scopes are inside a with. |
208 contains_with = true; | 206 contains_with = true; |
(...skipping 29 matching lines...) Expand all Loading... |
238 global_scope->ast_value_factory_, | 236 global_scope->ast_value_factory_, |
239 zone); | 237 zone); |
240 } else { | 238 } else { |
241 ASSERT(context->IsCatchContext()); | 239 ASSERT(context->IsCatchContext()); |
242 String* name = String::cast(context->extension()); | 240 String* name = String::cast(context->extension()); |
243 current_scope = new (zone) Scope( | 241 current_scope = new (zone) Scope( |
244 current_scope, | 242 current_scope, |
245 global_scope->ast_value_factory_->GetString(Handle<String>(name)), | 243 global_scope->ast_value_factory_->GetString(Handle<String>(name)), |
246 global_scope->ast_value_factory_, zone); | 244 global_scope->ast_value_factory_, zone); |
247 } | 245 } |
248 if (inner_contains_with) current_scope->inner_scope_contains_with_ = true; | 246 if (contains_with) current_scope->RecordWithStatement(); |
249 if (contains_with) { | |
250 current_scope->RecordWithStatement(); | |
251 inner_contains_with = true; | |
252 } | |
253 if (innermost_scope == NULL) innermost_scope = current_scope; | 247 if (innermost_scope == NULL) innermost_scope = current_scope; |
254 | 248 |
255 // Forget about a with when we move to a context for a different function. | 249 // Forget about a with when we move to a context for a different function. |
256 if (context->previous()->closure() != context->closure()) { | 250 if (context->previous()->closure() != context->closure()) { |
257 contains_with = false; | 251 contains_with = false; |
258 } | 252 } |
259 context = context->previous(); | 253 context = context->previous(); |
260 } | 254 } |
261 | 255 |
262 global_scope->AddInnerScope(current_scope); | 256 global_scope->AddInnerScope(current_scope); |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 | 874 |
881 // Scope info. | 875 // Scope info. |
882 if (HasTrivialOuterContext()) { | 876 if (HasTrivialOuterContext()) { |
883 Indent(n1, "// scope has trivial outer context\n"); | 877 Indent(n1, "// scope has trivial outer context\n"); |
884 } | 878 } |
885 if (strict_mode() == STRICT) { | 879 if (strict_mode() == STRICT) { |
886 Indent(n1, "// strict mode scope\n"); | 880 Indent(n1, "// strict mode scope\n"); |
887 } | 881 } |
888 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 882 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
889 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 883 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
890 if (inner_scope_contains_with_) { | |
891 Indent(n1, "// inner scope contains 'with'\n"); | |
892 } | |
893 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 884 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
894 if (outer_scope_calls_sloppy_eval_) { | 885 if (outer_scope_calls_sloppy_eval_) { |
895 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 886 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
896 } | 887 } |
897 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 888 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
898 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 889 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
899 PrintF("%d stack slots\n", num_stack_slots_); } | 890 PrintF("%d stack slots\n", num_stack_slots_); } |
900 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 891 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
901 PrintF("%d heap slots\n", num_heap_slots_); } | 892 PrintF("%d heap slots\n", num_heap_slots_); } |
902 | 893 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 } | 1154 } |
1164 | 1155 |
1165 bool calls_sloppy_eval = | 1156 bool calls_sloppy_eval = |
1166 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; | 1157 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; |
1167 for (int i = 0; i < inner_scopes_.length(); i++) { | 1158 for (int i = 0; i < inner_scopes_.length(); i++) { |
1168 Scope* inner = inner_scopes_[i]; | 1159 Scope* inner = inner_scopes_[i]; |
1169 inner->PropagateScopeInfo(calls_sloppy_eval); | 1160 inner->PropagateScopeInfo(calls_sloppy_eval); |
1170 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { | 1161 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { |
1171 inner_scope_calls_eval_ = true; | 1162 inner_scope_calls_eval_ = true; |
1172 } | 1163 } |
1173 if (inner->scope_contains_with_ || inner->inner_scope_contains_with_) { | |
1174 inner_scope_contains_with_ = true; | |
1175 } | |
1176 if (inner->force_eager_compilation_) { | 1164 if (inner->force_eager_compilation_) { |
1177 force_eager_compilation_ = true; | 1165 force_eager_compilation_ = true; |
1178 } | 1166 } |
1179 } | 1167 } |
1180 } | 1168 } |
1181 | 1169 |
1182 | 1170 |
1183 bool Scope::MustAllocate(Variable* var) { | 1171 bool Scope::MustAllocate(Variable* var) { |
1184 // Give var a read/write use if there is a chance it might be accessed | 1172 // Give var a read/write use if there is a chance it might be accessed |
1185 // via an eval() call. This is only possible if the variable has a | 1173 // via an eval() call. This is only possible if the variable has a |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 } | 1394 } |
1407 | 1395 |
1408 | 1396 |
1409 int Scope::ContextLocalCount() const { | 1397 int Scope::ContextLocalCount() const { |
1410 if (num_heap_slots() == 0) return 0; | 1398 if (num_heap_slots() == 0) return 0; |
1411 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1399 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1412 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1400 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1413 } | 1401 } |
1414 | 1402 |
1415 } } // namespace v8::internal | 1403 } } // namespace v8::internal |
OLD | NEW |