Home | History | Annotate | Download | only in src
      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/objects.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 template <typename T>
     23 class Handle;
     24 
     25 class DateFormat {
     26  public:
     27   // Create a formatter for the specificied locale and options. Returns the
     28   // resolved settings for the locale / options.
     29   static icu::SimpleDateFormat* InitializeDateTimeFormat(
     30       Isolate* isolate,
     31       Handle<String> locale,
     32       Handle<JSObject> options,
     33       Handle<JSObject> resolved);
     34 
     35   // Unpacks date format object from corresponding JavaScript object.
     36   static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate,
     37                                                  Handle<JSObject> obj);
     38 
     39   // Release memory we allocated for the DateFormat once the JS object that
     40   // holds the pointer gets garbage collected.
     41   static void DeleteDateFormat(const v8::WeakCallbackInfo<void>& data);
     42 
     43   // Layout description.
     44   static const int kSimpleDateFormat = JSObject::kHeaderSize;
     45   static const int kSize = kSimpleDateFormat + kPointerSize;
     46 
     47  private:
     48   DateFormat();
     49 };
     50 
     51 
     52 class NumberFormat {
     53  public:
     54   // Create a formatter for the specificied locale and options. Returns the
     55   // resolved settings for the locale / options.
     56   static icu::DecimalFormat* InitializeNumberFormat(
     57       Isolate* isolate,
     58       Handle<String> locale,
     59       Handle<JSObject> options,
     60       Handle<JSObject> resolved);
     61 
     62   // Unpacks number format object from corresponding JavaScript object.
     63   static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate,
     64                                                 Handle<JSObject> obj);
     65 
     66   // Release memory we allocated for the NumberFormat once the JS object that
     67   // holds the pointer gets garbage collected.
     68   static void DeleteNumberFormat(const v8::WeakCallbackInfo<void>& data);
     69 
     70   // Layout description.
     71   static const int kDecimalFormat = JSObject::kHeaderSize;
     72   static const int kSize = kDecimalFormat + kPointerSize;
     73 
     74  private:
     75   NumberFormat();
     76 };
     77 
     78 
     79 class Collator {
     80  public:
     81   // Create a collator for the specificied locale and options. Returns the
     82   // resolved settings for the locale / options.
     83   static icu::Collator* InitializeCollator(
     84       Isolate* isolate,
     85       Handle<String> locale,
     86       Handle<JSObject> options,
     87       Handle<JSObject> resolved);
     88 
     89   // Unpacks collator object from corresponding JavaScript object.
     90   static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj);
     91 
     92   // Release memory we allocated for the Collator once the JS object that holds
     93   // the pointer gets garbage collected.
     94   static void DeleteCollator(const v8::WeakCallbackInfo<void>& data);
     95 
     96   // Layout description.
     97   static const int kCollator = JSObject::kHeaderSize;
     98   static const int kSize = kCollator + kPointerSize;
     99 
    100  private:
    101   Collator();
    102 };
    103 
    104 class V8BreakIterator {
    105  public:
    106   // Create a BreakIterator for the specificied locale and options. Returns the
    107   // resolved settings for the locale / options.
    108   static icu::BreakIterator* InitializeBreakIterator(
    109       Isolate* isolate,
    110       Handle<String> locale,
    111       Handle<JSObject> options,
    112       Handle<JSObject> resolved);
    113 
    114   // Unpacks break iterator object from corresponding JavaScript object.
    115   static icu::BreakIterator* UnpackBreakIterator(Isolate* isolate,
    116                                                  Handle<JSObject> obj);
    117 
    118   // Release memory we allocated for the BreakIterator once the JS object that
    119   // holds the pointer gets garbage collected.
    120   static void DeleteBreakIterator(const v8::WeakCallbackInfo<void>& data);
    121 
    122   // Layout description.
    123   static const int kBreakIterator = JSObject::kHeaderSize;
    124   static const int kUnicodeString = kBreakIterator + kPointerSize;
    125   static const int kSize = kUnicodeString + kPointerSize;
    126 
    127  private:
    128   V8BreakIterator();
    129 };
    130 
    131 }  // namespace internal
    132 }  // namespace v8
    133 
    134 #endif  // V8_I18N_H_
    135