summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-06-23 19:49:11 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-24 22:12:03 +0100
commitddea6d451bbe6e2a944b3f598139ee837fd89fca (patch)
treec99b863c13649568631c1943f4f880f6f07bbd6d /Userland/Libraries/LibJS/Runtime/Temporal
parentd10e0f0e3e75a990e6bf6d3bb3c48d8a65b9afc6 (diff)
downloadserenity-ddea6d451bbe6e2a944b3f598139ee837fd89fca.zip
LibJS: Check for invalid epoch nanoseconds in InterpretISODateTimeOffset
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/cdfe4a5
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
index 414f8674cf..5d765c9e65 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
@@ -62,9 +62,17 @@ 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. Set epochNanoseconds to epochNanoseconds - ℤ(offsetNanoseconds).
+ // FIXME: Narrowing conversion from 'double' to 'i64'
auto offset_nanoseconds_bigint = Crypto::SignedBigInteger::create_from((i64)offset_nanoseconds);
- return js_bigint(vm, epoch_nanoseconds->big_integer().minus(offset_nanoseconds_bigint));
+ epoch_nanoseconds = js_bigint(vm, epoch_nanoseconds->big_integer().minus(offset_nanoseconds_bigint));
+
+ // c. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
+ if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);
+
+ // d. Return epochNanoseconds.
+ return epoch_nanoseconds;
}
// 5. Assert: offsetBehaviour is option.