Skip to content

Commit

Permalink
Fast-path conversion of Temporal.PlainDateTime to Temporal.PlainTime
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptomato committed Apr 13, 2021
1 parent 7598c9a commit 0012f06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions spec/plaintime.html
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ <h1>ToTemporalTime ( _item_ [ , _overflow_ ] )</h1>
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_).
Expand Down

0 comments on commit 0012f06

Please sign in to comment.