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/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 receiver_ = NULL; | 158 receiver_ = NULL; |
159 new_target_ = nullptr; | 159 new_target_ = nullptr; |
160 function_ = NULL; | 160 function_ = NULL; |
161 arguments_ = NULL; | 161 arguments_ = NULL; |
162 illegal_redecl_ = NULL; | 162 illegal_redecl_ = NULL; |
163 scope_inside_with_ = false; | 163 scope_inside_with_ = false; |
164 scope_contains_with_ = false; | 164 scope_contains_with_ = false; |
165 scope_calls_eval_ = false; | 165 scope_calls_eval_ = false; |
166 scope_uses_arguments_ = false; | 166 scope_uses_arguments_ = false; |
167 scope_uses_super_property_ = false; | 167 scope_uses_super_property_ = false; |
| 168 scope_uses_this_ = false; |
168 asm_module_ = false; | 169 asm_module_ = false; |
169 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; | 170 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |
170 // Inherit the language mode from the parent scope. | 171 // Inherit the language mode from the parent scope. |
171 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; | 172 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; |
172 outer_scope_calls_sloppy_eval_ = false; | 173 outer_scope_calls_sloppy_eval_ = false; |
173 inner_scope_calls_eval_ = false; | 174 inner_scope_calls_eval_ = false; |
174 inner_scope_uses_arguments_ = false; | 175 inner_scope_uses_arguments_ = false; |
| 176 inner_scope_uses_this_ = false; |
175 inner_scope_uses_super_property_ = false; | 177 inner_scope_uses_super_property_ = false; |
176 force_eager_compilation_ = false; | 178 force_eager_compilation_ = false; |
177 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 179 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
178 ? outer_scope->has_forced_context_allocation() : false; | 180 ? outer_scope->has_forced_context_allocation() : false; |
179 num_var_or_const_ = 0; | 181 num_var_or_const_ = 0; |
180 num_stack_slots_ = 0; | 182 num_stack_slots_ = 0; |
181 num_heap_slots_ = 0; | 183 num_heap_slots_ = 0; |
182 num_modules_ = 0; | 184 num_modules_ = 0; |
183 module_var_ = NULL, | 185 module_var_ = NULL, |
184 rest_parameter_ = NULL; | 186 rest_parameter_ = NULL; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 364 } |
363 | 365 |
364 // Move unresolved variables | 366 // Move unresolved variables |
365 for (int i = 0; i < unresolved_.length(); i++) { | 367 for (int i = 0; i < unresolved_.length(); i++) { |
366 outer_scope()->unresolved_.Add(unresolved_[i], zone()); | 368 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
367 } | 369 } |
368 | 370 |
369 // Propagate usage flags to outer scope. | 371 // Propagate usage flags to outer scope. |
370 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); | 372 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); |
371 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); | 373 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); |
| 374 if (uses_this()) outer_scope_->RecordThisUsage(); |
372 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); | 375 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); |
373 | 376 |
374 return NULL; | 377 return NULL; |
375 } | 378 } |
376 | 379 |
377 | 380 |
378 Variable* Scope::LookupLocal(const AstRawString* name) { | 381 Variable* Scope::LookupLocal(const AstRawString* name) { |
379 Variable* result = variables_.Lookup(name); | 382 Variable* result = variables_.Lookup(name); |
380 if (result != NULL || scope_info_.is_null()) { | 383 if (result != NULL || scope_info_.is_null()) { |
381 return result; | 384 return result; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 Indent(n1, "// strong mode scope\n"); | 914 Indent(n1, "// strong mode scope\n"); |
912 } else if (is_strict(language_mode())) { | 915 } else if (is_strict(language_mode())) { |
913 Indent(n1, "// strict mode scope\n"); | 916 Indent(n1, "// strict mode scope\n"); |
914 } | 917 } |
915 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 918 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
916 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 919 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
917 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 920 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
918 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); | 921 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); |
919 if (scope_uses_super_property_) | 922 if (scope_uses_super_property_) |
920 Indent(n1, "// scope uses 'super' property\n"); | 923 Indent(n1, "// scope uses 'super' property\n"); |
| 924 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n"); |
921 if (inner_scope_uses_arguments_) { | 925 if (inner_scope_uses_arguments_) { |
922 Indent(n1, "// inner scope uses 'arguments'\n"); | 926 Indent(n1, "// inner scope uses 'arguments'\n"); |
923 } | 927 } |
924 if (inner_scope_uses_super_property_) | 928 if (inner_scope_uses_super_property_) |
925 Indent(n1, "// inner scope uses 'super' property\n"); | 929 Indent(n1, "// inner scope uses 'super' property\n"); |
| 930 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n"); |
926 if (outer_scope_calls_sloppy_eval_) { | 931 if (outer_scope_calls_sloppy_eval_) { |
927 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 932 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
928 } | 933 } |
929 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 934 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
930 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 935 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
931 PrintF("%d stack slots\n", num_stack_slots_); } | 936 PrintF("%d stack slots\n", num_stack_slots_); } |
932 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 937 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
933 PrintF("%d heap slots\n", num_heap_slots_); } | 938 PrintF("%d heap slots\n", num_heap_slots_); } |
934 | 939 |
935 // Print locals. | 940 // Print locals. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 // usage of arguments/super/this, but do not propagate them out from normal | 1276 // usage of arguments/super/this, but do not propagate them out from normal |
1272 // functions. | 1277 // functions. |
1273 if (!inner->is_function_scope() || inner->is_arrow_scope()) { | 1278 if (!inner->is_function_scope() || inner->is_arrow_scope()) { |
1274 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { | 1279 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { |
1275 inner_scope_uses_arguments_ = true; | 1280 inner_scope_uses_arguments_ = true; |
1276 } | 1281 } |
1277 if (inner->scope_uses_super_property_ || | 1282 if (inner->scope_uses_super_property_ || |
1278 inner->inner_scope_uses_super_property_) { | 1283 inner->inner_scope_uses_super_property_) { |
1279 inner_scope_uses_super_property_ = true; | 1284 inner_scope_uses_super_property_ = true; |
1280 } | 1285 } |
| 1286 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { |
| 1287 inner_scope_uses_this_ = true; |
| 1288 } |
1281 } | 1289 } |
1282 if (inner->force_eager_compilation_) { | 1290 if (inner->force_eager_compilation_) { |
1283 force_eager_compilation_ = true; | 1291 force_eager_compilation_ = true; |
1284 } | 1292 } |
1285 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1293 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
1286 inner->asm_function_ = true; | 1294 inner->asm_function_ = true; |
1287 } | 1295 } |
1288 } | 1296 } |
1289 } | 1297 } |
1290 | 1298 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1551 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1544 } | 1552 } |
1545 | 1553 |
1546 | 1554 |
1547 int Scope::ContextLocalCount() const { | 1555 int Scope::ContextLocalCount() const { |
1548 if (num_heap_slots() == 0) return 0; | 1556 if (num_heap_slots() == 0) return 0; |
1549 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1557 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1550 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1558 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1551 } | 1559 } |
1552 } } // namespace v8::internal | 1560 } } // namespace v8::internal |
OLD | NEW |