summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-06-23 22:59:31 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-24 22:12:03 +0100
commit416f94eb3bb1792e2bbf06f9d07f42195bda9474 (patch)
tree943caa1395af02c5bcf88887a737a2f771ffe693 /Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
parent78bfeca643aa9764ad5f4bbcc2e5ede0594b1940 (diff)
downloadserenity-416f94eb3bb1792e2bbf06f9d07f42195bda9474.zip
LibJS: Add Number conversion in PrepareTemporalFields
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/687d06c
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index 4e64293b1d..9d8546d956 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -1786,14 +1786,25 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object,
any = true;
// ii. If property is in the Property column of Table 15 and there is a Conversion value in the same row, then
- // 1. Let Conversion represent the abstract operation named by the Conversion value of the same row.
- // 2. Set value to ? Conversion(value).
- if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv))
+ // 1. Let Conversion be the Conversion value of the same row.
+ // 2. If Conversion is ToIntegerThrowOnInfinity, then
+ if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv)) {
+ // a. Set value to ? ToIntegerThrowOnInfinity(value).
+ // b. Set value to 𝔽(value).
value = Value(TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)));
- else if (property.is_one_of("month"sv, "day"sv))
+ }
+ // 3. Else if Conversion is ToPositiveInteger, then
+ else if (property.is_one_of("month"sv, "day"sv)) {
+ // a. Set value to ? ToPositiveInteger(value).
+ // b. Set value to 𝔽(value).
value = Value(TRY(to_positive_integer(global_object, value)));
- else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv))
+ }
+ // 4. Else,
+ else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv)) {
+ // a. Assert: Conversion is ToString.
+ // b. Set value to ? ToString(value).
value = TRY(value.to_primitive_string(global_object));
+ }
// iii. Perform ! CreateDataPropertyOrThrow(result, property, value).
MUST(result->create_data_property_or_throw(property, value));