Browse Source

LibJS: Remove argument type assertion from ParseTemporalDurationString

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/8615b41
Linus Groh 3 years ago
parent
commit
1521c5f55c
1 changed files with 20 additions and 22 deletions
  1. 20 22
      Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

+ 20 - 22
Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

@@ -1339,16 +1339,14 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
 {
     auto& vm = global_object.vm();
 
-    // 1. Assert: Type(isoString) is String.
-
-    // 2. Let duration be ParseText(StringToCodePoints(isoString), TemporalDurationString).
+    // 1. Let duration be ParseText(StringToCodePoints(isoString), TemporalDurationString).
     auto parse_result = parse_iso8601(Production::TemporalDurationString, iso_string);
 
-    // 3. If duration is a List of errors, throw a RangeError exception.
+    // 2. If duration is a List of errors, throw a RangeError exception.
     if (!parse_result.has_value())
         return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDurationString, iso_string);
 
-    // 4. Let each of sign, years, months, weeks, days, hours, fHours, minutes, fMinutes, seconds, and fSeconds be the source text matched by the respective Sign, DurationYears, DurationMonths, DurationWeeks, DurationDays, DurationWholeHours, DurationHoursFraction, DurationWholeMinutes, DurationMinutesFraction, DurationWholeSeconds, and DurationSecondsFraction Parse Node enclosed by duration, or an empty sequence of code points if not present.
+    // 3. Let each of sign, years, months, weeks, days, hours, fHours, minutes, fMinutes, seconds, and fSeconds be the source text matched by the respective Sign, DurationYears, DurationMonths, DurationWeeks, DurationDays, DurationWholeHours, DurationHoursFraction, DurationWholeMinutes, DurationMinutesFraction, DurationWholeSeconds, and DurationSecondsFraction Parse Node enclosed by duration, or an empty sequence of code points if not present.
     auto sign_part = parse_result->sign;
     auto years_part = parse_result->duration_years;
     auto months_part = parse_result->duration_months;
@@ -1363,24 +1361,24 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
 
     // FIXME: I can has StringView::to<double>()?
 
-    // 5. Let yearsMV be ! ToIntegerOrInfinity(CodePointsToString(years)).
+    // 4. Let yearsMV be ! ToIntegerOrInfinity(CodePointsToString(years)).
     auto years = strtod(String { years_part.value_or("0"sv) }.characters(), nullptr);
 
-    // 6. Let monthsMV be ! ToIntegerOrInfinity(CodePointsToString(months)).
+    // 5. Let monthsMV be ! ToIntegerOrInfinity(CodePointsToString(months)).
     auto months = strtod(String { months_part.value_or("0"sv) }.characters(), nullptr);
 
-    // 7. Let weeksMV be ! ToIntegerOrInfinity(CodePointsToString(weeks)).
+    // 6. Let weeksMV be ! ToIntegerOrInfinity(CodePointsToString(weeks)).
     auto weeks = strtod(String { weeks_part.value_or("0"sv) }.characters(), nullptr);
 
-    // 8. Let daysMV be ! ToIntegerOrInfinity(CodePointsToString(days)).
+    // 7. Let daysMV be ! ToIntegerOrInfinity(CodePointsToString(days)).
     auto days = strtod(String { days_part.value_or("0"sv) }.characters(), nullptr);
 
-    // 9. Let hoursMV be ! ToIntegerOrInfinity(CodePointsToString(hours)).
+    // 8. Let hoursMV be ! ToIntegerOrInfinity(CodePointsToString(hours)).
     auto hours = strtod(String { hours_part.value_or("0"sv) }.characters(), nullptr);
 
     double minutes;
 
-    // 10. If fHours is not empty, then
+    // 9. If fHours is not empty, then
     if (f_hours_part.has_value()) {
         // a. If any of minutes, fMinutes, seconds, fSeconds is not empty, throw a RangeError exception.
         if (minutes_part.has_value() || f_minutes_part.has_value() || seconds_part.has_value() || f_seconds_part.has_value())
@@ -1395,7 +1393,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
         // d. Let minutesMV be ! ToIntegerOrInfinity(fHoursDigits) / 10^fHoursScale × 60.
         minutes = strtod(String { f_hours_digits }.characters(), nullptr) / pow(10, f_hours_scale) * 60;
     }
