Skip to content

Commit

Permalink
[browser][HybridGlobalization] Fix incorrect value in `FirstDayOfWeek…
Browse files Browse the repository at this point in the history
…` test (dotnet#93595)

* Prevent from returning Sunday randomly.

* Unify logic.

* Add wrap for exception, revert returning Sunday on error.
  • Loading branch information
ilonatommy authored Oct 18, 2023
1 parent 0f4196f commit 93fc05c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public static IEnumerable<object[]> FirstDayOfWeek_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, DayOfWeek.Sunday, "invariant" };
yield return new object[] { new CultureInfo("en-US", false).DateTimeFormat, DayOfWeek.Sunday, "en-US" };
// ActiveIssue: https://github.com/dotnet/runtime/issues/93354
if (!PlatformDetection.IsHybridGlobalizationOnBrowser)
yield return new object[] { new CultureInfo("fr-FR", false).DateTimeFormat, DayOfWeek.Monday, "fr-FR" };
yield return new object[] { new CultureInfo("fr-FR", false).DateTimeFormat, DayOfWeek.Monday, "fr-FR" };
}

public static IEnumerable<object[]> FirstDayOfWeek_Get_TestData_HybridGlobalization()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static unsafe int GetFirstWeekOfYear(string localeName)
if (exception != 0)
{
// Failed, just use 0
Debug.Fail($"[CultureData.GetFirstWeekOfYear()] failed with {ex_result}");
Debug.Fail($"[CultureData.GetFirstDayOfWeek()] failed with {ex_result}");
return 0;
}
return result;
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/runtime/hybrid-globalization/change-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function mono_wasm_change_case_invariant(src: number, srcLength: number,
}
}
}
wrap_no_error_root(is_exception, exceptionRoot);
}
catch (ex: any) {
wrap_error_root(is_exception, ex, exceptionRoot);
Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasm/runtime/hybrid-globalization/locales.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { wrap_error_root } from "../invoke-js";
import { wrap_error_root, wrap_no_error_root } from "../invoke-js";
import { mono_wasm_new_external_root } from "../roots";
import { monoStringToString } from "../strings";
import { Int32Ptr } from "../types/emscripten";
Expand All @@ -15,6 +15,7 @@ export function mono_wasm_get_first_day_of_week(culture: MonoStringRef, isExcept
try {
const cultureName = monoStringToString(cultureRoot);
const canonicalLocale = normalizeLocale(cultureName);
wrap_no_error_root(isException, exceptionRoot);
return getFirstDayOfWeek(canonicalLocale);
}
catch (ex: any) {
Expand All @@ -34,6 +35,7 @@ export function mono_wasm_get_first_week_of_year(culture: MonoStringRef, isExcep
try {
const cultureName = monoStringToString(cultureRoot);
const canonicalLocale = normalizeLocale(cultureName);
wrap_no_error_root(isException, exceptionRoot);
return getFirstWeekOfYear(canonicalLocale);
}
catch (ex: any) {
Expand Down

0 comments on commit 93fc05c

Please sign in to comment.