mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:27:34 +00:00
LibJS: Replace GetEpochFromISOParts with GetUTCEpochNanoseconds
This is an editorial change in the Temporal spec. See:
1b051cc
Note that since Date's implementation of this AO uses Crypto bigints
rather than allocating JS bigints, this change has the fallout of
removing some unused VM parameters and adding an overload of the
IsValidEpochNanoseconds AO for use without a JS::BigInt.
This commit is contained in:
parent
4fbec2e8b3
commit
1a84dbcb07
11 changed files with 56 additions and 72 deletions
|
@ -57,19 +57,18 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year
|
|||
|
||||
// 4. If offsetBehaviour is exact or offsetOption is "use", then
|
||||
if (offset_behavior == OffsetBehavior::Exact || offset_option == "use"sv) {
|
||||
// a. Let epochNanoseconds be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
|
||||
// a. Let epochNanoseconds be GetUTCEpochNanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
auto epoch_nanoseconds = get_utc_epoch_nanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
|
||||
|
||||
// b. Set epochNanoseconds to epochNanoseconds - ℤ(offsetNanoseconds).
|
||||
auto offset_nanoseconds_bigint = Crypto::SignedBigInteger { offset_nanoseconds };
|
||||
epoch_nanoseconds = js_bigint(vm, epoch_nanoseconds->big_integer().minus(offset_nanoseconds_bigint));
|
||||
epoch_nanoseconds = epoch_nanoseconds.minus(Crypto::SignedBigInteger { offset_nanoseconds });
|
||||
|
||||
// c. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
if (!is_valid_epoch_nanoseconds(epoch_nanoseconds))
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||
|
||||
// d. Return epochNanoseconds.
|
||||
return epoch_nanoseconds;
|
||||
return js_bigint(vm, move(epoch_nanoseconds));
|
||||
}
|
||||
|
||||
// 5. Assert: offsetBehaviour is option.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue