• 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_PLURAL_RULES_H_
10 #define V8_OBJECTS_JS_PLURAL_RULES_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/intl-objects.h"
19 #include "src/objects/managed.h"
20 #include "src/objects/objects.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 PluralRules;
27 namespace number {
28 class LocalizedNumberFormatter;
29 class LocalizedNumberRangeFormatter;
30 }  // namespace number
31 }  // namespace U_ICU_NAMESPACE
32 
33 namespace v8 {
34 namespace internal {
35 
36 #include "torque-generated/src/objects/js-plural-rules-tq.inc"
37 
38 class JSPluralRules
39     : public TorqueGeneratedJSPluralRules<JSPluralRules, JSObject> {
40  public:
41   V8_WARN_UNUSED_RESULT static MaybeHandle<JSPluralRules> New(
42       Isolate* isolate, Handle<Map> map, Handle<Object> locales,
43       Handle<Object> options);
44 
45   static Handle<JSObject> ResolvedOptions(Isolate* isolate,
46                                           Handle<JSPluralRules> plural_rules);
47 
48   V8_WARN_UNUSED_RESULT static MaybeHandle<String> ResolvePlural(
49       Isolate* isolate, Handle<JSPluralRules> plural_rules, double number);
50 
51   V8_WARN_UNUSED_RESULT static MaybeHandle<String> ResolvePluralRange(
52       Isolate* isolate, Handle<JSPluralRules> plural_rules, double x, double y);
53 
54   V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
55 
56   // [[Type]] is one of the values "cardinal" or "ordinal",
57   // identifying the plural rules used.
58   enum class Type { CARDINAL, ORDINAL };
59   inline void set_type(Type type);
60   inline Type type() const;
61 
62   Handle<String> TypeAsString() const;
63 
64   DECL_PRINTER(JSPluralRules)
65 
66   // Bit positions in |flags|.
67   DEFINE_TORQUE_GENERATED_JS_PLURAL_RULES_FLAGS()
68 
69   STATIC_ASSERT(Type::CARDINAL <= TypeBit::kMax);
70   STATIC_ASSERT(Type::ORDINAL <= TypeBit::kMax);
71 
72   DECL_ACCESSORS(icu_plural_rules, Managed<icu::PluralRules>)
73   DECL_ACCESSORS(icu_number_formatter,
74                  Managed<icu::number::LocalizedNumberFormatter>)
75   DECL_ACCESSORS(icu_number_range_formatter,
76                  Managed<icu::number::LocalizedNumberRangeFormatter>)
77 
78   TQ_OBJECT_CONSTRUCTORS(JSPluralRules)
79 };
80 
81 }  // namespace internal
82 }  // namespace v8
83 
84 #include "src/objects/object-macros-undef.h"
85 
86 #endif  // V8_OBJECTS_JS_PLURAL_RULES_H_
87