mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-03-19 20:06:29 +00:00
LibJS: Implement Temporal.PlainDateTime.prototype.daysInMonth
This commit is contained in:
committed by
Linus Groh
parent
01d33174c8
commit
2d86cbae45
@@ -42,6 +42,7 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
|
||||
define_native_accessor(vm.names.dayOfYear, day_of_year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.weekOfYear, week_of_year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.daysInWeek, days_in_week_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
@@ -281,6 +282,22 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_week_getter)
|
||||
return calendar_days_in_week(global_object, calendar, *date_time);
|
||||
}
|
||||
|
||||
// 5.3.18 get Temporal.PlainDateTime.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.daysinmonth
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_month_getter)
|
||||
{
|
||||
// 1. Let dateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||
auto* date_time = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Let calendar be dateTime.[[Calendar]].
|
||||
auto& calendar = date_time->calendar();
|
||||
|
||||
// 4. Return ? CalendarDaysInMonth(calendar, dateTime).
|
||||
return calendar_days_in_month(global_object, calendar, *date_time);
|
||||
}
|
||||
|
||||
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@ private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(day_of_year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(week_of_year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(days_in_week_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_iso_fields);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 30);
|
||||
expect(plainDateTime.daysInMonth).toBe(31);
|
||||
});
|
||||
});
|
||||
|
||||
test("errors", () => {
|
||||
test("this value must be a Temporal.PlainDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDateTime.prototype, "daysInMonth", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainDateTime");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user