• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "unicode/uversion.h"
10 #include "src/v8.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 class I18N {
23  public:
24   // Creates an ObjectTemplate with one internal field.
25   static Handle<ObjectTemplateInfo> GetTemplate(Isolate* isolate);
26 
27   // Creates an ObjectTemplate with two internal fields.
28   static Handle<ObjectTemplateInfo> GetTemplate2(Isolate* isolate);
29 
30  private:
31   I18N();
32 };
33 
34 
35 class DateFormat {
36  public:
37   // Create a formatter for the specificied locale and options. Returns the
38   // resolved settings for the locale / options.
39   static icu::SimpleDateFormat* InitializeDateTimeFormat(
40       Isolate* isolate,
41       Handle<String> locale,
42       Handle<JSObject> options,
43       Handle<JSObject> resolved);
44 
45   // Unpacks date format object from corresponding JavaScript object.
46   static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate,
47                                                  Handle<JSObject> obj);
48 
49   // Release memory we allocated for the DateFormat once the JS object that
50   // holds the pointer gets garbage collected.
51   static void DeleteDateFormat(
52       const v8::WeakCallbackData<v8::Value, void>& data);
53 
54  private:
55   DateFormat();
56 };
57 
58 
59 class NumberFormat {
60  public:
61   // Create a formatter for the specificied locale and options. Returns the
62   // resolved settings for the locale / options.
63   static icu::DecimalFormat* InitializeNumberFormat(
64       Isolate* isolate,
65       Handle<String> locale,
66       Handle<JSObject> options,
67       Handle<JSObject> resolved);
68 
69   // Unpacks number format object from corresponding JavaScript object.
70   static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate,
71                                                 Handle<JSObject> obj);
72 
73   // Release memory we allocated for the NumberFormat once the JS object that
74   // holds the pointer gets garbage collected.
75   static void DeleteNumberFormat(
76       const v8::WeakCallbackData<v8::Value, void>& data);
77 
78  private:
79   NumberFormat();
80 };
81 
82 
83 class Collator {
84  public:
85   // Create a collator for the specificied locale and options. Returns the
86   // resolved settings for the locale / options.
87   static icu::Collator* InitializeCollator(
88       Isolate* isolate,
89       Handle<String> locale,
90       Handle<JSObject> options,
91       Handle<JSObject> resolved);
92 
93   // Unpacks collator object from corresponding JavaScript object.
94   static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj);
95 
96   // Release memory we allocated for the Collator once the JS object that holds
97   // the pointer gets garbage collected.
98   static void DeleteCollator(
99       const v8::WeakCallbackData<v8::Value, 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(
122       const v8::WeakCallbackData<v8::Value, void>& data);
123 
124  private:
125   BreakIterator();
126 };
127 
128 } }  // namespace v8::internal
129 
130 #endif  // V8_I18N_H_
131