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 |
66 RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { | 67 RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { |
67 HandleScope scope(isolate); | 68 HandleScope scope(isolate); |
68 Factory* factory = isolate->factory(); | 69 Factory* factory = isolate->factory(); |
69 | 70 |
70 DCHECK(args.length() == 1); | 71 DCHECK(args.length() == 1); |
71 CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); | 72 CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); |
72 | 73 |
73 v8::String::Utf8Value locale_id(v8::Utils::ToLocal(locale_id_str)); | 74 v8::String::Utf8Value locale_id(v8::Utils::ToLocal(locale_id_str)); |
74 | 75 |
75 // Return value which denotes invalid language tag. | 76 // 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'. |
76 const char* const kInvalidTag = "invalid-tag"; | 79 const char* const kInvalidTag = "invalid-tag"; |
77 | 80 |
78 UErrorCode error = U_ZERO_ERROR; | 81 UErrorCode error = U_ZERO_ERROR; |
79 char icu_result[ULOC_FULLNAME_CAPACITY]; | 82 char icu_result[ULOC_FULLNAME_CAPACITY]; |
80 int icu_length = 0; | 83 int icu_length = 0; |
81 | 84 |
82 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, | 85 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, |
83 &icu_length, &error); | 86 &icu_length, &error); |
84 if (U_FAILURE(error) || icu_length == 0) { | 87 if (U_FAILURE(error) || icu_length == 0) { |
85 return *factory->NewStringFromAsciiChecked(kInvalidTag); | 88 return *factory->NewStringFromAsciiChecked(kInvalidTag); |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 Handle<FixedArray> date_cache_version = | 1156 Handle<FixedArray> date_cache_version = |
1154 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1157 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
1155 EternalHandles::DATE_CACHE_VERSION)); | 1158 EternalHandles::DATE_CACHE_VERSION)); |
1156 return date_cache_version->get(0); | 1159 return date_cache_version->get(0); |
1157 } | 1160 } |
1158 | 1161 |
1159 } // namespace internal | 1162 } // namespace internal |
1160 } // namespace v8 | 1163 } // namespace v8 |
1161 | 1164 |
1162 #endif // V8_I18N_SUPPORT | 1165 #endif // V8_I18N_SUPPORT |
OLD | NEW |