Index: src/compiler/js-builtin-reducer.cc |
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc |
index 96a8ae79704006fc06ff9959b362be89d7222727..1a6d09eee89cac3b727e22c34eb290f7ee809455 100644 |
--- a/src/compiler/js-builtin-reducer.cc |
+++ b/src/compiler/js-builtin-reducer.cc |
@@ -1522,8 +1522,17 @@ Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { |
Node* effect = NodeProperties::GetEffectInput(node); |
Node* control = NodeProperties::GetControlInput(node); |
- if (index_type->Is(Type::Unsigned32())) { |
+ if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
if (Node* receiver = GetStringWitness(node)) { |
+ if (!index_type->Is(Type::Unsigned32())) { |
+ // Map -0 and NaN to 0 (as per ToInteger), and the values in |
+ // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
+ // be considered out-of-bounds as well, because of the maximal |
+ // String length limit in V8. |
+ STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
+ index = graph()->NewNode(simplified()->NumberToUint32(), index); |
+ } |
+ |
// Determine the {receiver} length. |
Node* receiver_length = effect = graph()->NewNode( |
simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, |
@@ -1567,8 +1576,17 @@ Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { |
Node* effect = NodeProperties::GetEffectInput(node); |
Node* control = NodeProperties::GetControlInput(node); |
- if (index_type->Is(Type::Unsigned32())) { |
+ if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
if (Node* receiver = GetStringWitness(node)) { |
+ if (!index_type->Is(Type::Unsigned32())) { |
+ // Map -0 and NaN to 0 (as per ToInteger), and the values in |
+ // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
+ // be considered out-of-bounds as well, because of the maximal |
+ // String length limit in V8. |
+ STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
+ index = graph()->NewNode(simplified()->NumberToUint32(), index); |
+ } |
+ |
// Determine the {receiver} length. |
Node* receiver_length = effect = graph()->NewNode( |
simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, |