Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/scopes.cc

Issue 177683002: Mode clean-up pt 1: rename classic/non-strict mode to sloppy mode (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 dynamics_ = NULL; 184 dynamics_ = NULL;
185 receiver_ = NULL; 185 receiver_ = NULL;
186 function_ = NULL; 186 function_ = NULL;
187 arguments_ = NULL; 187 arguments_ = NULL;
188 illegal_redecl_ = NULL; 188 illegal_redecl_ = NULL;
189 scope_inside_with_ = false; 189 scope_inside_with_ = false;
190 scope_contains_with_ = false; 190 scope_contains_with_ = false;
191 scope_calls_eval_ = false; 191 scope_calls_eval_ = false;
192 // Inherit the strict mode from the parent scope. 192 // Inherit the strict mode from the parent scope.
193 language_mode_ = (outer_scope != NULL) 193 language_mode_ = (outer_scope != NULL)
194 ? outer_scope->language_mode_ : CLASSIC_MODE; 194 ? outer_scope->language_mode_ : SLOPPY_MODE;
195 outer_scope_calls_non_strict_eval_ = false; 195 outer_scope_calls_sloppy_eval_ = false;
196 inner_scope_calls_eval_ = false; 196 inner_scope_calls_eval_ = false;
197 force_eager_compilation_ = false; 197 force_eager_compilation_ = false;
198 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) 198 force_context_allocation_ = (outer_scope != NULL && !is_function_scope())
199 ? outer_scope->has_forced_context_allocation() : false; 199 ? outer_scope->has_forced_context_allocation() : false;
200 num_var_or_const_ = 0; 200 num_var_or_const_ = 0;
201 num_stack_slots_ = 0; 201 num_stack_slots_ = 0;
202 num_heap_slots_ = 0; 202 num_heap_slots_ = 0;
203 num_modules_ = 0; 203 num_modules_ = 0;
204 module_var_ = NULL, 204 module_var_ = NULL,
205 scope_info_ = scope_info; 205 scope_info_ = scope_info;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 } else if (var->IsContextSlot()) { 636 } else if (var->IsContextSlot()) {
637 context_locals->Add(var, zone()); 637 context_locals->Add(var, zone());
638 } 638 }
639 } 639 }
640 } 640 }
641 641
642 642
643 bool Scope::AllocateVariables(CompilationInfo* info, 643 bool Scope::AllocateVariables(CompilationInfo* info,
644 AstNodeFactory<AstNullVisitor>* factory) { 644 AstNodeFactory<AstNullVisitor>* factory) {
645 // 1) Propagate scope information. 645 // 1) Propagate scope information.
646 bool outer_scope_calls_non_strict_eval = false; 646 bool outer_scope_calls_sloppy_eval = false;
647 if (outer_scope_ != NULL) { 647 if (outer_scope_ != NULL) {
648 outer_scope_calls_non_strict_eval = 648 outer_scope_calls_sloppy_eval =
649 outer_scope_->outer_scope_calls_non_strict_eval() | 649 outer_scope_->outer_scope_calls_sloppy_eval() |
650 outer_scope_->calls_non_strict_eval(); 650 outer_scope_->calls_sloppy_eval();
651 } 651 }
652 PropagateScopeInfo(outer_scope_calls_non_strict_eval); 652 PropagateScopeInfo(outer_scope_calls_sloppy_eval);
653 653
654 // 2) Allocate module instances. 654 // 2) Allocate module instances.
655 if (FLAG_harmony_modules && (is_global_scope() || is_module_scope())) { 655 if (FLAG_harmony_modules && (is_global_scope() || is_module_scope())) {
656 ASSERT(num_modules_ == 0); 656 ASSERT(num_modules_ == 0);
657 AllocateModulesRecursively(this); 657 AllocateModulesRecursively(this);
658 } 658 }
659 659
660 // 3) Resolve variables. 660 // 3) Resolve variables.
661 if (!ResolveVariablesRecursively(info, factory)) return false; 661 if (!ResolveVariablesRecursively(info, factory)) return false;
662 662
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 Indent(n1, "// (local) function name: "); 875 Indent(n1, "// (local) function name: ");
876 PrintName(function_->proxy()->name()); 876 PrintName(function_->proxy()->name());
877 PrintF("\n"); 877 PrintF("\n");
878 } 878 }
879 879
880 // Scope info. 880 // Scope info.
881 if (HasTrivialOuterContext()) { 881 if (HasTrivialOuterContext()) {
882 Indent(n1, "// scope has trivial outer context\n"); 882 Indent(n1, "// scope has trivial outer context\n");
883 } 883 }
884 switch (language_mode()) { 884 switch (language_mode()) {
885 case CLASSIC_MODE: 885 case SLOPPY_MODE:
886 break; 886 break;
887 case STRICT_MODE: 887 case STRICT_MODE:
888 Indent(n1, "// strict mode scope\n"); 888 Indent(n1, "// strict mode scope\n");
889 break; 889 break;
890 case EXTENDED_MODE: 890 case EXTENDED_MODE:
891 Indent(n1, "// extended mode scope\n"); 891 Indent(n1, "// extended mode scope\n");
892 break; 892 break;
893 } 893 }
894 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 894 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
895 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); 895 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n");
896 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 896 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
897 if (outer_scope_calls_non_strict_eval_) { 897 if (outer_scope_calls_sloppy_eval_) {
898 Indent(n1, "// outer scope calls 'eval' in non-strict context\n"); 898 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
899 } 899 }
900 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 900 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
901 if (num_stack_slots_ > 0) { Indent(n1, "// "); 901 if (num_stack_slots_ > 0) { Indent(n1, "// ");
902 PrintF("%d stack slots\n", num_stack_slots_); } 902 PrintF("%d stack slots\n", num_stack_slots_); }
903 if (num_heap_slots_ > 0) { Indent(n1, "// "); 903 if (num_heap_slots_ > 0) { Indent(n1, "// ");
904 PrintF("%d heap slots\n", num_heap_slots_); } 904 PrintF("%d heap slots\n", num_heap_slots_); }
905 905
906 // Print locals. 906 // Print locals.
907 if (function_ != NULL) { 907 if (function_ != NULL) {
908 Indent(n1, "// function var:\n"); 908 Indent(n1, "// function var:\n");
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 if (is_with_scope()) { 1010 if (is_with_scope()) {
1011 ASSERT(!already_resolved()); 1011 ASSERT(!already_resolved());
1012 // The current scope is a with scope, so the variable binding can not be 1012 // The current scope is a with scope, so the variable binding can not be
1013 // statically resolved. However, note that it was necessary to do a lookup 1013 // statically resolved. However, note that it was necessary to do a lookup
1014 // in the outer scope anyway, because if a binding exists in an outer scope, 1014 // in the outer scope anyway, because if a binding exists in an outer scope,
1015 // the associated variable has to be marked as potentially being accessed 1015 // the associated variable has to be marked as potentially being accessed
1016 // from inside of an inner with scope (the property may not be in the 'with' 1016 // from inside of an inner with scope (the property may not be in the 'with'
1017 // object). 1017 // object).
1018 *binding_kind = DYNAMIC_LOOKUP; 1018 *binding_kind = DYNAMIC_LOOKUP;
1019 return NULL; 1019 return NULL;
1020 } else if (calls_non_strict_eval()) { 1020 } else if (calls_sloppy_eval()) {
1021 // A variable binding may have been found in an outer scope, but the current 1021 // A variable binding may have been found in an outer scope, but the current
1022 // scope makes a non-strict 'eval' call, so the found variable may not be 1022 // scope makes a sloppy 'eval' call, so the found variable may not be
1023 // the correct one (the 'eval' may introduce a binding with the same name). 1023 // the correct one (the 'eval' may introduce a binding with the same name).
1024 // In that case, change the lookup result to reflect this situation. 1024 // In that case, change the lookup result to reflect this situation.
1025 if (*binding_kind == BOUND) { 1025 if (*binding_kind == BOUND) {
1026 *binding_kind = BOUND_EVAL_SHADOWED; 1026 *binding_kind = BOUND_EVAL_SHADOWED;
1027 } else if (*binding_kind == UNBOUND) { 1027 } else if (*binding_kind == UNBOUND) {
1028 *binding_kind = UNBOUND_EVAL_SHADOWED; 1028 *binding_kind = UNBOUND_EVAL_SHADOWED;
1029 } 1029 }
1030 } 1030 }
1031 return var; 1031 return var;
1032 } 1032 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 var->set_local_if_not_shadowed(invalidated); 1064 var->set_local_if_not_shadowed(invalidated);
1065 } 1065 }
1066 break; 1066 break;
1067 1067
1068 case UNBOUND: 1068 case UNBOUND:
1069 // No binding has been found. Declare a variable on the global object. 1069 // No binding has been found. Declare a variable on the global object.
1070 var = info->global_scope()->DeclareDynamicGlobal(proxy->name()); 1070 var = info->global_scope()->DeclareDynamicGlobal(proxy->name());
1071 break; 1071 break;
1072 1072
1073 case UNBOUND_EVAL_SHADOWED: 1073 case UNBOUND_EVAL_SHADOWED:
1074 // No binding has been found. But some scope makes a 1074 // No binding has been found. But some scope makes a sloppy 'eval' call.
1075 // non-strict 'eval' call.
1076 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); 1075 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL);
1077 break; 1076 break;
1078 1077
1079 case DYNAMIC_LOOKUP: 1078 case DYNAMIC_LOOKUP:
1080 // The variable could not be resolved statically. 1079 // The variable could not be resolved statically.
1081 var = NonLocal(proxy->name(), DYNAMIC); 1080 var = NonLocal(proxy->name(), DYNAMIC);
1082 break; 1081 break;
1083 } 1082 }
1084 1083
1085 ASSERT(var != NULL); 1084 ASSERT(var != NULL);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 // Resolve unresolved variables for inner scopes. 1149 // Resolve unresolved variables for inner scopes.
1151 for (int i = 0; i < inner_scopes_.length(); i++) { 1150 for (int i = 0; i < inner_scopes_.length(); i++) {
1152 if (!inner_scopes_[i]->ResolveVariablesRecursively(info, factory)) 1151 if (!inner_scopes_[i]->ResolveVariablesRecursively(info, factory))
1153 return false; 1152 return false;
1154 } 1153 }
1155 1154
1156 return true; 1155 return true;
1157 } 1156 }
1158 1157
1159 1158
1160 bool Scope::PropagateScopeInfo(bool outer_scope_calls_non_strict_eval ) { 1159 bool Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) {
1161 if (outer_scope_calls_non_strict_eval) { 1160 if (outer_scope_calls_sloppy_eval) {
1162 outer_scope_calls_non_strict_eval_ = true; 1161 outer_scope_calls_sloppy_eval_ = true;
1163 } 1162 }
1164 1163
1165 bool calls_non_strict_eval = 1164 bool calls_sloppy_eval =
1166 this->calls_non_strict_eval() || outer_scope_calls_non_strict_eval_; 1165 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1167 for (int i = 0; i < inner_scopes_.length(); i++) { 1166 for (int i = 0; i < inner_scopes_.length(); i++) {
1168 Scope* inner_scope = inner_scopes_[i]; 1167 Scope* inner_scope = inner_scopes_[i];
1169 if (inner_scope->PropagateScopeInfo(calls_non_strict_eval)) { 1168 if (inner_scope->PropagateScopeInfo(calls_sloppy_eval)) {
1170 inner_scope_calls_eval_ = true; 1169 inner_scope_calls_eval_ = true;
1171 } 1170 }
1172 if (inner_scope->force_eager_compilation_) { 1171 if (inner_scope->force_eager_compilation_) {
1173 force_eager_compilation_ = true; 1172 force_eager_compilation_ = true;
1174 } 1173 }
1175 } 1174 }
1176 1175
1177 return scope_calls_eval_ || inner_scope_calls_eval_; 1176 return scope_calls_eval_ || inner_scope_calls_eval_;
1178 } 1177 }
1179 1178
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 void Scope::AllocateHeapSlot(Variable* var) { 1238 void Scope::AllocateHeapSlot(Variable* var) {
1240 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++); 1239 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++);
1241 } 1240 }
1242 1241
1243 1242
1244 void Scope::AllocateParameterLocals() { 1243 void Scope::AllocateParameterLocals() {
1245 ASSERT(is_function_scope()); 1244 ASSERT(is_function_scope());
1246 Variable* arguments = LocalLookup(isolate_->factory()->arguments_string()); 1245 Variable* arguments = LocalLookup(isolate_->factory()->arguments_string());
1247 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly 1246 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly
1248 1247
1249 bool uses_nonstrict_arguments = false; 1248 bool uses_sloppy_arguments = false;
1250 1249
1251 if (MustAllocate(arguments) && !HasArgumentsParameter()) { 1250 if (MustAllocate(arguments) && !HasArgumentsParameter()) {
1252 // 'arguments' is used. Unless there is also a parameter called 1251 // 'arguments' is used. Unless there is also a parameter called
1253 // 'arguments', we must be conservative and allocate all parameters to 1252 // 'arguments', we must be conservative and allocate all parameters to
1254 // the context assuming they will be captured by the arguments object. 1253 // the context assuming they will be captured by the arguments object.
1255 // If we have a parameter named 'arguments', a (new) value is always 1254 // If we have a parameter named 'arguments', a (new) value is always
1256 // assigned to it via the function invocation. Then 'arguments' denotes 1255 // assigned to it via the function invocation. Then 'arguments' denotes
1257 // that specific parameter value and cannot be used to access the 1256 // that specific parameter value and cannot be used to access the
1258 // parameters, which is why we don't need to allocate an arguments 1257 // parameters, which is why we don't need to allocate an arguments
1259 // object in that case. 1258 // object in that case.
1260 1259
1261 // We are using 'arguments'. Tell the code generator that is needs to 1260 // We are using 'arguments'. Tell the code generator that is needs to
1262 // allocate the arguments object by setting 'arguments_'. 1261 // allocate the arguments object by setting 'arguments_'.
1263 arguments_ = arguments; 1262 arguments_ = arguments;
1264 1263
1265 // In strict mode 'arguments' does not alias formal parameters. 1264 // In strict mode 'arguments' does not alias formal parameters.
1266 // Therefore in strict mode we allocate parameters as if 'arguments' 1265 // Therefore in strict mode we allocate parameters as if 'arguments'
1267 // were not used. 1266 // were not used.
1268 uses_nonstrict_arguments = is_classic_mode(); 1267 uses_sloppy_arguments = is_sloppy_mode();
1269 } 1268 }
1270 1269
1271 // The same parameter may occur multiple times in the parameters_ list. 1270 // The same parameter may occur multiple times in the parameters_ list.
1272 // If it does, and if it is not copied into the context object, it must 1271 // If it does, and if it is not copied into the context object, it must
1273 // receive the highest parameter index for that parameter; thus iteration 1272 // receive the highest parameter index for that parameter; thus iteration
1274 // order is relevant! 1273 // order is relevant!
1275 for (int i = params_.length() - 1; i >= 0; --i) { 1274 for (int i = params_.length() - 1; i >= 0; --i) {
1276 Variable* var = params_[i]; 1275 Variable* var = params_[i];
1277 ASSERT(var->scope() == this); 1276 ASSERT(var->scope() == this);
1278 if (uses_nonstrict_arguments) { 1277 if (uses_sloppy_arguments) {
1279 // Force context allocation of the parameter. 1278 // Force context allocation of the parameter.
1280 var->ForceContextAllocation(); 1279 var->ForceContextAllocation();
1281 } 1280 }
1282 1281
1283 if (MustAllocate(var)) { 1282 if (MustAllocate(var)) {
1284 if (MustAllocateInContext(var)) { 1283 if (MustAllocateInContext(var)) {
1285 ASSERT(var->IsUnallocated() || var->IsContextSlot()); 1284 ASSERT(var->IsUnallocated() || var->IsContextSlot());
1286 if (var->IsUnallocated()) { 1285 if (var->IsUnallocated()) {
1287 AllocateHeapSlot(var); 1286 AllocateHeapSlot(var);
1288 } 1287 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 } 1403 }
1405 1404
1406 1405
1407 int Scope::ContextLocalCount() const { 1406 int Scope::ContextLocalCount() const {
1408 if (num_heap_slots() == 0) return 0; 1407 if (num_heap_slots() == 0) return 0;
1409 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1408 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1410 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1409 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1411 } 1410 }
1412 1411
1413 } } // namespace v8::internal 1412 } } // namespace v8::internal
OLDNEW
« src/preparser.h ('K') | « src/scopes.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698