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

LibJS: Implement Temporal.PlainDate.prototype.year

This commit is contained in:
Idan Horowitz 2021-07-23 16:39:58 +03:00 committed by Linus Groh
parent 3895a8354d
commit 8434ca6c4b
6 changed files with 55 additions and 0 deletions

View file

@ -119,6 +119,27 @@ Vector<String> calendar_fields(GlobalObject& global_object, Object& calendar, Ve
return result;
}
// 12.1.9 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
double calendar_year(GlobalObject& global_object, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "year", « dateLike »).
auto result = calendar.invoke(vm.names.year, &date_like);
if (vm.exception())
return {};
// 3. If result is undefined, throw a RangeError exception.
if (result.is_undefined()) {
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string());
return {};
}
// 4. Return ? ToIntegerOrInfinity(result).
return result.to_integer_or_infinity(global_object);
}
// 12.1.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
{