From 065cf94c957eec9fea36411d25afb1447f2c9931 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 10 Dec 2024 13:01:54 -0800 Subject: [PATCH] Editorial: Remove dead code from ZonedDateTime.prototype.toLocaleString This removes some steps that can throw and therefore look observable, but they were effectively dead code; the value stored in the [[TimeZone]] internal slot is guaranteed to be a valid available time zone identifier. h/t Anba Closes: #3057 --- polyfill/lib/zoneddatetime.mjs | 8 ++------ spec/intl.html | 10 +--------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/polyfill/lib/zoneddatetime.mjs b/polyfill/lib/zoneddatetime.mjs index 7268272e3..f7e970620 100644 --- a/polyfill/lib/zoneddatetime.mjs +++ b/polyfill/lib/zoneddatetime.mjs @@ -391,14 +391,10 @@ export class ZonedDateTime { // The rest of the defaults will be filled in by formatting the Instant } - const timeZoneIdentifier = GetSlot(this, TIME_ZONE); - if (ES.IsOffsetTimeZoneIdentifier(timeZoneIdentifier)) { + optionsCopy.timeZone = GetSlot(this, TIME_ZONE); + if (ES.IsOffsetTimeZoneIdentifier(optionsCopy.timeZone)) { // Note: https://github.com/tc39/ecma402/issues/683 will remove this throw new RangeErrorCtor('toLocaleString does not currently support offset time zones'); - } else { - const record = ES.GetAvailableNamedTimeZoneIdentifier(timeZoneIdentifier); - if (!record) throw new RangeErrorCtor(`toLocaleString formats built-in time zones, not ${timeZoneIdentifier}`); - optionsCopy.timeZone = record.identifier; } const formatter = new DateTimeFormat(locales, optionsCopy); diff --git a/spec/intl.html b/spec/intl.html index bb6e2dc4a..d687caf01 100644 --- a/spec/intl.html +++ b/spec/intl.html @@ -1782,15 +1782,7 @@

Temporal.ZonedDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_ 1. Let _zonedDateTime_ be the *this* value. 1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]). - 1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]]. - 1. Let _timeZoneParseResult_ be ? ParseTimeZoneIdentifier(_timeZone_). - 1. If _timeZoneParseResult_.[[OffsetMinutes]] is ~empty~, then - 1. Let _timeZoneIdentifierRecord_ be GetAvailableNamedTimeZoneIdentifier(_timeZone_). - 1. If _timeZoneIdentifierRecord_ is ~empty~, throw a *RangeError* exception. - 1. Set _timeZone_ to _timeZoneIdentifierRecord_.[[Identifier]]. - 1. Else, - 1. Set _timeZone_ to FormatOffsetTimeZoneIdentifier(_timeZoneParseResult_.[[OffsetMinutes]]). - 1. Let _dateTimeFormat_ be ? CreateDateTimeFormat(%Intl.DateTimeFormat%, _locales_, _options_, ~any~, ~all~, _timeZone_). + 1. Let _dateTimeFormat_ be ? CreateDateTimeFormat(%Intl.DateTimeFormat%, _locales_, _options_, ~any~, ~all~, _zonedDateTime_.[[TimeZone]]). 1. If _zonedDateTime_.[[Calendar]] is not *"iso8601"* and CalendarEquals(_zonedDateTime_.[[Calendar]], _dateTimeFormat_.[[Calendar]]) is *false*, then 1. Throw a *RangeError* exception. 1. Let _instant_ be ! CreateTemporalInstant(_zonedDateTime_.[[EpochNanoseconds]]).