• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
50   // Style: identifying the display names style used.
51   //
52   // ecma402/#sec-properties-of-intl-displaynames-instances
53   enum class Style {
54     kLong,   // Everything spelled out.
55     kShort,  // Abbreviations used when possible.
56     kNarrow  // Use the shortest possible form.
57   };
58   inline void set_style(Style style);
59   inline Style style() const;
60 
61   // Type: identifying the fallback of the display names.
62   //
63   // ecma402/#sec-properties-of-intl-displaynames-instances
64   enum class Fallback {
65     kCode,
66     kNone,
67   };
68   inline void set_fallback(Fallback fallback);
69   inline Fallback fallback() const;
70 
71   // Bit positions in |flags|.
72   DEFINE_TORQUE_GENERATED_JS_DISPLAY_NAMES_FLAGS()
73 
74   STATIC_ASSERT(Style::kLong <= StyleBits::kMax);
75   STATIC_ASSERT(Style::kShort <= StyleBits::kMax);
76   STATIC_ASSERT(Style::kNarrow <= StyleBits::kMax);
77   STATIC_ASSERT(Fallback::kCode <= FallbackBit::kMax);
78   STATIC_ASSERT(Fallback::kNone <= FallbackBit::kMax);
79 
80   DECL_ACCESSORS(internal, Managed<DisplayNamesInternal>)
81 
82   DECL_PRINTER(JSDisplayNames)
83 
84   TQ_OBJECT_CONSTRUCTORS(JSDisplayNames)
85 };
86 
87 }  // namespace internal
88 }  // namespace v8
89 
90 #include "src/objects/object-macros-undef.h"
91 
92 #endif  // V8_OBJECTS_JS_DISPLAY_NAMES_H_
93