• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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> InitializeLocale(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   DECL_CAST(JSLocale)
36 
37   // Locale accessors.
38   DECL_ACCESSORS(language, Object)
39   DECL_ACCESSORS(script, Object)
40   DECL_ACCESSORS(region, Object)
41   DECL_ACCESSORS(base_name, Object)
42   DECL_ACCESSORS(locale, String)
43 
44   // Unicode extension accessors.
45   DECL_ACCESSORS(calendar, Object)
46   DECL_ACCESSORS(case_first, Object)
47   DECL_ACCESSORS(collation, Object)
48   DECL_ACCESSORS(hour_cycle, Object)
49   DECL_ACCESSORS(numeric, Object)
50   DECL_ACCESSORS(numbering_system, Object)
51 
52   DECL_PRINTER(JSLocale)
53   DECL_VERIFIER(JSLocale)
54 
55   // Layout description.
56   static const int kJSLocaleOffset = JSObject::kHeaderSize;
57   // Locale fields.
58   static const int kLanguageOffset = kJSLocaleOffset + kPointerSize;
59   static const int kScriptOffset = kLanguageOffset + kPointerSize;
60   static const int kRegionOffset = kScriptOffset + kPointerSize;
61   static const int kBaseNameOffset = kRegionOffset + kPointerSize;
62   static const int kLocaleOffset = kBaseNameOffset + kPointerSize;
63   // Unicode extension fields.
64   static const int kCalendarOffset = kLocaleOffset + kPointerSize;
65   static const int kCaseFirstOffset = kCalendarOffset + kPointerSize;
66   static const int kCollationOffset = kCaseFirstOffset + kPointerSize;
67   static const int kHourCycleOffset = kCollationOffset + kPointerSize;
68   static const int kNumericOffset = kHourCycleOffset + kPointerSize;
69   static const int kNumberingSystemOffset = kNumericOffset + kPointerSize;
70   // Final size.
71   static const int kSize = kNumberingSystemOffset + kPointerSize;
72 
73  private:
74   DISALLOW_IMPLICIT_CONSTRUCTORS(JSLocale);
75 };
76 
77 }  // namespace internal
78 }  // namespace v8
79 
80 #include "src/objects/object-macros-undef.h"
81 
82 #endif  // V8_OBJECTS_JS_LOCALE_H_
83