Skip to content

Commit

Permalink
CalendarEqualsOrThrow => ThrowIfCalendarsNotEqual
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
justingrant committed Apr 21, 2023
1 parent 3b2baa7 commit ca103d6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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), []);
Expand Down Expand Up @@ -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), []);
Expand Down Expand Up @@ -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), []);
Expand Down Expand Up @@ -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), []);
Expand Down

0 comments on commit ca103d6

Please sign in to comment.