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