Skip to content

Commit

Permalink
Polyfill: Avoid ToString(calendar) when the calendar-id is unused
Browse files Browse the repository at this point in the history
Implements the normative change in the previous commit in the polyfill,
for the purpose of verifying test262 tests.
  • Loading branch information
ptomato committed Jul 29, 2022
1 parent 1bab918 commit 1a0e382
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,11 @@ export const ES = ObjectAssign({}, ES2020, {
const year = ES.ISOYearString(GetSlot(date, ISO_YEAR));
const month = ES.ISODateTimePartString(GetSlot(date, ISO_MONTH));
const day = ES.ISODateTimePartString(GetSlot(date, ISO_DAY));
const calendarID = ES.ToString(GetSlot(date, CALENDAR));
const calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
let calendar = '';
if (showCalendar !== 'never') {
const calendarID = ES.ToString(GetSlot(date, CALENDAR));
calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
}
return `${year}-${month}-${day}${calendar}`;
},
TemporalDateTimeToString: (dateTime, precision, showCalendar = 'auto', options = undefined) => {
Expand Down Expand Up @@ -2063,8 +2066,11 @@ export const ES = ObjectAssign({}, ES2020, {
hour = ES.ISODateTimePartString(hour);
minute = ES.ISODateTimePartString(minute);
const seconds = ES.FormatSecondsStringPart(second, millisecond, microsecond, nanosecond, precision);
const calendarID = ES.ToString(GetSlot(dateTime, CALENDAR));
const calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
let calendar = '';
if (showCalendar !== 'never') {
const calendarID = ES.ToString(GetSlot(dateTime, CALENDAR));
calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
}
return `${year}-${month}-${day}T${hour}:${minute}${seconds}${calendar}`;
},
TemporalMonthDayToString: (monthDay, showCalendar = 'auto') => {
Expand Down Expand Up @@ -2134,8 +2140,10 @@ export const ES = ObjectAssign({}, ES2020, {
result += ES.FormatISOTimeZoneOffsetString(offsetNs);
}
if (showTimeZone !== 'never') result += `[${tz}]`;
const calendarID = ES.ToString(GetSlot(zdt, CALENDAR));
result += ES.FormatCalendarAnnotation(calendarID, showCalendar);
if (showCalendar !== 'never') {
const calendarID = ES.ToString(GetSlot(zdt, CALENDAR));
result += ES.FormatCalendarAnnotation(calendarID, showCalendar);
}
return result;
},

Expand Down

0 comments on commit 1a0e382

Please sign in to comment.