Skip to content

Commit

Permalink
Editorial: Allow passing pre-looked-up Calendar methods
Browse files Browse the repository at this point in the history
Do the same for CalendarDateFromFields as in CalendarDateAdd and
CalendarDateUntil: add an optional parameter to CalendarFields which can
supply the method to be called, in case the caller has already looked it
up.

This doesn't make any observable change, but it will be used for
optimizations in #2519.
  • Loading branch information
ptomato committed Apr 22, 2023
1 parent 1860fe0 commit 6b6d3ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,13 +2041,13 @@ export function ConsolidateCalendars(one, two) {
}
}

export function CalendarDateFromFields(calendar, fields, options) {
export function CalendarDateFromFields(calendar, fields, options, dateFromFields) {
if (typeof calendar === 'string') {
const TemporalCalendar = GetIntrinsic('%Temporal.Calendar%');
calendar = new TemporalCalendar(calendar);
return Call(GetIntrinsic('%Temporal.Calendar.prototype.dateFromFields%'), calendar, [fields, options]);
}
const dateFromFields = GetMethod(calendar, 'dateFromFields');
dateFromFields ??= GetMethod(calendar, 'dateFromFields');
const result = Call(dateFromFields, calendar, [fields, options]);
if (!IsTemporalDate(result)) throw new TypeError('invalid result');
return result;
Expand Down
9 changes: 7 additions & 2 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -595,18 +595,23 @@ <h1>
_calendar_: a String or Object,
_fields_: an Object,
optional _options_: an Object or *undefined*,
optional _dateFromFields_: a function object,
): either a normal completion containing a `Temporal.PlainDate` or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It calls the given _calendar_'s `dateFromFields()` method and validates the result.</dd>
<dd>
It calls the given _calendar_'s `dateFromFields()` method and validates the result.
If _dateFromFields_ is present, the `dateFromFields` method will not be observably looked up.
</dd>
</dl>
<emu-alg>
1. If _options_ is not present, set _options_ to *undefined*.
1. If _calendar_ is a String, then
1. Set _calendar_ to ! CreateTemporalCalendar(_calendar_).
1. Return ? Call(%Temporal.Calendar.prototype.dateFromFields%, _calendar_, « _fields_, _options_ »).
1. Let _date_ be ? Invoke(_calendar_, *"dateFromFields"*, « _fields_, _options_ »).
1. If _dateFromFields_ is not present, set _dateFromFields_ to ? GetMethod(_calendar_, *"dateFromFields"*).
1. Let _date_ be ? Call(_calendar_, _dateFromFields_, « _fields_, _options_ »).
1. Perform ? RequireInternalSlot(_date_, [[InitializedTemporalDate]]).
1. Return _date_.
</emu-alg>
Expand Down

0 comments on commit 6b6d3ad

Please sign in to comment.