Skip to content

Commit

Permalink
Normative: Consistently check overflow options
Browse files Browse the repository at this point in the history
In the fast paths for Temporal objects in ToTemporalDate and
ToTemporalDateTime, the overflow option should be validated (even though
it isn't used.) We do this for property bags and also for the case where
we call Temporal.PlainDate.from(plainDate) and
Temporal.PlainDateTime.from(plainDateTime), so it should be consistent.

The status quo wasn't the result of any decision, it was an oversight.

Closes: #2220
  • Loading branch information
ptomato committed Jul 1, 2022
1 parent 29cd94b commit c8ee2bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,13 +1057,15 @@ export const ES = ObjectAssign({}, ES2020, {
if (ES.Type(item) === 'Object') {
if (ES.IsTemporalDate(item)) return item;
if (ES.IsTemporalZonedDateTime(item)) {
ES.ToTemporalOverflow(options); // validate and ignore
item = ES.BuiltinTimeZoneGetPlainDateTimeFor(
GetSlot(item, TIME_ZONE),
GetSlot(item, INSTANT),
GetSlot(item, CALENDAR)
);
}
if (ES.IsTemporalDateTime(item)) {
ES.ToTemporalOverflow(options); // validate and ignore
return ES.CreateTemporalDate(
GetSlot(item, ISO_YEAR),
GetSlot(item, ISO_MONTH),
Expand Down Expand Up @@ -1105,13 +1107,15 @@ export const ES = ObjectAssign({}, ES2020, {
if (ES.Type(item) === 'Object') {
if (ES.IsTemporalDateTime(item)) return item;
if (ES.IsTemporalZonedDateTime(item)) {
ES.ToTemporalOverflow(options); // validate and ignore
return ES.BuiltinTimeZoneGetPlainDateTimeFor(
GetSlot(item, TIME_ZONE),
GetSlot(item, INSTANT),
GetSlot(item, CALENDAR)
);
}
if (ES.IsTemporalDate(item)) {
ES.ToTemporalOverflow(options); // validate and ignore
return ES.CreateTemporalDateTime(
GetSlot(item, ISO_YEAR),
GetSlot(item, ISO_MONTH),
Expand Down
2 changes: 2 additions & 0 deletions spec/plaindate.html
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,12 @@ <h1>ToTemporalDate ( _item_ [ , _options_ ] )</h1>
1. If _item_ has an [[InitializedTemporalDate]] internal slot, then
1. Return _item_.
1. If _item_ has an [[InitializedTemporalZonedDateTime]] internal slot, then
1. Perform ? ToTemporalOverflow(_options_).
1. Let _instant_ be ! CreateTemporalInstant(_item_.[[Nanoseconds]]).
1. Let _plainDateTime_ be ? BuiltinTimeZoneGetPlainDateTimeFor(_item_.[[TimeZone]], _instant_, _item_.[[Calendar]]).
1. Return ! CreateTemporalDate(_plainDateTime_.[[ISOYear]], _plainDateTime_.[[ISOMonth]], _plainDateTime_.[[ISODay]], _plainDateTime_.[[Calendar]]).
1. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then
1. Perform ? ToTemporalOverflow(_options_).
1. Return ! CreateTemporalDate(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], _item_.[[Calendar]]).
1. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_item_).
1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"*, *"monthCode"*, *"year"* »).
Expand Down
2 changes: 2 additions & 0 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@ <h1>ToTemporalDateTime ( _item_ [ , _options_ ] )</h1>
1. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then
1. Return _item_.
1. If _item_ has an [[InitializedTemporalZonedDateTime]] internal slot, then
1. Perform ? ToTemporalOverflow(_options_).
1. Let _instant_ be ! CreateTemporalInstant(_item_.[[Nanoseconds]]).
1. Return ? BuiltinTimeZoneGetPlainDateTimeFor(_item_.[[TimeZone]], _instant_, _item_.[[Calendar]]).
1. If _item_ has an [[InitializedTemporalDate]] internal slot, then
1. Perform ? ToTemporalOverflow(_options_).
1. Return ? CreateTemporalDateTime(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], 0, 0, 0, 0, 0, 0, _item_.[[Calendar]]).
1. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_item_).
1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"hour"*, *"microsecond"*, *"millisecond"*, *"minute"*, *"month"*, *"monthCode"*, *"nanosecond"*, *"second"*, *"year"* »).
Expand Down

0 comments on commit c8ee2bd

Please sign in to comment.