From 0012f066e98cee6bda86a8dd40ffcdef4936bd2c Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 9 Apr 2021 18:53:27 -0700 Subject: [PATCH] Fast-path conversion of Temporal.PlainDateTime to Temporal.PlainTime If passing a Temporal.PlainDateTime where a Temporal.PlainTime is expected, then create a Temporal.PlainTime directly from the PlainDateTime's [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], and [[ISONanosecond]] internal slots. Previously, the PlainDateTime's hour, minute, second, millisecond, microsecond, nanosecond, and calendar getters would have been called. See: #1428 --- polyfill/lib/ecmascript.mjs | 11 +++++++++++ spec/plaintime.html | 2 ++ 2 files changed, 13 insertions(+) diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 2f4541e15a..22daa3ed18 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1340,6 +1340,17 @@ export const ES = ObjectAssign({}, ES2020, { let hour, minute, second, millisecond, microsecond, nanosecond, calendar; if (ES.Type(item) === 'Object') { if (ES.IsTemporalTime(item)) return item; + if (ES.IsTemporalDateTime(item)) { + const TemporalPlainTime = GetIntrinsic('%Temporal.PlainTime%'); + return new TemporalPlainTime( + GetSlot(item, ISO_HOUR), + GetSlot(item, ISO_MINUTE), + GetSlot(item, ISO_SECOND), + GetSlot(item, ISO_MILLISECOND), + GetSlot(item, ISO_MICROSECOND), + GetSlot(item, ISO_NANOSECOND) + ); + } calendar = item.calendar; if (calendar) { calendar = ES.ToTemporalCalendar(calendar); diff --git a/spec/plaintime.html b/spec/plaintime.html index 5906594a4f..38ff1445ef 100644 --- a/spec/plaintime.html +++ b/spec/plaintime.html @@ -610,6 +610,8 @@

ToTemporalTime ( _item_ [ , _overflow_ ] )

1. If Type(_item_) is Object, then 1. If _item_ has an [[InitializedTemporalTime]] internal slot, then 1. Return _item_. + 1. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then + 1. Return ! CreateTemporalTime(_item_.[[ISOHour]], _item_.[[ISOMinute]], _item_.[[ISOSecond]], _item_.[[ISOMillisecond]], _item_.[[ISOMicrosecond]], _item_.[[ISONanosecond]]). 1. Let _calendar_ be ? Get(_item_, *"calendar"*). 1. If _calendar_ is not *undefined*, then 1. Set _calendar_ to ? ToTemporalCalendar(_calendar_).