OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 | 6 |
7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 | 1515 |
1516 // ES6 section 21.1.3.1 String.prototype.charAt ( pos ) | 1516 // ES6 section 21.1.3.1 String.prototype.charAt ( pos ) |
1517 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { | 1517 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { |
1518 // We need at least target, receiver and index parameters. | 1518 // We need at least target, receiver and index parameters. |
1519 if (node->op()->ValueInputCount() >= 3) { | 1519 if (node->op()->ValueInputCount() >= 3) { |
1520 Node* index = NodeProperties::GetValueInput(node, 2); | 1520 Node* index = NodeProperties::GetValueInput(node, 2); |
1521 Type* index_type = NodeProperties::GetType(index); | 1521 Type* index_type = NodeProperties::GetType(index); |
1522 Node* effect = NodeProperties::GetEffectInput(node); | 1522 Node* effect = NodeProperties::GetEffectInput(node); |
1523 Node* control = NodeProperties::GetControlInput(node); | 1523 Node* control = NodeProperties::GetControlInput(node); |
1524 | 1524 |
1525 if (index_type->Is(Type::Unsigned32())) { | 1525 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
1526 if (Node* receiver = GetStringWitness(node)) { | 1526 if (Node* receiver = GetStringWitness(node)) { |
| 1527 if (!index_type->Is(Type::Unsigned32())) { |
| 1528 // Map -0 and NaN to 0 (as per ToInteger), and the values in |
| 1529 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
| 1530 // be considered out-of-bounds as well, because of the maximal |
| 1531 // String length limit in V8. |
| 1532 STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
| 1533 index = graph()->NewNode(simplified()->NumberToUint32(), index); |
| 1534 } |
| 1535 |
1527 // Determine the {receiver} length. | 1536 // Determine the {receiver} length. |
1528 Node* receiver_length = effect = graph()->NewNode( | 1537 Node* receiver_length = effect = graph()->NewNode( |
1529 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, | 1538 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, |
1530 effect, control); | 1539 effect, control); |
1531 | 1540 |
1532 // Check if {index} is less than {receiver} length. | 1541 // Check if {index} is less than {receiver} length. |
1533 Node* check = graph()->NewNode(simplified()->NumberLessThan(), index, | 1542 Node* check = graph()->NewNode(simplified()->NumberLessThan(), index, |
1534 receiver_length); | 1543 receiver_length); |
1535 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), | 1544 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), |
1536 check, control); | 1545 check, control); |
(...skipping 23 matching lines...) Expand all Loading... |
1560 | 1569 |
1561 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) | 1570 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) |
1562 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { | 1571 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { |
1563 // We need at least target, receiver and index parameters. | 1572 // We need at least target, receiver and index parameters. |
1564 if (node->op()->ValueInputCount() >= 3) { | 1573 if (node->op()->ValueInputCount() >= 3) { |
1565 Node* index = NodeProperties::GetValueInput(node, 2); | 1574 Node* index = NodeProperties::GetValueInput(node, 2); |
1566 Type* index_type = NodeProperties::GetType(index); | 1575 Type* index_type = NodeProperties::GetType(index); |
1567 Node* effect = NodeProperties::GetEffectInput(node); | 1576 Node* effect = NodeProperties::GetEffectInput(node); |
1568 Node* control = NodeProperties::GetControlInput(node); | 1577 Node* control = NodeProperties::GetControlInput(node); |
1569 | 1578 |
1570 if (index_type->Is(Type::Unsigned32())) { | 1579 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
1571 if (Node* receiver = GetStringWitness(node)) { | 1580 if (Node* receiver = GetStringWitness(node)) { |
| 1581 if (!index_type->Is(Type::Unsigned32())) { |
| 1582 // Map -0 and NaN to 0 (as per ToInteger), and the values in |
| 1583 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
| 1584 // be considered out-of-bounds as well, because of the maximal |
| 1585 // String length limit in V8. |
| 1586 STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
| 1587 index = graph()->NewNode(simplified()->NumberToUint32(), index); |
| 1588 } |
| 1589 |
1572 // Determine the {receiver} length. | 1590 // Determine the {receiver} length. |
1573 Node* receiver_length = effect = graph()->NewNode( | 1591 Node* receiver_length = effect = graph()->NewNode( |
1574 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, | 1592 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, |
1575 effect, control); | 1593 effect, control); |
1576 | 1594 |
1577 // Check if {index} is less than {receiver} length. | 1595 // Check if {index} is less than {receiver} length. |
1578 Node* check = graph()->NewNode(simplified()->NumberLessThan(), index, | 1596 Node* check = graph()->NewNode(simplified()->NumberLessThan(), index, |
1579 receiver_length); | 1597 receiver_length); |
1580 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), | 1598 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), |
1581 check, control); | 1599 check, control); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 return jsgraph()->simplified(); | 2055 return jsgraph()->simplified(); |
2038 } | 2056 } |
2039 | 2057 |
2040 JSOperatorBuilder* JSBuiltinReducer::javascript() const { | 2058 JSOperatorBuilder* JSBuiltinReducer::javascript() const { |
2041 return jsgraph()->javascript(); | 2059 return jsgraph()->javascript(); |
2042 } | 2060 } |
2043 | 2061 |
2044 } // namespace compiler | 2062 } // namespace compiler |
2045 } // namespace internal | 2063 } // namespace internal |
2046 } // namespace v8 | 2064 } // namespace v8 |
OLD | NEW |