| 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/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/builtins/builtins-utils.h" | 8 #include "src/builtins/builtins-utils.h" |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/compilation-dependencies.h" | 10 #include "src/compilation-dependencies.h" |
| (...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 | 1915 |
| 1916 // ES6 section 21.1.3.1 String.prototype.charAt ( pos ) | 1916 // ES6 section 21.1.3.1 String.prototype.charAt ( pos ) |
| 1917 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { | 1917 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { |
| 1918 // We need at least target, receiver and index parameters. | 1918 // We need at least target, receiver and index parameters. |
| 1919 if (node->op()->ValueInputCount() >= 3) { | 1919 if (node->op()->ValueInputCount() >= 3) { |
| 1920 Node* index = NodeProperties::GetValueInput(node, 2); | 1920 Node* index = NodeProperties::GetValueInput(node, 2); |
| 1921 Type* index_type = NodeProperties::GetType(index); | 1921 Type* index_type = NodeProperties::GetType(index); |
| 1922 Node* effect = NodeProperties::GetEffectInput(node); | 1922 Node* effect = NodeProperties::GetEffectInput(node); |
| 1923 Node* control = NodeProperties::GetControlInput(node); | 1923 Node* control = NodeProperties::GetControlInput(node); |
| 1924 | 1924 |
| 1925 if (Node* receiver = GetStringWitness(node)) { | 1925 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
| 1926 if (isolate()->IsStringBoundsCheckIntact()) { | 1926 if (Node* receiver = GetStringWitness(node)) { |
| 1927 // Determine the {receiver} length. | |
| 1928 Node* receiver_length = effect = graph()->NewNode( | |
| 1929 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, | |
| 1930 effect, control); | |
| 1931 | |
| 1932 // Check that the {index} is within the range of {receiver}. | |
| 1933 index = effect = graph()->NewNode(simplified()->CheckBounds(), index, | |
| 1934 receiver_length, effect, control); | |
| 1935 | |
| 1936 // Return the character from the {receiver} as single character string. | |
| 1937 Node* value = graph()->NewNode(simplified()->StringCharAt(), receiver, | |
| 1938 index, control); | |
| 1939 | |
| 1940 ReplaceWithValue(node, value, effect, control); | |
| 1941 return Replace(value); | |
| 1942 } | |
| 1943 | |
| 1944 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { | |
| 1945 if (!index_type->Is(Type::Unsigned32())) { | 1927 if (!index_type->Is(Type::Unsigned32())) { |
| 1946 // Map -0 and NaN to 0 (as per ToInteger), and the values in | 1928 // Map -0 and NaN to 0 (as per ToInteger), and the values in |
| 1947 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will | 1929 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
| 1948 // be considered out-of-bounds as well, because of the maximal | 1930 // be considered out-of-bounds as well, because of the maximal |
| 1949 // String length limit in V8. | 1931 // String length limit in V8. |
| 1950 STATIC_ASSERT(String::kMaxLength <= kMaxInt); | 1932 STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
| 1951 index = graph()->NewNode(simplified()->NumberToUint32(), index); | 1933 index = graph()->NewNode(simplified()->NumberToUint32(), index); |
| 1952 } | 1934 } |
| 1953 | 1935 |
| 1954 // Determine the {receiver} length. | 1936 // Determine the {receiver} length. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 | 1969 |
| 1988 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) | 1970 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) |
| 1989 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { | 1971 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { |
| 1990 // We need at least target, receiver and index parameters. | 1972 // We need at least target, receiver and index parameters. |
| 1991 if (node->op()->ValueInputCount() >= 3) { | 1973 if (node->op()->ValueInputCount() >= 3) { |
| 1992 Node* index = NodeProperties::GetValueInput(node, 2); | 1974 Node* index = NodeProperties::GetValueInput(node, 2); |
| 1993 Type* index_type = NodeProperties::GetType(index); | 1975 Type* index_type = NodeProperties::GetType(index); |
| 1994 Node* effect = NodeProperties::GetEffectInput(node); | 1976 Node* effect = NodeProperties::GetEffectInput(node); |
| 1995 Node* control = NodeProperties::GetControlInput(node); | 1977 Node* control = NodeProperties::GetControlInput(node); |
| 1996 | 1978 |
| 1997 if (Node* receiver = GetStringWitness(node)) { | 1979 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { |
| 1998 if (isolate()->IsStringBoundsCheckIntact()) { | 1980 if (Node* receiver = GetStringWitness(node)) { |
| 1999 // Determine the {receiver} length. | |
| 2000 Node* receiver_length = effect = graph()->NewNode( | |
| 2001 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver, | |
| 2002 effect, control); | |
| 2003 | |
| 2004 // Check that the {index} is within the range of {receiver}. | |
| 2005 index = effect = graph()->NewNode(simplified()->CheckBounds(), index, | |
| 2006 receiver_length, effect, control); | |
| 2007 | |
| 2008 // Return the character from the {receiver} as character code. | |
| 2009 Node* value = graph()->NewNode(simplified()->StringCharCodeAt(), | |
| 2010 receiver, index, control); | |
| 2011 | |
| 2012 ReplaceWithValue(node, value, effect, control); | |
| 2013 return Replace(value); | |
| 2014 } | |
| 2015 | |
| 2016 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { | |
| 2017 if (!index_type->Is(Type::Unsigned32())) { | 1981 if (!index_type->Is(Type::Unsigned32())) { |
| 2018 // Map -0 and NaN to 0 (as per ToInteger), and the values in | 1982 // Map -0 and NaN to 0 (as per ToInteger), and the values in |
| 2019 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will | 1983 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will |
| 2020 // be considered out-of-bounds as well, because of the maximal | 1984 // be considered out-of-bounds as well, because of the maximal |
| 2021 // String length limit in V8. | 1985 // String length limit in V8. |
| 2022 STATIC_ASSERT(String::kMaxLength <= kMaxInt); | 1986 STATIC_ASSERT(String::kMaxLength <= kMaxInt); |
| 2023 index = graph()->NewNode(simplified()->NumberToUint32(), index); | 1987 index = graph()->NewNode(simplified()->NumberToUint32(), index); |
| 2024 } | 1988 } |
| 2025 | 1989 |
| 2026 // Determine the {receiver} length. | 1990 // Determine the {receiver} length. |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2563 return jsgraph()->simplified(); | 2527 return jsgraph()->simplified(); |
| 2564 } | 2528 } |
| 2565 | 2529 |
| 2566 JSOperatorBuilder* JSBuiltinReducer::javascript() const { | 2530 JSOperatorBuilder* JSBuiltinReducer::javascript() const { |
| 2567 return jsgraph()->javascript(); | 2531 return jsgraph()->javascript(); |
| 2568 } | 2532 } |
| 2569 | 2533 |
| 2570 } // namespace compiler | 2534 } // namespace compiler |
| 2571 } // namespace internal | 2535 } // namespace internal |
| 2572 } // namespace v8 | 2536 } // namespace v8 |
| OLD | NEW |