OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 context()->Plug(eax); | 1227 context()->Plug(eax); |
1228 break; | 1228 break; |
1229 } | 1229 } |
1230 | 1230 |
1231 case Variable::PARAMETER: | 1231 case Variable::PARAMETER: |
1232 case Variable::LOCAL: | 1232 case Variable::LOCAL: |
1233 case Variable::CONTEXT: { | 1233 case Variable::CONTEXT: { |
1234 Comment cmnt(masm_, var->IsContextSlot() | 1234 Comment cmnt(masm_, var->IsContextSlot() |
1235 ? "Context variable" | 1235 ? "Context variable" |
1236 : "Stack variable"); | 1236 : "Stack variable"); |
1237 if (var->binding_needs_init()) { | 1237 if (!var->binding_needs_init()) { |
1238 // var->scope() may be NULL when the proxy is located in eval code and | 1238 context()->Plug(var); |
1239 // refers to a potential outside binding. Currently those bindings are | 1239 } else { |
1240 // always looked up dynamically, i.e. in that case | 1240 // Let and const need a read barrier. |
1241 // var->location() == LOOKUP. | 1241 Label done; |
1242 // always holds. | 1242 GetVar(eax, var); |
1243 ASSERT(var->scope() != NULL); | 1243 __ cmp(eax, isolate()->factory()->the_hole_value()); |
1244 | 1244 __ j(not_equal, &done, Label::kNear); |
1245 // Check if the binding really needs an initialization check. The check | 1245 if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
1246 // can be skipped in the following situation: we have a LET or CONST | 1246 // Throw a reference error when using an uninitialized let/const |
1247 // binding in harmony mode, both the Variable and the VariableProxy have | 1247 // binding in harmony mode. |
1248 // the same declaration scope (i.e. they are both in global code, in the | 1248 __ push(Immediate(var->name())); |
1249 // same function or in the same eval code) and the VariableProxy is in | 1249 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1250 // the source physically located after the initializer of the variable. | 1250 } else { |
1251 // | 1251 // Uninitalized const bindings outside of harmony mode are unholed. |
1252 // We cannot skip any initialization checks for CONST in non-harmony | 1252 ASSERT(var->mode() == CONST); |
1253 // mode because const variables may be declared but never initialized: | 1253 __ mov(eax, isolate()->factory()->undefined_value()); |
1254 // if (false) { const x; }; var y = x; | |
1255 // | |
1256 // The condition on the declaration scopes is a conservative check for | |
1257 // nested functions that access a binding and are called before the | |
1258 // binding is initialized: | |
1259 // function() { f(); let x = 1; function f() { x = 2; } } | |
1260 // | |
1261 // Check that we always have valid source position. | |
1262 ASSERT(var->initializer_position() != RelocInfo::kNoPosition); | |
1263 ASSERT(proxy->position() != RelocInfo::kNoPosition); | |
1264 bool skip_init_check = | |
1265 var->mode() != CONST && | |
1266 var->scope()->DeclarationScope() == scope()->DeclarationScope() && | |
1267 var->initializer_position() < proxy->position(); | |
1268 if (!skip_init_check) { | |
1269 // Let and const need a read barrier. | |
1270 Label done; | |
1271 GetVar(eax, var); | |
1272 __ cmp(eax, isolate()->factory()->the_hole_value()); | |
1273 __ j(not_equal, &done, Label::kNear); | |
1274 if (var->mode() == LET || var->mode() == CONST_HARMONY) { | |
1275 // Throw a reference error when using an uninitialized let/const | |
1276 // binding in harmony mode. | |
1277 __ push(Immediate(var->name())); | |
1278 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
1279 } else { | |
1280 // Uninitalized const bindings outside of harmony mode are unholed. | |
1281 ASSERT(var->mode() == CONST); | |
1282 __ mov(eax, isolate()->factory()->undefined_value()); | |
1283 } | |
1284 __ bind(&done); | |
1285 context()->Plug(eax); | |
1286 break; | |
1287 } | 1254 } |
| 1255 __ bind(&done); |
| 1256 context()->Plug(eax); |
1288 } | 1257 } |
1289 context()->Plug(var); | |
1290 break; | 1258 break; |
1291 } | 1259 } |
1292 | 1260 |
1293 case Variable::LOOKUP: { | 1261 case Variable::LOOKUP: { |
1294 Label done, slow; | 1262 Label done, slow; |
1295 // Generate code for loading from variables potentially shadowed | 1263 // Generate code for loading from variables potentially shadowed |
1296 // by eval-introduced variables. | 1264 // by eval-introduced variables. |
1297 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); | 1265 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
1298 __ bind(&slow); | 1266 __ bind(&slow); |
1299 Comment cmnt(masm_, "Lookup variable"); | 1267 Comment cmnt(masm_, "Lookup variable"); |
(...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4322 *context_length = 0; | 4290 *context_length = 0; |
4323 return previous_; | 4291 return previous_; |
4324 } | 4292 } |
4325 | 4293 |
4326 | 4294 |
4327 #undef __ | 4295 #undef __ |
4328 | 4296 |
4329 } } // namespace v8::internal | 4297 } } // namespace v8::internal |
4330 | 4298 |
4331 #endif // V8_TARGET_ARCH_IA32 | 4299 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |