Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 scope_name_ = ast_value_factory_->empty_string(); | 154 scope_name_ = ast_value_factory_->empty_string(); |
| 155 dynamics_ = NULL; | 155 dynamics_ = NULL; |
| 156 receiver_ = NULL; | 156 receiver_ = NULL; |
| 157 function_ = NULL; | 157 function_ = NULL; |
| 158 arguments_ = NULL; | 158 arguments_ = NULL; |
| 159 illegal_redecl_ = NULL; | 159 illegal_redecl_ = NULL; |
| 160 scope_inside_with_ = false; | 160 scope_inside_with_ = false; |
| 161 scope_contains_with_ = false; | 161 scope_contains_with_ = false; |
| 162 scope_calls_eval_ = false; | 162 scope_calls_eval_ = false; |
| 163 scope_uses_arguments_ = false; | 163 scope_uses_arguments_ = false; |
| 164 scope_uses_super_ = false; | 164 scope_uses_super_property_ = false; |
| 165 scope_uses_super_constructor_call_ = false; | |
| 165 scope_uses_this_ = false; | 166 scope_uses_this_ = false; |
| 166 asm_module_ = false; | 167 asm_module_ = false; |
| 167 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; | 168 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |
| 168 // Inherit the strict mode from the parent scope. | 169 // Inherit the strict mode from the parent scope. |
| 169 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; | 170 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; |
| 170 outer_scope_calls_sloppy_eval_ = false; | 171 outer_scope_calls_sloppy_eval_ = false; |
| 171 inner_scope_calls_eval_ = false; | 172 inner_scope_calls_eval_ = false; |
| 172 inner_scope_uses_arguments_ = false; | 173 inner_scope_uses_arguments_ = false; |
| 173 inner_scope_uses_this_ = false; | 174 inner_scope_uses_this_ = false; |
| 174 inner_scope_uses_super_ = false; | 175 inner_scope_uses_super_property_ = false; |
| 176 inner_scope_uses_super_constructor_call_ = false; | |
| 175 force_eager_compilation_ = false; | 177 force_eager_compilation_ = false; |
| 176 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 178 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
| 177 ? outer_scope->has_forced_context_allocation() : false; | 179 ? outer_scope->has_forced_context_allocation() : false; |
| 178 num_var_or_const_ = 0; | 180 num_var_or_const_ = 0; |
| 179 num_stack_slots_ = 0; | 181 num_stack_slots_ = 0; |
| 180 num_heap_slots_ = 0; | 182 num_heap_slots_ = 0; |
| 181 num_modules_ = 0; | 183 num_modules_ = 0; |
| 182 module_var_ = NULL, | 184 module_var_ = NULL, |
| 183 scope_info_ = scope_info; | 185 scope_info_ = scope_info; |
| 184 start_position_ = RelocInfo::kNoPosition; | 186 start_position_ = RelocInfo::kNoPosition; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 outer_scope()->AddInnerScope(inner_scopes_[i]); | 370 outer_scope()->AddInnerScope(inner_scopes_[i]); |
| 369 } | 371 } |
| 370 | 372 |
| 371 // Move unresolved variables | 373 // Move unresolved variables |
| 372 for (int i = 0; i < unresolved_.length(); i++) { | 374 for (int i = 0; i < unresolved_.length(); i++) { |
| 373 outer_scope()->unresolved_.Add(unresolved_[i], zone()); | 375 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
| 374 } | 376 } |
| 375 | 377 |
| 376 // Propagate usage flags to outer scope. | 378 // Propagate usage flags to outer scope. |
| 377 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); | 379 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); |
| 378 if (uses_super()) outer_scope_->RecordSuperUsage(); | 380 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); |
| 381 if (uses_super_constructor_call()) | |
| 382 outer_scope_->RecordSuperConstructorCallUsage(); | |
| 379 if (uses_this()) outer_scope_->RecordThisUsage(); | 383 if (uses_this()) outer_scope_->RecordThisUsage(); |
| 380 | 384 |
| 381 return NULL; | 385 return NULL; |
| 382 } | 386 } |
| 383 | 387 |
| 384 | 388 |
| 385 Variable* Scope::LookupLocal(const AstRawString* name) { | 389 Variable* Scope::LookupLocal(const AstRawString* name) { |
| 386 Variable* result = variables_.Lookup(name); | 390 Variable* result = variables_.Lookup(name); |
| 387 if (result != NULL || scope_info_.is_null()) { | 391 if (result != NULL || scope_info_.is_null()) { |
| 388 return result; | 392 return result; |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 if (HasTrivialOuterContext()) { | 893 if (HasTrivialOuterContext()) { |
| 890 Indent(n1, "// scope has trivial outer context\n"); | 894 Indent(n1, "// scope has trivial outer context\n"); |
| 891 } | 895 } |
| 892 if (strict_mode() == STRICT) { | 896 if (strict_mode() == STRICT) { |
| 893 Indent(n1, "// strict mode scope\n"); | 897 Indent(n1, "// strict mode scope\n"); |
| 894 } | 898 } |
| 895 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 899 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
| 896 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 900 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
| 897 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 901 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
| 898 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); | 902 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); |
| 899 if (scope_uses_super_) Indent(n1, "// scope uses 'super'\n"); | 903 if (scope_uses_super_property_) |
| 904 Indent(n1, "// scope uses 'super' property\n"); | |
| 905 if (scope_uses_super_constructor_call_) { | |
|
arv (Not doing code reviews)
2014/12/01 15:14:07
Inconsistent use of {}
| |
| 906 Indent(n1, "// scope uses 'super' constructor\n"); | |
| 907 } | |
| 900 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n"); | 908 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n"); |
| 901 if (inner_scope_uses_arguments_) { | 909 if (inner_scope_uses_arguments_) { |
| 902 Indent(n1, "// inner scope uses 'arguments'\n"); | 910 Indent(n1, "// inner scope uses 'arguments'\n"); |
| 903 } | 911 } |
| 904 if (inner_scope_uses_super_) Indent(n1, "// inner scope uses 'super'\n"); | 912 if (inner_scope_uses_super_property_) |
| 913 Indent(n1, "// inner scope uses 'super' property\n"); | |
| 914 if (inner_scope_uses_super_constructor_call_) { | |
| 915 Indent(n1, "// inner scope uses 'super' constructor\n"); | |
| 916 } | |
| 905 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n"); | 917 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n"); |
| 906 if (outer_scope_calls_sloppy_eval_) { | 918 if (outer_scope_calls_sloppy_eval_) { |
| 907 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 919 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
| 908 } | 920 } |
| 909 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 921 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
| 910 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 922 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
| 911 PrintF("%d stack slots\n", num_stack_slots_); } | 923 PrintF("%d stack slots\n", num_stack_slots_); } |
| 912 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 924 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
| 913 PrintF("%d heap slots\n", num_heap_slots_); } | 925 PrintF("%d heap slots\n", num_heap_slots_); } |
| 914 | 926 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { | 1179 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { |
| 1168 inner_scope_calls_eval_ = true; | 1180 inner_scope_calls_eval_ = true; |
| 1169 } | 1181 } |
| 1170 // If the inner scope is an arrow function, propagate the flags tracking | 1182 // If the inner scope is an arrow function, propagate the flags tracking |
| 1171 // usage of arguments/super/this, but do not propagate them out from normal | 1183 // usage of arguments/super/this, but do not propagate them out from normal |
| 1172 // functions. | 1184 // functions. |
| 1173 if (!inner->is_function_scope() || inner->is_arrow_scope()) { | 1185 if (!inner->is_function_scope() || inner->is_arrow_scope()) { |
| 1174 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { | 1186 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { |
| 1175 inner_scope_uses_arguments_ = true; | 1187 inner_scope_uses_arguments_ = true; |
| 1176 } | 1188 } |
| 1177 if (inner->scope_uses_super_ || inner->inner_scope_uses_super_) { | 1189 if (inner->scope_uses_super_property_ || |
| 1178 inner_scope_uses_super_ = true; | 1190 inner->inner_scope_uses_super_property_) { |
| 1191 inner_scope_uses_super_property_ = true; | |
| 1192 } | |
| 1193 if (inner->uses_super_constructor_call() || | |
| 1194 inner->inner_scope_uses_super_constructor_call_) { | |
| 1195 inner_scope_uses_super_constructor_call_ = true; | |
| 1179 } | 1196 } |
| 1180 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { | 1197 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { |
| 1181 inner_scope_uses_this_ = true; | 1198 inner_scope_uses_this_ = true; |
| 1182 } | 1199 } |
| 1183 } | 1200 } |
| 1184 if (inner->force_eager_compilation_) { | 1201 if (inner->force_eager_compilation_) { |
| 1185 force_eager_compilation_ = true; | 1202 force_eager_compilation_ = true; |
| 1186 } | 1203 } |
| 1187 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1204 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
| 1188 inner->asm_function_ = true; | 1205 inner->asm_function_ = true; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1417 } | 1434 } |
| 1418 | 1435 |
| 1419 | 1436 |
| 1420 int Scope::ContextLocalCount() const { | 1437 int Scope::ContextLocalCount() const { |
| 1421 if (num_heap_slots() == 0) return 0; | 1438 if (num_heap_slots() == 0) return 0; |
| 1422 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1439 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1423 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1440 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1424 } | 1441 } |
| 1425 | 1442 |
| 1426 } } // namespace v8::internal | 1443 } } // namespace v8::internal |
| OLD | NEW |