| 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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 namespace { | 858 namespace { |
| 859 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, | 859 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, |
| 860 bool is_to_upper, const char* lang) { | 860 bool is_to_upper, const char* lang) { |
| 861 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; | 861 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; |
| 862 int32_t src_length = s->length(); | 862 int32_t src_length = s->length(); |
| 863 int32_t dest_length = src_length; | 863 int32_t dest_length = src_length; |
| 864 UErrorCode status; | 864 UErrorCode status; |
| 865 Handle<SeqTwoByteString> result; | 865 Handle<SeqTwoByteString> result; |
| 866 std::unique_ptr<uc16[]> sap; | 866 std::unique_ptr<uc16[]> sap; |
| 867 | 867 |
| 868 if (dest_length == 0) return isolate->heap()->empty_string(); | |
| 869 | |
| 870 // This is not a real loop. It'll be executed only once (no overflow) or | 868 // This is not a real loop. It'll be executed only once (no overflow) or |
| 871 // twice (overflow). | 869 // twice (overflow). |
| 872 for (int i = 0; i < 2; ++i) { | 870 for (int i = 0; i < 2; ++i) { |
| 873 // Case conversion can increase the string length (e.g. sharp-S => SS) so | 871 // Case conversion can increase the string length (e.g. sharp-S => SS) so |
| 874 // that we have to handle RangeError exceptions here. | 872 // that we have to handle RangeError exceptions here. |
| 875 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 873 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 876 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); | 874 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); |
| 877 DisallowHeapAllocation no_gc; | 875 DisallowHeapAllocation no_gc; |
| 878 String::FlatContent flat = s->GetFlatContent(); | 876 String::FlatContent flat = s->GetFlatContent(); |
| 879 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); | 877 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } | 1079 } |
| 1082 | 1080 |
| 1083 RUNTIME_FUNCTION(Runtime_StringToUpperCaseI18N) { | 1081 RUNTIME_FUNCTION(Runtime_StringToUpperCaseI18N) { |
| 1084 HandleScope scope(isolate); | 1082 HandleScope scope(isolate); |
| 1085 DCHECK_EQ(args.length(), 1); | 1083 DCHECK_EQ(args.length(), 1); |
| 1086 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 1084 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 1087 | 1085 |
| 1088 int32_t length = s->length(); | 1086 int32_t length = s->length(); |
| 1089 s = String::Flatten(s); | 1087 s = String::Flatten(s); |
| 1090 | 1088 |
| 1091 if (s->HasOnlyOneByteChars() && length > 0) { | 1089 if (s->HasOnlyOneByteChars()) { |
| 1092 Handle<SeqOneByteString> result = | 1090 Handle<SeqOneByteString> result = |
| 1093 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); | 1091 isolate->factory()->NewRawOneByteString(length).ToHandleChecked(); |
| 1094 | 1092 |
| 1095 int sharp_s_count; | 1093 int sharp_s_count; |
| 1096 bool is_result_single_byte; | 1094 bool is_result_single_byte; |
| 1097 { | 1095 { |
| 1098 DisallowHeapAllocation no_gc; | 1096 DisallowHeapAllocation no_gc; |
| 1099 String::FlatContent flat = s->GetFlatContent(); | 1097 String::FlatContent flat = s->GetFlatContent(); |
| 1100 uint8_t* dest = result->GetChars(); | 1098 uint8_t* dest = result->GetChars(); |
| 1101 if (flat.IsOneByte()) { | 1099 if (flat.IsOneByte()) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 Handle<FixedArray> date_cache_version = | 1181 Handle<FixedArray> date_cache_version = |
| 1184 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1182 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 1185 EternalHandles::DATE_CACHE_VERSION)); | 1183 EternalHandles::DATE_CACHE_VERSION)); |
| 1186 return date_cache_version->get(0); | 1184 return date_cache_version->get(0); |
| 1187 } | 1185 } |
| 1188 | 1186 |
| 1189 } // namespace internal | 1187 } // namespace internal |
| 1190 } // namespace v8 | 1188 } // namespace v8 |
| 1191 | 1189 |
| 1192 #endif // V8_I18N_SUPPORT | 1190 #endif // V8_I18N_SUPPORT |
| OLD | NEW |