V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-list-format.h
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/heap/factory.h"
16 #include "src/isolate.h"
17 #include "src/objects.h"
18 #include "src/objects/managed.h"
19 #include "unicode/uversion.h"
20 
21 // Has to be the last include (doesn't have include guards):
22 #include "src/objects/object-macros.h"
23 
24 namespace U_ICU_NAMESPACE {
25 class ListFormatter;
26 }
27 
28 namespace v8 {
29 namespace internal {
30 
31 class JSListFormat : public JSObject {
32  public:
33  // Initializes relative time format object with properties derived from input
34  // locales and options.
35  static MaybeHandle<JSListFormat> Initialize(
36  Isolate* isolate, Handle<JSListFormat> list_format_holder,
37  Handle<Object> locales, Handle<Object> options);
38 
39  static Handle<JSObject> ResolvedOptions(Isolate* isolate,
40  Handle<JSListFormat> format_holder);
41 
42  // ecma402 #sec-formatlist
43  V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatList(
44  Isolate* isolate, Handle<JSListFormat> format_holder,
45  Handle<JSArray> list);
46 
47  // ecma42 #sec-formatlisttoparts
48  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> FormatListToParts(
49  Isolate* isolate, Handle<JSListFormat> format_holder,
50  Handle<JSArray> list);
51 
52  static std::set<std::string> GetAvailableLocales();
53 
54  Handle<String> StyleAsString() const;
55  Handle<String> TypeAsString() const;
56 
57  DECL_CAST(JSListFormat)
58 
59  // ListFormat accessors.
60  DECL_ACCESSORS2(locale, String)
61  DECL_ACCESSORS(icu_formatter, Managed<icu::ListFormatter>)
62 
63  // Style: identifying the relative time format style used.
64  //
65  // ecma402/#sec-properties-of-intl-listformat-instances
66  enum class Style {
67  LONG, // Everything spelled out.
68  SHORT, // Abbreviations used when possible.
69  NARROW, // Use the shortest possible form.
70  COUNT
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  COUNT
83  };
84  inline void set_type(Type type);
85  inline Type type() const;
86 
87 // Bit positions in |flags|.
88 #define FLAGS_BIT_FIELDS(V, _) \
89  V(StyleBits, Style, 2, _) \
90  V(TypeBits, Type, 2, _)
91  DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
92 #undef FLAGS_BIT_FIELDS
93 
94  STATIC_ASSERT(Style::LONG <= StyleBits::kMax);
95  STATIC_ASSERT(Style::SHORT <= StyleBits::kMax);
96  STATIC_ASSERT(Style::NARROW <= StyleBits::kMax);
97  STATIC_ASSERT(Type::CONJUNCTION <= TypeBits::kMax);
98  STATIC_ASSERT(Type::DISJUNCTION <= TypeBits::kMax);
99  STATIC_ASSERT(Type::UNIT <= TypeBits::kMax);
100 
101  // [flags] Bit field containing various flags about the function.
102  DECL_INT_ACCESSORS(flags)
103 
104  DECL_PRINTER(JSListFormat)
105  DECL_VERIFIER(JSListFormat)
106 
107  // Layout description.
108 #define JS_LIST_FORMAT_FIELDS(V) \
109  V(kJSListFormatOffset, kTaggedSize) \
110  V(kLocaleOffset, kTaggedSize) \
111  V(kICUFormatterOffset, kTaggedSize) \
112  V(kFlagsOffset, kTaggedSize) \
113  /* Header size. */ \
114  V(kSize, 0)
115 
116  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_LIST_FORMAT_FIELDS)
117 #undef JS_LIST_FORMAT_FIELDS
118 
119  private:
120  DISALLOW_IMPLICIT_CONSTRUCTORS(JSListFormat);
121 };
122 
123 } // namespace internal
124 } // namespace v8
125 
126 #include "src/objects/object-macros-undef.h"
127 
128 #endif // V8_OBJECTS_JS_LIST_FORMAT_H_
Definition: libplatform.h:13