Home | History | Annotate | Download | only in src
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 // limitations under the License.
     28 
     29 #ifndef V8_I18N_H_
     30 #define V8_I18N_H_
     31 
     32 #include "unicode/uversion.h"
     33 #include "v8.h"
     34 
     35 namespace U_ICU_NAMESPACE {
     36 class BreakIterator;
     37 class Collator;
     38 class DecimalFormat;
     39 class SimpleDateFormat;
     40 }
     41 
     42 namespace v8 {
     43 namespace internal {
     44 
     45 class I18N {
     46  public:
     47   // Creates an ObjectTemplate with one internal field.
     48   static Handle<ObjectTemplateInfo> GetTemplate(Isolate* isolate);
     49 
     50   // Creates an ObjectTemplate with two internal fields.
     51   static Handle<ObjectTemplateInfo> GetTemplate2(Isolate* isolate);
     52 
     53  private:
     54   I18N();
     55 };
     56 
     57 
     58 class DateFormat {
     59  public:
     60   // Create a formatter for the specificied locale and options. Returns the
     61   // resolved settings for the locale / options.
     62   static icu::SimpleDateFormat* InitializeDateTimeFormat(
     63       Isolate* isolate,
     64       Handle<String> locale,
     65       Handle<JSObject> options,
     66       Handle<JSObject> resolved);
     67 
     68   // Unpacks date format object from corresponding JavaScript object.
     69   static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate,
     70                                                  Handle<JSObject> obj);
     71 
     72   // Release memory we allocated for the DateFormat once the JS object that
     73   // holds the pointer gets garbage collected.
     74   static void DeleteDateFormat(v8::Isolate* isolate,
     75                                Persistent<v8::Value>* object,
     76                                void* param);
     77  private:
     78   DateFormat();
     79 };
     80 
     81 
     82 class NumberFormat {
     83  public:
     84   // Create a formatter for the specificied locale and options. Returns the
     85   // resolved settings for the locale / options.
     86   static icu::DecimalFormat* InitializeNumberFormat(
     87       Isolate* isolate,
     88       Handle<String> locale,
     89       Handle<JSObject> options,
     90       Handle<JSObject> resolved);
     91 
     92   // Unpacks number format object from corresponding JavaScript object.
     93   static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate,
     94                                                 Handle<JSObject> obj);
     95 
     96   // Release memory we allocated for the NumberFormat once the JS object that
     97   // holds the pointer gets garbage collected.
     98   static void DeleteNumberFormat(v8::Isolate* isolate,
     99                                  Persistent<v8::Value>* object,
    100                                  void* param);
    101  private:
    102   NumberFormat();
    103 };
    104 
    105 
    106 class Collator {
    107  public:
    108   // Create a collator for the specificied locale and options. Returns the
    109   // resolved settings for the locale / options.
    110   static icu::Collator* InitializeCollator(
    111       Isolate* isolate,
    112       Handle<String> locale,
    113       Handle<JSObject> options,
    114       Handle<JSObject> resolved);
    115 
    116   // Unpacks collator object from corresponding JavaScript object.
    117   static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj);
    118 
    119   // Release memory we allocated for the Collator once the JS object that holds
    120   // the pointer gets garbage collected.
    121   static void DeleteCollator(v8::Isolate* isolate,
    122                              Persistent<v8::Value>* object,
    123                              void* param);
    124  private:
    125   Collator();
    126 };
    127 
    128 class BreakIterator {
    129  public:
    130   // Create a BreakIterator for the specificied locale and options. Returns the
    131   // resolved settings for the locale / options.
    132   static icu::BreakIterator* InitializeBreakIterator(
    133       Isolate* isolate,
    134       Handle<String> locale,
    135       Handle<JSObject> options,
    136       Handle<JSObject> resolved);
    137 
    138   // Unpacks break iterator object from corresponding JavaScript object.
    139   static icu::BreakIterator* UnpackBreakIterator(Isolate* isolate,
    140                                                  Handle<JSObject> obj);
    141 
    142   // Release memory we allocated for the BreakIterator once the JS object that
    143   // holds the pointer gets garbage collected.
    144   static void DeleteBreakIterator(v8::Isolate* isolate,
    145                                   Persistent<v8::Value>* object,
    146                                   void* param);
    147 
    148  private:
    149   BreakIterator();
    150 };
    151 
    152 } }  // namespace v8::internal
    153 
    154 #endif  // V8_I18N_H_
    155