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 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // and provide the proper functionality, so this is just a fallback. | 798 // and provide the proper functionality, so this is just a fallback. |
799 BUILTIN(StringPrototypeLocaleCompare) { | 799 BUILTIN(StringPrototypeLocaleCompare) { |
800 HandleScope handle_scope(isolate); | 800 HandleScope handle_scope(isolate); |
801 DCHECK_EQ(2, args.length()); | 801 DCHECK_EQ(2, args.length()); |
802 | 802 |
803 TO_THIS_STRING(str1, "String.prototype.localeCompare"); | 803 TO_THIS_STRING(str1, "String.prototype.localeCompare"); |
804 Handle<String> str2; | 804 Handle<String> str2; |
805 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 805 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
806 isolate, str2, Object::ToString(isolate, args.at<Object>(1))); | 806 isolate, str2, Object::ToString(isolate, args.at<Object>(1))); |
807 | 807 |
808 if (str1.is_identical_to(str2)) return Smi::FromInt(0); // Equal. | 808 if (str1.is_identical_to(str2)) return Smi::kZero; // Equal. |
809 int str1_length = str1->length(); | 809 int str1_length = str1->length(); |
810 int str2_length = str2->length(); | 810 int str2_length = str2->length(); |
811 | 811 |
812 // Decide trivial cases without flattening. | 812 // Decide trivial cases without flattening. |
813 if (str1_length == 0) { | 813 if (str1_length == 0) { |
814 if (str2_length == 0) return Smi::FromInt(0); // Equal. | 814 if (str2_length == 0) return Smi::kZero; // Equal. |
815 return Smi::FromInt(-str2_length); | 815 return Smi::FromInt(-str2_length); |
816 } else { | 816 } else { |
817 if (str2_length == 0) return Smi::FromInt(str1_length); | 817 if (str2_length == 0) return Smi::FromInt(str1_length); |
818 } | 818 } |
819 | 819 |
820 int end = str1_length < str2_length ? str1_length : str2_length; | 820 int end = str1_length < str2_length ? str1_length : str2_length; |
821 | 821 |
822 // No need to flatten if we are going to find the answer on the first | 822 // No need to flatten if we are going to find the answer on the first |
823 // character. At this point we know there is at least one character | 823 // character. At this point we know there is at least one character |
824 // in each string, due to the trivial case handling above. | 824 // in each string, due to the trivial case handling above. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 Label out(a), handle_length(a); | 884 Label out(a), handle_length(a); |
885 | 885 |
886 Variable var_start(a, MachineRepresentation::kTagged); | 886 Variable var_start(a, MachineRepresentation::kTagged); |
887 Variable var_length(a, MachineRepresentation::kTagged); | 887 Variable var_length(a, MachineRepresentation::kTagged); |
888 | 888 |
889 Node* const receiver = a->Parameter(0); | 889 Node* const receiver = a->Parameter(0); |
890 Node* const start = a->Parameter(1); | 890 Node* const start = a->Parameter(1); |
891 Node* const length = a->Parameter(2); | 891 Node* const length = a->Parameter(2); |
892 Node* const context = a->Parameter(5); | 892 Node* const context = a->Parameter(5); |
893 | 893 |
894 Node* const zero = a->SmiConstant(Smi::FromInt(0)); | 894 Node* const zero = a->SmiConstant(Smi::kZero); |
895 | 895 |
896 // Check that {receiver} is coercible to Object and convert it to a String. | 896 // Check that {receiver} is coercible to Object and convert it to a String. |
897 Node* const string = | 897 Node* const string = |
898 a->ToThisString(context, receiver, "String.prototype.substr"); | 898 a->ToThisString(context, receiver, "String.prototype.substr"); |
899 | 899 |
900 Node* const string_length = a->LoadStringLength(string); | 900 Node* const string_length = a->LoadStringLength(string); |
901 | 901 |
902 // Conversions and bounds-checks for {start}. | 902 // Conversions and bounds-checks for {start}. |
903 { | 903 { |
904 Node* const start_int = | 904 Node* const start_int = |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 a->Branch(a->SmiAbove(value_int, limit), &if_isoutofbounds, &if_isinbounds); | 1023 a->Branch(a->SmiAbove(value_int, limit), &if_isoutofbounds, &if_isinbounds); |
1024 | 1024 |
1025 a->Bind(&if_isinbounds); | 1025 a->Bind(&if_isinbounds); |
1026 { | 1026 { |
1027 var_result.Bind(value_int); | 1027 var_result.Bind(value_int); |
1028 a->Goto(&out); | 1028 a->Goto(&out); |
1029 } | 1029 } |
1030 | 1030 |
1031 a->Bind(&if_isoutofbounds); | 1031 a->Bind(&if_isoutofbounds); |
1032 { | 1032 { |
1033 Node* const zero = a->SmiConstant(Smi::FromInt(0)); | 1033 Node* const zero = a->SmiConstant(Smi::kZero); |
1034 var_result.Bind(a->Select(a->SmiLessThan(value_int, zero), zero, limit)); | 1034 var_result.Bind(a->Select(a->SmiLessThan(value_int, zero), zero, limit)); |
1035 a->Goto(&out); | 1035 a->Goto(&out); |
1036 } | 1036 } |
1037 } | 1037 } |
1038 | 1038 |
1039 a->Bind(&if_isnotsmi); | 1039 a->Bind(&if_isnotsmi); |
1040 { | 1040 { |
1041 // {value} is a heap number - in this case, it is definitely out of bounds. | 1041 // {value} is a heap number - in this case, it is definitely out of bounds. |
1042 a->Assert(a->WordEqual(a->LoadMap(value_int), a->HeapNumberMapConstant())); | 1042 a->Assert(a->WordEqual(a->LoadMap(value_int), a->HeapNumberMapConstant())); |
1043 | 1043 |
1044 Node* const float_zero = a->Float64Constant(0.); | 1044 Node* const float_zero = a->Float64Constant(0.); |
1045 Node* const smi_zero = a->SmiConstant(Smi::FromInt(0)); | 1045 Node* const smi_zero = a->SmiConstant(Smi::kZero); |
1046 Node* const value_float = a->LoadHeapNumberValue(value_int); | 1046 Node* const value_float = a->LoadHeapNumberValue(value_int); |
1047 var_result.Bind(a->Select(a->Float64LessThan(value_float, float_zero), | 1047 var_result.Bind(a->Select(a->Float64LessThan(value_float, float_zero), |
1048 smi_zero, limit)); | 1048 smi_zero, limit)); |
1049 a->Goto(&out); | 1049 a->Goto(&out); |
1050 } | 1050 } |
1051 | 1051 |
1052 a->Bind(&out); | 1052 a->Bind(&out); |
1053 return var_result.value(); | 1053 return var_result.value(); |
1054 } | 1054 } |
1055 | 1055 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 assembler->IntPtrConstant(Context::STRING_ITERATOR_MAP_INDEX), 0, | 1168 assembler->IntPtrConstant(Context::STRING_ITERATOR_MAP_INDEX), 0, |
1169 CodeStubAssembler::INTPTR_PARAMETERS); | 1169 CodeStubAssembler::INTPTR_PARAMETERS); |
1170 Node* iterator = assembler->Allocate(JSStringIterator::kSize); | 1170 Node* iterator = assembler->Allocate(JSStringIterator::kSize); |
1171 assembler->StoreMapNoWriteBarrier(iterator, map); | 1171 assembler->StoreMapNoWriteBarrier(iterator, map); |
1172 assembler->StoreObjectFieldRoot(iterator, JSValue::kPropertiesOffset, | 1172 assembler->StoreObjectFieldRoot(iterator, JSValue::kPropertiesOffset, |
1173 Heap::kEmptyFixedArrayRootIndex); | 1173 Heap::kEmptyFixedArrayRootIndex); |
1174 assembler->StoreObjectFieldRoot(iterator, JSObject::kElementsOffset, | 1174 assembler->StoreObjectFieldRoot(iterator, JSObject::kElementsOffset, |
1175 Heap::kEmptyFixedArrayRootIndex); | 1175 Heap::kEmptyFixedArrayRootIndex); |
1176 assembler->StoreObjectFieldNoWriteBarrier( | 1176 assembler->StoreObjectFieldNoWriteBarrier( |
1177 iterator, JSStringIterator::kStringOffset, string); | 1177 iterator, JSStringIterator::kStringOffset, string); |
1178 Node* index = assembler->SmiConstant(Smi::FromInt(0)); | 1178 Node* index = assembler->SmiConstant(Smi::kZero); |
1179 assembler->StoreObjectFieldNoWriteBarrier( | 1179 assembler->StoreObjectFieldNoWriteBarrier( |
1180 iterator, JSStringIterator::kNextIndexOffset, index); | 1180 iterator, JSStringIterator::kNextIndexOffset, index); |
1181 assembler->Return(iterator); | 1181 assembler->Return(iterator); |
1182 } | 1182 } |
1183 | 1183 |
1184 namespace { | 1184 namespace { |
1185 | 1185 |
1186 // Return the |word32| codepoint at {index}. Supports SeqStrings and | 1186 // Return the |word32| codepoint at {index}. Supports SeqStrings and |
1187 // ExternalStrings. | 1187 // ExternalStrings. |
1188 compiler::Node* LoadSurrogatePairInternal(CodeStubAssembler* assembler, | 1188 compiler::Node* LoadSurrogatePairInternal(CodeStubAssembler* assembler, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 Runtime::kThrowIncompatibleMethodReceiver, context, | 1341 Runtime::kThrowIncompatibleMethodReceiver, context, |
1342 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( | 1342 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( |
1343 "String Iterator.prototype.next", TENURED)), | 1343 "String Iterator.prototype.next", TENURED)), |
1344 iterator); | 1344 iterator); |
1345 assembler->Return(result); // Never reached. | 1345 assembler->Return(result); // Never reached. |
1346 } | 1346 } |
1347 } | 1347 } |
1348 | 1348 |
1349 } // namespace internal | 1349 } // namespace internal |
1350 } // namespace v8 | 1350 } // namespace v8 |
OLD | NEW |