| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if V8_TARGET_ARCH_X87 | 5 #if V8_TARGET_ARCH_X87 |
| 6 | 6 |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
| (...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 context()->Plug(eax); | 1370 context()->Plug(eax); |
| 1371 break; | 1371 break; |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 case VariableLocation::PARAMETER: | 1374 case VariableLocation::PARAMETER: |
| 1375 case VariableLocation::LOCAL: | 1375 case VariableLocation::LOCAL: |
| 1376 case VariableLocation::CONTEXT: { | 1376 case VariableLocation::CONTEXT: { |
| 1377 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | 1377 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); |
| 1378 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | 1378 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
| 1379 : "[ Stack variable"); | 1379 : "[ Stack variable"); |
| 1380 if (var->binding_needs_init()) { | 1380 if (NeedsHoleCheckForLoad(proxy)) { |
| 1381 // var->scope() may be NULL when the proxy is located in eval code and | 1381 // Let and const need a read barrier. |
| 1382 // refers to a potential outside binding. Currently those bindings are | 1382 Label done; |
| 1383 // always looked up dynamically, i.e. in that case | 1383 GetVar(eax, var); |
| 1384 // var->location() == LOOKUP. | 1384 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1385 // always holds. | 1385 __ j(not_equal, &done, Label::kNear); |
| 1386 DCHECK(var->scope() != NULL); | 1386 if (var->mode() == LET || var->mode() == CONST) { |
| 1387 | 1387 // Throw a reference error when using an uninitialized let/const |
| 1388 // Check if the binding really needs an initialization check. The check | 1388 // binding in harmony mode. |
| 1389 // can be skipped in the following situation: we have a LET or CONST | 1389 __ push(Immediate(var->name())); |
| 1390 // binding in harmony mode, both the Variable and the VariableProxy have | 1390 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1391 // the same declaration scope (i.e. they are both in global code, in the | |
| 1392 // same function or in the same eval code) and the VariableProxy is in | |
| 1393 // the source physically located after the initializer of the variable. | |
| 1394 // | |
| 1395 // We cannot skip any initialization checks for CONST in non-harmony | |
| 1396 // mode because const variables may be declared but never initialized: | |
| 1397 // if (false) { const x; }; var y = x; | |
| 1398 // | |
| 1399 // The condition on the declaration scopes is a conservative check for | |
| 1400 // nested functions that access a binding and are called before the | |
| 1401 // binding is initialized: | |
| 1402 // function() { f(); let x = 1; function f() { x = 2; } } | |
| 1403 // | |
| 1404 bool skip_init_check; | |
| 1405 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { | |
| 1406 skip_init_check = false; | |
| 1407 } else if (var->is_this()) { | |
| 1408 CHECK(info_->has_literal() && | |
| 1409 (info_->literal()->kind() & kSubclassConstructor) != 0); | |
| 1410 // TODO(dslomov): implement 'this' hole check elimination. | |
| 1411 skip_init_check = false; | |
| 1412 } else { | 1391 } else { |
| 1413 // Check that we always have valid source position. | 1392 // Uninitialized legacy const bindings are unholed. |
| 1414 DCHECK(var->initializer_position() != RelocInfo::kNoPosition); | 1393 DCHECK(var->mode() == CONST_LEGACY); |
| 1415 DCHECK(proxy->position() != RelocInfo::kNoPosition); | 1394 __ mov(eax, isolate()->factory()->undefined_value()); |
| 1416 skip_init_check = var->mode() != CONST_LEGACY && | |
| 1417 var->initializer_position() < proxy->position(); | |
| 1418 } | 1395 } |
| 1419 | 1396 __ bind(&done); |
| 1420 if (!skip_init_check) { | 1397 context()->Plug(eax); |
| 1421 // Let and const need a read barrier. | 1398 break; |
| 1422 Label done; | |
| 1423 GetVar(eax, var); | |
| 1424 __ cmp(eax, isolate()->factory()->the_hole_value()); | |
| 1425 __ j(not_equal, &done, Label::kNear); | |
| 1426 if (var->mode() == LET || var->mode() == CONST) { | |
| 1427 // Throw a reference error when using an uninitialized let/const | |
| 1428 // binding in harmony mode. | |
| 1429 __ push(Immediate(var->name())); | |
| 1430 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
| 1431 } else { | |
| 1432 // Uninitalized const bindings outside of harmony mode are unholed. | |
| 1433 DCHECK(var->mode() == CONST_LEGACY); | |
| 1434 __ mov(eax, isolate()->factory()->undefined_value()); | |
| 1435 } | |
| 1436 __ bind(&done); | |
| 1437 context()->Plug(eax); | |
| 1438 break; | |
| 1439 } | |
| 1440 } | 1399 } |
| 1441 context()->Plug(var); | 1400 context()->Plug(var); |
| 1442 break; | 1401 break; |
| 1443 } | 1402 } |
| 1444 | 1403 |
| 1445 case VariableLocation::LOOKUP: { | 1404 case VariableLocation::LOOKUP: { |
| 1446 Comment cmnt(masm_, "[ Lookup variable"); | 1405 Comment cmnt(masm_, "[ Lookup variable"); |
| 1447 Label done, slow; | 1406 Label done, slow; |
| 1448 // Generate code for loading from variables potentially shadowed | 1407 // Generate code for loading from variables potentially shadowed |
| 1449 // by eval-introduced variables. | 1408 // by eval-introduced variables. |
| (...skipping 3797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5247 Assembler::target_address_at(call_target_address, | 5206 Assembler::target_address_at(call_target_address, |
| 5248 unoptimized_code)); | 5207 unoptimized_code)); |
| 5249 return OSR_AFTER_STACK_CHECK; | 5208 return OSR_AFTER_STACK_CHECK; |
| 5250 } | 5209 } |
| 5251 | 5210 |
| 5252 | 5211 |
| 5253 } // namespace internal | 5212 } // namespace internal |
| 5254 } // namespace v8 | 5213 } // namespace v8 |
| 5255 | 5214 |
| 5256 #endif // V8_TARGET_ARCH_X87 | 5215 #endif // V8_TARGET_ARCH_X87 |
| OLD | NEW |