LibJS: Do not expose mathematical values to script in Duration methods

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/26a4c4f

No behavioral change as we already did this correctly, but I changed
some implicit JS::Value creations to explicit ones.
This commit is contained in:
Linus Groh 2022-03-10 16:58:10 +01:00
parent a496868ee5
commit 4722045e28
Notes: sideshowbarker 2024-07-17 17:36:28 +09:00
2 changed files with 10 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -157,16 +157,16 @@ JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::compare)
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);
// 11. If ns1 > ns2, return 1.
// 11. If ns1 > ns2, return 1𝔽.
if (ns1->big_integer() > ns2->big_integer())
return 1;
return Value(1);
// 12. If ns1 < ns2, return 1.
// 12. If ns1 < ns2, return 1𝔽.
if (ns1->big_integer() < ns2->big_integer())
return -1;
return Value(-1);
// 13. Return 0.
return 0;
// 13. Return +0𝔽.
return Value(0);
}
}

View File

@ -173,7 +173,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::sign_getter)
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
auto* duration = TRY(typed_this_object(global_object));
// 3. Return ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
// 3. Return 𝔽(! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]])).
return Value(duration_sign(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds()));
}
@ -572,8 +572,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
whole = round_result.nanoseconds;
}
// 24. Return whole + roundRecord.[[Remainder]].
return whole + round_record.remainder;
// 24. Return 𝔽(whole + roundRecord.[[Remainder]]).
return Value(whole + round_record.remainder);
}
// 7.3.22 Temporal.Duration.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.tostring