[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/+/3641938
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80513}
This commit is contained in:
Frank Tang 2022-05-11 09:44:43 -07:00 committed by V8 LUCI CQ
parent a9f802859b
commit 4819584a2c
4 changed files with 77 additions and 168 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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()

View File

@ -1967,16 +1967,6 @@
'intl402/DateTimeFormat/prototype/format/temporal-objects-resolved-time-zone': [FAIL],
'intl402/DateTimeFormat/prototype/formatToParts/temporal-objects-resolved-time-zone': [FAIL],
'intl402/Temporal/Calendar/prototype/dateFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-string-with-utc-designator': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'intl402/Temporal/Calendar/prototype/era/branding': [FAIL],
'intl402/Temporal/Calendar/prototype/era/calendar-datefromfields-called-with-options-undefined': [FAIL],
'intl402/Temporal/Calendar/prototype/era/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-string-with-utc-designator': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/branding': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/calendar-datefromfields-called-with-options-undefined': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/monthDayFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/weekOfYear/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/yearMonthFromFields/infinity-throws-rangeerror': [FAIL],
@ -2448,8 +2438,6 @@
'built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-invalid': [FAIL],
'built-ins/Temporal/PlainYearMonth/calendar-always': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-invalid': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-string-invalid': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-string-invalid': [FAIL],
'built-ins/Temporal/Duration/compare/options-wrong-type': [FAIL],
'built-ins/Temporal/Duration/prototype/add/options-wrong-type': [FAIL],
@ -2801,14 +2789,8 @@
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-number': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-wrong-type': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-wrong-type': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-number': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-wrong-type': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type': [FAIL],
'harness/temporalHelpers-one-shift-time-zone': [SKIP],
@ -2876,81 +2858,6 @@
'built-ins/Temporal/Now/zonedDateTimeISO/timezone-string-datetime': [SKIP],
'built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string-datetime': [SKIP],
'built-ins/Temporal/ZonedDateTime/timezone-string-datetime': [SKIP],
# Test passed in no_i18n only.
'built-ins/Temporal/Calendar/prototype/dateFromFields/overflow-undefined': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateFromFields/overflow-wrong-type': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day-need-constrain': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day-need-constrain': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day': [SKIP],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic': [SKIP],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain': [SKIP],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined': [SKIP],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-wrong-type': [SKIP],
'built-ins/Temporal/PlainDate/basic': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-number': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-object-invalid': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-object-valid': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-plaindate': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-plaindatetime': [SKIP],
'built-ins/Temporal/PlainDate/from/argument-string': [SKIP],
'built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string': [SKIP],
'built-ins/Temporal/PlainDate/from/order-of-operations': [SKIP],
'built-ins/Temporal/PlainDate/from/overflow-undefined': [SKIP],
'built-ins/Temporal/PlainDate/from/overflow-wrong-type': [SKIP],
'built-ins/Temporal/PlainDate/from/subclassing-ignored': [SKIP],
'built-ins/Temporal/PlainDate/prototype/withCalendar/basic': [SKIP],
'built-ins/Temporal/PlainDateTime/constructor-full': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-number': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-object': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-plaindate': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-plaindatetime': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-comma-decimal-separator': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-minus-sign': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-offset': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-optional-data': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-subsecond': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-time-separators': [SKIP],
'built-ins/Temporal/PlainDateTime/from/argument-string-timezone': [SKIP],
'built-ins/Temporal/PlainDateTime/from/leap-second': [SKIP],
'built-ins/Temporal/PlainDateTime/from/order-of-operations': [SKIP],
'built-ins/Temporal/PlainDateTime/from/overflow-default-constrain': [SKIP],
'built-ins/Temporal/PlainDateTime/from/overflow-reject': [SKIP],
'built-ins/Temporal/PlainDateTime/from/overflow-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/from/overflow-wrong-type': [SKIP],
'built-ins/Temporal/PlainDateTime/from/parser': [SKIP],
'built-ins/Temporal/PlainDateTime/from/subclassing-ignored': [SKIP],
'built-ins/Temporal/PlainDateTime/hour-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/microsecond-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/millisecond-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/minute-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/nanosecond-undefined': [SKIP],
'built-ins/Temporal/PlainDateTime/order-of-operations': [SKIP],
'built-ins/Temporal/PlainDateTime/second-undefined': [SKIP],
'built-ins/Temporal/PlainYearMonth/basic': [SKIP],
'built-ins/Temporal/PlainYearMonth/limits': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-number': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-plaindatetime': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/balance-smaller-units': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/basic': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-undefined': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-wrong-type': [SKIP],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type': [SKIP],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/custom-timezone': [SKIP],
# Flaky Temporal tests
'built-ins/Temporal/Instant/from/instant-string-sub-minute-offset': [SKIP],
'built-ins/Temporal/Instant/from/basic': [SKIP],
@ -3098,77 +3005,6 @@
'language/identifiers/start-unicode-8*': [FAIL],
'language/identifiers/start-unicode-9*': [FAIL],
# Passed test in no_i18n
'built-ins/Temporal/Calendar/prototype/dateFromFields/overflow-undefined': [PASS],
'built-ins/Temporal/Calendar/prototype/dateFromFields/overflow-wrong-type': [PASS],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day-need-constrain': [PASS],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day': [PASS],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day-need-constrain': [PASS],
'built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day': [PASS],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic': [PASS],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain': [PASS],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined': [PASS],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-wrong-type': [PASS],
'built-ins/Temporal/PlainDate/basic': [PASS],
'built-ins/Temporal/PlainDate/from/argument-number': [PASS],
'built-ins/Temporal/PlainDate/from/argument-object-invalid': [PASS],
'built-ins/Temporal/PlainDate/from/argument-object-valid': [PASS],
'built-ins/Temporal/PlainDate/from/argument-plaindate': [PASS],
'built-ins/Temporal/PlainDate/from/argument-plaindatetime': [PASS],
'built-ins/Temporal/PlainDate/from/argument-string': [PASS],
'built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string': [PASS],
'built-ins/Temporal/PlainDate/from/order-of-operations': [PASS],
'built-ins/Temporal/PlainDate/from/overflow-undefined': [PASS],
'built-ins/Temporal/PlainDate/from/overflow-wrong-type': [PASS],
'built-ins/Temporal/PlainDate/from/subclassing-ignored': [PASS],
'built-ins/Temporal/PlainDate/prototype/withCalendar/basic': [PASS],
'built-ins/Temporal/PlainDateTime/constructor-full': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-number': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-object': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-plaindate': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-plaindatetime': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-comma-decimal-separator': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-minus-sign': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-offset': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-optional-data': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-subsecond': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-time-separators': [PASS],
'built-ins/Temporal/PlainDateTime/from/argument-string-timezone': [PASS],
'built-ins/Temporal/PlainDateTime/from/leap-second': [PASS],
'built-ins/Temporal/PlainDateTime/from/order-of-operations': [PASS],
'built-ins/Temporal/PlainDateTime/from/overflow-default-constrain': [PASS],
'built-ins/Temporal/PlainDateTime/from/overflow-reject': [PASS],
'built-ins/Temporal/PlainDateTime/from/overflow-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/from/overflow-wrong-type': [PASS],
'built-ins/Temporal/PlainDateTime/from/parser': [PASS],
'built-ins/Temporal/PlainDateTime/from/subclassing-ignored': [PASS],
'built-ins/Temporal/PlainDateTime/hour-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/microsecond-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/millisecond-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/minute-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/nanosecond-undefined': [PASS],
'built-ins/Temporal/PlainDateTime/order-of-operations': [PASS],
'built-ins/Temporal/PlainDateTime/second-undefined': [PASS],
'built-ins/Temporal/PlainYearMonth/basic': [PASS],
'built-ins/Temporal/PlainYearMonth/limits': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-days': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-number': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-plaindatetime': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/balance-smaller-units': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/basic': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-undefined': [PASS],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-wrong-type': [PASS],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type': [PASS],
}], # no_i18n == True
['arch == arm or arch == mipsel or arch == mips or arch == arm64 or arch == mips64 or arch == mips64el', {