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 static Handle<Object> Language(Isolate* isolate, Handle<JSLocale> locale); 44 static Handle<Object> Script(Isolate* isolate, Handle<JSLocale> locale); 45 static Handle<Object> Region(Isolate* isolate, Handle<JSLocale> locale); 46 static Handle<String> BaseName(Isolate* isolate, Handle<JSLocale> locale); 47 static Handle<Object> Calendar(Isolate* isolate, Handle<JSLocale> locale); 48 static Handle<Object> CaseFirst(Isolate* isolate, Handle<JSLocale> locale); 49 static Handle<Object> Collation(Isolate* isolate, Handle<JSLocale> locale); 50 static Handle<Object> HourCycle(Isolate* isolate, Handle<JSLocale> locale); 51 static Handle<Object> Numeric(Isolate* isolate, Handle<JSLocale> locale); 52 static Handle<Object> NumberingSystem(Isolate* isolate, 53 Handle<JSLocale> locale); 54 static Handle<String> ToString(Isolate* isolate, Handle<JSLocale> locale); 55 static std::string ToString(Handle<JSLocale> locale); 56 57 // Help function to validate locale by other Intl objects. 58 static bool StartsWithUnicodeLanguageId(const std::string& value); 59 60 // Help function to check well-formed 61 // "(3*8alphanum) *("-" (3*8alphanum)) sequence" sequence 62 static bool Is38AlphaNumList(const std::string& value); 63 64 // Help function to check well-formed "3alpha" 65 static bool Is3Alpha(const std::string& value); 66 67 DECL_ACCESSORS(icu_locale, Managed<icu::Locale>) 68 69 DECL_PRINTER(JSLocale) 70 71 TQ_OBJECT_CONSTRUCTORS(JSLocale) 72 }; 73 74 } // namespace internal 75 } // namespace v8 76 77 #include "src/objects/object-macros-undef.h" 78 79 #endif // V8_OBJECTS_JS_LOCALE_H_ 80