diff options
author | Linus Groh <mail@linusgroh.de> | 2022-03-10 16:58:10 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-03-10 23:20:39 +0100 |
commit | 4722045e28777aacc33c5549b4839343d95ec1e7 (patch) | |
tree | 8de64ba0a6b18a1c6c46224c092c785d039d0d01 | |
parent | a496868ee52fbec42659bc62179364151b740ad4 (diff) | |
download | serenity-4722045e28777aacc33c5549b4839343d95ec1e7.zip |
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.
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp index 42ddc27bcc..4a3af29b3d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp @@ -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); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index 6bf004b2d5..c163bf3024 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -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 |