• 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_LIST_FORMAT_H_
10 #define V8_OBJECTS_JS_LIST_FORMAT_H_
11 
12 #include <set>
13 #include <string>
14 
15 #include "src/base/bit-field.h"
16 #include "src/execution/isolate.h"
17 #include "src/heap/factory.h"
18 #include "src/objects/managed.h"
19 #include "src/objects/objects.h"
20 #include "unicode/uversion.h"
21 
22 // Has to be the last include (doesn't have include guards):
23 #include "src/objects/object-macros.h"
24 
25 namespace U_ICU_NAMESPACE {
26 class ListFormatter;
27 }  // namespace U_ICU_NAMESPACE
28 
29 namespace v8 {
30 namespace internal {
31 
32 #include "torque-generated/src/objects/js-list-format-tq.inc"
33 
34 class JSListFormat
35     : public TorqueGeneratedJSListFormat<JSListFormat, JSObject> {
36  public:
37   // Creates relative time format object with properties derived from input
38   // locales and options.
39   static MaybeHandle<JSListFormat> New(Isolate* isolate, Handle<Map> map,
40                                        Handle<Object> locales,
41                                        Handle<Object> options);
42 
43   static Handle<JSObject> ResolvedOptions(Isolate* isolate,
44                                           Handle<JSListFormat> format_holder);
45 
46   // ecma402 #sec-formatlist
47   V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatList(
48       Isolate* isolate, Handle<JSListFormat> format_holder,
49       Handle<FixedArray> list);
50 
51   // ecma42 #sec-formatlisttoparts
52   V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> FormatListToParts(
53       Isolate* isolate, Handle<JSListFormat> format_holder,
54       Handle<FixedArray> list);
55 
56   V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
57 
58   Handle<String> StyleAsString() const;
59   Handle<String> TypeAsString() const;
60 
61   // ListFormat accessors.
62   DECL_ACCESSORS(icu_formatter, Managed<icu::ListFormatter>)
63 
64   // Style: identifying the relative time format style used.
65   //
66   // ecma402/#sec-properties-of-intl-listformat-instances
67   enum class Style {
68     LONG,   // Everything spelled out.
69     SHORT,  // Abbreviations used when possible.
70     NARROW  // Use the shortest possible form.
71   };
72   inline void set_style(Style style);
73   inline Style style() const;
74 
75   // Type: identifying the list of types used.
76   //
77   // ecma402/#sec-properties-of-intl-listformat-instances
78   enum class Type {
79     CONJUNCTION,  // for "and"-based lists (e.g., "A, B and C")
80     DISJUNCTION,  // for "or"-based lists (e.g., "A, B or C"),
81     UNIT  // for lists of values with units (e.g., "5 pounds, 12 ounces").
82   };
83   inline void set_type(Type type);
84   inline Type type() const;
85 
86   // Bit positions in |flags|.
87   DEFINE_TORQUE_GENERATED_JS_LIST_FORMAT_FLAGS()
88 
89   STATIC_ASSERT(Style::LONG <= StyleBits::kMax);
90   STATIC_ASSERT(Style::SHORT <= StyleBits::kMax);
91   STATIC_ASSERT(Style::NARROW <= StyleBits::kMax);
92   STATIC_ASSERT(Type::CONJUNCTION <= TypeBits::kMax);
93   STATIC_ASSERT(Type::DISJUNCTION <= TypeBits::kMax);
94   STATIC_ASSERT(Type::UNIT <= TypeBits::kMax);
95 
96   DECL_PRINTER(JSListFormat)
97 
98   TQ_OBJECT_CONSTRUCTORS(JSListFormat)
99 };
100 
101 }  // namespace internal
102 }  // namespace v8
103 
104 #include "src/objects/object-macros-undef.h"
105 
106 #endif  // V8_OBJECTS_JS_LIST_FORMAT_H_
107