V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-plural-rules.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_PLURAL_RULES_H_
10 #define V8_OBJECTS_JS_PLURAL_RULES_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/intl-objects.h"
19 #include "src/objects/managed.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 PluralRules;
26 } // namespace U_ICU_NAMESPACE
27 
28 namespace v8 {
29 namespace internal {
30 
31 class JSPluralRules : public JSObject {
32  public:
33  V8_WARN_UNUSED_RESULT static MaybeHandle<JSPluralRules> Initialize(
34  Isolate* isolate, Handle<JSPluralRules> plural_rules,
35  Handle<Object> locales, Handle<Object> options);
36 
37  static Handle<JSObject> ResolvedOptions(Isolate* isolate,
38  Handle<JSPluralRules> plural_rules);
39 
40  V8_WARN_UNUSED_RESULT static MaybeHandle<String> ResolvePlural(
41  Isolate* isolate, Handle<JSPluralRules> plural_rules, double number);
42 
43  static std::set<std::string> GetAvailableLocales();
44 
45  // [[Type]] is one of the values "cardinal" or "ordinal",
46  // identifying the plural rules used.
47  enum class Type {
48  CARDINAL,
49  ORDINAL,
50 
51  COUNT
52  };
53  inline void set_type(Type type);
54  inline Type type() const;
55 
56  Handle<String> TypeAsString() const;
57 
58  DECL_CAST(JSPluralRules)
59  DECL_PRINTER(JSPluralRules)
60  DECL_VERIFIER(JSPluralRules)
61 
62 // Bit positions in |flags|.
63 #define FLAGS_BIT_FIELDS(V, _) V(TypeBits, Type, 1, _)
64 
65  DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
66 #undef FLAGS_BIT_FIELDS
67 
68  STATIC_ASSERT(Type::CARDINAL <= TypeBits::kMax);
69  STATIC_ASSERT(Type::ORDINAL <= TypeBits::kMax);
70 
71 // Layout description.
72 #define JS_PLURAL_RULES_FIELDS(V) \
73  V(kLocaleOffset, kTaggedSize) \
74  V(kFlagsOffset, kTaggedSize) \
75  V(kICUPluralRulesOffset, kTaggedSize) \
76  V(kICUDecimalFormatOffset, kTaggedSize) \
77  /* Total size. */ \
78  V(kSize, 0)
79 
80  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_PLURAL_RULES_FIELDS)
81 #undef JS_PLURAL_RULES_FIELDS
82 
83  DECL_ACCESSORS2(locale, String)
84  DECL_INT_ACCESSORS(flags)
85  DECL_ACCESSORS(icu_plural_rules, Managed<icu::PluralRules>)
86  DECL_ACCESSORS(icu_decimal_format, Managed<icu::DecimalFormat>)
87 
88  private:
89  DISALLOW_IMPLICIT_CONSTRUCTORS(JSPluralRules);
90 };
91 
92 } // namespace internal
93 } // namespace v8
94 
95 #include "src/objects/object-macros-undef.h"
96 
97 #endif // V8_OBJECTS_JS_PLURAL_RULES_H_
Definition: libplatform.h:13