| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 CopyChars(dest->get(), flat.ToOneByteVector().start(), length); | 56 CopyChars(dest->get(), flat.ToOneByteVector().start(), length); |
| 57 } | 57 } |
| 58 return reinterpret_cast<const UChar*>(dest->get()); | 58 return reinterpret_cast<const UChar*>(dest->get()); |
| 59 } else { | 59 } else { |
| 60 return reinterpret_cast<const UChar*>(flat.ToUC16Vector().start()); | 60 return reinterpret_cast<const UChar*>(flat.ToUC16Vector().start()); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 // ECMA 402 6.2.3 | |
| 67 RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { | 66 RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { |
| 68 HandleScope scope(isolate); | 67 HandleScope scope(isolate); |
| 69 Factory* factory = isolate->factory(); | 68 Factory* factory = isolate->factory(); |
| 70 | 69 |
| 71 DCHECK(args.length() == 1); | 70 DCHECK(args.length() == 1); |
| 72 CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); | 71 CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); |
| 73 | 72 |
| 74 v8::String::Utf8Value locale_id(v8::Utils::ToLocal(locale_id_str)); | 73 v8::String::Utf8Value locale_id(v8::Utils::ToLocal(locale_id_str)); |
| 75 | 74 |
| 76 // Return value which denotes invalid language tag. | 75 // Return value which denotes invalid language tag. |
| 77 // TODO(jshin): Can uloc_{for,to}TanguageTag fail even for structually valid | |
| 78 // language tags? If not, just add CHECK instead of returning 'invalid-tag'. | |
| 79 const char* const kInvalidTag = "invalid-tag"; | 76 const char* const kInvalidTag = "invalid-tag"; |
| 80 | 77 |
| 81 UErrorCode error = U_ZERO_ERROR; | 78 UErrorCode error = U_ZERO_ERROR; |
| 82 char icu_result[ULOC_FULLNAME_CAPACITY]; | 79 char icu_result[ULOC_FULLNAME_CAPACITY]; |
| 83 int icu_length = 0; | 80 int icu_length = 0; |
| 84 | 81 |
| 85 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, | 82 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, |
| 86 &icu_length, &error); | 83 &icu_length, &error); |
| 87 if (U_FAILURE(error) || icu_length == 0) { | 84 if (U_FAILURE(error) || icu_length == 0) { |
| 88 return *factory->NewStringFromAsciiChecked(kInvalidTag); | 85 return *factory->NewStringFromAsciiChecked(kInvalidTag); |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; | 852 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; |
| 856 | 853 |
| 857 int32_t dest_length = src_length; | 854 int32_t dest_length = src_length; |
| 858 UErrorCode status; | 855 UErrorCode status; |
| 859 Handle<SeqTwoByteString> result; | 856 Handle<SeqTwoByteString> result; |
| 860 std::unique_ptr<uc16[]> sap; | 857 std::unique_ptr<uc16[]> sap; |
| 861 | 858 |
| 862 // This is not a real loop. It'll be executed only once (no overflow) or | 859 // This is not a real loop. It'll be executed only once (no overflow) or |
| 863 // twice (overflow). | 860 // twice (overflow). |
| 864 for (int i = 0; i < 2; ++i) { | 861 for (int i = 0; i < 2; ++i) { |
| 865 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 862 result = |
| 866 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); | 863 isolate->factory()->NewRawTwoByteString(dest_length).ToHandleChecked(); |
| 867 DisallowHeapAllocation no_gc; | 864 DisallowHeapAllocation no_gc; |
| 868 String::FlatContent flat = s->GetFlatContent(); | 865 String::FlatContent flat = s->GetFlatContent(); |
| 869 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); | 866 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); |
| 870 status = U_ZERO_ERROR; | 867 status = U_ZERO_ERROR; |
| 871 dest_length = case_converter(reinterpret_cast<UChar*>(result->GetChars()), | 868 dest_length = case_converter(reinterpret_cast<UChar*>(result->GetChars()), |
| 872 dest_length, src, src_length, lang, &status); | 869 dest_length, src, src_length, lang, &status); |
| 873 if (status != U_BUFFER_OVERFLOW_ERROR) break; | 870 if (status != U_BUFFER_OVERFLOW_ERROR) break; |
| 874 } | 871 } |
| 875 | 872 |
| 876 // In most cases, the output will fill the destination buffer completely | 873 // In most cases, the output will fill the destination buffer completely |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 Handle<FixedArray> date_cache_version = | 1151 Handle<FixedArray> date_cache_version = |
| 1155 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1152 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 1156 EternalHandles::DATE_CACHE_VERSION)); | 1153 EternalHandles::DATE_CACHE_VERSION)); |
| 1157 return date_cache_version->get(0); | 1154 return date_cache_version->get(0); |
| 1158 } | 1155 } |
| 1159 | 1156 |
| 1160 } // namespace internal | 1157 } // namespace internal |
| 1161 } // namespace v8 | 1158 } // namespace v8 |
| 1162 | 1159 |
| 1163 #endif // V8_I18N_SUPPORT | 1160 #endif // V8_I18N_SUPPORT |
| OLD | NEW |