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