[Temporal] Add Temporal.Calendar.prototype.year

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.year

Note- this is only the non-intl version. intl version in
https://tc39.es/proposal-temporal/#sup-temporal.calendar.prototype.year
will be implemented in later cl.

Bug: v8:11544
Change-Id: Ifadcdb4efe00a9954d5ac4c1154420c4903f28d5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531553
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79635}
This commit is contained in:
Frank Tang 2022-03-26 15:31:23 -07:00 committed by V8 LUCI CQ
parent cdafded496
commit 8b663818fc
5 changed files with 47 additions and 14 deletions

View File

@ -316,8 +316,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthDayFromFields)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDateAdd)
/* Temporal #sec-temporal.calendar.prototype.dateuntil */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDateUntil)
/* Temporal #sec-temporal.calendar.prototype.year */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeYear)
/* Temporal #sec-temporal.calendar.prototype.month */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonth)
/* Temporal #sec-temporal.calendar.prototype.monthcode */
@ -802,6 +800,7 @@ TEMPORAL_GET_BIGINT_AFTER_DIVID(Instant, EpochMicroseconds, nanoseconds, 1000,
// Calendar
TEMPORAL_CONSTRUCTOR1(Calendar)
TEMPORAL_ID_BY_TO_STRING(Calendar)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DaysInYear, daysInYear)
TEMPORAL_TO_STRING(Calendar)
// #sec-temporal.calendar.from

View File

@ -4829,6 +4829,47 @@ MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
return handle(Smi::FromInt(days_in_year), isolate);
}
// #sec-temporal.calendar.prototype.year
MaybeHandle<Smi> JSTemporalCalendar::Year(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not
// have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]],
// or [[InitializedTemporalYearMonth]]
// internal slot, then
if (!(temporal_date_like->IsJSTemporalPlainDate() ||
temporal_date_like->IsJSTemporalPlainDateTime() ||
temporal_date_like->IsJSTemporalPlainYearMonth())) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
ToTemporalDate(isolate, temporal_date_like,
isolate->factory()->NewJSObjectWithNullProto(),
"Temporal.Calendar.prototype.year"),
Smi);
}
// a. Let year be ! ISOYear(temporalDateLike).
int32_t year;
if (temporal_date_like->IsJSTemporalPlainDate()) {
year = Handle<JSTemporalPlainDate>::cast(temporal_date_like)->iso_year();
} else if (temporal_date_like->IsJSTemporalPlainDateTime()) {
year =
Handle<JSTemporalPlainDateTime>::cast(temporal_date_like)->iso_year();
} else {
DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth());
year =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_year();
}
// 6. Return 𝔽(year).
return handle(Smi::FromInt(year), isolate);
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,

View File

@ -52,6 +52,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSFunction> target,
Handle<HeapObject> new_target, Handle<Object> identifier);
// #sec-temporal.calendar.prototype.year
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Year(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.daysinyear
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,

View File

@ -60,7 +60,6 @@
'temporal/calendar-month-day-from-fields': [FAIL],
'temporal/calendar-months-in-year': [FAIL],
'temporal/calendar-week-of-year': [FAIL],
'temporal/calendar-year': [FAIL],
'temporal/calendar-year-month-from-fields': [FAIL],
'temporal/duration-add': [FAIL],
'temporal/duration-from': [FAIL],

View File

@ -629,17 +629,9 @@
'built-ins/Temporal/Calendar/prototype/weekOfYear/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/cross-year': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/date': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-not-object': [FAIL],
@ -647,9 +639,6 @@
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-invalid-string': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/year-month': [FAIL],
'built-ins/Temporal/Duration/compare/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/Duration/compare/calendar-dateadd-called-with-plaindate-instance': [FAIL],
'built-ins/Temporal/Duration/compare/options-undefined': [FAIL],