Commit 4bbe174c authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add ZonedDateTime.prototype.toPlain(MonthDay|YearMonth)

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplainyearmonth
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplainmonthday

Bug: v8:11544
Change-Id: I5b109282187055df767239ff240822591f95c9a7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3565009Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79717}
parent da1a2d12
......@@ -196,10 +196,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainDate)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainTime)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplaindatetime */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainDateTime)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplainyearmonth */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainYearMonth)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplainmonthday */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainMonthDay)
/* Temporal.Duration */
/* Temporal #sec-temporal.duration.from */
......@@ -737,6 +733,8 @@ TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Nanosecond,
iso_nanosecond)
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithCalendar, withCalendar)
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithTimeZone, withTimeZone)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainYearMonth, toPlainYearMonth)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainMonthDay, toPlainMonthDay)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_VALUE_OF(ZonedDateTime)
......
......@@ -1590,6 +1590,7 @@ MaybeHandle<T> FromFields(Isolate* isolate, Handle<JSReceiver> calendar,
return Handle<T>::cast(result);
}
// #sec-temporal-datefromfields
MaybeHandle<JSTemporalPlainDate> DateFromFields(Isolate* isolate,
Handle<JSReceiver> calendar,
Handle<JSReceiver> fields,
......@@ -1599,6 +1600,26 @@ MaybeHandle<JSTemporalPlainDate> DateFromFields(Isolate* isolate,
isolate->factory()->dateFromFields_string(), JS_TEMPORAL_PLAIN_DATE_TYPE);
}
// #sec-temporal-yearmonthfromfields
MaybeHandle<JSTemporalPlainYearMonth> YearMonthFromFields(
Isolate* isolate, Handle<JSReceiver> calendar, Handle<JSReceiver> fields,
Handle<Object> options) {
return FromFields<JSTemporalPlainYearMonth>(
isolate, calendar, fields, options,
isolate->factory()->yearMonthFromFields_string(),
JS_TEMPORAL_PLAIN_YEAR_MONTH_TYPE);
}
// #sec-temporal-monthdayfromfields
MaybeHandle<JSTemporalPlainMonthDay> MonthDayFromFields(
Isolate* isolate, Handle<JSReceiver> calendar, Handle<JSReceiver> fields,
Handle<Object> options) {
return FromFields<JSTemporalPlainMonthDay>(
isolate, calendar, fields, options,
isolate->factory()->monthDayFromFields_string(),
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
......@@ -5797,13 +5818,83 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::WithTimeZone(
// 4. Return ? CreateTemporalZonedDateTime(zonedDateTime.[[Nanoseconds]],
// timeZone, zonedDateTime.[[Calendar]]).
Handle<BigInt> nanoseconds =
Handle<BigInt>(zoned_date_time->nanoseconds(), isolate);
Handle<JSReceiver> calendar =
Handle<JSReceiver>(zoned_date_time->calendar(), isolate);
Handle<BigInt> nanoseconds = handle(zoned_date_time->nanoseconds(), isolate);
Handle<JSReceiver> calendar = handle(zoned_date_time->calendar(), isolate);
return CreateTemporalZonedDateTime(isolate, nanoseconds, time_zone, calendar);
}
// Common code shared by ZonedDateTime.prototype.toPlainYearMonth and
// toPlainMonthDay
template <typename T,
MaybeHandle<T> (*from_fields_func)(
Isolate*, Handle<JSReceiver>, Handle<JSReceiver>, Handle<Object>)>
MaybeHandle<T> ZonedDateTimeToPlainYearMonthOrMonthDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<String> field_name_1, Handle<String> field_name_2,
const char* method_name) {
TEMPORAL_ENTER_FUNC();
Factory* factory = isolate->factory();
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone = handle(zoned_date_time->time_zone(), isolate);
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)),
T);
// 5. Let calendar be zonedDateTime.[[Calendar]].
Handle<JSReceiver> calendar = handle(zoned_date_time->calendar(), isolate);
// 6. Let temporalDateTime be ?
// temporal::BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
Handle<JSTemporalPlainDateTime> temporal_date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
temporal::BuiltinTimeZoneGetPlainDateTimeFor(isolate, time_zone, instant,
calendar, method_name),
T);
// 7. Let fieldNames be ? CalendarFields(calendar, « field_name_1,
// field_name_2 »).
Handle<FixedArray> field_names = factory->NewFixedArray(2);
field_names->set(0, *field_name_1);
field_names->set(1, *field_name_2);
ASSIGN_RETURN_ON_EXCEPTION(isolate, field_names,
CalendarFields(isolate, calendar, field_names), T);
// 8. Let fields be ? PrepareTemporalFields(temporalDateTime, fieldNames, «»).
Handle<JSReceiver> fields;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, fields,
PrepareTemporalFields(isolate, temporal_date_time, field_names,
RequiredFields::kNone),
T);
// 9. Return ? XxxFromFields(calendar, fields).
return from_fields_func(isolate, calendar, fields,
factory->undefined_value());
}
// #sec-temporal.zoneddatetime.prototype.toplainyearmonth
MaybeHandle<JSTemporalPlainYearMonth> JSTemporalZonedDateTime::ToPlainYearMonth(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
return ZonedDateTimeToPlainYearMonthOrMonthDay<JSTemporalPlainYearMonth,
YearMonthFromFields>(
isolate, zoned_date_time, isolate->factory()->monthCode_string(),
isolate->factory()->year_string(),
"Temporal.ZonedDateTime.prototype.toPlainYearMonth");
}
// #sec-temporal.zoneddatetime.prototype.toplainmonthday
MaybeHandle<JSTemporalPlainMonthDay> JSTemporalZonedDateTime::ToPlainMonthDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
return ZonedDateTimeToPlainYearMonthOrMonthDay<JSTemporalPlainMonthDay,
MonthDayFromFields>(
isolate, zoned_date_time, isolate->factory()->day_string(),
isolate->factory()->monthCode_string(),
"Temporal.ZonedDateTime.prototype.toPlainMonthDay");
}
// #sec-temporal.now.zoneddatetime
MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::Now(
Isolate* isolate, Handle<Object> calendar_like,
......
......@@ -391,6 +391,16 @@ class JSTemporalZonedDateTime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toplainyearmonth
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainYearMonth>
ToPlainYearMonth(Isolate* isolate,
Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toplainmonthday
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainMonthDay>
ToPlainMonthDay(Isolate* isolate,
Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.now.zoneddatetime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> Now(
Isolate* isolate, Handle<Object> calendar_like,
......
......@@ -2057,14 +2057,9 @@
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/calendar-arguments': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/calendar-result': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainMonthDay/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/negative-epochnanoseconds': [FAIL],
......@@ -2072,14 +2067,9 @@
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/calendar-arguments': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/calendar-result': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainYearMonth/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string': [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