| 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 | 5 |
| 6 #ifdef V8_I18N_SUPPORT | 6 #ifdef V8_I18N_SUPPORT |
| 7 #include "src/runtime/runtime-utils.h" | 7 #include "src/runtime/runtime-utils.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 namespace { | 824 namespace { |
| 825 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, | 825 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, |
| 826 bool is_to_upper, const char* lang) { | 826 bool is_to_upper, const char* lang) { |
| 827 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; | 827 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; |
| 828 int32_t src_length = s->length(); | 828 int32_t src_length = s->length(); |
| 829 int32_t dest_length = src_length; | 829 int32_t dest_length = src_length; |
| 830 UErrorCode status; | 830 UErrorCode status; |
| 831 Handle<SeqTwoByteString> result; | 831 Handle<SeqTwoByteString> result; |
| 832 std::unique_ptr<uc16[]> sap; | 832 std::unique_ptr<uc16[]> sap; |
| 833 | 833 |
| 834 if (dest_length == 0) return isolate->heap()->empty_string(); |
| 835 |
| 834 // This is not a real loop. It'll be executed only once (no overflow) or | 836 // This is not a real loop. It'll be executed only once (no overflow) or |
| 835 // twice (overflow). | 837 // twice (overflow). |
| 836 for (int i = 0; i < 2; ++i) { | 838 for (int i = 0; i < 2; ++i) { |
| 837 // Case conversion can increase the string length (e.g. sharp-S => SS) so | 839 // Case conversion can increase the string length (e.g. sharp-S => SS) so |
| 838 // that we have to handle RangeError exceptions here. | 840 // that we have to handle RangeError exceptions here. |
| 839 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 841 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 840 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); | 842 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); |
| 841 DisallowHeapAllocation no_gc; | 843 DisallowHeapAllocation no_gc; |
| 842 DCHECK(s->IsFlat()); | 844 DCHECK(s->IsFlat()); |
| 843 String::FlatContent flat = s->GetFlatContent(); | 845 String::FlatContent flat = s->GetFlatContent(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 for (int index = index_to_first_unprocessed; index < length; ++index) { | 1036 for (int index = index_to_first_unprocessed; index < length; ++index) { |
| 1035 dest[index] = ToLatin1Lower(static_cast<uint16_t>(src[index])); | 1037 dest[index] = ToLatin1Lower(static_cast<uint16_t>(src[index])); |
| 1036 } | 1038 } |
| 1037 } | 1039 } |
| 1038 | 1040 |
| 1039 return *result; | 1041 return *result; |
| 1040 } | 1042 } |
| 1041 | 1043 |
| 1042 MUST_USE_RESULT Object* ConvertToUpper(Handle<String> s, Isolate* isolate) { | 1044 MUST_USE_RESULT Object* ConvertToUpper(Handle<String> s, Isolate* isolate) { |
| 1043 int32_t length = s->length(); | 1045 int32_t length = s->length(); |
| 1044 if (s->HasOnlyOneByteChars()) { | 1046 if (s->HasOnlyOneByteChars() && length > 0) { |
| 1045 Handle<SeqOneByteString> result = | 1047 Handle<SeqOneByteString> result = |
| 1046 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); | 1048 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); |
| 1047 | 1049 |
| 1048 DCHECK(s->IsFlat()); | 1050 DCHECK(s->IsFlat()); |
| 1049 int sharp_s_count; | 1051 int sharp_s_count; |
| 1050 bool is_result_single_byte; | 1052 bool is_result_single_byte; |
| 1051 { | 1053 { |
| 1052 DisallowHeapAllocation no_gc; | 1054 DisallowHeapAllocation no_gc; |
| 1053 String::FlatContent flat = s->GetFlatContent(); | 1055 String::FlatContent flat = s->GetFlatContent(); |
| 1054 uint8_t* dest = result->GetChars(); | 1056 uint8_t* dest = result->GetChars(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 Handle<FixedArray> date_cache_version = | 1180 Handle<FixedArray> date_cache_version = |
| 1179 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1181 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 1180 EternalHandles::DATE_CACHE_VERSION)); | 1182 EternalHandles::DATE_CACHE_VERSION)); |
| 1181 return date_cache_version->get(0); | 1183 return date_cache_version->get(0); |
| 1182 } | 1184 } |
| 1183 | 1185 |
| 1184 } // namespace internal | 1186 } // namespace internal |
| 1185 } // namespace v8 | 1187 } // namespace v8 |
| 1186 | 1188 |
| 1187 #endif // V8_I18N_SUPPORT | 1189 #endif // V8_I18N_SUPPORT |
| OLD | NEW |