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/execution/isolate.h"
13 #include "src/handles/global-handles.h"
14 #include "src/heap/factory.h"
15 #include "src/objects/managed.h"
16 #include "src/objects/objects.h"
17 
18 // Has to be the last include (doesn't have include guards):
19 #include "src/objects/object-macros.h"
20 
21 namespace U_ICU_NAMESPACE {
22 class Locale;
23 }
24 
25 namespace v8 {
26 namespace internal {
27 
28 class JSLocale : public JSObject {
29  public:
30   // Creates locale object with properties derived from input locale string
31   // and options.
32   static MaybeHandle<JSLocale> New(Isolate* isolate, Handle<Map> map,
33                                    Handle<String> locale,
34                                    Handle<JSReceiver> options);
35   static Handle<String> Maximize(Isolate* isolate, String locale);
36   static Handle<String> Minimize(Isolate* isolate, String locale);
37 
38   static Handle<Object> Language(Isolate* isolate, Handle<JSLocale> locale);
39   static Handle<Object> Script(Isolate* isolate, Handle<JSLocale> locale);
40   static Handle<Object> Region(Isolate* isolate, Handle<JSLocale> locale);
41   static Handle<String> BaseName(Isolate* isolate, Handle<JSLocale> locale);
42   static Handle<Object> Calendar(Isolate* isolate, Handle<JSLocale> locale);
43   static Handle<Object> CaseFirst(Isolate* isolate, Handle<JSLocale> locale);
44   static Handle<Object> Collation(Isolate* isolate, Handle<JSLocale> locale);
45   static Handle<Object> HourCycle(Isolate* isolate, Handle<JSLocale> locale);
46   static Handle<Object> Numeric(Isolate* isolate, Handle<JSLocale> locale);
47   static Handle<Object> NumberingSystem(Isolate* isolate,
48                                         Handle<JSLocale> locale);
49   static Handle<String> ToString(Isolate* isolate, Handle<JSLocale> locale);
50   static std::string ToString(Handle<JSLocale> locale);
51 
52   // Help function to validate locale by other Intl objects.
53   static bool StartsWithUnicodeLanguageId(const std::string& value);
54 
55   // Help function to check well-formed
56   // "(3*8alphanum) *("-" (3*8alphanum)) sequence" sequence
57   static bool Is38AlphaNumList(const std::string& value);
58 
59   // Help function to check well-formed "3alpha"
60   static bool Is3Alpha(const std::string& value);
61 
62   DECL_CAST(JSLocale)
63 
64   DECL_ACCESSORS(icu_locale, Managed<icu::Locale>)
65 
66   DECL_PRINTER(JSLocale)
67   DECL_VERIFIER(JSLocale)
68 
69   // Layout description.
70   DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
71                                 TORQUE_GENERATED_JS_LOCALE_FIELDS)
72 
73   OBJECT_CONSTRUCTORS(JSLocale, JSObject);
74 };
75 
76 }  // namespace internal
77 }  // namespace v8
78 
79 #include "src/objects/object-macros-undef.h"
80 
81 #endif  // V8_OBJECTS_JS_LOCALE_H_
82