mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Implement Temporal.PlainYearMonth.prototype.monthsInYear
This commit is contained in:
parent
703eb1f7b4
commit
3592a748b6
3 changed files with 32 additions and 0 deletions
|
@ -33,6 +33,7 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
|
||||||
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.daysInYear, days_in_year_getter, {}, Attribute::Configurable);
|
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.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
|
||||||
|
define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlainYearMonth* typed_this(GlobalObject& global_object)
|
static PlainYearMonth* typed_this(GlobalObject& global_object)
|
||||||
|
@ -141,4 +142,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_month_getter)
|
||||||
return Value(calendar_days_in_month(global_object, calendar, *year_month));
|
return Value(calendar_days_in_month(global_object, calendar, *year_month));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 9.3.9 get Temporal.PlainYearMonth.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthsinyear
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_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 ? CalendarMonthsInYear(calendar, yearMonth).
|
||||||
|
return Value(calendar_months_in_year(global_object, calendar, *year_month));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(days_in_year_getter);
|
JS_DECLARE_NATIVE_FUNCTION(days_in_year_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
|
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
describe("correct behavior", () => {
|
||||||
|
test("basic functionality", () => {
|
||||||
|
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||||
|
expect(plainYearMonth.monthsInYear).toBe(12);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Reflect.get(Temporal.PlainYearMonth.prototype, "monthsInYear", "foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainYearMonth");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue