ソースを参照

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
Linus Groh 3 年 前
コミット
631f270ac1
1 ファイル変更32 行追加14 行削除
  1. 32 14
      Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp

+ 32 - 14
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 };
 }