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_LOCALE_H_ 10 #define V8_OBJECTS_JS_LOCALE_H_ 11 12 #include "src/execution/isolate.h" 13 #include "src/handles/global-handles.h" 14 #include "src/heap/factory.h" 15 #include "src/objects/managed.h" 16 #include "src/objects/objects.h" 17 18 // Has to be the last include (doesn't have include guards): 19 #include "src/objects/object-macros.h" 20 21 namespace U_ICU_NAMESPACE { 22 class Locale; 23 } // namespace U_ICU_NAMESPACE 24 25 namespace v8 { 26 namespace internal { 27 28 #include "torque-generated/src/objects/js-locale-tq.inc" 29 30 class JSLocale : public TorqueGeneratedJSLocale<JSLocale, JSObject> { 31 public: 32 // Creates locale object with properties derived from input locale string 33 // and options. 34 static MaybeHandle<JSLocale> New(Isolate* isolate, Handle<Map> map, 35 Handle<String> locale, 36 Handle<JSReceiver> options); 37 38 static MaybeHandle<JSLocale> Maximize(Isolate* isolate, 39 Handle<JSLocale> locale); 40 static MaybeHandle<JSLocale> Minimize(Isolate* isolate, 41 Handle<JSLocale> locale); 42 43 V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> Calendars( 44 Isolate* isolate, Handle<JSLocale> locale); 45 V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> Collations( 46 Isolate* isolate, Handle<JSLocale> locale); 47 V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> HourCycles( 48 Isolate* isolate, Handle<JSLocale> locale); 49 V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> NumberingSystems( 50 Isolate* isolate, Handle<JSLocale> locale); 51 V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> TextInfo( 52 Isolate* isolate, Handle<JSLocale> locale); 53 V8_WARN_UNUSED_RESULT static MaybeHandle<Object> TimeZones( 54 Isolate* isolate, Handle<JSLocale> locale); 55 V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> WeekInfo( 56 Isolate* isolate, Handle<JSLocale> locale); 57 58 static Handle<Object> Language(Isolate* isolate, Handle<JSLocale> locale); 59 static Handle<Object> Script(Isolate* isolate, Handle<JSLocale> locale); 60 static Handle<Object> Region(Isolate* isolate, Handle<JSLocale> locale); 61 static Handle<String> BaseName(Isolate* isolate, Handle<JSLocale> locale); 62 static Handle<Object> Calendar(Isolate* isolate, Handle<JSLocale> locale); 63 static Handle<Object> CaseFirst(Isolate* isolate, Handle<JSLocale> locale); 64 static Handle<Object> Collation(Isolate* isolate, Handle<JSLocale> locale); 65 static Handle<Object> HourCycle(Isolate* isolate, Handle<JSLocale> locale); 66 static Handle<Object> Numeric(Isolate* isolate, Handle<JSLocale> locale); 67 static Handle<Object> NumberingSystem(Isolate* isolate, 68 Handle<JSLocale> locale); 69 static Handle<String> ToString(Isolate* isolate, Handle<JSLocale> locale); 70 static std::string ToString(Handle<JSLocale> locale); 71 72 // Help function to validate locale by other Intl objects. 73 static bool StartsWithUnicodeLanguageId(const std::string& value); 74 75 // Help function to check well-formed 76 // "(3*8alphanum) *("-" (3*8alphanum)) sequence" sequence 77 static bool Is38AlphaNumList(const std::string& value); 78 79 // Help function to check well-formed "3alpha" 80 static bool Is3Alpha(const std::string& value); 81 82 DECL_ACCESSORS(icu_locale, Managed<icu::Locale>) 83 84 DECL_PRINTER(JSLocale) 85 86 TQ_OBJECT_CONSTRUCTORS(JSLocale) 87 }; 88 89 } // namespace internal 90 } // namespace v8 91 92 #include "src/objects/object-macros-undef.h" 93 94 #endif // V8_OBJECTS_JS_LOCALE_H_ 95