Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 1157492

Browse files
committed
Bug 1974768 - Part 1: Remove return on-failure after CreateICU4XCalendar. r=spidermonkey-reviewers,dminor
`CreateICU4XCalendar` is no longer fallible after D252990 (bug 1960300). Differential Revision: https://phabricator.services.mozilla.com/D255509
1 parent 8c4decd commit 1157492

File tree

1 file changed

+3
-68
lines changed

1 file changed

+3
-68
lines changed

js/src/builtin/temporal/Calendar.cpp

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ using UniqueICU4XCalendar =
659659

660660
static UniqueICU4XCalendar CreateICU4XCalendar(CalendarId id) {
661661
auto* result = icu4x::capi::icu4x_Calendar_create_mv1(ToAnyCalendarKind(id));
662+
MOZ_ASSERT(result, "unexpected null-pointer result");
662663
return UniqueICU4XCalendar{result};
663664
}
664665

@@ -1045,6 +1046,7 @@ static bool FirstYearOfJapaneseEra(JSContext* cx, CalendarId calendarId,
10451046

10461047
auto date = dateResult.unwrap();
10471048
UniqueICU4XIsoDate isoDate{icu4x::capi::icu4x_Date_to_iso_mv1(date.get())};
1049+
MOZ_ASSERT(isoDate, "unexpected null-pointer result");
10481050

10491051
int32_t isoYear = icu4x::capi::icu4x_IsoDate_year_mv1(isoDate.get());
10501052
MOZ_ASSERT(isoYear > 0, "unexpected era start before 1 CE");
@@ -1709,9 +1711,6 @@ static bool CalendarEraYear(JSContext* cx, CalendarId calendarId,
17091711
MOZ_ASSERT(calendarId == CalendarId::Japanese);
17101712

17111713
auto cal = CreateICU4XCalendar(calendarId);
1712-
if (!cal) {
1713-
return false;
1714-
}
17151714
return JapaneseEraYearToCommonEraYear(cx, calendarId, cal.get(), eraYear,
17161715
result);
17171716
}
@@ -1991,6 +1990,7 @@ static bool CalendarFieldMonthCodeMatchesMonth(JSContext* cx,
19911990

19921991
static ISODate ToISODate(const icu4x::capi::Date* date) {
19931992
UniqueICU4XIsoDate isoDate{icu4x::capi::icu4x_Date_to_iso_mv1(date)};
1993+
MOZ_ASSERT(isoDate, "unexpected null-pointer result");
19941994

19951995
int32_t isoYear = icu4x::capi::icu4x_IsoDate_year_mv1(isoDate.get());
19961996

@@ -2141,10 +2141,6 @@ static bool CalendarDateToISO(JSContext* cx, CalendarId calendar,
21412141
}
21422142

21432143
auto cal = CreateICU4XCalendar(calendar);
2144-
if (!cal) {
2145-
return false;
2146-
}
2147-
21482144
auto date = CreateDateFrom(cx, calendar, cal.get(), eraYears, month, day,
21492145
fields, overflow);
21502146
if (!date) {
@@ -2223,9 +2219,6 @@ static bool CalendarMonthDayToISOReferenceDate(JSContext* cx,
22232219
}
22242220

22252221
auto cal = CreateICU4XCalendar(calendar);
2226-
if (!cal) {
2227-
return false;
2228-
}
22292222

22302223
// We first have to compute the month-code if it wasn't provided to us.
22312224
auto monthCode = month.code;
@@ -2498,10 +2491,6 @@ bool js::temporal::CalendarEra(JSContext* cx, Handle<CalendarValue> calendar,
24982491
}
24992492

25002493
auto cal = CreateICU4XCalendar(calendarId);
2501-
if (!cal) {
2502-
return false;
2503-
}
2504-
25052494
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
25062495
if (!dt) {
25072496
return false;
@@ -2551,10 +2540,6 @@ bool js::temporal::CalendarEraYear(JSContext* cx,
25512540
}
25522541

25532542
auto cal = CreateICU4XCalendar(calendarId);
2554-
if (!cal) {
2555-
return false;
2556-
}
2557-
25582543
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
25592544
if (!dt) {
25602545
return false;
@@ -2583,10 +2568,6 @@ bool js::temporal::CalendarYear(JSContext* cx, Handle<CalendarValue> calendar,
25832568

25842569
// Step 2.
25852570
auto cal = CreateICU4XCalendar(calendarId);
2586-
if (!cal) {
2587-
return false;
2588-
}
2589-
25902571
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
25912572
if (!dt) {
25922573
return false;
@@ -2619,10 +2600,6 @@ bool js::temporal::CalendarMonth(JSContext* cx, Handle<CalendarValue> calendar,
26192600

26202601
// Step 2.
26212602
auto cal = CreateICU4XCalendar(calendarId);
2622-
if (!cal) {
2623-
return false;
2624-
}
2625-
26262603
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
26272604
if (!dt) {
26282605
return false;
@@ -2659,10 +2636,6 @@ bool js::temporal::CalendarMonthCode(JSContext* cx,
26592636

26602637
// Step 2.
26612638
auto cal = CreateICU4XCalendar(calendarId);
2662-
if (!cal) {
2663-
return false;
2664-
}
2665-
26662639
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
26672640
if (!dt) {
26682641
return false;
@@ -2700,10 +2673,6 @@ bool js::temporal::CalendarDay(JSContext* cx, Handle<CalendarValue> calendar,
27002673

27012674
// Step 2.
27022675
auto cal = CreateICU4XCalendar(calendarId);
2703-
if (!cal) {
2704-
return false;
2705-
}
2706-
27072676
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
27082677
if (!dt) {
27092678
return false;
@@ -2733,10 +2702,6 @@ bool js::temporal::CalendarDayOfWeek(JSContext* cx,
27332702

27342703
// Step 2.
27352704
auto cal = CreateICU4XCalendar(calendarId);
2736-
if (!cal) {
2737-
return false;
2738-
}
2739-
27402705
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
27412706
if (!dt) {
27422707
return false;
@@ -2775,10 +2740,6 @@ bool js::temporal::CalendarDayOfYear(JSContext* cx,
27752740

27762741
// Step 2.
27772742
auto cal = CreateICU4XCalendar(calendarId);
2778-
if (!cal) {
2779-
return false;
2780-
}
2781-
27822743
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
27832744
if (!dt) {
27842745
return false;
@@ -2914,10 +2875,6 @@ bool js::temporal::CalendarDaysInMonth(JSContext* cx,
29142875

29152876
// Step 2.
29162877
auto cal = CreateICU4XCalendar(calendarId);
2917-
if (!cal) {
2918-
return false;
2919-
}
2920-
29212878
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
29222879
if (!dt) {
29232880
return false;
@@ -2947,10 +2904,6 @@ bool js::temporal::CalendarDaysInYear(JSContext* cx,
29472904

29482905
// Step 2.
29492906
auto cal = CreateICU4XCalendar(calendarId);
2950-
if (!cal) {
2951-
return false;
2952-
}
2953-
29542907
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
29552908
if (!dt) {
29562909
return false;
@@ -2980,10 +2933,6 @@ bool js::temporal::CalendarMonthsInYear(JSContext* cx,
29802933

29812934
// Step 2
29822935
auto cal = CreateICU4XCalendar(calendarId);
2983-
if (!cal) {
2984-
return false;
2985-
}
2986-
29872936
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
29882937
if (!dt) {
29892938
return false;
@@ -3018,10 +2967,6 @@ bool js::temporal::CalendarInLeapYear(JSContext* cx,
30182967
// https://github.com/unicode-org/icu4x/issues/5654
30192968

30202969
auto cal = CreateICU4XCalendar(calendarId);
3021-
if (!cal) {
3022-
return false;
3023-
}
3024-
30252970
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
30262971
if (!dt) {
30272972
return false;
@@ -3125,10 +3070,6 @@ static bool ISODateToFields(JSContext* cx, Handle<CalendarValue> calendar,
31253070

31263071
// Step 2.
31273072
auto cal = CreateICU4XCalendar(calendarId);
3128-
if (!cal) {
3129-
return false;
3130-
}
3131-
31323073
auto dt = CreateICU4XDate(cx, date, calendarId, cal.get());
31333074
if (!dt) {
31343075
return false;
@@ -3613,9 +3554,6 @@ static bool AddNonISODate(JSContext* cx, CalendarId calendarId,
36133554
MOZ_ASSERT(IsValidDuration(duration));
36143555

36153556
auto cal = CreateICU4XCalendar(calendarId);
3616-
if (!cal) {
3617-
return false;
3618-
}
36193557

36203558
auto dt = CreateICU4XDate(cx, isoDate, calendarId, cal.get());
36213559
if (!dt) {
@@ -3857,9 +3795,6 @@ static bool DifferenceNonISODate(JSContext* cx, CalendarId calendarId,
38573795
}
38583796

38593797
auto cal = CreateICU4XCalendar(calendarId);
3860-
if (!cal) {
3861-
return false;
3862-
}
38633798

38643799
auto dtOne = CreateICU4XDate(cx, one, calendarId, cal.get());
38653800
if (!dtOne) {

0 commit comments

Comments
 (0)