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