OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 // limitations under the License. | 4 // limitations under the License. |
5 | 5 |
6 #include "src/i18n.h" | 6 #include "src/i18n.h" |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 SLOPPY).Assert(); | 218 SLOPPY).Assert(); |
219 } else { | 219 } else { |
220 // This would never happen, since we got the locale from ICU. | 220 // This would never happen, since we got the locale from ICU. |
221 JSObject::SetProperty(resolved, factory->NewStringFromStaticChars("locale"), | 221 JSObject::SetProperty(resolved, factory->NewStringFromStaticChars("locale"), |
222 factory->NewStringFromStaticChars("und"), | 222 factory->NewStringFromStaticChars("und"), |
223 SLOPPY).Assert(); | 223 SLOPPY).Assert(); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 template<int internal_fields, EternalHandles::SingletonHandle field> | |
229 Handle<ObjectTemplateInfo> GetEternal(Isolate* isolate) { | |
230 if (isolate->eternal_handles()->Exists(field)) { | |
231 return Handle<ObjectTemplateInfo>::cast( | |
232 isolate->eternal_handles()->GetSingleton(field)); | |
233 } | |
234 v8::Local<v8::ObjectTemplate> raw_template = | |
235 v8::ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate)); | |
236 raw_template->SetInternalFieldCount(internal_fields); | |
237 return Handle<ObjectTemplateInfo>::cast( | |
238 isolate->eternal_handles()->CreateSingleton( | |
239 isolate, | |
240 *v8::Utils::OpenHandle(*raw_template), | |
241 field)); | |
242 } | |
243 | |
244 | |
245 icu::DecimalFormat* CreateICUNumberFormat( | 228 icu::DecimalFormat* CreateICUNumberFormat( |
246 Isolate* isolate, | 229 Isolate* isolate, |
247 const icu::Locale& icu_locale, | 230 const icu::Locale& icu_locale, |
248 Handle<JSObject> options) { | 231 Handle<JSObject> options) { |
249 // Make formatter from options. Numbering system is added | 232 // Make formatter from options. Numbering system is added |
250 // to the locale as Unicode extension (if it was specified at all). | 233 // to the locale as Unicode extension (if it was specified at all). |
251 UErrorCode status = U_ZERO_ERROR; | 234 UErrorCode status = U_ZERO_ERROR; |
252 icu::DecimalFormat* number_format = NULL; | 235 icu::DecimalFormat* number_format = NULL; |
253 icu::UnicodeString style; | 236 icu::UnicodeString style; |
254 icu::UnicodeString currency; | 237 icu::UnicodeString currency; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 JSObject::SetProperty(resolved, factory->NewStringFromStaticChars("locale"), | 679 JSObject::SetProperty(resolved, factory->NewStringFromStaticChars("locale"), |
697 factory->NewStringFromStaticChars("und"), | 680 factory->NewStringFromStaticChars("und"), |
698 SLOPPY).Assert(); | 681 SLOPPY).Assert(); |
699 } | 682 } |
700 } | 683 } |
701 | 684 |
702 } // namespace | 685 } // namespace |
703 | 686 |
704 | 687 |
705 // static | 688 // static |
706 Handle<ObjectTemplateInfo> I18N::GetTemplate(Isolate* isolate) { | |
707 return GetEternal<1, i::EternalHandles::I18N_TEMPLATE_ONE>(isolate); | |
708 } | |
709 | |
710 | |
711 // static | |
712 Handle<ObjectTemplateInfo> I18N::GetTemplate2(Isolate* isolate) { | |
713 return GetEternal<2, i::EternalHandles::I18N_TEMPLATE_TWO>(isolate); | |
714 } | |
715 | |
716 | |
717 // static | |
718 icu::SimpleDateFormat* DateFormat::InitializeDateTimeFormat( | 689 icu::SimpleDateFormat* DateFormat::InitializeDateTimeFormat( |
719 Isolate* isolate, | 690 Isolate* isolate, |
720 Handle<String> locale, | 691 Handle<String> locale, |
721 Handle<JSObject> options, | 692 Handle<JSObject> options, |
722 Handle<JSObject> resolved) { | 693 Handle<JSObject> resolved) { |
723 // Convert BCP47 into ICU locale format. | 694 // Convert BCP47 into ICU locale format. |
724 UErrorCode status = U_ZERO_ERROR; | 695 UErrorCode status = U_ZERO_ERROR; |
725 icu::Locale icu_locale; | 696 icu::Locale icu_locale; |
726 char icu_result[ULOC_FULLNAME_CAPACITY]; | 697 char icu_result[ULOC_FULLNAME_CAPACITY]; |
727 int icu_length = 0; | 698 int icu_length = 0; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 icu::Collator* Collator::UnpackCollator(Isolate* isolate, | 839 icu::Collator* Collator::UnpackCollator(Isolate* isolate, |
869 Handle<JSObject> obj) { | 840 Handle<JSObject> obj) { |
870 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); | 841 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); |
871 } | 842 } |
872 | 843 |
873 void Collator::DeleteCollator(const v8::WeakCallbackInfo<void>& data) { | 844 void Collator::DeleteCollator(const v8::WeakCallbackInfo<void>& data) { |
874 delete reinterpret_cast<icu::Collator*>(data.GetInternalField(0)); | 845 delete reinterpret_cast<icu::Collator*>(data.GetInternalField(0)); |
875 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); | 846 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); |
876 } | 847 } |
877 | 848 |
878 | 849 icu::BreakIterator* V8BreakIterator::InitializeBreakIterator( |
879 icu::BreakIterator* BreakIterator::InitializeBreakIterator( | 850 Isolate* isolate, Handle<String> locale, Handle<JSObject> options, |
880 Isolate* isolate, | |
881 Handle<String> locale, | |
882 Handle<JSObject> options, | |
883 Handle<JSObject> resolved) { | 851 Handle<JSObject> resolved) { |
884 // Convert BCP47 into ICU locale format. | 852 // Convert BCP47 into ICU locale format. |
885 UErrorCode status = U_ZERO_ERROR; | 853 UErrorCode status = U_ZERO_ERROR; |
886 icu::Locale icu_locale; | 854 icu::Locale icu_locale; |
887 char icu_result[ULOC_FULLNAME_CAPACITY]; | 855 char icu_result[ULOC_FULLNAME_CAPACITY]; |
888 int icu_length = 0; | 856 int icu_length = 0; |
889 v8::String::Utf8Value bcp47_locale(v8::Utils::ToLocal(locale)); | 857 v8::String::Utf8Value bcp47_locale(v8::Utils::ToLocal(locale)); |
890 if (bcp47_locale.length() != 0) { | 858 if (bcp47_locale.length() != 0) { |
891 uloc_forLanguageTag(*bcp47_locale, icu_result, ULOC_FULLNAME_CAPACITY, | 859 uloc_forLanguageTag(*bcp47_locale, icu_result, ULOC_FULLNAME_CAPACITY, |
892 &icu_length, &status); | 860 &icu_length, &status); |
(...skipping 19 matching lines...) Expand all Loading... |
912 SetResolvedBreakIteratorSettings( | 880 SetResolvedBreakIteratorSettings( |
913 isolate, no_extension_locale, break_iterator, resolved); | 881 isolate, no_extension_locale, break_iterator, resolved); |
914 } else { | 882 } else { |
915 SetResolvedBreakIteratorSettings( | 883 SetResolvedBreakIteratorSettings( |
916 isolate, icu_locale, break_iterator, resolved); | 884 isolate, icu_locale, break_iterator, resolved); |
917 } | 885 } |
918 | 886 |
919 return break_iterator; | 887 return break_iterator; |
920 } | 888 } |
921 | 889 |
922 | 890 icu::BreakIterator* V8BreakIterator::UnpackBreakIterator(Isolate* isolate, |
923 icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate, | 891 Handle<JSObject> obj) { |
924 Handle<JSObject> obj) { | |
925 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0)); | 892 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0)); |
926 } | 893 } |
927 | 894 |
928 void BreakIterator::DeleteBreakIterator( | 895 void V8BreakIterator::DeleteBreakIterator( |
929 const v8::WeakCallbackInfo<void>& data) { | 896 const v8::WeakCallbackInfo<void>& data) { |
930 delete reinterpret_cast<icu::BreakIterator*>(data.GetInternalField(0)); | 897 delete reinterpret_cast<icu::BreakIterator*>(data.GetInternalField(0)); |
931 delete reinterpret_cast<icu::UnicodeString*>(data.GetInternalField(1)); | 898 delete reinterpret_cast<icu::UnicodeString*>(data.GetInternalField(1)); |
932 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); | 899 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); |
933 } | 900 } |
934 | 901 |
935 } // namespace internal | 902 } // namespace internal |
936 } // namespace v8 | 903 } // namespace v8 |
OLD | NEW |