mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +00:00
LibJS: Change total_duration_nanoseconds() from JS to Crypto BigInts
This removes a bunch of silly wrapping and unwrapping of Crypto SignedBigInteger values in JS BigInt objects, which isn't even intended by the spec - it just wants us to take an integer value, not a BigInt specifically. Nice opportunity to remove a couple of allocations. :^)
This commit is contained in:
parent
213df97b55
commit
48856498f0
3 changed files with 18 additions and 24 deletions
|
@ -150,19 +150,17 @@ JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::compare)
|
|||
}
|
||||
|
||||
// 9. Let ns1 be ! TotalDurationNanoseconds(days1, one.[[Hours]], one.[[Minutes]], one.[[Seconds]], one.[[Milliseconds]], one.[[Microseconds]], one.[[Nanoseconds]], shift1).
|
||||
auto* nanoseconds1_bigint = js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)one->nanoseconds()));
|
||||
auto* ns1 = total_duration_nanoseconds(global_object, days1, one->hours(), one->minutes(), one->seconds(), one->milliseconds(), one->microseconds(), *nanoseconds1_bigint, shift1);
|
||||
auto ns1 = total_duration_nanoseconds(days1, one->hours(), one->minutes(), one->seconds(), one->milliseconds(), one->microseconds(), Crypto::SignedBigInteger::create_from((i64)one->nanoseconds()), shift1);
|
||||
|
||||
// 10. Let ns2 be ! TotalDurationNanoseconds(days2, two.[[Hours]], two.[[Minutes]], two.[[Seconds]], two.[[Milliseconds]], two.[[Microseconds]], two.[[Nanoseconds]], shift2).
|
||||
auto* nanoseconds2_bigint = js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)two->nanoseconds()));
|
||||
auto* ns2 = total_duration_nanoseconds(global_object, days2, two->hours(), two->minutes(), two->seconds(), two->milliseconds(), two->microseconds(), *nanoseconds2_bigint, shift2);
|
||||
auto ns2 = total_duration_nanoseconds(days2, two->hours(), two->minutes(), two->seconds(), two->milliseconds(), two->microseconds(), Crypto::SignedBigInteger::create_from((i64)two->nanoseconds()), shift2);
|
||||
|
||||
// 11. If ns1 > ns2, return 1𝔽.
|
||||
if (ns1->big_integer() > ns2->big_integer())
|
||||
if (ns1 > ns2)
|
||||
return Value(1);
|
||||
|
||||
// 12. If ns1 < ns2, return −1𝔽.
|
||||
if (ns1->big_integer() < ns2->big_integer())
|
||||
if (ns1 < ns2)
|
||||
return Value(-1);
|
||||
|
||||
// 13. Return +0𝔽.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue