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

LibJS: Implement Temporal.PlainDate.prototype.toPlainMonthDay()

This commit is contained in:
Linus Groh 2021-08-16 18:13:47 +01:00
parent 31f65b8c50
commit 795e077eb8
6 changed files with 76 additions and 0 deletions

View file

@ -447,6 +447,36 @@ PlainYearMonth* year_month_from_fields(GlobalObject& global_object, Object& cale
return static_cast<PlainYearMonth*>(year_month_object);
}
// 12.1.26 MonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-monthdayfromfields
PlainMonthDay* month_day_from_fields(GlobalObject& global_object, Object& calendar, Object& fields, Object* options)
{
auto& vm = global_object.vm();
// 1. Assert: Type(calendar) is Object.
// 2. Assert: Type(fields) is Object.
// 3. If options is not present, then
// a. Set options to undefined.
// 4. Else,
// a. Assert: Type(options) is Object.
// 5. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
auto month_day = Value(&calendar).invoke(global_object, vm.names.monthDayFromFields, &fields, options ?: js_undefined());
if (vm.exception())
return {};
// 6. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
auto* month_day_object = month_day.to_object(global_object);
if (!month_day_object)
return {};
if (!is<PlainMonthDay>(month_day_object)) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotA, "Temporal.PlainMonthDay");
return {};
}
// 7. Return monthDay.
return static_cast<PlainMonthDay*>(month_day_object);
}
// 12.1.28 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
bool calendar_equals(GlobalObject& global_object, Object& one, Object& two)
{