summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-06 22:26:21 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-07 13:00:24 +0100
commitef004c6b98496dec5c3f435e648adc5b1af296c5 (patch)
tree32550fd4dd85aa9ce50247637345385848ded992 /Userland/Libraries/LibJS
parent8b07453bce6744d3e979e0c667b349fe0e850bac (diff)
downloadserenity-ef004c6b98496dec5c3f435e648adc5b1af296c5.zip
LibJS: Use round_number_to_increment(double) in round_time()
Much nicer :^)
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp23
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp2
3 files changed, 11 insertions, 16 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
index f146b5adf1..0b12c8bd59 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
@@ -457,7 +457,7 @@ i8 compare_temporal_time(u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16
}
// 4.5.13 RoundTime ( hour, minute, second, millisecond, microsecond, nanosecond, increment, unit, roundingMode [ , dayLengthNs ] ), https://tc39.es/proposal-temporal/#sec-temporal-roundtime
-DaysAndTime round_time(GlobalObject& global_object, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns)
+DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns)
{
// 1. Assert: hour, minute, second, millisecond, microsecond, nanosecond, and increment are integers.
@@ -508,55 +508,50 @@ DaysAndTime round_time(GlobalObject& global_object, u8 hour, u8 minute, u8 secon
quantity = nanosecond;
}
- // FIXME: This doesn't seem right...
- auto* quantity_bigint = js_bigint(global_object.vm(), Crypto::SignedBigInteger::create_from((u64)quantity));
-
// 10. Let result be ! RoundNumberToIncrement(quantity, increment, roundingMode).
- auto* result = round_number_to_increment(global_object, *quantity_bigint, increment, rounding_mode);
-
- auto result_i64 = (i64)result->big_integer().to_double();
+ auto result = round_number_to_increment(quantity, increment, rounding_mode);
// If unit is "day", then
if (unit == "day"sv) {
// a. Return the Record { [[Days]]: result, [[Hour]]: 0, [[Minute]]: 0, [[Second]]: 0, [[Millisecond]]: 0, [[Microsecond]]: 0, [[Nanosecond]]: 0 }.
- return DaysAndTime { .days = (i32)result_i64, .hour = 0, .minute = 0, .second = 0, .millisecond = 0, .microsecond = 0, .nanosecond = 0 };
+ return DaysAndTime { .days = (i32)result, .hour = 0, .minute = 0, .second = 0, .millisecond = 0, .microsecond = 0, .nanosecond = 0 };
}
// 12. If unit is "hour", then
if (unit == "hour"sv) {
// a. Return ! BalanceTime(result, 0, 0, 0, 0, 0).
- return balance_time(result_i64, 0, 0, 0, 0, 0);
+ return balance_time(result, 0, 0, 0, 0, 0);
}
// 13. If unit is "minute", then
if (unit == "minute"sv) {
// a. Return ! BalanceTime(hour, result, 0, 0, 0, 0).
- return balance_time(hour, result_i64, 0, 0, 0, 0);
+ return balance_time(hour, result, 0, 0, 0, 0);
}
// 14. If unit is "second", then
if (unit == "second"sv) {
// a. Return ! BalanceTime(hour, minute, result, 0, 0, 0).
- return balance_time(hour, minute, result_i64, 0, 0, 0);
+ return balance_time(hour, minute, result, 0, 0, 0);
}
// 15. If unit is "millisecond", then
if (unit == "millisecond"sv) {
// a. Return ! BalanceTime(hour, minute, second, result, 0, 0).
- return balance_time(hour, minute, second, result_i64, 0, 0);
+ return balance_time(hour, minute, second, result, 0, 0);
}
// 16. If unit is "microsecond", then
if (unit == "microsecond"sv) {
// a. Return ! BalanceTime(hour, minute, second, millisecond, result, 0).
- return balance_time(hour, minute, second, millisecond, result_i64, 0);
+ return balance_time(hour, minute, second, millisecond, result, 0);
}
// 17. Assert: unit is "nanosecond".
VERIFY(unit == "nanosecond"sv);
// 18. Return ! BalanceTime(hour, minute, second, millisecond, microsecond, result).
- return balance_time(hour, minute, second, millisecond, microsecond, result_i64);
+ return balance_time(hour, minute, second, millisecond, microsecond, result);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.h
index 9bea876edf..111b653ff7 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.h
@@ -102,6 +102,6 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(GlobalObject&, u8 hour, u8 mi
ThrowCompletionOr<UnregulatedTemporalTime> to_temporal_time_record(GlobalObject&, Object const& temporal_time_like);
String temporal_time_to_string(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision);
i8 compare_temporal_time(u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
-DaysAndTime round_time(GlobalObject&, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns = {});
+DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns = {});
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
index ec46c2d16b..37577389c7 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
@@ -346,7 +346,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_string)
auto rounding_mode = TRY_OR_DISCARD(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
// 6. Let roundResult be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], precision.[[Increment]], precision.[[Unit]], roundingMode).
- auto round_result = round_time(global_object, temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), precision.increment, precision.unit, rounding_mode);
+ auto round_result = round_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), precision.increment, precision.unit, rounding_mode);
// 7. Return ! TemporalTimeToString(roundResult.[[Hour]], roundResult.[[Minute]], roundResult.[[Second]], roundResult.[[Millisecond]], roundResult.[[Microsecond]], roundResult.[[Nanosecond]], precision.[[Precision]]).
auto string = temporal_time_to_string(round_result.hour, round_result.minute, round_result.second, round_result.millisecond, round_result.microsecond, round_result.nanosecond, precision.precision);