1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

LibJS: Implement Temporal.PlainYearMonth.prototype.inLeapYear

This commit is contained in:
Linus Groh 2021-08-08 00:03:10 +01:00
parent 3592a748b6
commit d9ed0f1f47
3 changed files with 32 additions and 0 deletions

View file

@ -34,6 +34,7 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
define_native_accessor(vm.names.daysInYear, days_in_year_getter, {}, Attribute::Configurable);
define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable);
define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
}
static PlainYearMonth* typed_this(GlobalObject& global_object)
@ -158,4 +159,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_year_getter)
return Value(calendar_months_in_year(global_object, calendar, *year_month));
}
// 9.3.10 get Temporal.PlainYearMonth.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.inleapyear
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_getter)
{
// 1. Let yearMonth be the this value.
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
auto* year_month = typed_this(global_object);
if (vm.exception())
return {};
// 3. Let calendar be yearMonth.[[Calendar]].
auto& calendar = year_month->calendar();
// 4. Return ? CalendarInLeapYear(calendar, yearMonth).
return Value(calendar_in_leap_year(global_object, calendar, *year_month));
}
}

View file

@ -26,6 +26,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(days_in_year_getter);
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter);
JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter);
};
}