diff options
author | Linus Groh <mail@linusgroh.de> | 2022-04-29 19:10:21 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-29 22:40:46 +0200 |
commit | 76a6bd0e757303840f7715afc5e7dba290cfa365 (patch) | |
tree | a09de5363f04a108731072842ace200d04c55cb6 /Userland | |
parent | 70593b744835ffb880053dbb422fd1c576be00b6 (diff) | |
download | serenity-76a6bd0e757303840f7715afc5e7dba290cfa365.zip |
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
Diffstat (limited to 'Userland')
5 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp index 6c13c6cf80..6c934e4c7d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp +++ b/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); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index d71124387f..d409b1c260 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/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; } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index f19e035808..5ff423b9f6 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/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). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index 81507a85f1..f6b04aec5d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/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 ยป). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index a1955e17e1..4e492fd508 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/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)); } |