diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index d1865acd9e..93eb82dc8f 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1956,11 +1956,15 @@ export const ES = ObjectAssign({}, ES2022, { return result; }, + ObjectImplementsTemporalTimeZoneProtocol: (object) => { + if (ES.IsTemporalTimeZone(object)) return true; + return 'getOffsetNanosecondsFor' in object && 'getPossibleInstantsFor' in object && 'id' in object; + }, ToTemporalTimeZoneSlotValue: (temporalTimeZoneLike) => { if (ES.Type(temporalTimeZoneLike) === 'Object') { if (ES.IsTemporalZonedDateTime(temporalTimeZoneLike)) return GetSlot(temporalTimeZoneLike, TIME_ZONE); - if (ES.IsTemporalCalendar(temporalTimeZoneLike)) { - throw new RangeError('Expected a time zone object but received a Temporal.Calendar'); + if (!ES.ObjectImplementsTemporalTimeZoneProtocol(temporalTimeZoneLike)) { + throw new TypeError('expected a Temporal.TimeZone or object implementing the Temporal.TimeZone protocol'); } return temporalTimeZoneLike; } diff --git a/spec/timezone.html b/spec/timezone.html index ea4667f929..3b44f7d35f 100644 --- a/spec/timezone.html +++ b/spec/timezone.html @@ -546,6 +546,28 @@

FormatISOTimeZoneOffsetString ( _offsetNanoseconds_ )

+ +

+ ObjectImplementsTemporalTimeZoneProtocol ( + _object_: an Object, + ): either a normal completion containing a Boolean, or a throw completion +

+
+
description
+
+ It determines whether the given _object_ is a Temporal.TimeZone instance or implements the required methods from the Temporal.TimeZone protocol. + For ordinary objects, and some exotic objects, this operation is infallible and will always return a normal completion. + However, if _object_ is a Proxy or has one in its prototype chain, user code may be called. +
+
+ + 1. If _object_ has an [[InitializedTemporalTimeZone]] internal slot, return *true*. + 1. For each property key _key_ of « *"getOffsetNanosecondsFor"*, *"getPossibleInstantsFor"*, *"id"* », do + 1. If ? HasProperty(_object_, _key_) is *false*, return *false*. + 1. Return *true*. + +
+

ToTemporalTimeZoneSlotValue ( @@ -560,7 +582,7 @@

1. If Type(_temporalTimeZoneLike_) is Object, then 1. If _temporalTimeZoneLike_ has an [[InitializedTemporalZonedDateTime]] internal slot, then 1. Return _temporalTimeZoneLike_.[[TimeZone]]. - 1. If _temporalTimeZoneLike_ has an [[InitializedTemporalCalendar]] internal slot, throw a *RangeError* exception. + 1. If ? ObjectImplementsTemporalTimeZoneProtocol(_temporalTimeZoneLike_) is *false*, throw a *TypeError* exception. 1. Return _temporalTimeZoneLike_. 1. Let _identifier_ be ? ToString(_temporalTimeZoneLike_). 1. Let _parseResult_ be ? ParseTemporalTimeZoneString(_identifier_).