OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-info.h" | 10 #include "src/compilation-info.h" |
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1485 // Load the "prototype" from the constructor. | 1485 // Load the "prototype" from the constructor. |
1486 register_allocator()->PrepareForConsecutiveAllocations(2); | 1486 register_allocator()->PrepareForConsecutiveAllocations(2); |
1487 Register literal = register_allocator()->NextConsecutiveRegister(); | 1487 Register literal = register_allocator()->NextConsecutiveRegister(); |
1488 Register prototype = register_allocator()->NextConsecutiveRegister(); | 1488 Register prototype = register_allocator()->NextConsecutiveRegister(); |
1489 FeedbackVectorSlot slot = expr->PrototypeSlot(); | 1489 FeedbackVectorSlot slot = expr->PrototypeSlot(); |
1490 builder() | 1490 builder() |
1491 ->StoreAccumulatorInRegister(literal) | 1491 ->StoreAccumulatorInRegister(literal) |
1492 .LoadNamedProperty(literal, prototype_string(), feedback_index(slot)) | 1492 .LoadNamedProperty(literal, prototype_string(), feedback_index(slot)) |
1493 .StoreAccumulatorInRegister(prototype); | 1493 .StoreAccumulatorInRegister(prototype); |
1494 | 1494 |
1495 // TODO(bakkot) This shouldn't be necessary; I just couldn't figure out how to | |
1496 // invoke the function literal with appropriate home object and receiver | |
1497 // (mainly because of FeedbackVector check failures which are totally opaque | |
1498 // to me) | |
Dan Ehrenberg
2016/09/10 04:06:54
Seems OK; it'd be good to note that this is motiva
bakkot
2016/09/12 23:05:15
Added a more reasonable comment mentioning that th
| |
1499 VariableProxy* static_initializer_proxy = expr->static_initializer_proxy(); | |
1500 if (static_initializer_proxy != nullptr) { | |
1501 Variable* variable = static_initializer_proxy->var(); | |
1502 builder()->LoadAccumulatorWithRegister(literal); | |
1503 VisitVariableAssignment(variable, Token::INIT, // TODO(bakkot) tokens | |
Dan Ehrenberg
2016/09/10 04:06:54
What is this TODO?
bakkot
2016/09/12 23:05:15
Oh, I just wasn't sure if Token::INIT or Token::AS
| |
1504 FeedbackVectorSlot::Invalid()); | |
1505 } | |
1506 | |
1495 VisitClassLiteralProperties(expr, literal, prototype); | 1507 VisitClassLiteralProperties(expr, literal, prototype); |
1496 builder()->CallRuntime(Runtime::kToFastProperties, literal, 1); | 1508 builder()->CallRuntime(Runtime::kToFastProperties, literal, 1); |
1497 // Assign to class variable. | 1509 // Assign to class variable. |
1498 if (expr->class_variable_proxy() != nullptr) { | 1510 if (expr->class_variable_proxy() != nullptr) { |
1499 Variable* var = expr->class_variable_proxy()->var(); | 1511 Variable* var = expr->class_variable_proxy()->var(); |
1500 FeedbackVectorSlot slot = expr->NeedsProxySlot() | 1512 FeedbackVectorSlot slot = expr->NeedsProxySlot() |
1501 ? expr->ProxySlot() | 1513 ? expr->ProxySlot() |
1502 : FeedbackVectorSlot::Invalid(); | 1514 : FeedbackVectorSlot::Invalid(); |
1503 VisitVariableAssignment(var, Token::INIT, slot); | 1515 VisitVariableAssignment(var, Token::INIT, slot); |
1504 } | 1516 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1539 Register attr = register_allocator()->NextConsecutiveRegister(); | 1551 Register attr = register_allocator()->NextConsecutiveRegister(); |
1540 Register set_function_name = register_allocator()->NextConsecutiveRegister(); | 1552 Register set_function_name = register_allocator()->NextConsecutiveRegister(); |
1541 | 1553 |
1542 bool attr_assigned = false; | 1554 bool attr_assigned = false; |
1543 Register old_receiver = Register::invalid_value(); | 1555 Register old_receiver = Register::invalid_value(); |
1544 | 1556 |
1545 // Create nodes to store method values into the literal. | 1557 // Create nodes to store method values into the literal. |
1546 for (int i = 0; i < expr->properties()->length(); i++) { | 1558 for (int i = 0; i < expr->properties()->length(); i++) { |
1547 ClassLiteral::Property* property = expr->properties()->at(i); | 1559 ClassLiteral::Property* property = expr->properties()->at(i); |
1548 | 1560 |
1561 if (property->kind() == ClassLiteral::Property::FIELD && | |
1562 !property->is_static()) { | |
1563 // This just does the ToName call on the field name and stores it in a | |
Dan Ehrenberg
2016/09/10 04:06:54
Was Melissa O'Neill at Mudd when you went there? O
bakkot
2016/09/12 23:05:15
I've written a more reasonable if slightly wordy c
| |
1564 // variable (a proxy for which is the value() of this property) | |
1565 DCHECK(property->value()->IsVariableProxy()); | |
1566 Variable* variable = property->value()->AsVariableProxy()->var(); | |
1567 VisitForAccumulatorValue(property->key()); | |
1568 VisitVariableAssignment(variable, Token::INIT, | |
1569 FeedbackVectorSlot::Invalid()); | |
1570 continue; | |
1571 } | |
1572 | |
1549 // Set-up receiver. | 1573 // Set-up receiver. |
1550 Register new_receiver = property->is_static() ? literal : prototype; | 1574 Register new_receiver = property->is_static() ? literal : prototype; |
1551 if (new_receiver != old_receiver) { | 1575 if (new_receiver != old_receiver) { |
1552 builder()->MoveRegister(new_receiver, receiver); | 1576 builder()->MoveRegister(new_receiver, receiver); |
1553 old_receiver = new_receiver; | 1577 old_receiver = new_receiver; |
1554 } | 1578 } |
1555 | 1579 |
1556 VisitForAccumulatorValue(property->key()); | 1580 VisitForAccumulatorValue(property->key()); |
1557 builder()->ConvertAccumulatorToName(key); | 1581 builder()->ConvertAccumulatorToName(key); |
1558 // The static prototype property is read only. We handle the non computed | 1582 // The static prototype property is read only. We handle the non computed |
(...skipping 28 matching lines...) Expand all Loading... | |
1587 builder()->CallRuntime(Runtime::kDefineGetterPropertyUnchecked, | 1611 builder()->CallRuntime(Runtime::kDefineGetterPropertyUnchecked, |
1588 receiver, 4); | 1612 receiver, 4); |
1589 break; | 1613 break; |
1590 } | 1614 } |
1591 case ClassLiteral::Property::SETTER: { | 1615 case ClassLiteral::Property::SETTER: { |
1592 builder()->CallRuntime(Runtime::kDefineSetterPropertyUnchecked, | 1616 builder()->CallRuntime(Runtime::kDefineSetterPropertyUnchecked, |
1593 receiver, 4); | 1617 receiver, 4); |
1594 break; | 1618 break; |
1595 } | 1619 } |
1596 case ClassLiteral::Property::FIELD: { | 1620 case ClassLiteral::Property::FIELD: { |
1597 UNREACHABLE(); | 1621 DCHECK(property->is_static()); |
1622 builder() | |
1623 ->LoadLiteral(Smi::FromInt(property->NeedsSetFunctionName())) | |
1624 .StoreAccumulatorInRegister(set_function_name); | |
1625 builder()->CallRuntime(Runtime::kDefineDataPropertyInLiteral, receiver, | |
1626 5); | |
1598 break; | 1627 break; |
1599 } | 1628 } |
1600 } | 1629 } |
1601 } | 1630 } |
1602 } | 1631 } |
1603 | 1632 |
1604 void BytecodeGenerator::VisitClassLiteralStaticPrototypeWithComputedName( | 1633 void BytecodeGenerator::VisitClassLiteralStaticPrototypeWithComputedName( |
1605 Register key) { | 1634 Register key) { |
1606 BytecodeLabel done; | 1635 BytecodeLabel done; |
1607 builder() | 1636 builder() |
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3391 return execution_context()->scope()->language_mode(); | 3420 return execution_context()->scope()->language_mode(); |
3392 } | 3421 } |
3393 | 3422 |
3394 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3423 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3395 return TypeFeedbackVector::GetIndex(slot); | 3424 return TypeFeedbackVector::GetIndex(slot); |
3396 } | 3425 } |
3397 | 3426 |
3398 } // namespace interpreter | 3427 } // namespace interpreter |
3399 } // namespace internal | 3428 } // namespace internal |
3400 } // namespace v8 | 3429 } // namespace v8 |
OLD | NEW |