From ca103d69032126a3dea24687b8219ea9dcfc5372 Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Fri, 21 Apr 2023 11:49:38 -0700 Subject: [PATCH] CalendarEqualsOrThrow => ThrowIfCalendarsNotEqual Currently `CalendarEqualsOrThrow`, returns `true`, returns `undefined`, or throws. This variation in return values doesn't break anything as the return value is not used by any callers. To prevent future problems this commit renames it to `ThrowIfCalendarsNotEqual` and always returns `undefined`. --- polyfill/lib/ecmascript.mjs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 81176f6afb..4742154b49 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -2014,13 +2014,13 @@ export function CalendarEquals(one, two) { const cal2 = ToTemporalCalendarIdentifier(two); return cal1 === cal2; } + // This operation is not in the spec, it implements the following: // "If ? CalendarEquals(one, two) is false, throw a RangeError exception." // This is so that we can build an informative error message without // re-getting the .id properties. - -export function CalendarEqualsOrThrow(one, two, errorMessageAction) { - if (one === two) return true; +export function ThrowIfCalendarsNotEqual(one, two, errorMessageAction) { + if (one === two) return; const cal1 = ToTemporalCalendarIdentifier(one); const cal2 = ToTemporalCalendarIdentifier(two); if (cal1 !== cal2) { @@ -3985,7 +3985,7 @@ export function DifferenceTemporalPlainDate(operation, plainDate, other, options other = ToTemporalDate(other); const calendar = GetSlot(plainDate, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); - CalendarEqualsOrThrow(calendar, otherCalendar, 'compute difference between dates'); + ThrowIfCalendarsNotEqual(calendar, otherCalendar, 'compute difference between dates'); const resolvedOptions = ObjectCreate(null); CopyDataProperties(resolvedOptions, GetOptionsObject(options), []); @@ -4022,7 +4022,7 @@ export function DifferenceTemporalPlainDateTime(operation, plainDateTime, other, other = ToTemporalDateTime(other); const calendar = GetSlot(plainDateTime, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); - CalendarEqualsOrThrow(calendar, otherCalendar, 'compute difference between dates'); + ThrowIfCalendarsNotEqual(calendar, otherCalendar, 'compute difference between dates'); const resolvedOptions = ObjectCreate(null); CopyDataProperties(resolvedOptions, GetOptionsObject(options), []); @@ -4163,7 +4163,7 @@ export function DifferenceTemporalPlainYearMonth(operation, yearMonth, other, op other = ToTemporalYearMonth(other); const calendar = GetSlot(yearMonth, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); - CalendarEqualsOrThrow(calendar, otherCalendar, 'compute difference between months'); + ThrowIfCalendarsNotEqual(calendar, otherCalendar, 'compute difference between months'); const resolvedOptions = ObjectCreate(null); CopyDataProperties(resolvedOptions, GetOptionsObject(options), []); @@ -4208,7 +4208,7 @@ export function DifferenceTemporalZonedDateTime(operation, zonedDateTime, other, other = ToTemporalZonedDateTime(other); const calendar = GetSlot(zonedDateTime, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); - CalendarEqualsOrThrow(calendar, otherCalendar, 'compute difference between dates'); + ThrowIfCalendarsNotEqual(calendar, otherCalendar, 'compute difference between dates'); const resolvedOptions = ObjectCreate(null); CopyDataProperties(resolvedOptions, GetOptionsObject(options), []);