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 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 context()->Plug(r0); | 1287 context()->Plug(r0); |
1288 break; | 1288 break; |
1289 } | 1289 } |
1290 | 1290 |
1291 case Variable::PARAMETER: | 1291 case Variable::PARAMETER: |
1292 case Variable::LOCAL: | 1292 case Variable::LOCAL: |
1293 case Variable::CONTEXT: { | 1293 case Variable::CONTEXT: { |
1294 Comment cmnt(masm_, var->IsContextSlot() | 1294 Comment cmnt(masm_, var->IsContextSlot() |
1295 ? "Context variable" | 1295 ? "Context variable" |
1296 : "Stack variable"); | 1296 : "Stack variable"); |
1297 if (!var->binding_needs_init()) { | 1297 if (var->binding_needs_init()) { |
1298 context()->Plug(var); | 1298 // var->scope() may be NULL when the proxy is located in eval code and |
1299 } else { | 1299 // refers to a potential outside binding. Currently those bindings are |
1300 // Let and const need a read barrier. | 1300 // always looked up dynamically, i.e. in that case |
1301 GetVar(r0, var); | 1301 // var->location() == LOOKUP. |
1302 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); | 1302 // always holds. |
1303 if (var->mode() == LET || var->mode() == CONST_HARMONY) { | 1303 ASSERT(var->scope() != NULL); |
1304 // Throw a reference error when using an uninitialized let/const | 1304 |
1305 // binding in harmony mode. | 1305 // Check if the binding really needs an initialization check. The check |
1306 Label done; | 1306 // can be skipped in the following situation: we have a LET or CONST |
1307 __ b(ne, &done); | 1307 // binding in harmony mode, both the Variable and the VariableProxy have |
1308 __ mov(r0, Operand(var->name())); | 1308 // the same declaration scope (i.e. they are both in global code, in the |
1309 __ push(r0); | 1309 // same function or in the same eval code) and the VariableProxy is in |
1310 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1310 // the source physically located after the initializer of the variable. |
1311 __ bind(&done); | 1311 // |
1312 } else { | 1312 // We cannot skip any initialization checks for CONST in non-harmony |
1313 // Uninitalized const bindings outside of harmony mode are unholed. | 1313 // mode because const variables may be declared but never initialized: |
1314 ASSERT(var->mode() == CONST); | 1314 // if (false) { const x; }; var y = x; |
1315 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); | 1315 // |
| 1316 // The condition on the declaration scopes is a conservative check for |
| 1317 // nested functions that access a binding and are called before the |
| 1318 // binding is initialized: |
| 1319 // function() { f(); let x = 1; function f() { x = 2; } } |
| 1320 // |
| 1321 // Check that we always have valid source position. |
| 1322 ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1323 ASSERT(proxy->position() != RelocInfo::kNoPosition); |
| 1324 bool skip_init_check = |
| 1325 var->mode() != CONST && |
| 1326 var->scope()->DeclarationScope() == scope()->DeclarationScope() && |
| 1327 var->initializer_position() < proxy->position(); |
| 1328 if (!skip_init_check) { |
| 1329 // Let and const need a read barrier. |
| 1330 GetVar(r0, var); |
| 1331 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); |
| 1332 if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1333 // Throw a reference error when using an uninitialized let/const |
| 1334 // binding in harmony mode. |
| 1335 Label done; |
| 1336 __ b(ne, &done); |
| 1337 __ mov(r0, Operand(var->name())); |
| 1338 __ push(r0); |
| 1339 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1340 __ bind(&done); |
| 1341 } else { |
| 1342 // Uninitalized const bindings outside of harmony mode are unholed. |
| 1343 ASSERT(var->mode() == CONST); |
| 1344 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1345 } |
| 1346 context()->Plug(r0); |
| 1347 break; |
1316 } | 1348 } |
1317 context()->Plug(r0); | |
1318 } | 1349 } |
| 1350 context()->Plug(var); |
1319 break; | 1351 break; |
1320 } | 1352 } |
1321 | 1353 |
1322 case Variable::LOOKUP: { | 1354 case Variable::LOOKUP: { |
1323 Label done, slow; | 1355 Label done, slow; |
1324 // Generate code for loading from variables potentially shadowed | 1356 // Generate code for loading from variables potentially shadowed |
1325 // by eval-introduced variables. | 1357 // by eval-introduced variables. |
1326 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); | 1358 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
1327 __ bind(&slow); | 1359 __ bind(&slow); |
1328 Comment cmnt(masm_, "Lookup variable"); | 1360 Comment cmnt(masm_, "Lookup variable"); |
(...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4319 *context_length = 0; | 4351 *context_length = 0; |
4320 return previous_; | 4352 return previous_; |
4321 } | 4353 } |
4322 | 4354 |
4323 | 4355 |
4324 #undef __ | 4356 #undef __ |
4325 | 4357 |
4326 } } // namespace v8::internal | 4358 } } // namespace v8::internal |
4327 | 4359 |
4328 #endif // V8_TARGET_ARCH_ARM | 4360 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |