V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-locale.h
1 // Copyright 2018 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 
5 #ifndef V8_INTL_SUPPORT
6 #error Internationalization is expected to be enabled.
7 #endif // V8_INTL_SUPPORT
8 
9 #ifndef V8_OBJECTS_JS_LOCALE_H_
10 #define V8_OBJECTS_JS_LOCALE_H_
11 
12 #include "src/global-handles.h"
13 #include "src/heap/factory.h"
14 #include "src/isolate.h"
15 #include "src/objects.h"
16 #include "unicode/unistr.h"
17 
18 // Has to be the last include (doesn't have include guards):
19 #include "src/objects/object-macros.h"
20 
21 namespace v8 {
22 namespace internal {
23 
24 class JSLocale : public JSObject {
25  public:
26  // Initializes locale object with properties derived from input locale string
27  // and options.
28  static MaybeHandle<JSLocale> Initialize(Isolate* isolate,
29  Handle<JSLocale> locale_holder,
30  Handle<String> locale,
31  Handle<JSReceiver> options);
32  static Handle<String> Maximize(Isolate* isolate, String locale);
33  static Handle<String> Minimize(Isolate* isolate, String locale);
34 
35  Handle<String> CaseFirstAsString() const;
36  Handle<String> NumericAsString() const;
37  Handle<String> HourCycleAsString() const;
38 
39  DECL_CAST(JSLocale)
40 
41  // Locale accessors.
42  DECL_ACCESSORS(language, Object)
43  DECL_ACCESSORS(script, Object)
44  DECL_ACCESSORS(region, Object)
45  DECL_ACCESSORS(base_name, Object)
46  DECL_ACCESSORS2(locale, String)
47 
48  // Unicode extension accessors.
49  DECL_ACCESSORS(calendar, Object)
50  DECL_ACCESSORS(collation, Object)
51  DECL_ACCESSORS(numbering_system, Object)
52 
53  // CaseFirst: "kf"
54  //
55  // ecma402 #sec-Intl.Locale.prototype.caseFirst
56  enum class CaseFirst {
57  UPPER, // upper case sorts before lower case
58  LOWER, // lower case sorts before upper case
59  // (compiler does not like FALSE so we have to name it FALSE_VALUE)
60  FALSE_VALUE, // Turn the feature off
61  COUNT
62  };
63  inline void set_case_first(CaseFirst case_first);
64  inline CaseFirst case_first() const;
65 
66  // Numeric: 'kn"
67  //
68  // ecma402 #sec-Intl.Locale.prototype.numeric
69  enum class Numeric { NOTSET, TRUE_VALUE, FALSE_VALUE, COUNT };
70  inline void set_numeric(Numeric numeric);
71  inline Numeric numeric() const;
72 
73  // CaseFirst: "hc"
74  //
75  // ecma402 #sec-Intl.Locale.prototype.hourCycle
76  enum class HourCycle {
77  H11, // 12-hour format start with hour 0 and go up to 11.
78  H12, // 12-hour format start with hour 1 and go up to 12.
79  H23, // 24-hour format start with hour 0 and go up to 23.
80  H24, // 24-hour format start with hour 1 and go up to 24.
81  COUNT
82  };
83  inline void set_hour_cycle(HourCycle hour_cycle);
84  inline HourCycle hour_cycle() const;
85 
86 // Bit positions in |flags|.
87 #define FLAGS_BIT_FIELDS(V, _) \
88  V(CaseFirstBits, CaseFirst, 2, _) \
89  V(NumericBits, Numeric, 2, _) \
90  V(HourCycleBits, HourCycle, 2, _)
91  DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
92 #undef FLAGS_BIT_FIELDS
93 
94  STATIC_ASSERT(CaseFirst::UPPER <= CaseFirstBits::kMax);
95  STATIC_ASSERT(CaseFirst::LOWER <= CaseFirstBits::kMax);
96  STATIC_ASSERT(CaseFirst::FALSE_VALUE <= CaseFirstBits::kMax);
97  STATIC_ASSERT(Numeric::NOTSET <= NumericBits::kMax);
98  STATIC_ASSERT(Numeric::FALSE_VALUE <= NumericBits::kMax);
99  STATIC_ASSERT(Numeric::TRUE_VALUE <= NumericBits::kMax);
100  STATIC_ASSERT(HourCycle::H11 <= HourCycleBits::kMax);
101  STATIC_ASSERT(HourCycle::H12 <= HourCycleBits::kMax);
102  STATIC_ASSERT(HourCycle::H23 <= HourCycleBits::kMax);
103  STATIC_ASSERT(HourCycle::H24 <= HourCycleBits::kMax);
104 
105  // [flags] Bit field containing various flags about the function.
106  DECL_INT_ACCESSORS(flags)
107 
108  DECL_PRINTER(JSLocale)
109  DECL_VERIFIER(JSLocale)
110 
111  // Layout description.
112 #define JS_LOCALE_FIELDS(V) \
113  V(kJSLocaleOffset, kTaggedSize) \
114  /* Locale fields. */ \
115  V(kLanguageOffset, kTaggedSize) \
116  V(kScriptOffset, kTaggedSize) \
117  V(kRegionOffset, kTaggedSize) \
118  V(kBaseNameOffset, kTaggedSize) \
119  V(kLocaleOffset, kTaggedSize) \
120  /* Unicode extension fields. */ \
121  V(kFlagsOffset, kTaggedSize) \
122  V(kCalendarOffset, kTaggedSize) \
123  V(kCollationOffset, kTaggedSize) \
124  V(kNumberingSystemOffset, kTaggedSize) \
125  /* Header size. */ \
126  V(kSize, 0)
127 
128  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_LOCALE_FIELDS)
129 #undef JS_LOCALE_FIELDS
130 
131  private:
132  DISALLOW_IMPLICIT_CONSTRUCTORS(JSLocale);
133 };
134 
135 } // namespace internal
136 } // namespace v8
137 
138 #include "src/objects/object-macros-undef.h"
139 
140 #endif // V8_OBJECTS_JS_LOCALE_H_
Definition: libplatform.h:13