Commit 63f9f0fa authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Calendar.prototype.daysInMonth

Spect Text:
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.daysinmonth

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

Bug: v8:11544
Change-Id: Id5d426d9c5fe1db94c15433afbad443c7056abe3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3441703Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79720}
parent e4ac08c5
......@@ -322,8 +322,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDay)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
/* Temporal #sec-temporal.calendar.prototype.daysinweek */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInWeek)
/* Temporal #sec-temporal.calendar.prototype.daysinmonth */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInMonth)
/* Temporal #sec-temporal.calendar.prototype.mergefields */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMergeFields)
/* Temporal #sec-temporal.calendar.prototype.tojson */
......@@ -790,12 +788,13 @@ 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, DaysInMonth, daysInMonth)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DaysInYear, daysInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfWeek, dayOfWeek)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfYear, dayOfYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, InLeapYear, inLeapYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
TEMPORAL_TO_STRING(Calendar)
// #sec-temporal.calendar.from
BUILTIN(TemporalCalendarFrom) {
......
......@@ -1620,8 +1620,6 @@ MaybeHandle<JSTemporalPlainMonthDay> MonthDayFromFields(
JS_TEMPORAL_PLAIN_MONTH_DAY_TYPE);
}
// IMPL_FROM_FIELDS_ABSTRACT_OPERATION(Date, date, JS_TEMPORAL_PLAIN_DATE_TYPE)
#undef IMPL_FROM_FIELDS_ABSTRACT_OPERATION
// #sec-temporal-totemporaloverflow
Maybe<ShowOverflow> ToTemporalOverflow(Isolate* isolate,
Handle<JSReceiver> options,
......@@ -4898,6 +4896,49 @@ MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
return handle(Smi::FromInt(days_in_year), isolate);
}
// #sec-temporal.calendar.prototype.daysinmonth
MaybeHandle<Smi> JSTemporalCalendar::DaysInMonth(
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.daysInMonth"),
Smi);
}
// 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]],
// temporalDateLike.[[ISOMonth]])).
int32_t year;
int32_t month;
if (temporal_date_like->IsJSTemporalPlainDate()) {
year = Handle<JSTemporalPlainDate>::cast(temporal_date_like)->iso_year();
month = Handle<JSTemporalPlainDate>::cast(temporal_date_like)->iso_month();
} else if (temporal_date_like->IsJSTemporalPlainDateTime()) {
year =
Handle<JSTemporalPlainDateTime>::cast(temporal_date_like)->iso_year();
month =
Handle<JSTemporalPlainDateTime>::cast(temporal_date_like)->iso_month();
} else {
DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth());
year =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_year();
month =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_month();
}
return handle(Smi::FromInt(ISODaysInMonth(isolate, year, month)), isolate);
}
// #sec-temporal.calendar.prototype.year
MaybeHandle<Smi> JSTemporalCalendar::Year(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
......
......@@ -82,6 +82,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.daysinmonth
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DaysInMonth(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.tostring
static MaybeHandle<String> ToString(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
......
......@@ -48,7 +48,6 @@
'temporal/calendar-date-from-fields': [FAIL],
'temporal/calendar-date-until': [FAIL],
'temporal/calendar-day': [FAIL],
'temporal/calendar-days-in-month': [FAIL],
'temporal/calendar-days-in-week': [FAIL],
'temporal/calendar-fields': [FAIL],
'temporal/calendar-merge-fields': [FAIL],
......
......@@ -496,20 +496,10 @@
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
......@@ -2574,7 +2564,6 @@
'built-ins/Temporal/PlainYearMonth/prototype/add/limits': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/add/month-length': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/add/options-invalid': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar': [FAIL],
......@@ -2659,7 +2648,6 @@
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/day/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-string-invalid': [FAIL],
......@@ -2709,7 +2697,6 @@
'built-ins/Temporal/PlainDateTime/prototype/add/negative-duration': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/add/options-empty': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/add/options-invalid': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/daysInMonth/basic': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/daysInWeek/basic': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/equals/argument-object-insufficient-data': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/equals/basic': [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