-    // 11. Else,
+    // 10. Else,
     else {
         // a. Let minutesMV be ! ToIntegerOrInfinity(CodePointsToString(minutes)).
         minutes = strtod(String { minutes_part.value_or("0"sv) }.characters(), nullptr);
@@ -1403,7 +1401,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
 
     double seconds;
 
-    // 12. If fMinutes is not empty, then
+    // 11. If fMinutes is not empty, then
     if (f_minutes_part.has_value()) {
         // a. If any of seconds, fSeconds is not empty, throw a RangeError exception.
         if (seconds_part.has_value() || f_seconds_part.has_value())
@@ -1418,12 +1416,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
         // d. Let secondsMV be ! ToIntegerOrInfinity(fMinutesDigits) / 10^fMinutesScale × 60.
         seconds = strtod(String { f_minutes_digits }.characters(), nullptr) / pow(10, f_minutes_scale) * 60;
     }
-    // 13. Else if seconds is not empty, then
+    // 12. Else if seconds is not empty, then
     else if (seconds_part.has_value()) {
         // a. Let secondsMV be ! ToIntegerOrInfinity(CodePointsToString(seconds)).
         seconds = strtod(String { *seconds_part }.characters(), nullptr);
     }
-    // 14. Else,
+    // 13. Else,
     else {
         // a. Let secondsMV be remainder(minutesMV, 1) × 60.
         seconds = fmod(minutes, 1) * 60;
@@ -1431,7 +1429,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
 
     double milliseconds;
 
-    // 15. If fSeconds is not empty, then
+    // 14. If fSeconds is not empty, then
     if (f_seconds_part.has_value()) {
         // a. Let fSecondsDigits be the substring of CodePointsToString(fSeconds) from 1.
         auto f_seconds_digits = f_seconds_part->substring_view(1);
@@ -1442,7 +1440,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
         // c. Let millisecondsMV be ! ToIntegerOrInfinity(fSecondsDigits) / 10^fSecondsScale × 1000.
         milliseconds = strtod(String { f_seconds_digits }.characters(), nullptr) / pow(10, f_seconds_scale) * 1000;
     }
-    // 16. Else,
+    // 15. Else,
     else {
         // a. Let millisecondsMV be remainder(secondsMV, 1) × 1000.
         milliseconds = fmod(seconds, 1) * 1000;
@@ -1453,26 +1451,26 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
     //        expected 100. Oof. This is the reason all of these are suffixed with "MV" in the spec:
     //        mathematical values are not supposed to have this issue.
 
-    // 17. Let microsecondsMV be remainder(millisecondsMV, 1) × 1000.
+    // 16. Let microsecondsMV be remainder(millisecondsMV, 1) × 1000.
     auto microseconds = fmod(milliseconds, 1) * 1000;
 
-    // 18. Let nanosecondsMV be remainder(microsecondsMV, 1) × 1000.
+    // 17. Let nanosecondsMV be remainder(microsecondsMV, 1) × 1000.
     auto nanoseconds = fmod(microseconds, 1) * 1000;
 
     i8 factor;
 
-    // 19. If sign contains the code point 0x002D (HYPHEN-MINUS) or 0x2212 (MINUS SIGN), then
+    // 18. If sign contains the code point 0x002D (HYPHEN-MINUS) or 0x2212 (MINUS SIGN), then
     if (sign_part.has_value() && sign_part->is_one_of("-", "\u2212")) {
         // a. Let factor be −1.
         factor = -1;
     }
-    // 20. Else,
+    // 19. Else,
     else {
         // a. Let factor be 1.
         factor = 1;
     }
 
-    // 21. Return ? CreateDurationRecord(yearsMV × factor, monthsMV × factor, weeksMV × factor, daysMV × factor, hoursMV × factor, floor(minutesMV) × factor, floor(secondsMV) × factor, floor(millisecondsMV) × factor, floor(microsecondsMV) × factor, floor(nanosecondsMV) × factor).
+    // 20. Return ? CreateDurationRecord(yearsMV × factor, monthsMV × factor, weeksMV × factor, daysMV × factor, hoursMV × factor, floor(minutesMV) × factor, floor(secondsMV) × factor, floor(millisecondsMV) × factor, floor(microsecondsMV) × factor, floor(nanosecondsMV) × factor).
     return create_duration_record(global_object, years * factor, months * factor, weeks * factor, days * factor, hours * factor, floor(minutes) * factor, floor(seconds) * factor, floor(milliseconds) * factor, floor(microseconds) * factor, floor(nanoseconds) * factor);
 }