Commit 4819584a authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Implement the iso8601 part of Calendar.prototype.era(Year)?

Spec text:
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.erayear

Notice this only implement the "iso8601" calendar and we will implement the
code for other calendar later by calling ICU with other Calendar methods.
This CL reduce the differences of testing result between ALWAYS and no_i18n
because the code in no_i18n will not call Calendar era or eraYear and therefore
passed the test even w/o this CL but the ALWAYS tests will cause Temporal
object to internal call era and eraYear and therefore fail if w/o this CL.

Bug: v8:11544
Change-Id: I921fbfbbd26473c238024161eb58b096c38b881b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3641938Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80513}
parent a9f80285
......@@ -287,10 +287,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
#ifdef V8_INTL_SUPPORT
/* Temporal */
/* Temporal #sec-temporal.calendar.prototype.era */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeEra)
/* Temporal #sec-temporal.calendar.prototype.erayear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeEraYear)
/* Temporal #sec-temporal.duration.prototype.tolocalestring */
TO_BE_IMPLEMENTED(TemporalDurationPrototypeToLocaleString)
/* Temporal #sec-temporal.instant.prototype.tolocalestring */
......@@ -858,6 +854,9 @@ BUILTIN(TemporalTimeZoneFrom) {
}
#ifdef V8_INTL_SUPPORT
// Temporal.Calendar.prototype.era/eraYear
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Era, era)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, EraYear, eraYEar)
// get Temporal.*.prototype.era/eraYear
TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainDate, Era, era)
TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainDate, EraYear, eraYear)
......
......@@ -6666,6 +6666,71 @@ MaybeHandle<JSTemporalPlainYearMonth> JSTemporalCalendar::YearMonthFromFields(
UNREACHABLE();
}
#ifdef V8_INTL_SUPPORT
// #sup-temporal.calendar.prototype.era
MaybeHandle<Object> JSTemporalCalendar::Era(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. If Type(temporalDateLike) is not Object or temporalDateLike does not
// have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]],
// or [[InitializedTemporalYearMonth]]
// internal slot, then
if (!IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like)) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
ToTemporalDate(isolate, temporal_date_like,
"Temporal.Calendar.prototype.era"),
Object);
}
// 4. If calendar.[[Identifier]] is "iso8601", then
if (calendar->calendar_index() == 0) {
// a. Return undefined.
return isolate->factory()->undefined_value();
}
UNIMPLEMENTED();
// TODO(ftang) implement other calendars
// 5. Return ! CalendarDateEra(calendar.[[Identifier]], temporalDateLike).
}
// #sup-temporal.calendar.prototype.erayear
MaybeHandle<Object> JSTemporalCalendar::EraYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. If Type(temporalDateLike) is not Object or temporalDateLike does not
// have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]],
// or [[InitializedTemporalYearMonth]]
// internal slot, then
if (!IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like)) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
ToTemporalDate(isolate, temporal_date_like,
"Temporal.Calendar.prototype.eraYear"),
Object);
}
// 4. If calendar.[[Identifier]] is "iso8601", then
if (calendar->calendar_index() == 0) {
// a. Return undefined.
return isolate->factory()->undefined_value();
}
UNIMPLEMENTED();
// TODO(ftang) implement other calendars
// 5. Let eraYear be ! CalendarDateEraYear(calendar.[[Identifier]],
// temporalDateLike).
// 6. If eraYear is undefined, then
// a. Return undefined.
// 7. Return 𝔽(eraYear).
}
#endif // V8_INTL_SUPPORT
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -142,6 +142,15 @@ class JSTemporalCalendar
Handle<JSTemporalCalendar> calendar,
const char* method_name);
#ifdef V8_INTL_SUPPORT
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Era(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> EraYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
#endif // V8_INTL_SUPPORT
DECL_PRINTER(JSTemporalCalendar)
DEFINE_TORQUE_GENERATED_JS_TEMPORAL_CALENDAR_FLAGS()
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment