summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-06-14 19:58:32 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-15 17:49:20 +0100
commit631f270ac14e9c024d81b31f9313e048532f430c (patch)
tree5c6559e85b1678def080ad1c9c5953216a7a93f0 /Userland/Libraries
parent03f48056d564d03cecfb5fb4dc222247bbc4ca29 (diff)
downloadserenity-631f270ac14e9c024d81b31f9313e048532f430c.zip
LibJS: Add missing conversion to integer values in Calendar AOs
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/bfeb523
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index 18c9bb72a5..4c4be8cbbf 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -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 };
}