From 9d2377ff6055d07d16d3d9fa90fa79aa9716ce50 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 14 Jun 2022 23:22:42 +0100 Subject: [PATCH] LibJS: Only call CanonicalizeTimeZoneName on valid time zone IDs This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/30122e6 --- .../Libraries/LibJS/Runtime/Temporal/TimeZone.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 224ef04e4c..4248f74ef8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -450,12 +450,12 @@ ThrowCompletionOr to_temporal_time_zone(GlobalObject& global_object, Va // TimeZoneIANAName for the returned [[Name]] slot, not TimeZoneUTCOffsetName. // So when we provide a numeric time zone offset, this branch won't be executed, // and if we provide an IANA name, it won't be a valid TimeZoneNumericUTCOffset. - // This should be fixed by: https://github.com/tc39/proposal-temporal/pull/1941 + // This should be fixed by: https://github.com/tc39/proposal-temporal/pull/2200 // 4. If parseResult.[[Name]] is not undefined, then if (parse_result.name.has_value()) { // a. Let name be parseResult.[[Name]]. - auto& name = *parse_result.name; + auto name = parse_result.name.release_value(); // b. If ParseText(StringToCodePoints(name, TimeZoneNumericUTCOffset)) is not a List of errors, then if (is_valid_time_zone_numeric_utc_offset_syntax(name)) { @@ -468,10 +468,13 @@ ThrowCompletionOr to_temporal_time_zone(GlobalObject& global_object, Va // i. If IsValidTimeZoneName(name) is false, throw a RangeError exception. if (!is_valid_time_zone_name(name)) return vm.throw_completion(global_object, ErrorType::TemporalInvalidTimeZoneName, name); + + // ii. Set name to ! CanonicalizeTimeZoneName(name). + name = canonicalize_time_zone_name(name); } - // c. Return ! CreateTemporalTimeZone(! CanonicalizeTimeZoneName(name)). - return MUST(create_temporal_time_zone(global_object, canonicalize_time_zone_name(name))); + // c. Return ! CreateTemporalTimeZone(name). + return MUST(create_temporal_time_zone(global_object, name)); } // 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC").