tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6fbded534bc2552052cdb178825ab2406cc38afc
parent 18d4db910547464c5b8ca8870b9f9b69b17779de
Author: André Bargull <andre.bargull@gmail.com>
Date:   Thu, 27 Nov 2025 10:03:37 +0000

Bug 1999316 - Part 3: Add CalendarHasMidYearEras. r=spidermonkey-reviewers,mgaudet

Rename `CalendarEraStartsAtYearBoundary` to `CalendarHasMidYearEras` to match
the spec.

Also rename `CalendarEraStartsAtYearBoundary` to `IsJapaneseEraName`.

Differential Revision: https://phabricator.services.mozilla.com/D272032

Diffstat:
Mjs/src/builtin/temporal/Calendar.cpp | 6+++---
Mjs/src/builtin/temporal/CalendarFields.cpp | 5++---
Mjs/src/builtin/temporal/Era.h | 53+++++++++++++++++++++--------------------------------
3 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/js/src/builtin/temporal/Calendar.cpp b/js/src/builtin/temporal/Calendar.cpp @@ -962,7 +962,7 @@ static bool FirstYearOfJapaneseEra(JSContext* cx, CalendarId calendarId, const icu4x::capi::Calendar* calendar, EraCode era, int32_t* result) { MOZ_ASSERT(calendarId == CalendarId::Japanese); - MOZ_ASSERT(!CalendarEraStartsAtYearBoundary(calendarId, era)); + MOZ_ASSERT(IsJapaneseEraName(era)); // All supported Japanese eras last at least one year, so December 31 is // guaranteed to be in the first year of the era. @@ -1141,7 +1141,7 @@ static UniqueICU4XDate CreateDateFromCodes( // or case 3. Handle a possible case 1 error first by mapping the era year // to a common era year and then re-try creating the date. if (calendarId == CalendarId::Japanese && - !CalendarEraStartsAtYearBoundary(calendarId, eraYear.era)) { + IsJapaneseEraName(eraYear.era)) { EraYear commonEraYear; if (!JapaneseEraYearToCommonEraYear(cx, calendarId, calendar, eraYear, &commonEraYear)) { @@ -1219,7 +1219,7 @@ static UniqueICU4XDate CreateDateFrom(JSContext* cx, CalendarId calendarId, if (!date) { return nullptr; } - MOZ_ASSERT_IF(CalendarEraStartsAtYearBoundary(calendarId), + MOZ_ASSERT_IF(!CalendarHasMidYearEras(calendarId), OrdinalMonth(date.get()) == month); return date; } diff --git a/js/src/builtin/temporal/CalendarFields.cpp b/js/src/builtin/temporal/CalendarFields.cpp @@ -577,10 +577,9 @@ static auto NonISOFieldKeysToIgnore(CalendarId calendar, result += eraOrAnyYear; } - // If eras don't start at year boundaries, we have to ignore "era" and + // If eras can start in the middle of the year, we have to ignore "era" and // "eraYear" if any of "day", "month", or "monthCode" is present. - if (!CalendarEraStartsAtYearBoundary(calendar) && - !(keys & dayOrAnyMonth).isEmpty()) { + if (CalendarHasMidYearEras(calendar) && !(keys & dayOrAnyMonth).isEmpty()) { result += eraOrEraYear; } diff --git a/js/src/builtin/temporal/Era.h b/js/src/builtin/temporal/Era.h @@ -206,41 +206,30 @@ constexpr auto CalendarEraName(CalendarId calendar, EraCode era) { return *names.begin(); } -constexpr bool CalendarEraStartsAtYearBoundary(CalendarId id) { - switch (id) { - // Calendar system which use a single era. - case CalendarId::ISO8601: - case CalendarId::Buddhist: - case CalendarId::Chinese: - case CalendarId::Coptic: - case CalendarId::Dangi: - case CalendarId::Ethiopian: - case CalendarId::EthiopianAmeteAlem: - case CalendarId::Hebrew: - case CalendarId::Indian: - case CalendarId::Persian: - return true; - - // Calendar system which use multiple eras, but each era starts at a year - // boundary. - case CalendarId::Gregorian: - case CalendarId::IslamicCivil: - case CalendarId::IslamicTabular: - case CalendarId::IslamicUmmAlQura: - case CalendarId::ROC: - return true; +/** + * CalendarHasMidYearEras ( calendar ) + */ +constexpr bool CalendarHasMidYearEras(CalendarId calendar) { + // Steps 1-2. + // + // Japanese eras can start in the middle of the year. All other calendars + // start their eras at year boundaries. (Or don't have eras at all.) + return calendar == CalendarId::Japanese; +} - // Calendar system which use multiple eras and eras can start within a year. - case CalendarId::Japanese: +constexpr bool IsJapaneseEraName(EraCode era) { + switch (era) { + case EraCode::Standard: + case EraCode::Inverse: return false; + case EraCode::Meiji: + case EraCode::Taisho: + case EraCode::Showa: + case EraCode::Heisei: + case EraCode::Reiwa: + return true; } - MOZ_CRASH("invalid calendar id"); -} - -constexpr bool CalendarEraStartsAtYearBoundary(CalendarId id, EraCode era) { - MOZ_ASSERT_IF(id != CalendarId::Japanese, - CalendarEraStartsAtYearBoundary(id)); - return era == EraCode::Standard || era == EraCode::Inverse; + MOZ_CRASH("invalid era"); } struct EraYear {