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 3 // found in the LICENSE file. 4 // limitations under the License. 5 6 #ifndef V8_I18N_H_ 7 #define V8_I18N_H_ 8 9 #include "src/handles.h" 10 #include "unicode/uversion.h" 11 12 namespace U_ICU_NAMESPACE { 13 class BreakIterator; 14 class Collator; 15 class DecimalFormat; 16 class SimpleDateFormat; 17 } 18 19 namespace v8 { 20 namespace internal { 21 22 // Forward declarations. 23 class ObjectTemplateInfo; 24 25 class I18N { 26 public: 27 // Creates an ObjectTemplate with one internal field. 28 static Handle<ObjectTemplateInfo> GetTemplate(Isolate* isolate); 29 30 // Creates an ObjectTemplate with two internal fields. 31 static Handle<ObjectTemplateInfo> GetTemplate2(Isolate* isolate); 32 33 private: 34 I18N(); 35 }; 36 37 38 class DateFormat { 39 public: 40 // Create a formatter for the specificied locale and options. Returns the 41 // resolved settings for the locale / options. 42 static icu::SimpleDateFormat* InitializeDateTimeFormat( 43 Isolate* isolate, 44 Handle<String> locale, 45 Handle<JSObject> options, 46 Handle<JSObject> resolved); 47 48 // Unpacks date format object from corresponding JavaScript object. 49 static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate, 50 Handle<JSObject> obj); 51 52 // Release memory we allocated for the DateFormat once the JS object that 53 // holds the pointer gets garbage collected. 54 static void DeleteDateFormat(const v8::WeakCallbackInfo<void>& data); 55 56 private: 57 DateFormat(); 58 }; 59 60 61 class NumberFormat { 62 public: 63 // Create a formatter for the specificied locale and options. Returns the 64 // resolved settings for the locale / options. 65 static icu::DecimalFormat* InitializeNumberFormat( 66 Isolate* isolate, 67 Handle<String> locale, 68 Handle<JSObject> options, 69 Handle<JSObject> resolved); 70 71 // Unpacks number format object from corresponding JavaScript object. 72 static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate, 73 Handle<JSObject> obj); 74 75 // Release memory we allocated for the NumberFormat once the JS object that 76 // holds the pointer gets garbage collected. 77 static void DeleteNumberFormat(const v8::WeakCallbackInfo<void>& data); 78 79 private: 80 NumberFormat(); 81 }; 82 83 84 class Collator { 85 public: 86 // Create a collator for the specificied locale and options. Returns the 87 // resolved settings for the locale / options. 88 static icu::Collator* InitializeCollator( 89 Isolate* isolate, 90 Handle<String> locale, 91 Handle<JSObject> options, 92 Handle<JSObject> resolved); 93 94 // Unpacks collator object from corresponding JavaScript object. 95 static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj); 96 97 // Release memory we allocated for the Collator once the JS object that holds 98 // the pointer gets garbage collected. 99 static void DeleteCollator(const v8::WeakCallbackInfo<void>& data); 100 101 private: 102 Collator(); 103 }; 104 105 class BreakIterator { 106 public: 107 // Create a BreakIterator for the specificied locale and options. Returns the 108 // resolved settings for the locale / options. 109 static icu::BreakIterator* InitializeBreakIterator( 110 Isolate* isolate, 111 Handle<String> locale, 112 Handle<JSObject> options, 113 Handle<JSObject> resolved); 114 115 // Unpacks break iterator object from corresponding JavaScript object. 116 static icu::BreakIterator* UnpackBreakIterator(Isolate* isolate, 117 Handle<JSObject> obj); 118 119 // Release memory we allocated for the BreakIterator once the JS object that 120 // holds the pointer gets garbage collected. 121 static void DeleteBreakIterator(const v8::WeakCallbackInfo<void>& data); 122 123 private: 124 BreakIterator(); 125 }; 126 127 } // namespace internal 128 } // namespace v8 129 130 #endif // V8_I18N_H_ 131