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