Commit 10bbb38f authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Temporal.Calendar.prototype.month

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

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

Bug: v8:11544
Change-Id: Ibbbb00faa0bdb4d49784cd9aae69fb779d95f924
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531554
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80359}
parent 65b412e3
......@@ -298,8 +298,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeYearMonthFromFields)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthDayFromFields)
/* Temporal #sec-temporal.calendar.prototype.dateadd */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDateAdd)
/* Temporal #sec-temporal.calendar.prototype.month */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonth)
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
/* Temporal #sec-temporal.calendar.prototype.tojson */
......@@ -795,6 +793,7 @@ TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfWeek, dayOfWeek)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfYear, dayOfYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, InLeapYear, inLeapYear)
TEMPORAL_PROTOTYPE_METHOD2(Calendar, MergeFields, mergeFields)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Month, month)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthCode, monthCode)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
......
......@@ -6281,6 +6281,47 @@ MaybeHandle<String> JSTemporalCalendar::MonthCode(
return builder.Finish();
}
// #sec-temporal.calendar.prototype.month
MaybeHandle<Smi> JSTemporalCalendar::Month(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 4. If Type(temporalDateLike) is Object and temporalDateLike has an
// [[InitializedTemporalMonthDay]] internal slot, then
if (temporal_date_like->IsJSTemporalPlainMonthDay()) {
// a. Throw a TypeError exception.
THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(), Smi);
}
// 5. 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.month"),
Smi);
}
// 6. Return ! ISOMonth(temporalDateLike).
int32_t month;
if (temporal_date_like->IsJSTemporalPlainDate()) {
month = Handle<JSTemporalPlainDate>::cast(temporal_date_like)->iso_month();
} else if (temporal_date_like->IsJSTemporalPlainDateTime()) {
month =
Handle<JSTemporalPlainDateTime>::cast(temporal_date_like)->iso_month();
} else {
DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth());
month =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_month();
}
// 7. Return 𝔽(month).
return handle(Smi::FromInt(month), isolate);
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -112,6 +112,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.month
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Month(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.day
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Day(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -48,7 +48,6 @@
'temporal/calendar-date-add': [FAIL],
'temporal/calendar-date-from-fields': [FAIL],
'temporal/calendar-date-until': [FAIL],
'temporal/calendar-month': [FAIL],
'temporal/calendar-month-day-from-fields': [FAIL],
'temporal/calendar-week-of-year': [FAIL],
'temporal/calendar-year-month-from-fields': [FAIL],
......
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