summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-04-29 19:10:21 +0200
committerLinus Groh <mail@linusgroh.de>2022-04-29 22:40:46 +0200
commit76a6bd0e757303840f7715afc5e7dba290cfa365 (patch)
treea09de5363f04a108731072842ace200d04c55cb6 /Userland
parent70593b744835ffb880053dbb422fd1c576be00b6 (diff)
downloadserenity-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')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp2
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));
}