Skip to content

Commit ef91b3d

Browse files
committed
Add internal create operations to avoid observable effects
The constructors of PlainDate, PlainDateTime, PlainMonthDay, PlainYearMonth, and ZonedDateTime call ToTemporalCalendar on the calendar argument, and the constructor of ZonedDateTime additionally calls ToTemporalTimeZone on its timeZone argument. Now that these operations include an observable HasProperty operation, we do not want to call them more than once on the same calendar or time zone object. Therefore we add CreateTemporalDate etc. which create an instance without any observable validation of the arguments. The spec text already works like this, with abstract operations such as CreateTemporalZonedDateTime and friends that do not call ToTemporalCalendar or ToTemporalTimeZone. So this is not a normative change; it's a compliance bug in the polyfill. It is required for the test262 tests in 19cd26f7 to pass, which observe HasProperty(`timeZone`) operations. See: #1428
1 parent badd7f0 commit ef91b3d

File tree

10 files changed

+478
-429
lines changed

10 files changed

+478
-429
lines changed

lib/calendar.mjs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,15 @@ impl['iso8601'] = {
179179
fields = resolveNonLunisolarMonth(fields);
180180
let { year, month, day } = fields;
181181
({ year, month, day } = ES.RegulateISODate(year, month, day, overflow));
182-
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
183-
return new TemporalPlainDate(year, month, day, calendar);
182+
return ES.CreateTemporalDate(year, month, day, calendar);
184183
},
185184
yearMonthFromFields(fields, options, calendar) {
186185
const overflow = ES.ToTemporalOverflow(options);
187186
fields = ES.PrepareTemporalFields(fields, [['month', undefined], ['monthCode', undefined], ['year']]);
188187
fields = resolveNonLunisolarMonth(fields);
189188
let { year, month } = fields;
190189
({ year, month } = ES.RegulateISOYearMonth(year, month, overflow));
191-
const TemporalPlainYearMonth = GetIntrinsic('%Temporal.PlainYearMonth%');
192-
return new TemporalPlainYearMonth(year, month, calendar, /* referenceISODay */ 1);
190+
return ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ 1);
193191
},
194192
monthDayFromFields(fields, options, calendar) {
195193
const overflow = ES.ToTemporalOverflow(options);
@@ -207,8 +205,7 @@ impl['iso8601'] = {
207205
fields = resolveNonLunisolarMonth(fields);
208206
let { month, day, year } = fields;
209207
({ month, day } = ES.RegulateISODate(useYear ? year : referenceISOYear, month, day, overflow));
210-
const TemporalPlainMonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
211-
return new TemporalPlainMonthDay(month, day, calendar, referenceISOYear);
208+
return ES.CreateTemporalMonthDay(month, day, calendar, referenceISOYear);
212209
},
213210
fields(fields) {
214211
return fields;
@@ -228,8 +225,7 @@ impl['iso8601'] = {
228225
let month = GetSlot(date, ISO_MONTH);
229226
let day = GetSlot(date, ISO_DAY);
230227
({ year, month, day } = ES.AddISODate(year, month, day, years, months, weeks, days, overflow));
231-
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
232-
return new TemporalPlainDate(year, month, day, calendar);
228+
return ES.CreateTemporalDate(year, month, day, calendar);
233229
},
234230
dateUntil(one, two, largestUnit) {
235231
return ES.DifferenceISODate(
@@ -1782,8 +1778,7 @@ const nonIsoGeneralImpl = {
17821778
['year', undefined]
17831779
]);
17841780
const { year, month, day } = this.helper.calendarToIsoDate(fields, overflow, cache);
1785-
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
1786-
const result = new TemporalPlainDate(year, month, day, calendar);
1781+
const result = ES.CreateTemporalDate(year, month, day, calendar);
17871782
cache.setObject(result);
17881783
return result;
17891784
},
@@ -1799,8 +1794,7 @@ const nonIsoGeneralImpl = {
17991794
['year', undefined]
18001795
]);
18011796
const { year, month, day } = this.helper.calendarToIsoDate({ ...fields, day: 1 }, overflow, cache);
1802-
const TemporalPlainYearMonth = GetIntrinsic('%Temporal.PlainYearMonth%');
1803-
const result = new TemporalPlainYearMonth(year, month, calendar, /* referenceISODay = */ day);
1797+
const result = ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ day);
18041798
cache.setObject(result);
18051799
return result;
18061800
},
@@ -1821,8 +1815,7 @@ const nonIsoGeneralImpl = {
18211815
]);
18221816
const { year, month, day } = this.helper.monthDayFromFields(fields, overflow, cache);
18231817
// `year` is a reference year where this month/day exists in this calendar
1824-
const TemporalPlainMonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
1825-
const result = new TemporalPlainMonthDay(month, day, calendar, /* referenceISOYear */ year);
1818+
const result = ES.CreateTemporalMonthDay(month, day, calendar, /* referenceISOYear = */ year);
18261819
cache.setObject(result);
18271820
return result;
18281821
},
@@ -1857,8 +1850,7 @@ const nonIsoGeneralImpl = {
18571850
const added = this.helper.addCalendar(calendarDate, { years, months, weeks, days }, overflow, cache);
18581851
const isoAdded = this.helper.calendarToIsoDate(added, 'constrain', cache);
18591852
const { year, month, day } = isoAdded;
1860-
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
1861-
const newTemporalObject = new TemporalPlainDate(year, month, day, calendar);
1853+
const newTemporalObject = ES.CreateTemporalDate(year, month, day, calendar);
18621854
// The new object's cache starts with the cache of the old object
18631855
const newCache = new OneObjectCache(cache);
18641856
newCache.setObject(newTemporalObject);

0 commit comments

Comments
 (0)