v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-display-names.cc
Go to the documentation of this file.
1// Copyright 2019 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
10
11#include <memory>
12#include <vector>
13
15#include "src/heap/factory.h"
22#include "unicode/dtfmtsym.h"
23#include "unicode/dtptngen.h"
24#include "unicode/localebuilder.h"
25#include "unicode/locdspnm.h"
26#include "unicode/measfmt.h"
27#include "unicode/timezone.h"
28#include "unicode/tznames.h"
29#include "unicode/uloc.h"
30#include "unicode/unistr.h"
31#include "unicode/uscript.h"
32
33namespace v8 {
34namespace internal {
35
36namespace {
37// Type: identifying the types of the display names.
38//
39// ecma402/#sec-properties-of-intl-displaynames-instances
40enum class Type {
42 kLanguage,
43 kRegion,
44 kScript,
45 kCurrency,
46 kCalendar,
47 kDateTimeField
48};
49
50bool IsUnicodeScriptSubtag(const std::string& value) {
51 UErrorCode status = U_ZERO_ERROR;
52 icu::LocaleBuilder builder;
53 builder.setScript(value).build(status);
54 return U_SUCCESS(status);
55}
56
57bool IsUnicodeRegionSubtag(const std::string& value) {
58 if (value.empty()) return false;
59 UErrorCode status = U_ZERO_ERROR;
60 icu::LocaleBuilder builder;
61 builder.setRegion(value).build(status);
62 return U_SUCCESS(status);
63}
64
65UDisplayContext ToUDisplayContext(JSDisplayNames::Style style) {
66 switch (style) {
68 return UDISPCTX_LENGTH_FULL;
71 return UDISPCTX_LENGTH_SHORT;
72 }
73}
74
75} // anonymous namespace
76
77// Abstract class for all different types.
79 public:
81
83 virtual ~DisplayNamesInternal() = default;
84 virtual const char* type() const = 0;
85 virtual icu::Locale locale() const = 0;
87 const char* code) const = 0;
88};
89
90namespace {
91
92class LocaleDisplayNamesCommon : public DisplayNamesInternal {
93 public:
94 LocaleDisplayNamesCommon(const icu::Locale& locale,
95 JSDisplayNames::Style style, bool fallback,
96 bool dialect)
97 : style_(style) {
98 UDisplayContext sub =
99 fallback ? UDISPCTX_SUBSTITUTE : UDISPCTX_NO_SUBSTITUTE;
100 UDisplayContext dialect_context =
101 dialect ? UDISPCTX_DIALECT_NAMES : UDISPCTX_STANDARD_NAMES;
102 UDisplayContext display_context[] = {ToUDisplayContext(style_),
103 dialect_context,
104 UDISPCTX_CAPITALIZATION_NONE, sub};
105 ldn_.reset(
106 icu::LocaleDisplayNames::createInstance(locale, display_context, 4));
107 }
108
109 ~LocaleDisplayNamesCommon() override = default;
110
111 icu::Locale locale() const override { return ldn_->getLocale(); }
112
113 protected:
114 icu::LocaleDisplayNames* locale_display_names() const { return ldn_.get(); }
115
116 private:
117 std::unique_ptr<icu::LocaleDisplayNames> ldn_;
119};
120
121class LanguageNames : public LocaleDisplayNamesCommon {
122 public:
123 LanguageNames(const icu::Locale& locale, JSDisplayNames::Style style,
124 bool fallback, bool dialect)
125 : LocaleDisplayNamesCommon(locale, style, fallback, dialect) {}
126
127 ~LanguageNames() override = default;
128
129 const char* type() const override { return "language"; }
130
131 Maybe<icu::UnicodeString> of(Isolate* isolate,
132 const char* code) const override {
133 UErrorCode status = U_ZERO_ERROR;
134 // 1.a If code does not match the unicode_language_id production, throw a
135 // RangeError exception.
136 icu::Locale tagLocale = icu::Locale::forLanguageTag(code, status);
137 icu::Locale l(tagLocale.getBaseName());
138 if (U_FAILURE(status) || tagLocale != l ||
141 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
143 }
144
145 // 1.b If IsStructurallyValidLanguageTag(code) is false, throw a RangeError
146 // exception.
147
148 // 1.c Set code to CanonicalizeUnicodeLocaleId(code).
149 l.canonicalize(status);
150 std::string checked = l.toLanguageTag<std::string>(status);
151
152 if (U_FAILURE(status)) {
154 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
156 }
157
158 icu::UnicodeString result;
159 locale_display_names()->localeDisplayName(checked.c_str(), result);
160
161 return Just(result);
162 }
163};
164
165class RegionNames : public LocaleDisplayNamesCommon {
166 public:
167 RegionNames(const icu::Locale& locale, JSDisplayNames::Style style,
168 bool fallback, bool dialect)
169 : LocaleDisplayNamesCommon(locale, style, fallback, dialect) {}
170
171 ~RegionNames() override = default;
172
173 const char* type() const override { return "region"; }
174
175 Maybe<icu::UnicodeString> of(Isolate* isolate,
176 const char* code) const override {
177 std::string code_str(code);
178 if (!IsUnicodeRegionSubtag(code_str)) {
180 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
182 }
183
184 icu::UnicodeString result;
185 locale_display_names()->regionDisplayName(code_str.c_str(), result);
186 return Just(result);
187 }
188};
189
190class ScriptNames : public LocaleDisplayNamesCommon {
191 public:
192 ScriptNames(const icu::Locale& locale, JSDisplayNames::Style style,
193 bool fallback, bool dialect)
194 : LocaleDisplayNamesCommon(locale, style, fallback, dialect) {}
195
196 ~ScriptNames() override = default;
197
198 const char* type() const override { return "script"; }
199
200 Maybe<icu::UnicodeString> of(Isolate* isolate,
201 const char* code) const override {
202 std::string code_str(code);
203 if (!IsUnicodeScriptSubtag(code_str)) {
205 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
207 }
208
209 icu::UnicodeString result;
210 locale_display_names()->scriptDisplayName(code_str.c_str(), result);
211 return Just(result);
212 }
213};
214
215class KeyValueDisplayNames : public LocaleDisplayNamesCommon {
216 public:
217 KeyValueDisplayNames(const icu::Locale& locale, JSDisplayNames::Style style,
218 bool fallback, bool dialect, const char* key,
219 bool prevent_fallback)
220 : LocaleDisplayNamesCommon(locale, style, fallback, dialect),
221 key_(key),
222 prevent_fallback_(prevent_fallback) {}
223
224 ~KeyValueDisplayNames() override = default;
225
226 const char* type() const override { return key_.c_str(); }
227
228 Maybe<icu::UnicodeString> of(Isolate* isolate,
229 const char* code) const override {
230 std::string code_str(code);
231 icu::UnicodeString result;
232 locale_display_names()->keyValueDisplayName(key_.c_str(), code_str.c_str(),
233 result);
234 // Work around the issue that the keyValueDisplayNames ignore no
235 // substitution and always fallback.
236 if (prevent_fallback_ && (result.length() == 3) &&
237 (code_str.length() == 3) &&
238 (result == icu::UnicodeString(code_str.c_str(), -1, US_INV))) {
239 result.setToBogus();
240 }
241
242 return Just(result);
243 }
244
245 private:
246 std::string key_;
248};
249
250class CurrencyNames : public KeyValueDisplayNames {
251 public:
252 CurrencyNames(const icu::Locale& locale, JSDisplayNames::Style style,
253 bool fallback, bool dialect)
254 : KeyValueDisplayNames(locale, style, fallback, dialect, "currency",
255 fallback == false) {}
256
257 ~CurrencyNames() override = default;
258
259 Maybe<icu::UnicodeString> of(Isolate* isolate,
260 const char* code) const override {
261 std::string code_str(code);
262 if (!Intl::IsWellFormedCurrency(code_str)) {
264 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
266 }
267 return KeyValueDisplayNames::of(isolate, code);
268 }
269};
270
271class CalendarNames : public KeyValueDisplayNames {
272 public:
273 CalendarNames(const icu::Locale& locale, JSDisplayNames::Style style,
274 bool fallback, bool dialect)
275 : KeyValueDisplayNames(locale, style, fallback, dialect, "calendar",
276 false) {}
277
278 ~CalendarNames() override = default;
279
280 Maybe<icu::UnicodeString> of(Isolate* isolate,
281 const char* code) const override {
282 std::string code_str(code);
283 if (!Intl::IsWellFormedCalendar(code_str)) {
285 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
287 }
288 return KeyValueDisplayNames::of(isolate, strcmp(code, "gregory") == 0
289 ? "gregorian"
290 : strcmp(code, "ethioaa") == 0
291 ? "ethiopic-amete-alem"
292 : code);
293 }
294};
295
296UDateTimePGDisplayWidth StyleToUDateTimePGDisplayWidth(
298 switch (style) {
300 return UDATPG_WIDE;
302 return UDATPG_ABBREVIATED;
304 return UDATPG_NARROW;
305 }
306}
307
308UDateTimePatternField StringToUDateTimePatternField(const char* code) {
309 switch (code[0]) {
310 case 'd':
311 if (strcmp(code, "day") == 0) return UDATPG_DAY_FIELD;
312 if (strcmp(code, "dayPeriod") == 0) return UDATPG_DAYPERIOD_FIELD;
313 break;
314 case 'e':
315 if (strcmp(code, "era") == 0) return UDATPG_ERA_FIELD;
316 break;
317 case 'h':
318 if (strcmp(code, "hour") == 0) return UDATPG_HOUR_FIELD;
319 break;
320 case 'm':
321 if (strcmp(code, "minute") == 0) return UDATPG_MINUTE_FIELD;
322 if (strcmp(code, "month") == 0) return UDATPG_MONTH_FIELD;
323 break;
324 case 'q':
325 if (strcmp(code, "quarter") == 0) return UDATPG_QUARTER_FIELD;
326 break;
327 case 's':
328 if (strcmp(code, "second") == 0) return UDATPG_SECOND_FIELD;
329 break;
330 case 't':
331 if (strcmp(code, "timeZoneName") == 0) return UDATPG_ZONE_FIELD;
332 break;
333 case 'w':
334 if (strcmp(code, "weekOfYear") == 0) return UDATPG_WEEK_OF_YEAR_FIELD;
335 if (strcmp(code, "weekday") == 0) return UDATPG_WEEKDAY_FIELD;
336 break;
337 case 'y':
338 if (strcmp(code, "year") == 0) return UDATPG_YEAR_FIELD;
339 break;
340 default:
341 break;
342 }
343 return UDATPG_FIELD_COUNT;
344}
345
346class DateTimeFieldNames : public DisplayNamesInternal {
347 public:
348 DateTimeFieldNames(const icu::Locale& locale, JSDisplayNames::Style style,
349 bool fallback)
350 : locale_(locale), width_(StyleToUDateTimePGDisplayWidth(style)) {
351 UErrorCode status = U_ZERO_ERROR;
352 generator_.reset(
353 icu::DateTimePatternGenerator::createInstance(locale_, status));
354 DCHECK(U_SUCCESS(status));
355 }
356
357 ~DateTimeFieldNames() override = default;
358
359 const char* type() const override { return "dateTimeField"; }
360
361 icu::Locale locale() const override { return locale_; }
362
363 Maybe<icu::UnicodeString> of(Isolate* isolate,
364 const char* code) const override {
365 UDateTimePatternField field = StringToUDateTimePatternField(code);
366 if (field == UDATPG_FIELD_COUNT) {
368 isolate, NewRangeError(MessageTemplate::kInvalidArgument),
370 }
371 return Just(generator_->getFieldDisplayName(field, width_));
372 }
373
374 private:
375 icu::Locale locale_;
376 UDateTimePGDisplayWidth width_;
377 std::unique_ptr<icu::DateTimePatternGenerator> generator_;
378};
379
380DisplayNamesInternal* CreateInternal(const icu::Locale& locale,
381 JSDisplayNames::Style style, Type type,
382 bool fallback, bool dialect) {
383 switch (type) {
384 case Type::kLanguage:
385 return new LanguageNames(locale, style, fallback, dialect);
386 case Type::kRegion:
387 return new RegionNames(locale, style, fallback, false);
388 case Type::kScript:
389 return new ScriptNames(locale, style, fallback, false);
390 case Type::kCurrency:
391 return new CurrencyNames(locale, style, fallback, false);
392 case Type::kCalendar:
393 return new CalendarNames(locale, style, fallback, false);
394 case Type::kDateTimeField:
395 return new DateTimeFieldNames(locale, style, fallback);
396 default:
397 UNREACHABLE();
398 }
399}
400
401} // anonymous namespace
402
403// ecma402 #sec-Intl.DisplayNames
405 Isolate* isolate, DirectHandle<Map> map, DirectHandle<Object> locales,
406 DirectHandle<Object> input_options) {
407 const char* service = "Intl.DisplayNames";
408 Factory* factory = isolate->factory();
409
411 // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
412 Maybe<std::vector<std::string>> maybe_requested_locales =
413 Intl::CanonicalizeLocaleList(isolate, locales);
414 MAYBE_RETURN(maybe_requested_locales, DirectHandle<JSDisplayNames>());
415 std::vector<std::string> requested_locales =
416 maybe_requested_locales.FromJust();
417
418 // 4. Let options be ? GetOptionsObject(options).
419 ASSIGN_RETURN_ON_EXCEPTION(isolate, options,
420 GetOptionsObject(isolate, input_options, service));
421
422 // Note: No need to create a record. It's not observable.
423 // 5. Let opt be a new Record.
424
425 // 6. Let localeData be %DisplayNames%.[[LocaleData]].
426
427 // 7. Let matcher be ? GetOption(options, "localeMatcher", "string", «
428 // "lookup", "best fit" », "best fit").
429 Maybe<Intl::MatcherOption> maybe_locale_matcher =
430 Intl::GetLocaleMatcher(isolate, options, service);
431 MAYBE_RETURN(maybe_locale_matcher, MaybeDirectHandle<JSDisplayNames>());
432
433 // 8. Set opt.[[localeMatcher]] to matcher.
434 Intl::MatcherOption matcher = maybe_locale_matcher.FromJust();
435
436 // ecma402/#sec-Intl.DisplayNames-internal-slots
437 // The value of the [[RelevantExtensionKeys]] internal slot is
438 // « ».
439 std::set<std::string> relevant_extension_keys = {};
440 // 9. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]],
441 // requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]).
442 Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
444 requested_locales, matcher, relevant_extension_keys);
445 if (maybe_resolve_locale.IsNothing()) {
446 THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError));
447 }
448 Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
449
450 icu::Locale icu_locale = r.icu_locale;
451
452 // 10. Let s be ? GetOption(options, "style", "string",
453 // «"long", "short", "narrow"», "long").
455 isolate, options, "style", service, {"long", "short", "narrow"},
458 Style style_enum = maybe_style.FromJust();
459
460 // 11. Set displayNames.[[Style]] to style.
461
462 // 12. Let type be ? GetOption(options, "type", "string", « "language",
463 // "region", "script", "currency" , "calendar", "dateTimeField", "unit"»,
464 // undefined).
466 isolate, options, "type", service,
467 {"language", "region", "script", "currency", "calendar", "dateTimeField"},
468 {Type::kLanguage, Type::kRegion, Type::kScript, Type::kCurrency,
469 Type::kCalendar, Type::kDateTimeField},
470 Type::kUndefined);
472 Type type_enum = maybe_type.FromJust();
473
474 // 13. If type is undefined, throw a TypeError exception.
475 if (type_enum == Type::kUndefined) {
476 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kInvalidArgument));
477 }
478
479 // 14. Set displayNames.[[Type]] to type.
480
481 // 15. Let fallback be ? GetOption(options, "fallback", "string",
482 // « "code", "none" », "code").
484 isolate, options, "fallback", service, {"code", "none"},
487 Fallback fallback_enum = maybe_fallback.FromJust();
488
489 // 16. Set displayNames.[[Fallback]] to fallback.
490
491 LanguageDisplay language_display_enum = LanguageDisplay::kDialect;
492 // 24. Let languageDisplay be ? GetOption(options, "languageDisplay",
493 // "string", « "dialect", "standard" », "dialect").
494 Maybe<LanguageDisplay> maybe_language_display =
496 isolate, options, "languageDisplay", service, {"dialect", "standard"},
499 MAYBE_RETURN(maybe_language_display, MaybeDirectHandle<JSDisplayNames>());
500 // 25. If type is "language", then
501 if (type_enum == Type::kLanguage) {
502 // a. Set displayNames.[[LanguageDisplay]] to languageDisplay.
503 language_display_enum = maybe_language_display.FromJust();
504 }
505
506 // Set displayNames.[[Fallback]] to fallback.
507
508 // 17. Set displayNames.[[Locale]] to the value of r.[[Locale]].
509
510 // Let dataLocale be r.[[dataLocale]].
511
512 // Let dataLocaleData be localeData.[[<dataLocale>]].
513
514 // Let types be dataLocaleData.[[types]].
515
516 // Assert: types is a Record (see 1.3.3).
517
518 // Let typeFields be types.[[<type>]].
519
520 // Assert: typeFields is a Record (see 1.3.3).
521
522 // Let styleFields be typeFields.[[<style>]].
523
524 // Assert: styleFields is a Record (see 1.3.3).
525
526 // Set displayNames.[[Fields]] to styleFields.
527
528 std::shared_ptr<DisplayNamesInternal> internal{CreateInternal(
529 icu_locale, style_enum, type_enum, fallback_enum == Fallback::kCode,
530 language_display_enum == LanguageDisplay::kDialect)};
531 if (internal == nullptr) {
532 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIcuError));
533 }
534
536 Managed<DisplayNamesInternal>::From(isolate, 0, std::move(internal));
537
538 DirectHandle<JSDisplayNames> display_names =
540 display_names->set_flags(0);
541 display_names->set_style(style_enum);
542 display_names->set_fallback(fallback_enum);
543 display_names->set_language_display(language_display_enum);
544
546 display_names->set_internal(*managed_internal);
547
548 // Return displayNames.
549 return display_names;
550}
551
552// ecma402 #sec-Intl.DisplayNames.prototype.resolvedOptions
554 Isolate* isolate, DirectHandle<JSDisplayNames> display_names) {
555 Factory* factory = isolate->factory();
556 // 4. Let options be ! ObjectCreate(%ObjectPrototype%).
557 DirectHandle<JSObject> options =
558 factory->NewJSObject(isolate->object_function());
559
560 DisplayNamesInternal* internal = display_names->internal()->raw();
561
562 Maybe<std::string> maybe_locale = Intl::ToLanguageTag(internal->locale());
563 DCHECK(maybe_locale.IsJust());
564 DirectHandle<String> locale = isolate->factory()->NewStringFromAsciiChecked(
565 maybe_locale.FromJust().c_str());
566 DirectHandle<String> style = display_names->StyleAsString(isolate);
568 factory->NewStringFromAsciiChecked(internal->type());
569 DirectHandle<String> fallback = display_names->FallbackAsString(isolate);
571 display_names->LanguageDisplayAsString(isolate);
572
573 Maybe<bool> maybe_create_locale = JSReceiver::CreateDataProperty(
574 isolate, options, factory->locale_string(), locale, Just(kDontThrow));
575 DCHECK(maybe_create_locale.FromJust());
576 USE(maybe_create_locale);
577
578 Maybe<bool> maybe_create_style = JSReceiver::CreateDataProperty(
579 isolate, options, factory->style_string(), style, Just(kDontThrow));
580 DCHECK(maybe_create_style.FromJust());
581 USE(maybe_create_style);
582
584 isolate, options, factory->type_string(), type, Just(kDontThrow));
585 DCHECK(maybe_create_type.FromJust());
586 USE(maybe_create_type);
587
588 Maybe<bool> maybe_create_fallback = JSReceiver::CreateDataProperty(
589 isolate, options, factory->fallback_string(), fallback, Just(kDontThrow));
590 DCHECK(maybe_create_fallback.FromJust());
591 USE(maybe_create_fallback);
592
593 if (std::strcmp("language", internal->type()) == 0) {
594 Maybe<bool> maybe_create_language_display =
595 JSReceiver::CreateDataProperty(isolate, options,
596 factory->languageDisplay_string(),
598 DCHECK(maybe_create_language_display.FromJust());
599 USE(maybe_create_language_display);
600 }
601
602 return options;
603}
604
605// ecma402 #sec-Intl.DisplayNames.prototype.of
607 Isolate* isolate, DirectHandle<JSDisplayNames> display_names,
608 Handle<Object> code_obj) {
610 ASSIGN_RETURN_ON_EXCEPTION(isolate, code,
611 Object::ToString(isolate, code_obj));
612 DisplayNamesInternal* internal = display_names->internal()->raw();
613 Maybe<icu::UnicodeString> maybe_result =
614 internal->of(isolate, code->ToCString().get());
615 MAYBE_RETURN(maybe_result, DirectHandle<Object>());
616 icu::UnicodeString result = maybe_result.FromJust();
617 if (result.isBogus()) {
618 return isolate->factory()->undefined_value();
619 }
620 return Intl::ToString(isolate, result).ToHandleChecked();
621}
622
623namespace {
624
625struct CheckCalendar {
626 static const char* key() { return "calendar"; }
627 static const char* path() { return nullptr; }
628};
629
630} // namespace
631
632const std::set<std::string>& JSDisplayNames::GetAvailableLocales() {
634 available_locales = LAZY_INSTANCE_INITIALIZER;
635 return available_locales.Pointer()->Get();
636}
637
639 switch (style()) {
640 case Style::kLong:
641 return isolate->factory()->long_string();
642 case Style::kShort:
643 return isolate->factory()->short_string();
644 case Style::kNarrow:
645 return isolate->factory()->narrow_string();
646 }
647 UNREACHABLE();
648}
649
651 switch (fallback()) {
652 case Fallback::kCode:
653 return isolate->factory()->code_string();
654 case Fallback::kNone:
655 return isolate->factory()->none_string();
656 }
657 UNREACHABLE();
658}
659
661 Isolate* isolate) const {
662 switch (language_display()) {
664 return isolate->factory()->dialect_string();
666 return isolate->factory()->standard_string();
667 }
668 UNREACHABLE();
669}
670
671} // namespace internal
672} // namespace v8
V8_INLINE bool IsJust() const
Definition v8-maybe.h:36
V8_INLINE T FromJust() const &
Definition v8-maybe.h:64
V8_INLINE bool IsNothing() const
Definition v8-maybe.h:35
virtual const char * type() const =0
virtual Maybe< icu::UnicodeString > of(Isolate *isolate, const char *code) const =0
static constexpr ExternalPointerTag kManagedTag
virtual icu::Locale locale() const =0
virtual ~DisplayNamesInternal()=default
Handle< String > NewStringFromAsciiChecked(const char *str, AllocationType allocation=AllocationType::kYoung)
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:2985
Handle< JSObject > NewFastOrSlowJSObjectFromMap(DirectHandle< Map > map, int number_of_slow_properties, AllocationType allocation=AllocationType::kYoung, DirectHandle< AllocationSite > allocation_site=DirectHandle< AllocationSite >::null(), NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
static bool IsWellFormedCurrency(const std::string &value)
static V8_WARN_UNUSED_RESULT MaybeHandle< String > ToString(Isolate *isolate, const icu::UnicodeString &string)
static Maybe< std::vector< std::string > > CanonicalizeLocaleList(Isolate *isolate, DirectHandle< Object > locales, bool only_return_one_result=false)
static Maybe< ResolvedLocale > ResolveLocale(Isolate *isolate, const std::set< std::string > &available_locales, const std::vector< std::string > &requested_locales, MatcherOption options, const std::set< std::string > &relevant_extension_keys)
static V8_WARN_UNUSED_RESULT Maybe< MatcherOption > GetLocaleMatcher(Isolate *isolate, DirectHandle< JSReceiver > options, const char *method_name)
static bool IsWellFormedCalendar(const std::string &value)
static Maybe< std::string > ToLanguageTag(const icu::Locale &locale)
static MaybeDirectHandle< Object > Of(Isolate *isolate, DirectHandle< JSDisplayNames > holder, Handle< Object > code_obj)
static V8_EXPORT_PRIVATE const std::set< std::string > & GetAvailableLocales()
LanguageDisplay language_display() const
Handle< String > StyleAsString(Isolate *isolate) const
DirectHandle< String > LanguageDisplayAsString(Isolate *isolate) const
Handle< String > FallbackAsString(Isolate *isolate) const
static MaybeDirectHandle< JSDisplayNames > New(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Object > locales, DirectHandle< Object > options)
static DirectHandle< JSObject > ResolvedOptions(Isolate *isolate, DirectHandle< JSDisplayNames > format_holder)
static bool StartsWithUnicodeLanguageId(const std::string &value)
Definition js-locale.cc:224
static V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > key, DirectHandle< Object > value, Maybe< ShouldThrow > should_throw)
static DirectHandle< Managed< CppType > > From(Isolate *isolate, size_t estimated_size, std::shared_ptr< CppType > shared_ptr, AllocationType allocation_type=AllocationType::kYoung)
Definition managed-inl.h:27
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
Handle< Code > code
Handle< SharedFunctionInfo > key_
#define THROW_NEW_ERROR_RETURN_VALUE(isolate, call, value)
Definition isolate.h:300
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:291
#define THROW_NEW_ERROR(isolate, call)
Definition isolate.h:307
#define MAYBE_RETURN(call, value)
Definition isolate.h:408
icu::Locale locale_
JSDisplayNames::Style style_
std::unique_ptr< icu::DateTimePatternGenerator > generator_
UDateTimePGDisplayWidth width_
std::unique_ptr< icu::LocaleDisplayNames > ldn_
bool prevent_fallback_
JSDurationFormat::FieldStyle style
DirectHandle< JSReceiver > options
ZoneVector< RpoNumber > & result
#define LAZY_INSTANCE_INITIALIZER
int r
Definition mul-fft.cc:298
MaybeDirectHandle< JSReceiver > GetOptionsObject(Isolate *isolate, DirectHandle< Object > options, const char *method_name)
@ kDisplayNamesInternalTag
Maybe< bool > GetStringOption(Isolate *isolate, DirectHandle< JSReceiver > options, const char *property, const std::vector< const char * > &values, const char *method_name, std::unique_ptr< char[]> *result)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Maybe< T > Nothing()
Definition v8-maybe.h:112
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
#define DCHECK(condition)
Definition logging.h:482
#define USE(...)
Definition macros.h:293
wasm::ValueType type