Przeglądaj źródła

LibJS: Fix numeric type confusion in GetEpochFromISOParts return value

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2a59eac
Linus Groh 3 lat temu
rodzic
commit
76a6bd0e75

+ 3 - 3
Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp

@@ -118,7 +118,7 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
     // 5. Let utc be GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
     auto* utc = get_epoch_from_iso_parts(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond);
 
-    // 6. If utc < −8.64 × 10^21 or utc > 8.64 × 10^21, then
+    // 6. If ℝ(utc) < −8.64 × 10^21 or ℝ(utc) > 8.64 × 10^21, then
     if (utc->big_integer() < INSTANT_NANOSECONDS_MIN || utc->big_integer() > INSTANT_NANOSECONDS_MAX) {
         // a. Throw a RangeError exception.
         return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);
@@ -127,10 +127,10 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
     // 7. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
     auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
 
-    // 8. Let result be utc − offsetNanoseconds.
+    // 8. Let result be utc − ℤ(offsetNanoseconds).
     auto* result_ns = js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
 
-    // 9. If ! IsValidEpochNanoseconds(ℤ(result)) is false, then
+    // 9. If ! IsValidEpochNanoseconds(result) is false, then
     if (!is_valid_epoch_nanoseconds(*result_ns)) {
         // a. Throw a RangeError exception.
         return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);

+ 5 - 5
Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp

@@ -64,7 +64,7 @@ BigInt* get_epoch_from_iso_parts(GlobalObject& global_object, i32 year, u8 month
     // 5. Assert: ms is finite.
     VERIFY(ms.is_finite_number());
 
-    // 6. Return ℝ(ms) × 10^6 + microsecond × 10^3 + nanosecond.
+    // 6. Return ℤ(ℝ(ms) × 10^6 + microsecond × 10^3 + nanosecond).
     return js_bigint(vm, Crypto::SignedBigInteger::create_from(static_cast<i64>(ms.as_double())).multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }).plus(Crypto::SignedBigInteger::create_from((i64)microsecond * 1000)).plus(Crypto::SignedBigInteger(nanosecond)));
 }
 
@@ -76,17 +76,17 @@ auto const DATETIME_NANOSECONDS_MAX = "8640000086400000000000"_sbigint;
 // 5.5.2 ISODateTimeWithinLimits ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetimewithinlimits
 bool iso_date_time_within_limits(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
 {
-    // 1. Let ns be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
-    auto ns = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
+    // 1. Let ns be ℝ(GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)).
+    auto ns = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)->big_integer();
 
     // 2. If ns ≤ -8.64 × 10^21 - 8.64 × 10^13, then
-    if (ns->big_integer() <= DATETIME_NANOSECONDS_MIN) {
+    if (ns <= DATETIME_NANOSECONDS_MIN) {
         // a. Return false.
         return false;
     }
 
     // 3. If ns ≥ 8.64 × 10^21 + 8.64 × 10^13, then
-    if (ns->big_integer() >= DATETIME_NANOSECONDS_MAX) {
+    if (ns >= DATETIME_NANOSECONDS_MAX) {
         // a. Return false.
         return false;
     }

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp

@@ -586,10 +586,10 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
     // 7. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
     auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
 
-    // 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds − 8.64 × 10^13).
+    // 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds − 8.64 × 10^13).
     auto* day_before = MUST(create_temporal_instant(global_object, *js_bigint(vm, epoch_nanoseconds->big_integer().minus("86400000000000"_sbigint))));
 
-    // 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 × 10^13).
+    // 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 × 10^13).
     auto* day_after = MUST(create_temporal_instant(global_object, *js_bigint(vm, epoch_nanoseconds->big_integer().plus("86400000000000"_sbigint))));
 
     // 10. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp

@@ -140,7 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
         // a. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
         auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
 
-        // b. Let instant be ! CreateTemporalInstant(ℤ(epochNanoseconds − timeZone.[[OffsetNanoseconds]])).
+        // b. Let instant be ! CreateTemporalInstant(epochNanoseconds − ℤ(timeZone.[[OffsetNanoseconds]])).
         auto* instant = MUST(create_temporal_instant(global_object, *js_bigint(vm, epoch_nanoseconds->big_integer().minus(Crypto::SignedBigInteger::create_from(*time_zone->offset_nanoseconds())))));
 
         // c. Return CreateArrayFromList(« instant »).

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp

@@ -61,7 +61,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
         // a. Let epochNanoseconds be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
         auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
 
-        // b. Return epochNanoseconds − offsetNanoseconds.
+        // b. Return epochNanoseconds − ℤ(offsetNanoseconds).
         auto offset_nanoseconds_bigint = Crypto::SignedBigInteger::create_from((i64)offset_nanoseconds);
         return js_bigint(vm, epoch_nanoseconds->big_integer().minus(offset_nanoseconds_bigint));
     }