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

LibJS: Implement Temporal.PlainDate.prototype.eraYear

This commit is contained in:
Linus Groh 2021-08-27 20:09:15 +01:00
parent 6f7d6d917e
commit 418c22f9b3
5 changed files with 67 additions and 0 deletions

View file

@ -312,6 +312,30 @@ Value calendar_era(GlobalObject& global_object, Object& calendar, Object& date_l
return result;
}
// 15.6.1.3 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
Value calendar_era_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, "eraYear", « dateLike »).
auto result = Value(&calendar).invoke(global_object, vm.names.eraYear, &date_like);
if (vm.exception())
return {};
// 3. If result is not undefined, set result to ? ToIntegerOrInfinity(result).
if (!result.is_undefined()) {
auto result_number = result.to_integer_or_infinity(global_object);
if (vm.exception())
return {};
result = Value(result_number);
}
// 4. Return result.
return result;
}
// 12.1.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
{