Commit 803d1d39 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Calendar.prototype.monthsInYear

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

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


Bug: v8:11544
Change-Id: Ibf7a9f1e64ce638f745df2649ee3a69dc9e08139
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531559Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79682}
parent eb9a19a0
......@@ -330,8 +330,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInWeek)
/* Temporal #sec-temporal.calendar.prototype.daysinmonth */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInMonth)
/* Temporal #sec-temporal.calendar.prototype.monthsinyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthsInYear)
/* Temporal #sec-temporal.calendar.prototype.inleapyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeInLeapYear)
/* Temporal #sec-temporal.calendar.prototype.mergefields */
......@@ -801,6 +799,7 @@ TEMPORAL_ID_BY_TO_STRING(Calendar)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DaysInYear, daysInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfYear, dayOfYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
TEMPORAL_TO_STRING(Calendar)
// #sec-temporal.calendar.from
BUILTIN(TemporalCalendarFrom) {
......
......@@ -4805,6 +4805,12 @@ int32_t ToISODayOfYear(Isolate* isolate, int32_t year, int32_t month,
isolate->date_cache()->DaysFromYearMonth(year, 0);
}
bool IsPlainDatePlainDateTimeOrPlainYearMonth(
Handle<Object> temporal_date_like) {
return temporal_date_like->IsJSTemporalPlainDate() ||
temporal_date_like->IsJSTemporalPlainDateTime() ||
temporal_date_like->IsJSTemporalPlainYearMonth();
}
} // namespace
// #sec-temporal.calendar.prototype.daysinyear
......@@ -4818,9 +4824,7 @@ MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
// 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())) {
if (!IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like)) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
......@@ -4859,9 +4863,7 @@ MaybeHandle<Smi> JSTemporalCalendar::Year(Isolate* isolate,
// have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]],
// or [[InitializedTemporalYearMonth]]
// internal slot, then
if (!(temporal_date_like->IsJSTemporalPlainDate() ||
temporal_date_like->IsJSTemporalPlainDateTime() ||
temporal_date_like->IsJSTemporalPlainYearMonth())) {
if (!IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like)) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
......@@ -4912,6 +4914,33 @@ MaybeHandle<Smi> JSTemporalCalendar::DayOfYear(
return handle(Smi::FromInt(value), isolate);
}
// #sec-temporal.calendar.prototype.monthsinyear
MaybeHandle<Smi> JSTemporalCalendar::MonthsInYear(
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 (!IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like)) {
// 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.monthsInYear"),
Smi);
}
// a. a. Let monthsInYear be 12.
int32_t months_in_year = 12;
// 6. Return 𝔽(monthsInYear).
return handle(Smi::FromInt(months_in_year), isolate);
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -67,6 +67,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.monthsinyear
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> MonthsInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.tostring
static MaybeHandle<String> ToString(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
......
......@@ -57,7 +57,6 @@
'temporal/calendar-month': [FAIL],
'temporal/calendar-month-code': [FAIL],
'temporal/calendar-month-day-from-fields': [FAIL],
'temporal/calendar-months-in-year': [FAIL],
'temporal/calendar-week-of-year': [FAIL],
'temporal/calendar-year-month-from-fields': [FAIL],
'temporal/duration-add': [FAIL],
......
......@@ -595,13 +595,7 @@
'built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/month-day-throw-type-error': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/infinity-throws-rangeerror': [FAIL],
......@@ -984,7 +978,6 @@
'built-ins/Temporal/PlainDate/prototype/equals/calendar-no-call': [FAIL],
'built-ins/Temporal/PlainDate/prototype/equals/calendar-temporal-object': [FAIL],
'built-ins/Temporal/PlainDate/prototype/equals/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainDate/prototype/monthsInYear/basic': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-plaindatetime': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
......@@ -2615,7 +2608,6 @@
'built-ins/Temporal/PlainYearMonth/prototype/equals/compare-reference-day': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/use-internal-slots': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/year-zero': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/since/argument-casting': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-auto': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-months': [FAIL],
......
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