LibJS: Make more use of Value::is and Value::as_if in Intl
This commit is contained in:
parent
e95db70d2d
commit
cbf25177bb
3 changed files with 19 additions and 25 deletions
|
|
@ -264,7 +264,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
|
|||
|
||||
Object* object = nullptr;
|
||||
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
|
||||
if (locales.is_string() || (locales.is_object() && is<Locale>(locales.as_object()))) {
|
||||
if (locales.is_string() || locales.is<Locale>()) {
|
||||
// a. Let O be CreateArrayFromList(« locales »).
|
||||
object = Array::create_from(realm, { locales });
|
||||
}
|
||||
|
|
@ -299,9 +299,9 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
|
|||
String tag;
|
||||
|
||||
// iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then
|
||||
if (key_value.is_object() && is<Locale>(key_value.as_object())) {
|
||||
if (auto locale = key_value.as_if<Locale>()) {
|
||||
// 1. Let tag be kValue.[[Locale]].
|
||||
tag = static_cast<Locale const&>(key_value.as_object()).locale();
|
||||
tag = locale->locale();
|
||||
}
|
||||
// iv. Else,
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -474,24 +474,20 @@ Unicode::CalendarPattern adjust_date_time_style_format(VM& vm, Unicode::Calendar
|
|||
ThrowCompletionOr<FormattableDateTime> to_date_time_formattable(VM& vm, Value value)
|
||||
{
|
||||
// 1. If IsTemporalObject(value) is true, return value.
|
||||
if (value.is_object()) {
|
||||
auto& object = value.as_object();
|
||||
|
||||
if (is<Temporal::Instant>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::Instant&>(object) };
|
||||
if (is<Temporal::PlainDate>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::PlainDate&>(object) };
|
||||
if (is<Temporal::PlainDateTime>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::PlainDateTime&>(object) };
|
||||
if (is<Temporal::PlainMonthDay>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::PlainMonthDay&>(object) };
|
||||
if (is<Temporal::PlainTime>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::PlainTime&>(object) };
|
||||
if (is<Temporal::PlainYearMonth>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::PlainYearMonth&>(object) };
|
||||
if (is<Temporal::ZonedDateTime>(object))
|
||||
return FormattableDateTime { static_cast<Temporal::ZonedDateTime&>(object) };
|
||||
}
|
||||
if (auto instant = value.as_if<Temporal::Instant>())
|
||||
return FormattableDateTime { *instant };
|
||||
if (auto plain_date = value.as_if<Temporal::PlainDate>())
|
||||
return FormattableDateTime { *plain_date };
|
||||
if (auto plain_date_time = value.as_if<Temporal::PlainDateTime>())
|
||||
return FormattableDateTime { *plain_date_time };
|
||||
if (auto plain_month_day = value.as_if<Temporal::PlainMonthDay>())
|
||||
return FormattableDateTime { *plain_month_day };
|
||||
if (auto plain_time = value.as_if<Temporal::PlainTime>())
|
||||
return FormattableDateTime { *plain_time };
|
||||
if (auto plain_year_month = value.as_if<Temporal::PlainYearMonth>())
|
||||
return FormattableDateTime { *plain_year_month };
|
||||
if (auto zoned_date_time = value.as_if<Temporal::ZonedDateTime>())
|
||||
return FormattableDateTime { *zoned_date_time };
|
||||
|
||||
// 2. Return ? ToNumber(value).
|
||||
return FormattableDateTime { TRY(value.to_number(vm)).as_double() };
|
||||
|
|
|
|||
|
|
@ -285,10 +285,8 @@ ThrowCompletionOr<GC::Ref<Object>> LocaleConstructor::construct(FunctionObject&
|
|||
auto tag = TRY([&]() -> ThrowCompletionOr<String> {
|
||||
// 8. If tag is an Object and tag has an [[InitializedLocale]] internal slot, then
|
||||
// a. Let tag be tag.[[Locale]].
|
||||
if (tag_value.is_object()) {
|
||||
if (auto* locale_tag = as_if<Locale>(tag_value.as_object()))
|
||||
return locale_tag->locale();
|
||||
}
|
||||
if (auto locale_tag = tag_value.as_if<Locale>())
|
||||
return locale_tag->locale();
|
||||
// 9. Else,
|
||||
// a. Let tag be ? ToString(tag).
|
||||
return tag_value.to_string(vm);
|
||||
|
|
|
|||
Loading…
Reference in a new issue