diff --git a/src/builtins/builtins-temporal.cc b/src/builtins/builtins-temporal.cc index 7f9deff2f8..1b3238d2ca 100644 --- a/src/builtins/builtins-temporal.cc +++ b/src/builtins/builtins-temporal.cc @@ -328,8 +328,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear) TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInWeek) /* Temporal #sec-temporal.calendar.prototype.daysinmonth */ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInMonth) -/* Temporal #sec-temporal.calendar.prototype.inleapyear */ -TO_BE_IMPLEMENTED(TemporalCalendarPrototypeInLeapYear) /* Temporal #sec-temporal.calendar.prototype.mergefields */ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMergeFields) /* Temporal #sec-temporal.calendar.prototype.tojson */ @@ -799,6 +797,7 @@ 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_TO_STRING(Calendar) // #sec-temporal.calendar.from BUILTIN(TemporalCalendarFrom) { diff --git a/src/objects/js-temporal-objects.cc b/src/objects/js-temporal-objects.cc index b0ec56c0b6..f1511cc2b5 100644 --- a/src/objects/js-temporal-objects.cc +++ b/src/objects/js-temporal-objects.cc @@ -4991,6 +4991,42 @@ MaybeHandle JSTemporalCalendar::MonthsInYear( return handle(Smi::FromInt(months_in_year), isolate); } +// #sec-temporal.calendar.prototype.inleapyear +MaybeHandle JSTemporalCalendar::InLeapYear( + Isolate* isolate, Handle calendar, + Handle 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.inLeapYear"), + Oddball); + } + + // a. Let inLeapYear be ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). + int32_t year; + if (temporal_date_like->IsJSTemporalPlainDate()) { + year = Handle::cast(temporal_date_like)->iso_year(); + } else if (temporal_date_like->IsJSTemporalPlainDateTime()) { + year = + Handle::cast(temporal_date_like)->iso_year(); + } else { + DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth()); + year = + Handle::cast(temporal_date_like)->iso_year(); + } + return isolate->factory()->ToBoolean(IsISOLeapYear(isolate, year)); +} + // #sec-temporal.calendar.prototype.tostring MaybeHandle JSTemporalCalendar::ToString( Isolate* isolate, Handle calendar, diff --git a/src/objects/js-temporal-objects.h b/src/objects/js-temporal-objects.h index c1eefa71c1..fdc195ffe5 100644 --- a/src/objects/js-temporal-objects.h +++ b/src/objects/js-temporal-objects.h @@ -77,6 +77,11 @@ class JSTemporalCalendar Isolate* isolate, Handle calendar, Handle temporal_date_like); + // #sec-temporal.calendar.prototype.inleapyear + V8_WARN_UNUSED_RESULT static MaybeHandle InLeapYear( + Isolate* isolate, Handle calendar, + Handle temporal_date_like); + // #sec-temporal.calendar.prototype.tostring static MaybeHandle ToString(Isolate* isolate, Handle calendar, diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index 3779eb4f56..c9aa1644e1 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -51,7 +51,6 @@ 'temporal/calendar-days-in-month': [FAIL], 'temporal/calendar-days-in-week': [FAIL], 'temporal/calendar-fields': [FAIL], - 'temporal/calendar-in-leap-year': [FAIL], 'temporal/calendar-merge-fields': [FAIL], 'temporal/calendar-month': [FAIL], 'temporal/calendar-month-code': [FAIL], diff --git a/test/test262/test262.status b/test/test262/test262.status index 2e1b1f019b..68c07e3a45 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -538,13 +538,7 @@ 'built-ins/Temporal/Calendar/prototype/fields/non-string-element-throws': [FAIL], 'built-ins/Temporal/Calendar/prototype/fields/repeated-throw': [FAIL], 'built-ins/Temporal/Calendar/prototype/fields/reverse': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-with-utc-designator': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL], 'built-ins/Temporal/Calendar/prototype/inLeapYear/basic': [FAIL], - 'built-ins/Temporal/Calendar/prototype/inLeapYear/branding': [FAIL], 'built-ins/Temporal/Calendar/prototype/inLeapYear/calendar-fields-iterable': [FAIL], 'built-ins/Temporal/Calendar/prototype/inLeapYear/calendar-temporal-object': [FAIL], 'built-ins/Temporal/Calendar/prototype/inLeapYear/infinity-throws-rangeerror': [FAIL],