[wasm] Throw exception if culture data does not exist in icu#47301
[wasm] Throw exception if culture data does not exist in icu#47301tqiu8 merged 27 commits intodotnet:mainfrom
Conversation
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
Add PredefinedOnly GlobalizationMode Modified tests if Culture Data not found
|
|
||
| internal static bool UseNls => false; | ||
|
|
||
| internal static bool PredefinedOnly { get; } = GetSwitchValue("System.Globalization.PredefinedOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY"); |
There was a problem hiding this comment.
PredefinedOnly [](start = 29, length = 14)
are you adding this for Linux only? looks the calling site will call it even running on Windows. maybe you need to move this to the file GlobalizationMode.cs?
There was a problem hiding this comment.
This is for Browser only.
There was a problem hiding this comment.
Why we need to restrict this to the browser only? We may enable this flag globally if we need to. Note the calling site of this property is called from shared code which runs with ICU and Nls. Give me a few minutes and I can send you what I propose.
Also, does the browser always runs with Icu?
There was a problem hiding this comment.
I guess I just assumed only Browser would need this use case, but I can definitely move to GlobalizationMode.cs. And yes, the browser always runs with icu.
There was a problem hiding this comment.
I would suggest to move the checks
and
to its own methods, something like
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IcuIsEnsurePredefinedLocaleName(string name) // may put this in CultureData.Icu.cs
{
Debug.Assert(!GlobalizationMode.UseNls);
if (!Interop.Globalization.IsPredefinedLocale(name))
{
throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_InvalidPredefinedCultureName, name));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static NlsIsEnsurePredefinedLocaleName(string name) // may put this in CultureData.Nls.cs
{
Debug.Assert(GlobalizationMode.UseNls);
if (CultureData.GetLocaleInfoExInt(name, Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE) == 1)
{
throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_InvalidPredefinedCultureName, name));
}
}Then replace the code here with
if (GlobalizationMode.PredefinedOnly)
{
if (GlobalizationMode.UseNls)
{
NlsIsEnsurePredefinedLocaleName(cultureName);
}
else
{
IcuIsEnsurePredefinedLocaleName(cultureName);
}
}Last, replace the checks in the links I mentioned above with the new methods calls. and move the code in GlobalizationMode.Unix.cs to GlobalizationMode.cs.
There was a problem hiding this comment.
Ok yes that makes sense.
| this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1"); | ||
|
|
||
| // Set globalization mode to PredefinedOnly | ||
| this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY", "1"); |
There was a problem hiding this comment.
Why is it env variable if it's always set?
There was a problem hiding this comment.
Just leaving the option open if we don't want it always set.
There was a problem hiding this comment.
This won't be easy to change and it'll cost us on size. I think we should just compile the setting in
There was a problem hiding this comment.
We want it always set for wasm but I'm not sure if other OS want this option by default. @tarekgh
There was a problem hiding this comment.
outside WASM, we shouldn't turn this option on by default. Whoever need it would need to opt-in to get it.
There was a problem hiding this comment.
We could do this by setting a default value for the flag and making that default value be true for wasm based on an OS check when you are setting the PredefinedCulturesOnly flag. Or, just if def the code for WASM to always be ON.
There was a problem hiding this comment.
Here is a place where we do something similar for WASM:
So we could do something like:
GetSwitchValue("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY") || OperatingSystem.IsBrowser()|
CC @safern |
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs
Show resolved
Hide resolved
|
Could you please replace the checks in and with the new introduced method calls? thank you! |
|
One last ask, could you please add a new test (not specific to the browser) to test the new environment variable? here is some test example which doing similar idea (testing setting environment variable). |
Modify Globalization tests to catch unsupported locales Change var names
I don't think RemoteExcutor or System.Diagnostics.Process are supported on wasm right now. I'm going to store the current env var and reset it back to that after the test? |
Yes, just exclude the added test from running on WASM. just mark the test with the attribute |
…est data to indicate whether or not that locale is expected to throw exception on browser
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
Thank you so much for your feedback! |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Assembly/AssemblyTests.cs
Outdated
Show resolved
Hide resolved
|
This is looking good but the failures look like they might be related. |
…Tests/Assembly/AssemblyTests.cs Co-authored-by: Larry Ewing <lewing@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs
Outdated
Show resolved
Hide resolved
…otnet#47301)" This reverts commit 128c757.
Fix #47068
Fix #46327
Throw exception if culture data doesn't exist. Currently defaults to
en-us.