Implement new methods of Intl.Locale

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2025-08-05 16:35:26 +09:00 committed by MuHong Byun
commit a058a43145
5 changed files with 43 additions and 66 deletions

View file

@ -1793,6 +1793,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyCalendars()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetCalendars(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetCalendars(), builtinIntlLocaleCalendarsGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1800,6 +1802,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyCollations()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetCollations(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetCollations(), builtinIntlLocaleCollationsGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1807,6 +1811,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyHourCycles()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetHourCycles(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetHourCycles(), builtinIntlLocaleHourCyclesGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1814,6 +1820,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyNumberingSystems()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetNumberingSystems(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetNumberingSystems(), builtinIntlLocaleNumberingSystemsGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1821,6 +1829,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyTextInfo()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetTextInfo(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetTextInfo(), builtinIntlLocaleTextInfoGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1828,6 +1838,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyWeekInfo()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetWeekInfo(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetWeekInfo(), builtinIntlLocaleWeekInfoGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
{
@ -1835,6 +1847,8 @@ void GlobalObject::installIntl(ExecutionState& state)
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_intlLocalePrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->lazyTimeZones()), desc);
m_intlLocalePrototype->directDefineOwnProperty(state, state.context()->staticStrings().lazyGetTimeZones(),
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetTimeZones(), builtinIntlLocaleTimeZonesGetter, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent)));
}
#if defined(ENABLE_INTL_RELATIVETIMEFORMAT)

View file

@ -1768,6 +1768,7 @@ bool LanguageTagParser::parseUnicodeLanguageId()
if (iter != subtags.end()) {
return false;
}
subtags.insert(lowerVariant);
if (!next())
return true;
}

View file

@ -662,33 +662,6 @@ Value IntlLocaleObject::weekInfo(ExecutionState& state)
return Value();
}
int32_t weekendStart = 0;
int32_t weekendEnd = 0;
for (int32_t day = UCAL_SUNDAY; day <= UCAL_SATURDAY; ++day) {
UCalendarWeekdayType type = canonicalizeDayOfWeekType(ucal_getDayOfWeekType(calendar.get(), static_cast<UCalendarDaysOfWeek>(day), &status));
if (!U_SUCCESS(status)) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Invalid locale");
return Value();
}
if (previous != type) {
switch (type) {
case UCAL_WEEKDAY: // WeekEnd => WeekDay
if (day == UCAL_SUNDAY)
weekendEnd = UCAL_SATURDAY;
else
weekendEnd = day - 1;
break;
case UCAL_WEEKEND: // WeekDay => WeekEnd
weekendStart = day;
break;
default:
ASSERT_NOT_REACHED();
break;
}
}
previous = type;
}
auto convertUCalendarDaysOfWeekToMondayBasedDay = [](int32_t day) -> int32_t {
// Convert from
// Sunday => 1
@ -701,10 +674,29 @@ Value IntlLocaleObject::weekInfo(ExecutionState& state)
return day - 1;
};
ArrayObject* weekendArray = new ArrayObject(state);
size_t index = 0;
for (int32_t day = 1; day <= 7; ++day) {
UCalendarWeekdayType type = canonicalizeDayOfWeekType(ucal_getDayOfWeekType(calendar.get(), static_cast<UCalendarDaysOfWeek>(convertUCalendarDaysOfWeekToMondayBasedDay(day)), &status));
if (!U_SUCCESS(status)) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Invalid locale");
return Value();
}
switch (type) {
case UCAL_WEEKDAY:
break;
case UCAL_WEEKEND:
weekendArray->setIndexedProperty(state, Value(index++), Value(day), weekendArray);
break;
default:
ASSERT_NOT_REACHED();
break;
}
}
Object* result = new Object(state);
result->set(state, ObjectPropertyName(state, String::fromASCII("firstDay")), Value(convertUCalendarDaysOfWeekToMondayBasedDay(firstDayOfWeek)), result);
result->set(state, ObjectPropertyName(state, String::fromASCII("weekendStart")), Value(convertUCalendarDaysOfWeekToMondayBasedDay(weekendStart)), result);
result->set(state, ObjectPropertyName(state, String::fromASCII("weekendEnd")), Value(convertUCalendarDaysOfWeekToMondayBasedDay(weekendEnd)), result);
result->set(state, ObjectPropertyName(state, String::fromASCII("weekend")), weekendArray, result);
result->set(state, ObjectPropertyName(state, String::fromASCII("minimalDays")), Value(minimalDays), result);
return result;
}

View file

@ -776,6 +776,13 @@ namespace Escargot {
F(FractionalSecond, "fractionalSecond") \
F(FractionalSecondDigits, "fractionalSecondDigits") \
F(Full, "full") \
F(GetCalendars, "getCalendars") \
F(GetCollations, "getCollations") \
F(GetHourCycles, "getHourCycles") \
F(GetNumberingSystems, "getNumberingSystems") \
F(GetTextInfo, "getTextInfo") \
F(GetTimeZones, "getTimeZones") \
F(GetWeekInfo, "getWeekInfo") \
F(Group, "group") \
F(H11, "h11") \
F(H12, "h12") \

View file

@ -4652,43 +4652,6 @@
<test id="intl402/Locale/extensions-grandfathered"><reason>TODO</reason></test>
<test id="intl402/Locale/getters-grandfathered"><reason>TODO</reason></test>
<test id="intl402/Locale/likely-subtags-grandfathered"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCalendars/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCalendars/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCalendars/output-array"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCalendars/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCollations/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCollations/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCollations/output-array"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCollations/output-array-values"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getCollations/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getHourCycles/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getHourCycles/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getHourCycles/output-array"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getHourCycles/output-array-values"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getHourCycles/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getNumberingSystems/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getNumberingSystems/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getNumberingSystems/output-array"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getNumberingSystems/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTextInfo/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTextInfo/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTextInfo/output-object"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTextInfo/output-object-keys"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTextInfo/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/output-array"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/output-array-sorted"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/output-array-undefined"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getTimeZones/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/branding"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/firstDay-by-id"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/firstDay-by-option"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/name"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/output-object"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/output-object-keys"><reason>TODO</reason></test>
<test id="intl402/Locale/prototype/getWeekInfo/prop-desc"><reason>TODO</reason></test>
<test id="intl402/Locale/reject-duplicate-variants-in-tlang"><reason>TODO</reason></test>
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-long"><reason>TODO</reason></test>
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-narrow"><reason>TODO</reason></test>
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-short"><reason>TODO</reason></test>