Commit 08a5a573 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Temporal.Calendar.prototype.monthCode

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

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

Bug: v8:11544
Change-Id: I52dfc1bda6d2ed8c0aba735c64d7ae8227844ed1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531555Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80348}
parent 97122a48
......@@ -302,8 +302,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthDayFromFields)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDateAdd)
/* Temporal #sec-temporal.calendar.prototype.month */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonth)
/* Temporal #sec-temporal.calendar.prototype.monthcode */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthCode)
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
/* Temporal #sec-temporal.calendar.prototype.tojson */
......@@ -799,6 +797,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, MonthCode, monthCode)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
TEMPORAL_TO_STRING(Calendar)
......
......@@ -6224,6 +6224,51 @@ MaybeHandle<Smi> JSTemporalCalendar::Day(Isolate* isolate,
return handle(Smi::FromInt(day), isolate);
}
// #sec-temporal.calendar.prototype.monthcode
MaybeHandle<String> JSTemporalCalendar::MonthCode(
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]],
// [[InitializedTemporalMonthDay]], or
// [[InitializedTemporalYearMonth]] internal slot, then
if (!(IsPlainDatePlainDateTimeOrPlainYearMonth(temporal_date_like) ||
temporal_date_like->IsJSTemporalPlainMonthDay())) {
// 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.monthCode"),
String);
}
// 5. Return ! ISOMonthCode(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 if (temporal_date_like->IsJSTemporalPlainMonthDay()) {
month =
Handle<JSTemporalPlainMonthDay>::cast(temporal_date_like)->iso_month();
} else {
DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth());
month =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_month();
}
IncrementalStringBuilder builder(isolate);
builder.AppendCString((month < 10) ? "M0" : "M");
builder.AppendInt(month);
return builder.Finish();
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
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.dateuntil
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalDuration> DateUntil(
Isolate* isolate, Handle<JSTemporalCalendar> calendar, Handle<Object> one,
Handle<Object> two, Handle<Object> options);
// #sec-temporal.calendar.prototype.daysinmonth
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DaysInMonth(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......@@ -102,10 +107,10 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> fields, Handle<Object> additional_fields);
// #sec-temporal.calendar.prototype.dateuntil
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalDuration> DateUntil(
Isolate* isolate, Handle<JSTemporalCalendar> calendar, Handle<Object> one,
Handle<Object> two, Handle<Object> options);
// #sec-temporal.calendar.prototype.monthcode
V8_WARN_UNUSED_RESULT static MaybeHandle<String> MonthCode(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.day
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Day(
......
......@@ -49,7 +49,6 @@
'temporal/calendar-date-from-fields': [FAIL],
'temporal/calendar-date-until': [FAIL],
'temporal/calendar-month': [FAIL],
'temporal/calendar-month-code': [FAIL],
'temporal/calendar-month-day-from-fields': [FAIL],
'temporal/calendar-week-of-year': [FAIL],
'temporal/calendar-year-month-from-fields': [FAIL],
......
......@@ -484,22 +484,7 @@
'built-ins/Temporal/Calendar/prototype/month/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/date': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/month-day': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/year-month': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/date': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthDayFromFields/branding': [FAIL],
......@@ -1268,7 +1253,6 @@
'built-ins/Temporal/PlainDateTime/prototype/withPlainTime/time-undefined': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/with/read-time-fields-before-datefromfields': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/with/subclassing-ignored': [FAIL],
'built-ins/Temporal/PlainMonthDay/basic': [FAIL],
'built-ins/Temporal/PlainMonthDay/from/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/PlainMonthDay/from/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/PlainMonthDay/from/calendar-monthdayfromfields-called-with-options-undefined': [FAIL],
......@@ -1296,7 +1280,6 @@
'built-ins/Temporal/PlainMonthDay/prototype/equals/calendars': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/equals/calendar-temporal-object': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/equals/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/monthCode/basic': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/branding': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format': [FAIL],
......@@ -2151,7 +2134,6 @@
'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/monthCode/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/monthDayFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/month/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/weekOfYear/infinity-throws-rangeerror': [FAIL],
......@@ -2568,7 +2550,6 @@
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-missing-properties': [FAIL],
......@@ -2838,10 +2819,8 @@
'built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/argument-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number': [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