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