Browse Source

LibJS: Don't assume calendar was parsed in to_temporal_zoned_date_time()

The first step of to_temporal_calendar_with_iso_default() is checking
whether the given value is undefined, so we should actually pass that
instead of unconditionally dereferencing the Optional<String>.
Linus Groh 3 năm trước cách đây
mục cha
commit
27304017e3

+ 4 - 1
Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp

@@ -219,7 +219,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
         time_zone = TRY(create_temporal_time_zone(global_object, *parsed_result.time_zone.name));
 
         // i. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
-        calendar = TRY(to_temporal_calendar_with_iso_default(global_object, js_string(vm, parsed_result.date_time.calendar.value())));
+        auto temporal_calendar_like = parsed_result.date_time.calendar.has_value()
+            ? js_string(vm, parsed_result.date_time.calendar.value())
+            : js_undefined();
+        calendar = TRY(to_temporal_calendar_with_iso_default(global_object, temporal_calendar_like));
 
         // j. Set matchBehaviour to match minutes.
         match_behavior = MatchBehavior::MatchMinutes;