1 // Copyright 2019 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_DISPLAY_NAMES_H_
10 #define V8_OBJECTS_JS_DISPLAY_NAMES_H_
11 
12 #include <set>
13 #include <string>
14 
15 #include "src/execution/isolate.h"
16 #include "src/heap/factory.h"
17 #include "src/objects/managed.h"
18 #include "src/objects/objects.h"
19 
20 // Has to be the last include (doesn't have include guards):
21 #include "src/objects/object-macros.h"
22 
23 namespace v8 {
24 namespace internal {
25 
26 class DisplayNamesInternal;
27 
28 #include "torque-generated/src/objects/js-display-names-tq.inc"
29 
30 class JSDisplayNames
31     : public TorqueGeneratedJSDisplayNames<JSDisplayNames, JSObject> {
32  public:
33   // Creates display names object with properties derived from input
34   // locales and options.
35   static MaybeHandle<JSDisplayNames> New(Isolate* isolate, Handle<Map> map,
36                                          Handle<Object> locales,
37                                          Handle<Object> options);
38 
39   static Handle<JSObject> ResolvedOptions(Isolate* isolate,
40                                           Handle<JSDisplayNames> format_holder);
41 
42   static MaybeHandle<Object> Of(Isolate* isolate, Handle<JSDisplayNames> holder,
43                                 Handle<Object> code_obj);
44 
45   V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
46 
47   Handle<String> StyleAsString() const;
48   Handle<String> FallbackAsString() const;
49   Handle<String> LanguageDisplayAsString() const;
50 
51   // Style: identifying the display names style used.
52   //
53   // ecma402/#sec-properties-of-intl-displaynames-instances
54   enum class Style {
55     kLong,   // Everything spelled out.
56     kShort,  // Abbreviations used when possible.
57     kNarrow  // Use the shortest possible form.
58   };
59   inline void set_style(Style style);
60   inline Style style() const;
61 
62   // Type: identifying the fallback of the display names.
63   //
64   // ecma402/#sec-properties-of-intl-displaynames-instances
65   enum class Fallback {
66     kCode,
67     kNone,
68   };
69   inline void set_fallback(Fallback fallback);
70   inline Fallback fallback() const;
71 
72   enum class LanguageDisplay {
73     kDialect,
74     kStandard,
75   };
76   inline void set_language_display(LanguageDisplay language_display);
77   inline LanguageDisplay language_display() const;
78 
79   // Bit positions in |flags|.
80   DEFINE_TORQUE_GENERATED_JS_DISPLAY_NAMES_FLAGS()
81 
82   STATIC_ASSERT(Style::kLong <= StyleBits::kMax);
83   STATIC_ASSERT(Style::kShort <= StyleBits::kMax);
84   STATIC_ASSERT(Style::kNarrow <= StyleBits::kMax);
85   STATIC_ASSERT(Fallback::kCode <= FallbackBit::kMax);
86   STATIC_ASSERT(Fallback::kNone <= FallbackBit::kMax);
87   STATIC_ASSERT(LanguageDisplay::kDialect <= LanguageDisplayBit::kMax);
88   STATIC_ASSERT(LanguageDisplay::kStandard <= LanguageDisplayBit::kMax);
89 
90   DECL_ACCESSORS(internal, Managed<DisplayNamesInternal>)
91 
92   DECL_PRINTER(JSDisplayNames)
93 
94   TQ_OBJECT_CONSTRUCTORS(JSDisplayNames)
95 };
96 
97 }  // namespace internal
98 }  // namespace v8
99 
100 #include "src/objects/object-macros-undef.h"
101 
102 #endif  // V8_OBJECTS_JS_DISPLAY_NAMES_H_
103