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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 scope_name_ = ast_value_factory_->empty_string(); | 156 scope_name_ = ast_value_factory_->empty_string(); |
157 dynamics_ = NULL; | 157 dynamics_ = NULL; |
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_super_property_ = false; | 167 scope_uses_super_property_ = false; |
167 asm_module_ = false; | 168 asm_module_ = false; |
168 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; | 169 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |
169 // Inherit the language mode from the parent scope. | 170 // Inherit the language mode from the parent scope. |
170 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; | 171 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; |
171 outer_scope_calls_sloppy_eval_ = false; | 172 outer_scope_calls_sloppy_eval_ = false; |
172 inner_scope_calls_eval_ = false; | 173 inner_scope_calls_eval_ = false; |
| 174 inner_scope_uses_arguments_ = false; |
173 inner_scope_uses_super_property_ = false; | 175 inner_scope_uses_super_property_ = false; |
174 force_eager_compilation_ = false; | 176 force_eager_compilation_ = false; |
175 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 177 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
176 ? outer_scope->has_forced_context_allocation() : false; | 178 ? outer_scope->has_forced_context_allocation() : false; |
177 num_var_or_const_ = 0; | 179 num_var_or_const_ = 0; |
178 num_stack_slots_ = 0; | 180 num_stack_slots_ = 0; |
179 num_heap_slots_ = 0; | 181 num_heap_slots_ = 0; |
180 num_modules_ = 0; | 182 num_modules_ = 0; |
181 module_var_ = NULL, | 183 module_var_ = NULL, |
182 rest_parameter_ = NULL; | 184 rest_parameter_ = NULL; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 for (int i = 0; i < inner_scopes_.length(); i++) { | 360 for (int i = 0; i < inner_scopes_.length(); i++) { |
359 outer_scope()->AddInnerScope(inner_scopes_[i]); | 361 outer_scope()->AddInnerScope(inner_scopes_[i]); |
360 } | 362 } |
361 | 363 |
362 // Move unresolved variables | 364 // Move unresolved variables |
363 for (int i = 0; i < unresolved_.length(); i++) { | 365 for (int i = 0; i < unresolved_.length(); i++) { |
364 outer_scope()->unresolved_.Add(unresolved_[i], zone()); | 366 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
365 } | 367 } |
366 | 368 |
367 // Propagate usage flags to outer scope. | 369 // Propagate usage flags to outer scope. |
| 370 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); |
368 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); | 371 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); |
369 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); | 372 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); |
370 | 373 |
371 return NULL; | 374 return NULL; |
372 } | 375 } |
373 | 376 |
374 | 377 |
375 Variable* Scope::LookupLocal(const AstRawString* name) { | 378 Variable* Scope::LookupLocal(const AstRawString* name) { |
376 Variable* result = variables_.Lookup(name); | 379 Variable* result = variables_.Lookup(name); |
377 if (result != NULL || scope_info_.is_null()) { | 380 if (result != NULL || scope_info_.is_null()) { |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 Indent(n1, "// scope has trivial outer context\n"); | 908 Indent(n1, "// scope has trivial outer context\n"); |
906 } | 909 } |
907 if (is_strong(language_mode())) { | 910 if (is_strong(language_mode())) { |
908 Indent(n1, "// strong mode scope\n"); | 911 Indent(n1, "// strong mode scope\n"); |
909 } else if (is_strict(language_mode())) { | 912 } else if (is_strict(language_mode())) { |
910 Indent(n1, "// strict mode scope\n"); | 913 Indent(n1, "// strict mode scope\n"); |
911 } | 914 } |
912 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 915 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
913 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 916 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
914 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 917 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
| 918 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); |
915 if (scope_uses_super_property_) | 919 if (scope_uses_super_property_) |
916 Indent(n1, "// scope uses 'super' property\n"); | 920 Indent(n1, "// scope uses 'super' property\n"); |
| 921 if (inner_scope_uses_arguments_) { |
| 922 Indent(n1, "// inner scope uses 'arguments'\n"); |
| 923 } |
917 if (inner_scope_uses_super_property_) | 924 if (inner_scope_uses_super_property_) |
918 Indent(n1, "// inner scope uses 'super' property\n"); | 925 Indent(n1, "// inner scope uses 'super' property\n"); |
919 if (outer_scope_calls_sloppy_eval_) { | 926 if (outer_scope_calls_sloppy_eval_) { |
920 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 927 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
921 } | 928 } |
922 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 929 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
923 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 930 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
924 PrintF("%d stack slots\n", num_stack_slots_); } | 931 PrintF("%d stack slots\n", num_stack_slots_); } |
925 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 932 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
926 PrintF("%d heap slots\n", num_heap_slots_); } | 933 PrintF("%d heap slots\n", num_heap_slots_); } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 for (int i = 0; i < inner_scopes_.length(); i++) { | 1264 for (int i = 0; i < inner_scopes_.length(); i++) { |
1258 Scope* inner = inner_scopes_[i]; | 1265 Scope* inner = inner_scopes_[i]; |
1259 inner->PropagateScopeInfo(calls_sloppy_eval); | 1266 inner->PropagateScopeInfo(calls_sloppy_eval); |
1260 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { | 1267 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { |
1261 inner_scope_calls_eval_ = true; | 1268 inner_scope_calls_eval_ = true; |
1262 } | 1269 } |
1263 // If the inner scope is an arrow function, propagate the flags tracking | 1270 // If the inner scope is an arrow function, propagate the flags tracking |
1264 // usage of arguments/super/this, but do not propagate them out from normal | 1271 // usage of arguments/super/this, but do not propagate them out from normal |
1265 // functions. | 1272 // functions. |
1266 if (!inner->is_function_scope() || inner->is_arrow_scope()) { | 1273 if (!inner->is_function_scope() || inner->is_arrow_scope()) { |
| 1274 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { |
| 1275 inner_scope_uses_arguments_ = true; |
| 1276 } |
1267 if (inner->scope_uses_super_property_ || | 1277 if (inner->scope_uses_super_property_ || |
1268 inner->inner_scope_uses_super_property_) { | 1278 inner->inner_scope_uses_super_property_) { |
1269 inner_scope_uses_super_property_ = true; | 1279 inner_scope_uses_super_property_ = true; |
1270 } | 1280 } |
1271 } | 1281 } |
1272 if (inner->force_eager_compilation_) { | 1282 if (inner->force_eager_compilation_) { |
1273 force_eager_compilation_ = true; | 1283 force_eager_compilation_ = true; |
1274 } | 1284 } |
1275 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1285 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
1276 inner->asm_function_ = true; | 1286 inner->asm_function_ = true; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1543 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1534 } | 1544 } |
1535 | 1545 |
1536 | 1546 |
1537 int Scope::ContextLocalCount() const { | 1547 int Scope::ContextLocalCount() const { |
1538 if (num_heap_slots() == 0) return 0; | 1548 if (num_heap_slots() == 0) return 0; |
1539 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1549 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1540 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1550 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1541 } | 1551 } |
1542 } } // namespace v8::internal | 1552 } } // namespace v8::internal |
OLD | NEW |