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

LibJS: Add missing conversion to integer values in Calendar AOs

This is an editorial change in the Temporal spec.

See: bfeb523
This commit is contained in:
Linus Groh 2022-06-14 19:58:32 +01:00
parent 03f48056d5
commit 631f270ac1

View file

@ -679,7 +679,10 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object
if (month.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, vm.names.month.as_string());
// b. Return month.
// b. Assert: Type(month) is Number.
VERIFY(month.is_number());
// c. Return (month).
return month.as_double();
}
@ -740,17 +743,23 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject& global_objec
if (year.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, vm.names.year.as_string());
// 6. Let month be ? ResolveISOMonth(fields).
// 6. Assert: Type(year) is Number.
VERIFY(year.is_number());
// 7. Let month be ? ResolveISOMonth(fields).
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
// 7. Let day be ! Get(fields, "day").
// 8. Let day be ! Get(fields, "day").
auto day = MUST(prepared_fields->get(vm.names.day));
// 8. If day is undefined, throw a TypeError exception.
// 9. If day is undefined, throw a TypeError exception.
if (day.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, vm.names.day.as_string());
// 9. Return ? RegulateISODate(year, month, day, overflow).
// 10. Assert: Type(day) is Number.
VERIFY(day.is_number());
// 11. Return ? RegulateISODate((year), month, (day), overflow).
return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow);
}
@ -770,13 +779,16 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_
// 4. Let year be ! Get(fields, "year").
auto year = MUST(prepared_fields->get(vm.names.year));
// 5. Let month be ? ResolveISOMonth(fields).
// 5. Assert: Type(year) is Number.
VERIFY(year.is_number());
// 6. Let month be ? ResolveISOMonth(fields).
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
// 6. Let result be ? RegulateISOYearMonth(year, month, overflow).
// 7. Let result be ? RegulateISOYearMonth((year), month, overflow).
auto result = TRY(regulate_iso_year_month(global_object, year.as_double(), month, overflow));
// 7. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
// 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 };
}
@ -818,23 +830,29 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
if (day.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, vm.names.day.as_string());
// 11. Let referenceISOYear be 1972 (the first leap year after the Unix epoch).
// 11. Assert: Type(day) is Number.
VERIFY(day.is_number());
// 12. Let referenceISOYear be 1972 (the first leap year after the Unix epoch).
i32 reference_iso_year = 1972;
Optional<ISODateRecord> result;
// 12. If monthCode is undefined, then
// 13. If monthCode is undefined, then
if (month_code.is_undefined()) {
// a. Let result be ? RegulateISODate(year, month, day, overflow).
// a. Assert: Type(year) is Number.
VERIFY(year.is_number());
// b. Let result be ? RegulateISODate((year), month, (day), overflow).
result = TRY(regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow));
}
// 13. Else,
// 14. Else,
else {
// a. Let result be ? RegulateISODate(referenceISOYear, month, day, overflow).
// a. Let result be ? RegulateISODate(referenceISOYear, month, (day), overflow).
result = TRY(regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), overflow));
}
// 14. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
// 15. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
return ISOMonthDay { .month = result->month, .day = result->day, .reference_iso_year = reference_iso_year };
}