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