From bb60629d3b09bcb97f9d163c2044350a67ff16f3 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 4 Nov 2021 15:58:06 +0100 Subject: [PATCH] LibJS: Update ToTemporalTimeRecord to not require all properties This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/84b7d53 --- .../LibJS/Runtime/Temporal/PlainTime.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp index ec5db05d7bf..e8567a50c31 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp @@ -390,17 +390,20 @@ ThrowCompletionOr to_temporal_time_record(GlobalObject& // 2. Let result be the Record { [[Hour]]: undefined, [[Minute]]: undefined, [[Second]]: undefined, [[Millisecond]]: undefined, [[Microsecond]]: undefined, [[Nanosecond]]: undefined }. auto result = UnregulatedTemporalTime {}; - // 3. For each row of Table 3, except the header row, in table order, do + // 3. Let any be false. + auto any = false; + + // 4. For each row of Table 3, except the header row, in table order, do for (auto& [internal_slot, property] : temporal_time_like_properties(vm)) { // a. Let property be the Property value of the current row. // b. Let value be ? Get(temporalTimeLike, property). auto value = TRY(temporal_time_like.get(property)); - // c. If value is undefined, then - if (value.is_undefined()) { - // i. Throw a TypeError exception. - return vm.throw_completion(global_object, ErrorType::MissingRequiredProperty, property); + // c. If value is not undefined, then + if (!value.is_undefined()) { + // i. Set any to true. + any = true; } // d. Set value to ? ToIntegerThrowOnInfinity(value). @@ -410,7 +413,13 @@ ThrowCompletionOr to_temporal_time_record(GlobalObject& result.*internal_slot = value_number; } - // 4. Return result. + // 5. If any is false, then + if (!any) { + // a. Throw a TypeError exception. + return vm.throw_completion(global_object, ErrorType::TemporalInvalidPlainTimeLikeObject); + } + + // 6. Return result. return result; }