diff --git a/src/builtins/builtins-temporal.cc b/src/builtins/builtins-temporal.cc index 1b3238d2ca..e76387caa1 100644 --- a/src/builtins/builtins-temporal.cc +++ b/src/builtins/builtins-temporal.cc @@ -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) diff --git a/src/objects/js-temporal-objects.cc b/src/objects/js-temporal-objects.cc index f1511cc2b5..1036bbdda6 100644 --- a/src/objects/js-temporal-objects.cc +++ b/src/objects/js-temporal-objects.cc @@ -1590,6 +1590,7 @@ MaybeHandle FromFields(Isolate* isolate, Handle calendar, return Handle::cast(result); } +// #sec-temporal-datefromfields MaybeHandle DateFromFields(Isolate* isolate, Handle calendar, Handle fields, @@ -1599,6 +1600,26 @@ MaybeHandle DateFromFields(Isolate* isolate, isolate->factory()->dateFromFields_string(), JS_TEMPORAL_PLAIN_DATE_TYPE); } +// #sec-temporal-yearmonthfromfields +MaybeHandle YearMonthFromFields( + Isolate* isolate, Handle calendar, Handle fields, + Handle options) { + return FromFields( + isolate, calendar, fields, options, + isolate->factory()->yearMonthFromFields_string(), + JS_TEMPORAL_PLAIN_YEAR_MONTH_TYPE); +} + +// #sec-temporal-monthdayfromfields +MaybeHandle MonthDayFromFields( + Isolate* isolate, Handle calendar, Handle fields, + Handle options) { + return FromFields( + 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::WithTimeZone( // 4. Return ? CreateTemporalZonedDateTime(zonedDateTime.[[Nanoseconds]], // timeZone, zonedDateTime.[[Calendar]]). - Handle nanoseconds = - Handle(zoned_date_time->nanoseconds(), isolate); - Handle calendar = - Handle(zoned_date_time->calendar(), isolate); + Handle nanoseconds = handle(zoned_date_time->nanoseconds(), isolate); + Handle calendar = handle(zoned_date_time->calendar(), isolate); return CreateTemporalZonedDateTime(isolate, nanoseconds, time_zone, calendar); } +// Common code shared by ZonedDateTime.prototype.toPlainYearMonth and +// toPlainMonthDay +template (*from_fields_func)( + Isolate*, Handle, Handle, Handle)> +MaybeHandle ZonedDateTimeToPlainYearMonthOrMonthDay( + Isolate* isolate, Handle zoned_date_time, + Handle field_name_1, Handle 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 time_zone = handle(zoned_date_time->time_zone(), isolate); + // 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). + Handle instant; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, instant, + temporal::CreateTemporalInstant( + isolate, Handle(zoned_date_time->nanoseconds(), isolate)), + T); + // 5. Let calendar be zonedDateTime.[[Calendar]]. + Handle calendar = handle(zoned_date_time->calendar(), isolate); + // 6. Let temporalDateTime be ? + // temporal::BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar). + Handle 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 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 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 JSTemporalZonedDateTime::ToPlainYearMonth( + Isolate* isolate, Handle zoned_date_time) { + return ZonedDateTimeToPlainYearMonthOrMonthDay( + isolate, zoned_date_time, isolate->factory()->monthCode_string(), + isolate->factory()->year_string(), + "Temporal.ZonedDateTime.prototype.toPlainYearMonth"); +} + +// #sec-temporal.zoneddatetime.prototype.toplainmonthday +MaybeHandle JSTemporalZonedDateTime::ToPlainMonthDay( + Isolate* isolate, Handle zoned_date_time) { + return ZonedDateTimeToPlainYearMonthOrMonthDay( + isolate, zoned_date_time, isolate->factory()->day_string(), + isolate->factory()->monthCode_string(), + "Temporal.ZonedDateTime.prototype.toPlainMonthDay"); +} + // #sec-temporal.now.zoneddatetime MaybeHandle JSTemporalZonedDateTime::Now( Isolate* isolate, Handle calendar_like, diff --git a/src/objects/js-temporal-objects.h b/src/objects/js-temporal-objects.h index fdc195ffe5..6e6c30533d 100644 --- a/src/objects/js-temporal-objects.h +++ b/src/objects/js-temporal-objects.h @@ -391,6 +391,16 @@ class JSTemporalZonedDateTime V8_WARN_UNUSED_RESULT static MaybeHandle GetISOFields( Isolate* isolate, Handle zoned_date_time); + // #sec-temporal.zoneddatetime.prototype.toplainyearmonth + V8_WARN_UNUSED_RESULT static MaybeHandle + ToPlainYearMonth(Isolate* isolate, + Handle zoned_date_time); + + // #sec-temporal.zoneddatetime.prototype.toplainmonthday + V8_WARN_UNUSED_RESULT static MaybeHandle + ToPlainMonthDay(Isolate* isolate, + Handle zoned_date_time); + // #sec-temporal.now.zoneddatetime V8_WARN_UNUSED_RESULT static MaybeHandle Now( Isolate* isolate, Handle calendar_like, diff --git a/test/test262/test262.status b/test/test262/test262.status index 847ed085eb..66fde1bcf7 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -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],