OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/regexp/regexp-utils.h" | 9 #include "src/regexp/regexp-utils.h" |
10 | 10 |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 Node* const start_int = | 964 Node* const start_int = |
965 a.ToInteger(context, start, CodeStubAssembler::kTruncateMinusZero); | 965 a.ToInteger(context, start, CodeStubAssembler::kTruncateMinusZero); |
966 | 966 |
967 Label if_issmi(&a), if_isheapnumber(&a, Label::kDeferred); | 967 Label if_issmi(&a), if_isheapnumber(&a, Label::kDeferred); |
968 a.Branch(a.TaggedIsSmi(start_int), &if_issmi, &if_isheapnumber); | 968 a.Branch(a.TaggedIsSmi(start_int), &if_issmi, &if_isheapnumber); |
969 | 969 |
970 a.Bind(&if_issmi); | 970 a.Bind(&if_issmi); |
971 { | 971 { |
972 Node* const length_plus_start = a.SmiAdd(string_length, start_int); | 972 Node* const length_plus_start = a.SmiAdd(string_length, start_int); |
973 var_start.Bind(a.Select(a.SmiLessThan(start_int, zero), | 973 var_start.Bind(a.Select(a.SmiLessThan(start_int, zero), |
974 a.SmiMax(length_plus_start, zero), start_int)); | 974 [&] { return a.SmiMax(length_plus_start, zero); }, |
| 975 [&] { return start_int; }, |
| 976 MachineRepresentation::kTagged)); |
975 a.Goto(&handle_length); | 977 a.Goto(&handle_length); |
976 } | 978 } |
977 | 979 |
978 a.Bind(&if_isheapnumber); | 980 a.Bind(&if_isheapnumber); |
979 { | 981 { |
980 // If {start} is a heap number, it is definitely out of bounds. If it is | 982 // If {start} is a heap number, it is definitely out of bounds. If it is |
981 // negative, {start} = max({string_length} + {start}),0) = 0'. If it is | 983 // negative, {start} = max({string_length} + {start}),0) = 0'. If it is |
982 // positive, set {start} to {string_length} which ultimately results in | 984 // positive, set {start} to {string_length} which ultimately results in |
983 // returning an empty string. | 985 // returning an empty string. |
984 Node* const float_zero = a.Float64Constant(0.); | 986 Node* const float_zero = a.Float64Constant(0.); |
985 Node* const start_float = a.LoadHeapNumberValue(start_int); | 987 Node* const start_float = a.LoadHeapNumberValue(start_int); |
986 var_start.Bind(a.Select(a.Float64LessThan(start_float, float_zero), zero, | 988 var_start.Bind(a.SelectTaggedConstant( |
987 string_length)); | 989 a.Float64LessThan(start_float, float_zero), zero, string_length)); |
988 a.Goto(&handle_length); | 990 a.Goto(&handle_length); |
989 } | 991 } |
990 } | 992 } |
991 | 993 |
992 // Conversions and bounds-checks for {length}. | 994 // Conversions and bounds-checks for {length}. |
993 a.Bind(&handle_length); | 995 a.Bind(&handle_length); |
994 { | 996 { |
995 Label if_issmi(&a), if_isheapnumber(&a, Label::kDeferred); | 997 Label if_issmi(&a), if_isheapnumber(&a, Label::kDeferred); |
996 | 998 |
997 // Default to {string_length} if {length} is undefined. | 999 // Default to {string_length} if {length} is undefined. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1085 |
1084 a->Bind(&if_isinbounds); | 1086 a->Bind(&if_isinbounds); |
1085 { | 1087 { |
1086 var_result.Bind(value_int); | 1088 var_result.Bind(value_int); |
1087 a->Goto(&out); | 1089 a->Goto(&out); |
1088 } | 1090 } |
1089 | 1091 |
1090 a->Bind(&if_isoutofbounds); | 1092 a->Bind(&if_isoutofbounds); |
1091 { | 1093 { |
1092 Node* const zero = a->SmiConstant(Smi::kZero); | 1094 Node* const zero = a->SmiConstant(Smi::kZero); |
1093 var_result.Bind(a->Select(a->SmiLessThan(value_int, zero), zero, limit)); | 1095 var_result.Bind(a->SelectTaggedConstant(a->SmiLessThan(value_int, zero), |
| 1096 zero, limit)); |
1094 a->Goto(&out); | 1097 a->Goto(&out); |
1095 } | 1098 } |
1096 } | 1099 } |
1097 | 1100 |
1098 a->Bind(&if_isnotsmi); | 1101 a->Bind(&if_isnotsmi); |
1099 { | 1102 { |
1100 // {value} is a heap number - in this case, it is definitely out of bounds. | 1103 // {value} is a heap number - in this case, it is definitely out of bounds. |
1101 CSA_ASSERT(a, a->IsHeapNumberMap(a->LoadMap(value_int))); | 1104 CSA_ASSERT(a, a->IsHeapNumberMap(a->LoadMap(value_int))); |
1102 | 1105 |
1103 Node* const float_zero = a->Float64Constant(0.); | 1106 Node* const float_zero = a->Float64Constant(0.); |
1104 Node* const smi_zero = a->SmiConstant(Smi::kZero); | 1107 Node* const smi_zero = a->SmiConstant(Smi::kZero); |
1105 Node* const value_float = a->LoadHeapNumberValue(value_int); | 1108 Node* const value_float = a->LoadHeapNumberValue(value_int); |
1106 var_result.Bind(a->Select(a->Float64LessThan(value_float, float_zero), | 1109 var_result.Bind(a->SelectTaggedConstant( |
1107 smi_zero, limit)); | 1110 a->Float64LessThan(value_float, float_zero), smi_zero, limit)); |
1108 a->Goto(&out); | 1111 a->Goto(&out); |
1109 } | 1112 } |
1110 | 1113 |
1111 a->Bind(&out); | 1114 a->Bind(&out); |
1112 return var_result.value(); | 1115 return var_result.value(); |
1113 } | 1116 } |
1114 | 1117 |
1115 } // namespace | 1118 } // namespace |
1116 | 1119 |
1117 // ES6 section 21.1.3.19 String.prototype.substring ( start, end ) | 1120 // ES6 section 21.1.3.19 String.prototype.substring ( start, end ) |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 Runtime::kThrowIncompatibleMethodReceiver, context, | 1461 Runtime::kThrowIncompatibleMethodReceiver, context, |
1459 assembler.HeapConstant(assembler.factory()->NewStringFromAsciiChecked( | 1462 assembler.HeapConstant(assembler.factory()->NewStringFromAsciiChecked( |
1460 "String Iterator.prototype.next", TENURED)), | 1463 "String Iterator.prototype.next", TENURED)), |
1461 iterator); | 1464 iterator); |
1462 assembler.Return(result); // Never reached. | 1465 assembler.Return(result); // Never reached. |
1463 } | 1466 } |
1464 } | 1467 } |
1465 | 1468 |
1466 } // namespace internal | 1469 } // namespace internal |
1467 } // namespace v8 | 1470 } // namespace v8 |
OLD | NEW |