| OLD | NEW |
| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 scope_name_ = isolate_->factory()->empty_string(); | 183 scope_name_ = isolate_->factory()->empty_string(); |
| 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 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; |
| 194 ? outer_scope->language_mode_ : SLOPPY_MODE; | |
| 195 outer_scope_calls_sloppy_eval_ = false; | 194 outer_scope_calls_sloppy_eval_ = false; |
| 196 inner_scope_calls_eval_ = false; | 195 inner_scope_calls_eval_ = false; |
| 197 force_eager_compilation_ = false; | 196 force_eager_compilation_ = false; |
| 198 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 197 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
| 199 ? outer_scope->has_forced_context_allocation() : false; | 198 ? outer_scope->has_forced_context_allocation() : false; |
| 200 num_var_or_const_ = 0; | 199 num_var_or_const_ = 0; |
| 201 num_stack_slots_ = 0; | 200 num_stack_slots_ = 0; |
| 202 num_heap_slots_ = 0; | 201 num_heap_slots_ = 0; |
| 203 num_modules_ = 0; | 202 num_modules_ = 0; |
| 204 module_var_ = NULL, | 203 module_var_ = NULL, |
| 205 scope_info_ = scope_info; | 204 scope_info_ = scope_info; |
| 206 start_position_ = RelocInfo::kNoPosition; | 205 start_position_ = RelocInfo::kNoPosition; |
| 207 end_position_ = RelocInfo::kNoPosition; | 206 end_position_ = RelocInfo::kNoPosition; |
| 208 if (!scope_info.is_null()) { | 207 if (!scope_info.is_null()) { |
| 209 scope_calls_eval_ = scope_info->CallsEval(); | 208 scope_calls_eval_ = scope_info->CallsEval(); |
| 210 language_mode_ = scope_info->language_mode(); | 209 strict_mode_ = scope_info->strict_mode(); |
| 211 } | 210 } |
| 212 } | 211 } |
| 213 | 212 |
| 214 | 213 |
| 215 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope, | 214 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope, |
| 216 Zone* zone) { | 215 Zone* zone) { |
| 217 // Reconstruct the outer scope chain from a closure's context chain. | 216 // Reconstruct the outer scope chain from a closure's context chain. |
| 218 Scope* current_scope = NULL; | 217 Scope* current_scope = NULL; |
| 219 Scope* innermost_scope = NULL; | 218 Scope* innermost_scope = NULL; |
| 220 bool contains_with = false; | 219 bool contains_with = false; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 kCreatedInitialized); | 462 kCreatedInitialized); |
| 464 params_.Add(var, zone()); | 463 params_.Add(var, zone()); |
| 465 } | 464 } |
| 466 | 465 |
| 467 | 466 |
| 468 Variable* Scope::DeclareLocal(Handle<String> name, | 467 Variable* Scope::DeclareLocal(Handle<String> name, |
| 469 VariableMode mode, | 468 VariableMode mode, |
| 470 InitializationFlag init_flag, | 469 InitializationFlag init_flag, |
| 471 Interface* interface) { | 470 Interface* interface) { |
| 472 ASSERT(!already_resolved()); | 471 ASSERT(!already_resolved()); |
| 473 // This function handles VAR and CONST modes. DYNAMIC variables are | 472 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
| 474 // introduces during variable allocation, INTERNAL variables are allocated | 473 // introduces during variable allocation, INTERNAL variables are allocated |
| 475 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). | 474 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
| 476 ASSERT(IsDeclaredVariableMode(mode)); | 475 ASSERT(IsDeclaredVariableMode(mode)); |
| 477 ++num_var_or_const_; | 476 ++num_var_or_const_; |
| 478 return variables_.Declare( | 477 return variables_.Declare( |
| 479 this, name, mode, true, Variable::NORMAL, init_flag, interface); | 478 this, name, mode, true, Variable::NORMAL, init_flag, interface); |
| 480 } | 479 } |
| 481 | 480 |
| 482 | 481 |
| 483 Variable* Scope::DeclareDynamicGlobal(Handle<String> name) { | 482 Variable* Scope::DeclareDynamicGlobal(Handle<String> name) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 if (function_ != NULL) { | 873 if (function_ != NULL) { |
| 875 Indent(n1, "// (local) function name: "); | 874 Indent(n1, "// (local) function name: "); |
| 876 PrintName(function_->proxy()->name()); | 875 PrintName(function_->proxy()->name()); |
| 877 PrintF("\n"); | 876 PrintF("\n"); |
| 878 } | 877 } |
| 879 | 878 |
| 880 // Scope info. | 879 // Scope info. |
| 881 if (HasTrivialOuterContext()) { | 880 if (HasTrivialOuterContext()) { |
| 882 Indent(n1, "// scope has trivial outer context\n"); | 881 Indent(n1, "// scope has trivial outer context\n"); |
| 883 } | 882 } |
| 884 switch (language_mode()) { | 883 if (strict_mode() == STRICT) { |
| 885 case SLOPPY_MODE: | 884 Indent(n1, "// strict mode scope\n"); |
| 886 break; | |
| 887 case STRICT_MODE: | |
| 888 Indent(n1, "// strict mode scope\n"); | |
| 889 break; | |
| 890 case EXTENDED_MODE: | |
| 891 Indent(n1, "// extended mode scope\n"); | |
| 892 break; | |
| 893 } | 885 } |
| 894 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 886 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
| 895 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 887 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
| 896 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 888 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
| 897 if (outer_scope_calls_sloppy_eval_) { | 889 if (outer_scope_calls_sloppy_eval_) { |
| 898 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 890 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
| 899 } | 891 } |
| 900 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 892 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
| 901 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 893 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
| 902 PrintF("%d stack slots\n", num_stack_slots_); } | 894 PrintF("%d stack slots\n", num_stack_slots_); } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 break; | 1068 break; |
| 1077 | 1069 |
| 1078 case DYNAMIC_LOOKUP: | 1070 case DYNAMIC_LOOKUP: |
| 1079 // The variable could not be resolved statically. | 1071 // The variable could not be resolved statically. |
| 1080 var = NonLocal(proxy->name(), DYNAMIC); | 1072 var = NonLocal(proxy->name(), DYNAMIC); |
| 1081 break; | 1073 break; |
| 1082 } | 1074 } |
| 1083 | 1075 |
| 1084 ASSERT(var != NULL); | 1076 ASSERT(var != NULL); |
| 1085 | 1077 |
| 1086 if (FLAG_harmony_scoping && is_extended_mode() && | 1078 if (FLAG_harmony_scoping && strict_mode() == STRICT && |
| 1087 var->is_const_mode() && proxy->IsLValue()) { | 1079 var->is_const_mode() && proxy->IsLValue()) { |
| 1088 // Assignment to const. Throw a syntax error. | 1080 // Assignment to const. Throw a syntax error. |
| 1089 MessageLocation location( | 1081 MessageLocation location( |
| 1090 info->script(), proxy->position(), proxy->position()); | 1082 info->script(), proxy->position(), proxy->position()); |
| 1091 Isolate* isolate = info->isolate(); | 1083 Isolate* isolate = info->isolate(); |
| 1092 Factory* factory = isolate->factory(); | 1084 Factory* factory = isolate->factory(); |
| 1093 Handle<JSArray> array = factory->NewJSArray(0); | 1085 Handle<JSArray> array = factory->NewJSArray(0); |
| 1094 Handle<Object> result = | 1086 Handle<Object> result = |
| 1095 factory->NewSyntaxError("harmony_const_assign", array); | 1087 factory->NewSyntaxError("harmony_const_assign", array); |
| 1096 isolate->Throw(*result, &location); | 1088 isolate->Throw(*result, &location); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1115 } | 1107 } |
| 1116 #endif | 1108 #endif |
| 1117 | 1109 |
| 1118 // Inconsistent use of module. Throw a syntax error. | 1110 // Inconsistent use of module. Throw a syntax error. |
| 1119 // TODO(rossberg): generate more helpful error message. | 1111 // TODO(rossberg): generate more helpful error message. |
| 1120 MessageLocation location( | 1112 MessageLocation location( |
| 1121 info->script(), proxy->position(), proxy->position()); | 1113 info->script(), proxy->position(), proxy->position()); |
| 1122 Isolate* isolate = info->isolate(); | 1114 Isolate* isolate = info->isolate(); |
| 1123 Factory* factory = isolate->factory(); | 1115 Factory* factory = isolate->factory(); |
| 1124 Handle<JSArray> array = factory->NewJSArray(1); | 1116 Handle<JSArray> array = factory->NewJSArray(1); |
| 1125 USE(JSObject::SetElement(array, 0, var->name(), NONE, kStrictMode)); | 1117 USE(JSObject::SetElement(array, 0, var->name(), NONE, STRICT)); |
| 1126 Handle<Object> result = | 1118 Handle<Object> result = |
| 1127 factory->NewSyntaxError("module_type_error", array); | 1119 factory->NewSyntaxError("module_type_error", array); |
| 1128 isolate->Throw(*result, &location); | 1120 isolate->Throw(*result, &location); |
| 1129 return false; | 1121 return false; |
| 1130 } | 1122 } |
| 1131 } | 1123 } |
| 1132 | 1124 |
| 1133 proxy->BindTo(var); | 1125 proxy->BindTo(var); |
| 1134 | 1126 |
| 1135 return true; | 1127 return true; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 // parameters, which is why we don't need to allocate an arguments | 1249 // parameters, which is why we don't need to allocate an arguments |
| 1258 // object in that case. | 1250 // object in that case. |
| 1259 | 1251 |
| 1260 // We are using 'arguments'. Tell the code generator that is needs to | 1252 // We are using 'arguments'. Tell the code generator that is needs to |
| 1261 // allocate the arguments object by setting 'arguments_'. | 1253 // allocate the arguments object by setting 'arguments_'. |
| 1262 arguments_ = arguments; | 1254 arguments_ = arguments; |
| 1263 | 1255 |
| 1264 // In strict mode 'arguments' does not alias formal parameters. | 1256 // In strict mode 'arguments' does not alias formal parameters. |
| 1265 // Therefore in strict mode we allocate parameters as if 'arguments' | 1257 // Therefore in strict mode we allocate parameters as if 'arguments' |
| 1266 // were not used. | 1258 // were not used. |
| 1267 uses_sloppy_arguments = is_sloppy_mode(); | 1259 uses_sloppy_arguments = strict_mode() == SLOPPY; |
| 1268 } | 1260 } |
| 1269 | 1261 |
| 1270 // The same parameter may occur multiple times in the parameters_ list. | 1262 // The same parameter may occur multiple times in the parameters_ list. |
| 1271 // If it does, and if it is not copied into the context object, it must | 1263 // If it does, and if it is not copied into the context object, it must |
| 1272 // receive the highest parameter index for that parameter; thus iteration | 1264 // receive the highest parameter index for that parameter; thus iteration |
| 1273 // order is relevant! | 1265 // order is relevant! |
| 1274 for (int i = params_.length() - 1; i >= 0; --i) { | 1266 for (int i = params_.length() - 1; i >= 0; --i) { |
| 1275 Variable* var = params_[i]; | 1267 Variable* var = params_[i]; |
| 1276 ASSERT(var->scope() == this); | 1268 ASSERT(var->scope() == this); |
| 1277 if (uses_sloppy_arguments) { | 1269 if (uses_sloppy_arguments) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 } | 1395 } |
| 1404 | 1396 |
| 1405 | 1397 |
| 1406 int Scope::ContextLocalCount() const { | 1398 int Scope::ContextLocalCount() const { |
| 1407 if (num_heap_slots() == 0) return 0; | 1399 if (num_heap_slots() == 0) return 0; |
| 1408 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1400 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1409 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1401 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1410 } | 1402 } |
| 1411 | 1403 |
| 1412 } } // namespace v8::internal | 1404 } } // namespace v8::internal |
| OLD | NEW |